ck@123911.net 1 week ago
parent
commit
fe60186825
1 changed files with 52 additions and 2 deletions
  1. 52 2
      pages/vip/M_purchase.vue

+ 52 - 2
pages/vip/M_purchase.vue

@@ -153,7 +153,9 @@ export default {
       isSubmitting: false,
       lastClickTime: 0,
       isIOS: false, // 是否为iOS系统
-      currentOrderId: "" // 当前苹果内购订单ID
+      currentOrderId: "", // 当前苹果内购订单ID
+      appleProducts: [], // 苹果产品列表
+      appleProductsLoaded: false // 苹果产品是否已加载
     };
   },
   onLoad() {
@@ -349,6 +351,8 @@ export default {
         });
     },
     loadData() {
+      const that = this;
+      
       // 获取M币数量
       uni.request({
         url: this.$apiHost + '/My/getnum',
@@ -385,6 +389,8 @@ export default {
             this.tid = this.list[1]["id"];
             this.sel = 1;
             this.money = this.list[1]["money"];
+            
+            // 充值列表已加载完成
           }
         },
       });
@@ -410,6 +416,24 @@ export default {
       const systemInfo = uni.getSystemInfoSync();
       this.isIOS = systemInfo.platform === 'ios';
       console.log('当前平台:', systemInfo.platform, '是否为iOS:', this.isIOS);
+      
+      // iOS系统已检测完成
+    },
+    
+    // 验证苹果产品是否可用(简化版本)
+    validateAppleProduct(productId) {
+      // 对于M币充值,我们采用简化的验证方式
+      // 在实际购买时如果产品ID无效,苹果会返回错误
+      console.log('验证苹果产品ID:', productId);
+      
+      // 基本验证:检查产品ID是否符合苹果内购产品ID格式
+      if (!productId || typeof productId !== 'string' || productId.length === 0) {
+        return false;
+      }
+      
+      // 标记已加载,避免重复检查
+      this.appleProductsLoaded = true;
+      return true;
     },
     // 苹果内购提交
     submitAppleIap() {
@@ -453,6 +477,19 @@ export default {
     requestApplePayment(productId) {
       let that = this;
       
+      // 验证产品ID是否有效
+      if (!this.validateAppleProduct(productId)) {
+        console.log('苹果产品ID无效:', productId);
+        uni.showToast({
+          title: '产品ID无效',
+          icon: 'none'
+        });
+        this.isSubmitting = false;
+        return;
+      }
+      
+      console.log('开始苹果内购,产品ID:', productId);
+      
       // 请求苹果内购
       uni.requestPayment({
         provider: 'appleiap',
@@ -466,8 +503,21 @@ export default {
         },
         fail: function (err) {
           console.log('苹果内购支付失败:', err);
+          let errorMessage = '支付失败';
+          
+          // 根据错误类型给出更具体的提示
+          if (err.errMsg) {
+            if (err.errMsg.includes('cancel')) {
+              errorMessage = '支付已取消';
+            } else if (err.errMsg.includes('product')) {
+              errorMessage = '商品不可用';
+            } else if (err.errMsg.includes('network')) {
+              errorMessage = '网络错误,请检查网络连接';
+            }
+          }
+          
           uni.showToast({
-            title: '支付失败',
+            title: errorMessage,
             icon: 'none'
           });
           that.isSubmitting = false;