看大佬们写案例真好 虽然我看不懂
socket onSocketOpen 不触发回调socket在开发者工具正常使用 在真机上无法触发 wx.onSocketOpen 服务器地址是wss的[图片] [图片] [代码]wx.connectSocket({[代码][代码] [代码][代码]url: url,[代码][代码] [代码][代码]method: [代码][代码]'GET'[代码][代码],[代码][代码] [代码][代码]success: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'连接成功'[代码] [代码]+ res)[代码][代码] [代码][代码]console.log(JSON.stringify(res))[代码][代码] [代码][代码]},[代码][代码] [代码][代码]fail: [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'连接失败'[代码] [代码]+ res)[代码][代码] [代码][代码]}[代码][代码]})[代码][代码] [代码] [代码]wx.onSocketOpen([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接已打开!'[代码][代码])[代码][代码]})[代码][代码]wx.onSocketError([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'WebSocket连接打开失败,请检查!'[代码][代码])[代码][代码]})[代码][代码] [代码] [代码]wx.onSocketMessage([代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]console.log([代码][代码]'收到服务器内容:'[代码] [代码]+ res.data)[代码][代码]}[代码]
2022-04-06