From 8304eac2a45a32b00563c03a2f3fd303ecd5872a Mon Sep 17 00:00:00 2001
From: zhuguifei <zhuguifei@zhuguifeideiMac.local>
Date: 星期五, 22 八月 2025 13:54:36 +0800
Subject: [PATCH] 1.解决微信小程序真机MQTT无法连接问题

---
 mqtt/MqttView.vue |   44 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/mqtt/MqttView.vue b/mqtt/MqttView.vue
index 94f4b88..0064474 100644
--- a/mqtt/MqttView.vue
+++ b/mqtt/MqttView.vue
@@ -41,10 +41,13 @@
 				}
 				let opts = {
 					// #ifdef H5
-					url: 'ws://' + this.$api.mqttBaseUrl + ':8083/mqtt',
+					url: 'wss://' + this.$api.mqttBaseUrl + ':8084/mqtt',
 					// #endif
-					// #ifdef APP-PLUS
-					url: 'wx://' + this.$api.mqttBaseUrl + ':8083/mqtt',
+					// #ifdef MP-WEIXIN
+					url: 'wxs://' + this.$api.mqttBaseUrl + ':8084/mqtt',// 寰俊灏忕▼搴忓己鍒� WSS
+					// #endif
+					// #ifdef APP-PLUS
+					url: 'wxs://' + this.$api.mqttBaseUrl + ':8084/mqtt',  // Android/iOS 鐢ㄦ櫘閫� WebSocket
 					// #endif
 					clientId: deviceid,
 					username: account.username,
@@ -76,6 +79,29 @@
 				}).then(res => {
 					console.error(res)
 				})
+				
+				//璁㈤槄骞茬嚗璁惧杩炴帴鏂紑鐘舵�佹洿鏂�-绉熸埛鍐呮墍鏈夎澶�
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_BROADCAST_TENANT_UPDATE_EQU_STATU.replace('%s', this.tenantId),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+				//璁㈤槄鏌ヨ骞茬嚗璁惧杩炴帴鐘舵��-鍗曚釜璁惧
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_RES_EQU_STATU.replace('%s', deviceid),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
+				
+				//璁㈤槄骞茬嚗璁惧瀹炴椂鏁版嵁
+				this.$mqttTool.subscribe({
+					topic: this.$constant.SERVICE_BROADCAST_TENANT_REAL_DATA.replace('%s', this.tenantId),
+					qos: 0
+				}).then(res => {
+					console.error(res)
+				})
 				 
 				//璁㈤槄鍙戦�佹寚浠よ繑鍥炵粨鏋�
 				// this.$mqttTool.subscribe({
@@ -91,17 +117,21 @@
 				let client = this.$mqttTool.client
 
 				client.on('connect', function(res) {
-					console.error('杩炴帴鎴愬姛')
+					console.error('杩炴帴鎴愬姛')
+					console.error(res)
 				})
 				client.on('reconnect', function(res) {
-					console.error('閲嶆柊杩炴帴')
+					console.error('閲嶆柊杩炴帴')
+					console.error(res)
 				})
 				client.on('error', function(res) {
-					console.info('杩炴帴閿欒')
+					console.info('杩炴帴閿欒')
+					console.error(res)
 				})
 				client.on('close', function(res) {
 
-					console.error('鍏抽棴鎴愬姛')
+					console.error('鍏抽棴鎴愬姛')
+					console.error(res)
 
 				})
 				client.on('message', function(topic, message, buffer) {

--
Gitblit v1.9.3