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

This commit is contained in:
兔姬桑
2020-11-07 09:37:45 +08:00
parent af218f1c5a
commit 8e4693fca9
3 changed files with 17 additions and 0 deletions

View File

@@ -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);
}

View File

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

View File

@@ -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,