瀏覽代碼

Tcping API 异常 & 跳过无用户订单

兔姬桑 4 年之前
父節點
當前提交
8e4693fca9

+ 12 - 0
app/Components/NetworkDetection.php

@@ -2,6 +2,7 @@
 
 namespace App\Components;
 
+use Cache;
 use Http;
 use Log;
 
@@ -18,6 +19,12 @@ class NetworkDetection
      */
     public static function networkCheck(string $ip, bool $type, $port = null)
     {
+        $cacheKey = 'network_times_'.md5($ip);
+        if (Cache::has($cacheKey)) {
+            Cache::decrement($cacheKey);
+        } else {
+            Cache::put($cacheKey, 2, Day); // 24小时
+        }
         $url = 'https://api.50network.com/china-firewall/check/ip/'.($type ? 'icmp/' : ($port ? 'tcp_port/' : 'tcp_ack/')).$ip.($port ? '/'.$port : '');
 
         $checkName = $type ? 'ICMP' : 'TCP';
@@ -34,6 +41,11 @@ class NetworkDetection
             if (! $message['success']) {
                 if ($message['error'] === 'execute timeout (3s)') {
                     sleep(10);
+                    if (Cache::get($cacheKey) < 0) {
+                        Log::warning('【'.$checkName.'阻断检测】检测'.$ip.$port.'时,重复请求后无结果,最后返回'.$message['error']);
+
+                        return false;
+                    }
 
                     return self::networkCheck($ip, $type, $port);
                 }

+ 1 - 0
app/Console/Commands/NodeBlockedDetection.php

@@ -74,6 +74,7 @@ class NodeBlockedDetection extends Command
                     $info = true;
                 }
             }
+            sleep(5);
 
             // 节点检测次数
             if ($info && $detectionCheckTimes) {

+ 4 - 0
app/Console/Commands/ServiceTimer.php

@@ -32,6 +32,10 @@ class ServiceTimer extends Command
         foreach (Order::activePlan()->where('expired_at', '<=', date('Y-m-d H:i:s'))->with('user')->get() as $order) {
             // 清理全部流量,重置重置日期和等级 TODO 可用流量变动日志加入至UserObserver
             $user = $order->user;
+            // 无用户订单,跳过
+            if (! $user) {
+                continue;
+            }
             $user->update([
                 'u'               => 0,
                 'd'               => 0,