同步
This commit is contained in:
@@ -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) {
|
||||
// 静默失败,不影响主流程
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user