哥,我的也是这样,请问怎么设置?
// 以websocket协议连接远程websocket服务器
$wssUrl = 'ws://tts-api.xfyun.cn:443/v2/tts?authorization=YXBpX2tleT0iNGMzZDc2MjBlOTI3MmYyNmI1OTY0ZWM0ZmI0MGVkYjQiLGFsZ29yaXRobT0iaG1hYy1zaGEyNTYiLGhlYWRlcnM9Imhvc3QgZGF0ZSByZXF1ZXN0LWxpbmUiLHNpZ25hdHVyZT0iRWtFeENmRVlmVVQ3VVI5OEVuTEdoR1U2YmNqQ0RnV3QvdEVUSTJobHdJZz0i&date=Sat, 07 Nov 2020 13:32:33 GMT&host=tts-api.xfyun.cn';
$ws_connection = new AsyncTcpConnection($wssUrl);
// 设置以ssl加密方式访问,使之成为wss
$ws_connection->transport = 'sslv3';
// 连上后发送hello字符串
$ws_connection->onConnect = function($connection) use($frame){
$connection->send(json_encode($frame));
};
// 远程websocket服务器发来消息时
$ws_connection->onMessage = function($connection, $data){
echo "recv: $data\n";
};
// 连接上发生错误时,一般是连接远程websocket服务器失败错误
$ws_connection->onError = function($connection, $code, $msg){
echo "error: $msg\n";
};
// 当连接远程websocket服务器的连接断开时
$ws_connection->onClose = function($connection){
echo "connection closed\n";
};
// 设置好以上各种回调后,执行连接操作
$ws_connection->connect();
返回:
Sec-WebSocket-Accept not found. Header:
HTTP/1.1 400 Bad Request
Date: Sat, 07 Nov 2020 13:31:17 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 220
Connection: close
Server: kong/1.3.0
connection closed