This commit is contained in:
Developer
2026-06-02 03:52:54 +08:00
parent 1cb9bc8649
commit 10df6b705c
38 changed files with 2285 additions and 167 deletions

View File

@@ -1110,6 +1110,9 @@ class UserSecurity extends Api
}
db('qrcode_login')->where('code', $code)->update(['status' => 'cancelled', 'updatetime' => time()]);
$this->_notifyWsRelay($code, 'cancelled');
$this->success('已取消');
}
@@ -1220,4 +1223,42 @@ class UserSecurity extends Api
'is_online' => 1,
]);
}
/**
* @name 通知WebSocket中继服务器
* @desc 二维码状态变更时通过HTTP通知WebSocket中继服务器推送更新
* @lastUpdate v10.4.0 新增
*/
private function _notifyWsRelay($code, $status, $token = '')
{
try {
$wsRelayUrl = Config::get('qrcode_ws_relay_url') ?: 'http://127.0.0.1:9444';
$data = json_encode([
'code' => $code,
'status' => $status,
]);
if ($token) {
$data = json_encode([
'code' => $code,
'status' => $status,
'token' => $token,
]);
}
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => $wsRelayUrl . '/notify',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $data,
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 2,
CURLOPT_CONNECTTIMEOUT => 1,
]);
curl_exec($ch);
curl_close($ch);
} catch (\Exception $e) {
// 静默失败,不影响主流程
}
}
}