From 8d3b3a04915e7eda647a34e163cabb22eed8737d Mon Sep 17 00:00:00 2001 From: iven Date: Sat, 30 May 2026 13:59:05 +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=E6=94=B9=E5=9B=9E=E8=BF=9E=E6=8E=A5=E5=B0=B1=E7=BB=AA?= =?UTF-8?q?=E5=90=8E=E6=B3=A8=E5=86=8C=20+=20=E5=A2=9E=E5=8A=A0=E8=BD=AE?= =?UTF-8?q?=E8=AF=A2=E8=AF=8A=E6=96=AD=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit wx.onBLECharacteristicValueChange 只支持一个回调, SDK 合并连接函数可能内部也调用它,连接前注册会被覆盖。 改为 connection:true 回调后、认证前注册(对齐 SDK 文档顺序)。 增加每 500ms 轮询时打印 deviceChipStatus 实际值便于定位。 --- apps/miniprogram/native/pkg-veepoo/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/miniprogram/native/pkg-veepoo/index.js b/apps/miniprogram/native/pkg-veepoo/index.js index 3d363c9..1876ad3 100644 --- a/apps/miniprogram/native/pkg-veepoo/index.js +++ b/apps/miniprogram/native/pkg-veepoo/index.js @@ -174,18 +174,11 @@ 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)); // 只响应最终回调(connection:true),忽略中间阶段(services/characteristics/errno:0) - // 连接回调会触发多次:createBLEConnection → services → characteristics → connection:true - // 认证必须在特征值订阅完成后发送 if (result.connection === true) { self._connected = true; self._connecting = false; @@ -193,7 +186,10 @@ Page({ deviceId: device.deviceId || device.mac || '', }); - // 连接成功后延迟 500ms 发送认证指令(等待特征值订阅就绪) + // 按 SDK 文档顺序:连接就绪 → 注册数据监听器 → 延迟 → 认证 + // wx.onBLECharacteristicValueChange 只支持一个回调,连接后注册避免被 SDK 内部覆盖 + self._registerListeners(); + // eslint-disable-next-line no-undef setTimeout(function () { veepooFeature.veepooBlePasswordCheckManager(); @@ -202,11 +198,13 @@ Page({ console.log('[veepoo-native] 认证指令已发送'); }, 500); - // 双重检测认证结果:事件监听器(type=1)+ Storage 轮询兜底 + // 双重检测:事件监听器(type=1)+ Storage 轮询兜底 self._authTimer = setInterval(function () { try { // eslint-disable-next-line no-undef var status = wx.getStorageSync('deviceChipStatus'); + // eslint-disable-next-line no-undef + console.log('[veepoo-native] 轮询 deviceChipStatus=', status); if (status === 'successfulVerification' || status === 'passTheVerification') { clearInterval(self._authTimer); self._authTimer = null;