接口对接
This commit is contained in:
32
App.vue
32
App.vue
@@ -1,7 +1,37 @@
|
||||
<script>
|
||||
import encrypt from './common/js/aes.js'
|
||||
import {
|
||||
MQTT_IP,
|
||||
MQTT_OPTIONS
|
||||
} from './common/js/mqtt.js';
|
||||
import mqtt from 'mqtt/dist/mqtt.js'
|
||||
export default {
|
||||
methods: {
|
||||
connect () {
|
||||
MQTT_OPTIONS.clientId = uni.getStorageSync('cidAES')
|
||||
var that = this
|
||||
let client = mqtt.connect('ws://' + MQTT_IP, MQTT_OPTIONS)
|
||||
client.on('connect', function () {
|
||||
console.log('连接成功')
|
||||
client.subscribe(that.topic, function (err) {
|
||||
if (!err) {
|
||||
console.log('订阅成功')
|
||||
}
|
||||
})
|
||||
}).on('reconnect', function (error) {
|
||||
console.log(error);
|
||||
console.log('正在重连...', that.topic)
|
||||
}).on('error', function (error) {
|
||||
console.log('连接失败...', error)
|
||||
}).on('end', function () {
|
||||
console.log('连接断开')
|
||||
}).on('message', function (topic, message) {
|
||||
console.log('接收推送信息:', message.toString())
|
||||
})
|
||||
}
|
||||
},
|
||||
onLaunch: function () {
|
||||
// this.connect()
|
||||
let cidAES = uni.getStorageSync('cidAES') || 'nnvmhMk8626D8QHhJefm+W9rTAJWuBPRxcnRm4+9bWXdSLRIyTnTruoYfLxGK3Oy'
|
||||
uni.setStorageSync('cidAES', cidAES);
|
||||
if (!cidAES) {
|
||||
@@ -13,7 +43,7 @@ export default {
|
||||
uni.setStorageSync('cidAES', cidAES);
|
||||
}, false);
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
onShow: function () {
|
||||
console.log('App Show')
|
||||
|
||||
Reference in New Issue
Block a user