Просмотр исходного кода

Merge branch 'Thailand' of https://gitee.com/wangwenfan/congkong into Thailand

gltfxe 1 год назад
Родитель
Сommit
abc9cfb29f
1 измененных файлов с 32 добавлено и 14 удалено
  1. 32 14
      webServer/src/controller/ApiController.ts

+ 32 - 14
webServer/src/controller/ApiController.ts

@@ -218,28 +218,46 @@ const appleCallPay = async (ctx) => {
 
     let receipt_data = data.purchaseToken.replace(/ /g, '+')
     let orderId = data.orderId
-    
-    const apiData = {
-        "receipt-data": receipt_data,
-    }
+    let maxRetries = 5;
+    let currentRetry = 0;
+    let isCheck = false;
+    let out_trade_no = orderId
+
+    // 使用 while 循环进行重试
+    while (currentRetry < maxRetries) {
+        try {
+
+            const apiData = {
+                "receipt-data": receipt_data,
+            }
+
+            const response = await axios.post(sandbox_ios_url, apiData, {
+                headers: {
+                    'Content-Type': 'application/json'
+                }
+            });
+
+            logger.info(`苹果返回的状态:${response.data.status}`)
+            // 如果操作成功,退出循环
+            if (response.data.status == 0) {
+                isCheck = true
+                break;
+            }
 
-    console.log(apiData)
-    const response = await axios.post(sandbox_ios_url, apiData, {
-        headers: {
-            'Content-Type': 'application/json'
+        } catch (error) {
+            // 如果操作失败,记录错误并继续尝试
+            console.log(error)
         }
-    });
 
-    logger.info(`苹果返回的状态:${response.data.status}`)
+        currentRetry++;
+    }
 
-    if (response.data.status != 0) {
+    if (!isCheck) {
         logger.info(`票据验证失败!`)
         ret.msg = `票据验证失败!`
-        return ret
+        return ret;
     }
 
-    let out_trade_no = response.data.original_transaction_id || orderId
-
     const orderInfo = (await Order.getOrder(orderId))[0]
 
     if (!orderInfo) {