真机结束消息,收到的消息被截取了
链接成功了,pako.deflate(JSON.stringify(setting), {to: "string"}),发送数据前加密了一下,就会出现某种特定组合,真机收到的消息截断了,比如我发送消息长度为10 ,但是实际收到长度为5
代码:
// pages/test/test.js
const app = getApp();
import pako from "../../utils/pako.min";
Page({
/** * 页面的初始数据 */
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let that = this;
that.data.websocket= wx.connectSocket({
url: '',//链接地址
complete(res){
console.log(res);
if(res.errMsg == "connectSocket:ok"){
that.data.socketTaskId = res.socketTaskId;
}
}
});
if(that.data.socketTaskId){
app.globalData.testList["id"+that.data.socketTaskId] = that.data.websocket;
}
that.onTest();
},
onTest(){
let that = this;
console.log(111);
that.data.websocket.onMessage(function (msg){
console.log(msg.data.length);
console.log(msg);
console.log(pako.inflate(msg.data, {to: 'string'}));
});
// 接收websocket 实时消息
that.data.websocket.onError(function (err){
console.log("onError",err);
});
// websocket关闭监听
that.data.websocket.onClose(function (res){
console.log("onClose",res);
});
that.data.websocket.onOpen(function (res){
console.log("onOpen",res);
});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。
pakoold.deflate(JSON.stringify(1631008581),{to:"string"})
先确定是否连接成功?