Browse Source

fix: 增加 wx.openBusinessView 调试日志,检查 wx 对象可用性

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline 2 tuần trước cách đây
mục cha
commit
2628976162
1 tập tin đã thay đổi với 15 bổ sung2 xóa
  1. 15 2
      haha-mp/src/pages/index/index.vue

+ 15 - 2
haha-mp/src/pages/index/index.vue

@@ -169,6 +169,16 @@ const confirmPayScoreAndOpenDoor = async (deviceId: string) => {
     uni.hideLoading();
 
     // 2. 拉起微信支付分确认页面
+    logger.log('[支付分] 准备调起 openBusinessView, result:', JSON.stringify(result));
+    logger.log('[支付分] mchId:', result.mchId, 'package:', result.package);
+
+    // 检查 wx 对象是否可用
+    if (typeof wx === 'undefined' || !wx.openBusinessView) {
+      logger.error('[支付分] wx.openBusinessView 不可用');
+      uni.showToast({ title: '当前环境不支持支付分,请在手机上尝试', icon: 'none' });
+      return;
+    }
+
     wx.openBusinessView({
       businessType: 'payscore',
       extraData: {
@@ -176,13 +186,16 @@ const confirmPayScoreAndOpenDoor = async (deviceId: string) => {
         package: result.package,
       },
       success: async () => {
-        logger.log('支付分确认成功,开始开门');
+        logger.log('[支付分] 用户确认成功,开始开门');
         await doOpenDoor(deviceId);
       },
       fail: (err: any) => {
-        logger.error('支付分确认取消或失败', err);
+        logger.error('[支付分] openBusinessView 失败或用户取消', JSON.stringify(err));
         uni.showToast({ title: '授权已取消', icon: 'none' });
       },
+      complete: () => {
+        logger.log('[支付分] openBusinessView complete 回调触发');
+      },
     });
   } catch (error: any) {
     uni.hideLoading();