فهرست منبع

支付错误捕获。

ith5 3 هفته پیش
والد
کامیت
759ab8ff93
5فایلهای تغییر یافته به همراه75 افزوده شده و 61 حذف شده
  1. 14 11
      core/init/dnsdk/dnsdk-init.ts
  2. 19 13
      core/payment/index.ts
  3. 8 3
      game.js
  4. 33 33
      project.config.json
  5. 1 1
      project.private.config.json

+ 14 - 11
core/init/dnsdk/dnsdk-init.ts

@@ -8,18 +8,21 @@ import GameConfigModel from "../../../store/models/gameConfig.model";
  */
 export const dnsdkInit = async () => {
     const dnSdkRes = await getDnsdkConfigApi();
-    return new Promise((resolve,reject)=>{
+    return new Promise((resolve, reject) => {
         if (dnSdkRes) {
-                DNSDKConfigModel.getInstance().save(dnSdkRes);
-                // 腾讯广告小游戏SDK要求尽早初始化(使用单例模式)
-                DnSdk.init({
-                    user_action_set_id: dnSdkRes.dn_source_id,
-                    secret_key: dnSdkRes.dn_source_secret,
-                    appid: GameConfigModel.getInstance().get().mini_program_id,
-                });
-                resolve({code:0,message:"成功"})
-        }else{
-            reject({code:-1,message:"失败"})
+            DNSDKConfigModel.getInstance().save(dnSdkRes);
+
+            // 腾讯广告小游戏SDK要求尽早初始化(使用单例模式)
+
+            DnSdk.init({
+                user_action_set_id: dnSdkRes.dn_source_id,
+                secret_key: dnSdkRes.dn_source_secret,
+                appid: GameConfigModel.getInstance().get().mini_program_id,
+            });
+
+            resolve({ code: 0, message: "成功" })
+        } else {
+            reject({ code: -1, message: "失败" })
         }
     })
 }

+ 19 - 13
core/payment/index.ts

@@ -32,9 +32,6 @@ export const createOrder = async (orderData) => {
         const { inapp, wechat_jsapi } = createOrderResult.pay_channel;
 
 
-        console.log("createOrderResult", createOrderResult)
-
-
         let midasPayParams = {}
         let gzhPayParams = {}
 
@@ -137,7 +134,7 @@ const makePay = async ({ curOrderInfo, gzhPayParams }) => {
             });
         }
     } else if (curOrderInfo.pay_type === "kf") {
-       
+
         // 拉起客服消息
         wx.openCustomerServiceConversation({
             sessionFrom: gzhPayParams.sessionFrom,
@@ -146,7 +143,7 @@ const makePay = async ({ curOrderInfo, gzhPayParams }) => {
             sendMessageTitle: gzhPayParams.sendMessageTitle,
             sendMessageImg: gzhPayParams.sendMessageImage,
         });
-        console.log("kfkkk===>",{
+        console.log("kfkkk===>", {
             sessionFrom: gzhPayParams.sessionFrom,
             showMessageCard: gzhPayParams.showMessageCard,
             sendMessagePath: gzhPayParams.sendMessagePath,
@@ -159,7 +156,19 @@ const makePay = async ({ curOrderInfo, gzhPayParams }) => {
 const midasPay = async ({ curOrderInfo, midasPayParams }) => {
 
     let platform = getDeviceInfo('platform')
-    try {
+    console.log({
+        mode: "game",
+        env: midasPayParams.env,
+        offerId: midasPayParams.offerId,
+        currencyType: "CNY",
+        platform: platform,
+        buyQuantity: midasPayParams.buyQuantity,
+        amt: curOrderInfo.money,
+        zoneId: midasPayParams.zoneId,
+        outTradeNo: curOrderInfo.order_id,
+    })
+    return new Promise((resolve, reject) => {
+        // console.log("curOrderInfo.money * 100", curOrderInfo.money * 100)
         wx.requestMidasPayment({
             mode: "game",
             env: midasPayParams.env,
@@ -171,6 +180,7 @@ const midasPay = async ({ curOrderInfo, midasPayParams }) => {
             zoneId: midasPayParams.zoneId,
             outTradeNo: curOrderInfo.order_id,
             success: (res) => {
+
                 // 腾讯广告小游戏SDK上报支付
                 DnSdk.getInstance().onPurchase(curOrderInfo.money * 100);
                 // 支付成功后回调
@@ -180,17 +190,13 @@ const midasPay = async ({ curOrderInfo, midasPayParams }) => {
                     order_id: curOrderInfo.order_id,
                     callback_type: "client",
                 });
-                return Promise.resolve();
+                resolve(res);
             },
             fail: (error) => {
-                return Promise.reject(error);
+                reject(error); // ✅ 正确传递,外层 try/catch 能捕获
             },
         });
-
-
-    } catch (error) {
-        return Promise.reject(error);
-    }
+    });
 };
 
 /**

+ 8 - 3
game.js

@@ -19,7 +19,7 @@ import {
       game_name: "测试游戏", // 游戏名称
     };
     // 静默授权
-    const res = await init(data); 
+    const res = await init(data);
     console.log("init", res);
     wx.showToast({
       title: "进入游戏成功",
@@ -78,7 +78,7 @@ const handleOnShareAppMessage = () => {
 const handleMakePayment = async () => {
   let params = {
     money: 1,
-    cp_order_id: new Date().getTime()/1000,
+    cp_order_id: new Date().getTime() / 1000,
     server_id: 1,
     server_name: "仙侠幻世1服",
     role_id: "90980001",
@@ -88,7 +88,12 @@ const handleMakePayment = async () => {
     product_id: "-1",
     product_name: "1元的大礼包",
   };
-  await payment(params)
+  try {
+    await payment(params)
+  } catch (error) {
+    console.log('payment cancel or fail', error)
+  }
+  
 }
 
 // 获取当前用户信息

+ 33 - 33
project.config.json

@@ -1,36 +1,36 @@
 {
-    "setting": {
-        "es6": true,
-        "postcss": true,
-        "minified": true,
-        "uglifyFileName": false,
-        "enhance": true,
-        "packNpmRelationList": [],
-        "babelSetting": {
-            "ignore": [],
-            "disablePlugins": [],
-            "outputPath": ""
-        },
-        "useCompilerPlugins": false,
-        "swc": true,
-        "disableSWC": false,
-        "compileWorklet": false,
-        "uploadWithSourceMap": true,
-        "packNpmManually": false,
-        "minifyWXSS": true,
-        "minifyWXML": true,
-        "localPlugins": false,
-        "disableUseStrict": false,
-        "condition": false
+  "setting": {
+    "es6": true,
+    "postcss": true,
+    "minified": true,
+    "uglifyFileName": false,
+    "enhance": true,
+    "packNpmRelationList": [],
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
     },
-    "compileType": "game",
-    "simulatorPluginLibVersion": {},
-    "packOptions": {
-        "ignore": [],
-        "include": []
-    },
-    "isGameTourist": false,
-    "appid": "wx0cc61b77db2c5e2d",
-    "editorSetting": {},
-    "libVersion": "3.14.1"
+    "useCompilerPlugins": false,
+    "swc": true,
+    "disableSWC": false,
+    "compileWorklet": false,
+    "uploadWithSourceMap": true,
+    "packNpmManually": false,
+    "minifyWXSS": true,
+    "minifyWXML": true,
+    "localPlugins": false,
+    "disableUseStrict": false,
+    "condition": false
+  },
+  "compileType": "game",
+  "simulatorPluginLibVersion": {},
+  "packOptions": {
+    "ignore": [],
+    "include": []
+  },
+  "isGameTourist": false,
+  "appid": "wx0cc61b77db2c5e2d",
+  "editorSetting": {},
+  "libVersion": "3.14.1"
 }

+ 1 - 1
project.private.config.json

@@ -1,5 +1,5 @@
 {
-  "libVersion": "3.14.1",
+  "libVersion": "3.15.0",
   "projectname": "wxxyx-sdk-new",
   "setting": {
     "urlCheck": false,