From 3e36e31cf6f8485e484dc960ddd36a04610ee6db Mon Sep 17 00:00:00 2001 From: iven Date: Sat, 30 May 2026 13:43:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(mp):=20=E6=95=B0=E6=8D=AE=E7=9B=91=E5=90=AC?= =?UTF-8?q?=E5=99=A8=E7=A7=BB=E5=88=B0=E8=BF=9E=E6=8E=A5=E5=89=8D=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=EF=BC=8C=E4=BF=AE=E5=A4=8D=E8=AE=A4=E8=AF=81=E8=B6=85?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因:veepooWeiXinSDKNotifyMonitorValueChange 封装 wx.onBLECharacteristicValueChange,必须在连接+订阅 特征值之前注册,否则认证响应(type=1)丢失。 流程修正:registerListeners → connect → auth 原流程:connect → callback → registerListeners → auth(错误) 同时增加 SDK 事件诊断日志和认证超时时输出 deviceChipStatus 实际值便于排查。 --- apps/miniprogram/native/pkg-veepoo/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/apps/miniprogram/native/pkg-veepoo/index.js b/apps/miniprogram/native/pkg-veepoo/index.js index e77b548..b65e15c 100644 --- a/apps/miniprogram/native/pkg-veepoo/index.js +++ b/apps/miniprogram/native/pkg-veepoo/index.js @@ -174,11 +174,16 @@ Page({ console.log('[veepoo-native] 连接设备:', device.deviceId || device.mac); var self = this; + // 关键修复:在连接前注册数据监听器 + // SDK 的 veepooWeiXinSDKNotifyMonitorValueChange 内部封装 wx.onBLECharacteristicValueChange + // 必须在连接 + 订阅特征值之前注册,否则会丢失认证响应(type=1) + self._registerListeners(); + veepooBle.veepooWeiXinSDKBleConnectionServicesCharacteristicsNotifyManager(device, function (result) { // eslint-disable-next-line no-undef console.log('[veepoo-native] 连接回调:', JSON.stringify(result)); - // C4 修复:按官方 Demo 检查 connection:true,同时兼容 errno:0 + // 按官方 Demo 检查 connection:true,同时兼容 errno:0 / errCode:0 if (result.connection === true || result.errno === 0 || result.errCode === 0) { self._connected = true; self._connecting = false; @@ -186,8 +191,7 @@ Page({ deviceId: device.deviceId || device.mac || '', }); - self._registerListeners(); - + // 连接成功后延迟 500ms 发送认证指令(等待特征值订阅就绪) // eslint-disable-next-line no-undef setTimeout(function () { veepooFeature.veepooBlePasswordCheckManager(); @@ -196,6 +200,7 @@ Page({ console.log('[veepoo-native] 认证指令已发送'); }, 500); + // 双重检测认证结果:事件监听器(type=1)+ Storage 轮询兜底 self._authTimer = setInterval(function () { try { // eslint-disable-next-line no-undef @@ -213,6 +218,8 @@ Page({ clearInterval(self._authTimer); self._authTimer = null; self._connecting = false; + // eslint-disable-next-line no-undef + console.error('[veepoo-native] 认证超时,deviceChipStatus=', wx.getStorageSync('deviceChipStatus')); self.setData({ phase: 'error', error: '设备认证超时,请重新连接' }); } }, 8000); @@ -250,6 +257,8 @@ Page({ _handleSdkEvent: function (data) { if (!data || data.type === undefined) return; var type = data.type; + // eslint-disable-next-line no-undef + console.log('[veepoo-native] SDK 事件: type=' + type, JSON.stringify(data).substring(0, 300)); if (type === SDK_EVENT_AUTH) { var password = (data.content || {}).VPDevicepassword;