已经解决了,url参数"/"也算中文字符。。。。。。。加了encodeURL就可以了
socket小程序开发工具内运行正常,发布线上连接成功后马上监听错误1004?[图片] initSocket: function () { var that = this; SocketTask.onOpen(res => { socketOpen = true; console.log('监听 WebSocket 连接打开事件。', res) }) SocketTask.onClose(onClose => { console.log('监听 WebSocket 连接关闭事件。', onClose) socketOpen = false; }) SocketTask.onError(onError => { console.log('监听 WebSocket 错误。错误信息', onError) socketOpen = false }) SocketTask.onMessage(onMessage => { console.log('监听WebSocket接受到服务器的消息事件。服务器返回的消息', JSON.parse(onMessage.data)) var onMessage_data = JSON.parse(onMessage.data) that.data.chatList.push(onMessage_data); that.setData({ chatList: that.data.chatList }) that.bottom() }) }, webSocket: function () { let that = this var url = `wss://ws.dusun.com.cn/websocket/${this.data.shopId}|${this.data.mid}/${this.data.mid}`; // 创建Socket SocketTask = wx.connectSocket({ url: url, header: { 'content-type': 'application/json' }, method: 'post', success: function (res) { console.log('WebSocket连接创建', res,url) }, fail: function (err) { wx.showToast({ title: '网络异常!', }) console.log(err) }, }) //监听 that.initSocket() },
2021-04-07