websocket連接數(shù)據(jù)庫 報(bào)錯(cuò)
$ws_worker->onMessage = function (TcpConnection $connection, $data) {
self::$_req_time = date("Y-m-d H:i:s");
$reqData = json_decode($data, true);
// 給connection臨時(shí)設(shè)置一個(gè)lastMessageTime屬性,用來記錄上次收到消息的時(shí)間
$connection->lastMessageTime = time();
self::$_connection = $connection;
$this->output('接受到消息-data:%s:', [json_encode($reqData, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
$botInfo = app(SysTemBotListModel::class)->getInfo([
['bot_id', '=', '123']
], ['source']);
$response = self::chatSend($reqData);
if ($response) {
$this->output('發(fā)送消息-data:%s:', [json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)]);
$connection->send(json_encode($response, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
};