Quellcode durchsuchen

修复:H5端支付宝支付后未提示主动查单

萤火科技 vor 2 Jahren
Ursprung
Commit
6c19e0c777
4 geänderte Dateien mit 66 neuen und 83 gelöschten Zeilen
  1. 6 17
      core/payment/alipay.js
  2. 0 15
      core/payment/wechat.js
  3. 28 23
      pages/checkout/cashier/index.vue
  4. 32 28
      pages/wallet/recharge/index.vue

+ 6 - 17
core/payment/alipay.js

@@ -1,4 +1,5 @@
 import platform from '@/core/platform'
+import storage from '@/utils/storage'
 import ClientEnum from '@/common/enum/Client'
 import { PayMethodEnum } from '@/common/enum/payment'
 
@@ -8,6 +9,11 @@ import { PayMethodEnum } from '@/common/enum/payment'
  */
 const paymentAsH5 = option => {
   const options = { formHtml: '', ...option }
+  // 记录下单的信息
+  storage.set('tempUnifyData_' + options.orderKey, {
+    method: PayMethodEnum.ALIPAY.value,
+    outTradeNo: options.out_trade_no
+  }, 60 * 60)
   // 跳转到支付宝支付页
   return new Promise((resolve, reject) => {
     // console.log(options.formHtml)
@@ -72,20 +78,3 @@ export const extraAsUnify = () => {
   // #endif
   return extra
 }
-
-// H5端支付宝支付下单时的数据
-// 用于从支付宝支付页返回到收银台页面后拿到下单数据
-// #ifdef H5
-export const performance = () => {
-  const query = getCurrentQuery()
-  if (query.method && query.method === 'alipay.trade.wap.pay.return') {
-    return { method: PayMethodEnum.ALIPAY.value, outTradeNo: query.out_trade_no }
-  }
-  return null
-}
-
-const getCurrentQuery = () => {
-  const pages = getCurrentPages()
-  return pages[pages.length - 1].$route.query
-}
-// #endif

+ 0 - 15
core/payment/wechat.js

@@ -102,18 +102,3 @@ export const payment = (option) => {
 export const extraAsUnify = () => {
   return {}
 }
-
-// H5端微信支付下单时的数据
-// 用于从微信支付页返回到收银台页面后拿到下单数据
-// #ifdef H5
-export const performance = (orderKey) => {
-  if (window.performance && window.performance.navigation.type == 2) {
-    const tempUnifyData = storage.get('tempUnifyData_' + orderKey)
-    if (tempUnifyData) {
-      storage.remove('tempUnifyData_' + orderKey)
-      return tempUnifyData
-    }
-  }
-  return null
-}
-// #endif

+ 28 - 23
pages/checkout/cashier/index.vue

@@ -76,6 +76,19 @@
     [PayMethodEnum.ALIPAY.value]: '支付宝'
   }
 
+  // H5端支付下单时的数据
+  // 用于从第三方支付页返回到收银台页面后拿到下单数据
+  const getTempUnifyData = orderKey => {
+    // if (window.performance && window.performance.navigation.type == 2) {
+    const tempUnifyData = storage.get('tempUnifyData_' + orderKey)
+    if (tempUnifyData) {
+      storage.remove('tempUnifyData_' + orderKey)
+      return tempUnifyData
+    }
+    // }
+    return null
+  }
+
   export default {
     components: {
       CountDown
@@ -103,7 +116,7 @@
         // 支付确认弹窗
         showConfirmModal: false,
         // #ifdef H5
-        // 当前微信支付信息 (临时数据, 仅用于H5端)
+        // 当前第三方支付信息 (临时数据, 仅用于H5端)
         tempUnifyData: { outTradeNo: '', method: '' },
         // #endif
       }
@@ -115,6 +128,12 @@
     onLoad({ orderId }) {
       // 记录订单ID
       this.orderId = Number(orderId)
+    },
+
+    /**
+     * 生命周期函数--监听页面显示
+     */
+    onShow() {
       // 获取收银台信息
       this.getCashierInfo()
     },
@@ -144,6 +163,7 @@
       setDefaultPayType() {
         const app = this
         if (app.disabled) return
+        if (app.curPaymentItem) return
         const defaultIndex = app.methods.findIndex(item => item.is_default == true)
         defaultIndex > -1 && app.handleSelectPayType(defaultIndex)
       },
@@ -162,32 +182,17 @@
         this.curPaymentItem = this.methods[index]
       },
 
-      // 判断当前页面来源于浏览器返回
+      // 判断当前页面来源于浏览器返回并提示手动查单
       // #ifdef H5
       performance() {
         const app = this
         // 判断订单状态, 异步回调会将订单状态变为已支付, 那么就不需要让用户手动查单了
         if (app.order.pay_status == PayStatusEnum.PENDING.value) {
-          app.alipayPerformance()
-          app.wechatPerformance()
-        }
-      },
-
-      // H5端支付宝支付完成跳转回当前页面时触发
-      alipayPerformance() {
-        const app = this
-        app.tempUnifyData = Alipay.performance()
-        if (app.tempUnifyData) {
-          app.onTradeQuery(app.tempUnifyData.outTradeNo, app.tempUnifyData.method)
-        }
-      },
-
-      // H5端微信支付完成或返回时触发
-      wechatPerformance() {
-        const app = this
-        app.tempUnifyData = Wechat.performance(app.orderId)
-        if (app.tempUnifyData) {
-          app.showConfirmModal = true
+          const performanceData = getTempUnifyData(app.orderId)
+          if (performanceData) {
+            app.tempUnifyData = performanceData
+            app.showConfirmModal = true
+          }
         }
       },
       // #endif
@@ -236,7 +241,7 @@
         // 发起支付宝支付
         if (method === PayMethodEnum.ALIPAY.value) {
           console.log('paymentData', paymentData)
-          Alipay.payment(paymentData)
+          Alipay.payment({ orderKey: app.orderId, ...paymentData })
             .then(res => app.onPaySuccess(res))
             .catch(err => app.onPayFail(err))
         }

+ 32 - 28
pages/wallet/recharge/index.vue

@@ -14,8 +14,7 @@
       </view>
       <view class="recharge-plan clearfix">
         <block v-for="(item, index) in planList" :key="index">
-          <view class="recharge-plan_item" :class="{ active: selectedPlanId == item.plan_id }"
-            @click="onSelectPlan(item.plan_id)">
+          <view class="recharge-plan_item" :class="{ active: selectedPlanId == item.plan_id }" @click="onSelectPlan(item.plan_id)">
             <view class="plan_money">
               <text>{{ item.money }}</text>
             </view>
@@ -35,8 +34,7 @@
         <text>支付方式</text>
       </view>
       <view class="payment-method">
-        <view v-for="(item, index) in methods" :key="index" class="pay-item dis-flex flex-x-between"
-          @click="handleSelectPayType(index)">
+        <view v-for="(item, index) in methods" :key="index" class="pay-item dis-flex flex-x-between" @click="handleSelectPayType(index)">
           <view class="item-left dis-flex flex-y-center">
             <view class="item-left_icon" :class="[item.method]">
               <text class="iconfont" :class="[PayMethodIconEnum[item.method]]"></text>
@@ -83,6 +81,7 @@
 </template>
 
 <script>
+  import storage from '@/utils/storage'
   import * as RechargeApi from '@/api/recharge'
   import { PayMethodEnum } from '@/common/enum/payment'
   import { inArray, urlEncode } from '@/utils/util'
@@ -100,6 +99,19 @@
     [PayMethodEnum.ALIPAY.value]: '支付宝'
   }
 
+  // H5端支付下单时的数据
+  // 用于从第三方支付页返回到收银台页面后拿到下单数据
+  const getTempUnifyData = orderKey => {
+    // if (window.performance && window.performance.navigation.type == 2) {
+    const tempUnifyData = storage.get('tempUnifyData_' + orderKey)
+    if (tempUnifyData) {
+      storage.remove('tempUnifyData_' + orderKey)
+      return tempUnifyData
+    }
+    // }
+    return null
+  }
+
   export default {
     data() {
       return {
@@ -128,16 +140,16 @@
         // 支付确认弹窗
         showConfirmModal: false,
         // #ifdef H5
-        // 当前微信支付信息 (临时数据, 仅用于H5端)
+        // 当前第三方支付信息 (临时数据, 仅用于H5端)
         tempUnifyData: { outTradeNo: '', method: '' },
         // #endif
       }
     },
 
     /**
-     * 生命周期函数--监听页面加载
+     * 生命周期函数--监听页面显示
      */
-    onLoad(options) {
+    onShow(options) {
       // 获取页面数据
       this.getPageData()
     },
@@ -174,7 +186,7 @@
               app.methods = result.data.paymentMethods
               app.isLoading = false
               // 默认选中的支付方式
-              app.handleSelectPayType(0)
+              app.setDefaultPayType()
               // #ifdef H5
               // 判断当前页面来源于浏览器返回
               this.performance()
@@ -183,28 +195,20 @@
         })
       },
 
-      // 判断当前页面来源于浏览器返回
-      // #ifdef H5
-      performance() {
-        this.alipayPerformance()
-        this.wechatPerformance()
-      },
-
-      // H5端支付宝支付完成跳转回当前页面时触发
-      alipayPerformance() {
-        const app = this
-        app.tempUnifyData = Alipay.performance()
-        if (app.tempUnifyData) {
-          app.onTradeQuery(app.tempUnifyData.outTradeNo, app.tempUnifyData.method)
+      // 默认选中的支付方式
+      setDefaultPayType() {
+        if (!this.curPaymentItem) {
+          this.handleSelectPayType(0)
         }
       },
 
-      // H5端微信支付完成或返回时触发
-      wechatPerformance() {
+      // 判断当前页面来源于浏览器返回并提示手动查单
+      // #ifdef H5
+      performance() {
         const app = this
-        app.tempUnifyData = Wechat.performance('recharge')
-        console.log('wechatPerformance', app.tempUnifyData)
-        if (app.tempUnifyData) {
+        const performanceData = getTempUnifyData('recharge')
+        if (performanceData) {
+          app.tempUnifyData = performanceData
           app.showConfirmModal = true
         }
       },
@@ -258,7 +262,7 @@
         // 发起支付宝支付
         if (method === PayMethodEnum.ALIPAY.value) {
           console.log('paymentData', paymentData)
-          Alipay.payment(paymentData)
+          Alipay.payment({ orderKey: 'recharge', ...paymentData })
             .then(res => app.onPaySuccess(res))
             .catch(err => app.onPayFail(err))
         }
@@ -505,4 +509,4 @@
     // height: 620rpx;
     box-sizing: border-box;
   }
-</style>
+</style>