小程序
小游戏
企业微信
微信支付
扫描小程序码分享
小程序使用mqtt时,在开发者工具,真机测试,预览时都能够正常的连接订阅主题,也能收到消息,但是发到线上,体验版的话就不行了,就一直连接不上,这是什么操作?
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
wss?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
let client = connect('wxs://xxxx:8084/mqtt', {
clientId: 'wss_'+num,
username: "",
password: ""
})
wx.showToast({
title: client.connackTimer.toString()
console.log(client)
try {
client.on('connect', (e) => {
console.log(e)
console.log('mqtt连接成功')
title: 'mqtt连接成功'
var productCode = this.data.productCode
var productSecretKey = this.data.productSecretKey
console.log(productCode, "'.......code'", productSecretKey, "'......key'")
var str = 'NDFLift/POST/' + productCode + '/' + productSecretKey + '/CmdBack'
console.log(str)
client.subscribe(str)
}catch(error){
wx.request({
url: app.globalData.apiurl + 'api/Log/CreateRecord',
data:{
"param": error,
},
method: 'POST',
header: { 'content-Type': 'application/json' },
success: function (res) {
console.log(res)
}
console.log(error)
wx.showModal({
title:error
client.on('error', error => {
client.on('message', (topic, message) => { // message is Buffer
console.log('收到消息:' + message.toString())
var obj1 = JSON.parse(message)
console.log(obj1)
var newObj = obj1.CmdResult
that.setData({
newObj1: newObj
console.log(newObj)
var IsLiftingObj = newObj.IsLifting
var IsSuccessObj = newObj.IsSuccess
var LiftingDirectionObj = newObj.LiftingDirection
楼主解决了吗?上线后,体验版就是连接不上,wxs
楼主你好,我这跟你的差不多 不过我的真机测试也连接不上,您知道什么原因吗?
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
wss?
let client = connect('wxs://xxxx:8084/mqtt', {
clientId: 'wss_'+num,
username: "",
password: ""
})
wx.showToast({
title: client.connackTimer.toString()
})
console.log(client)
try {
client.on('connect', (e) => {
console.log(e)
console.log('mqtt连接成功')
wx.showToast({
title: 'mqtt连接成功'
})
var productCode = this.data.productCode
var productSecretKey = this.data.productSecretKey
console.log(productCode, "'.......code'", productSecretKey, "'......key'")
var str = 'NDFLift/POST/' + productCode + '/' + productSecretKey + '/CmdBack'
console.log(str)
client.subscribe(str)
})
}catch(error){
wx.request({
url: app.globalData.apiurl + 'api/Log/CreateRecord',
data:{
"param": error,
},
method: 'POST',
header: { 'content-Type': 'application/json' },
success: function (res) {
console.log(res)
}
})
console.log(error)
wx.showModal({
title:error
})
}
client.on('error', error => {
console.log(error)
wx.showModal({
title:error
})
})
client.on('message', (topic, message) => { // message is Buffer
console.log('收到消息:' + message.toString())
var obj1 = JSON.parse(message)
console.log(obj1)
var newObj = obj1.CmdResult
that.setData({
newObj1: newObj
})
console.log(newObj)
var IsLiftingObj = newObj.IsLifting
var IsSuccessObj = newObj.IsSuccess
var LiftingDirectionObj = newObj.LiftingDirection
}
})
},
楼主解决了吗?上线后,体验版就是连接不上,wxs
楼主你好,我这跟你的差不多 不过我的真机测试也连接不上,您知道什么原因吗?