ck@123911.net 1 周之前
父节点
当前提交
104d104bb7
共有 2 个文件被更改,包括 74 次插入9 次删除
  1. 41 6
      pages/vip/M_purchase.vue
  2. 33 3
      pages/vip/index.vue

+ 41 - 6
pages/vip/M_purchase.vue

@@ -439,22 +439,42 @@ export default {
     submitAppleIap() {
       let that = this;
       
+      // 获取当前选中的充值项目信息
+      const currentItem = this.list[this.sel];
+      console.log("当前选中的充值项目:", currentItem);
+      
+      if (!currentItem || !currentItem.spec) {
+        uni.showToast({
+          title: "产品配置错误,请联系客服",
+          icon: "none",
+        });
+        that.isSubmitting = false;
+        return;
+      }
+      
+      console.log("准备创建苹果内购订单 - 产品ID:", this.tid, "苹果产品ID:", currentItem.spec);
+      
       // 先创建订单
       uni.request({
         url: this.$apiHost + "/AppleIap/submit",
         data: {
           uuid: getApp().globalData.uuid,
           product_id: this.tid,
+          type: "buyM"
         },
         header: {
           "content-type": "application/json",
         },
         success: (res) => {
-          console.log("苹果内购订单创建:", res.data);
+          console.log("苹果内购订单创建响应:", res.data);
           if (res.data.success == "yes") {
             that.currentOrderId = res.data.order_id;
+            // 使用数据库中配置的spec作为苹果产品ID
+            const appleProductId = res.data.apple_product_id || currentItem.spec;
+            console.log("使用苹果产品ID进行支付:", appleProductId);
+            
             // 调用苹果内购
-            that.requestApplePayment(res.data.apple_product_id);
+            that.requestApplePayment(appleProductId);
           } else {
             uni.showToast({
               title: res.data.msg || "创建订单失败",
@@ -489,6 +509,12 @@ export default {
       }
       
       console.log('开始苹果内购,产品ID:', productId);
+      console.log('苹果内购参数:', {
+        provider: 'appleiap',
+        orderInfo: {
+          productid: productId
+        }
+      });
       
       // 请求苹果内购
       uni.requestPayment({
@@ -502,23 +528,32 @@ export default {
           that.verifyAppleReceipt(res.transactionReceipt, res.transactionIdentifier);
         },
         fail: function (err) {
-          console.log('苹果内购支付失败:', 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('订单的ID不存在') || err.errMsg.includes('product')) {
+              errorMessage = '产品ID不存在,请检查App Store Connect配置';
+              console.error('产品ID配置错误 - 当前产品ID:', productId);
+              console.error('请确认以下事项:');
+              console.error('1. App Store Connect中是否已创建此产品ID');
+              console.error('2. 产品状态是否为"Ready for Sale"');
+              console.error('3. Bundle ID是否匹配');
+              console.error('4. 是否在正确的环境(沙盒/生产)');
             } else if (err.errMsg.includes('network')) {
               errorMessage = '网络错误,请检查网络连接';
+            } else {
+              errorMessage = '支付失败: ' + (err.errMsg || JSON.stringify(err));
             }
           }
           
           uni.showToast({
             title: errorMessage,
-            icon: 'none'
+            icon: 'none',
+            duration: 3000
           });
           that.isSubmitting = false;
         }

+ 33 - 3
pages/vip/index.vue

@@ -672,6 +672,14 @@ export default {
 		requestApplePayment(productId) {
 			let that = this;
 			
+			console.log('开始苹果内购VIP,产品ID:', productId);
+			console.log('苹果内购VIP参数:', {
+				provider: 'appleiap',
+				orderInfo: {
+					productid: productId
+				}
+			});
+			
 			// 请求苹果内购
 			uni.requestPayment({
 				provider: 'appleiap',
@@ -684,10 +692,32 @@ export default {
 					that.verifyAppleReceipt(res.transactionReceipt, res.transactionIdentifier);
 				},
 				fail: function (err) {
-					console.log('苹果内购VIP支付失败:', err);
+					console.log('苹果内购VIP支付失败详情:', err);
+					let errorMessage = '支付失败';
+					
+					// 根据错误类型给出更具体的提示
+					if (err.errMsg) {
+						if (err.errMsg.includes('cancel')) {
+							errorMessage = '支付已取消';
+						} else if (err.errMsg.includes('订单的ID不存在') || err.errMsg.includes('product')) {
+							errorMessage = '产品ID不存在,请检查App Store Connect配置';
+							console.error('VIP产品ID配置错误 - 当前产品ID:', productId);
+							console.error('请确认以下事项:');
+							console.error('1. App Store Connect中是否已创建此产品ID');
+							console.error('2. 产品状态是否为"Ready for Sale"');
+							console.error('3. Bundle ID是否匹配');
+							console.error('4. 是否在正确的环境(沙盒/生产)');
+						} else if (err.errMsg.includes('network')) {
+							errorMessage = '网络错误,请检查网络连接';
+						} else {
+							errorMessage = '支付失败: ' + (err.errMsg || JSON.stringify(err));
+						}
+					}
+					
 					uni.showToast({
-						title: '支付失败:' + err,
-						icon: 'none'
+						title: errorMessage,
+						icon: 'none',
+						duration: 3000
 					});
 					that.isSubmitting = false;
 				}