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;