收藏
回答

开发工具上能完美运行的在手机上有问题

框架类型 问题类型 操作系统 操作系统版本 手机型号 微信版本
小程序 Bug Android miui9.5 电脑win10 安卓 红米note4 6.7.2

- 当前 Bug 的表现(可附上截图)

开发端成功运行sendsocketmessage并回调success函数,附上函数

wx.connectSocket({

//url: 'url:test',

url: 'ws://www.stserver.xyz:30000',

header: {

'Sec-WebSocket-Protocol': this._protocols    //need add this

},

})

wx.onSocketError(function (res) {

console.log('WebSocket连接打开失败,请检查!')

})

wx.onSocketOpen(function (res) {

that.setData({

socketOpen:true

})

wx.sendSocketMessage({

data: [that.data.phone + ' ' + that.data.password],

success: (res) => {

//console.log(res.data)

console.log('收到服务器内容:' + res.data)

},

fail: (res) =>{

console.log('失败:'+res.data);

}

})

})

手机端是这样:



- 预期表现

服务器应该受到小程序发送来的数据并返回success函数但是却回调了fail函数。

- 复现路径


- 提供一个最简复现 Demo

wx11619ba9c74bf4ac

回答关注问题邀请回答
收藏

1 个回答

  • 是小白啊
    是小白啊
    2018-08-27

    你好,请提供一下出现问题的机型和微信版本,以及能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    2018-08-27
    有用
    回复 4
    • 2018-08-27

      您好,我的问题已经解决了,原来错误的副本被改掉我没有留下来。但是同一个程序在开发工具上能运行,在手机微信上不能运行的情况也确实发生了,我试着复原我改过的代码片段。

      wx.sendSocketMessage({

      data: [that.data.phone + ' ' + that.data.password],

      success: (res) => {

      //console.log(res.data)

      console.log('收到服务器内容:' + res.data)

      },

      fail: (res) =>{

      console.log('失败:'+res.data);

      }

      })

      function sendSocketMessage(msg) {

      if (that.data.socketOpen) {

      wx.sendSocketMessage({

      data: msg,

      })

      } else {

      socketMsgQueue.push(msg)

      }

      }


      2018-08-27
      回复
    • 是小白啊
      是小白啊
      2018-08-27回复

      麻烦按照教程提供一下代码片段:https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

      2018-08-27
      回复
    • 2018-08-27回复是小白啊

      wechatide://minicode/WIN8XYmq7i1x

      2018-08-27
      回复
    • 机智的小黄
      机智的小黄
      2018-11-30回复

      Sec-WebSocket-Protocol:this._protocols 这个是什么?我也是开发工具调试完了,手机调试就是在非洲的海里


      2018-11-30
      回复
登录 后发表内容