Browse Source

座位预定-创建订单:微信支付

panyong 3 years ago
parent
commit
6651b54651

+ 3 - 3
htmldev/dashboard/src/api/request.js

@@ -35,10 +35,10 @@ request.interceptors.request.use(request => {
 // Add a response interceptor
 request.interceptors.response.use(response => {
   // Do something with response data
-  const { code, authorizeUrl } = response.data
-  if (code === 301 && authorizeUrl) {
+  const { code, url } = response.data
+  if (code === 301 && url) {
     Vue.cookie.delete('afhousewechatToken')
-    location.replace(authorizeUrl)
+    location.replace(url)
   } else if (code === 403) {
     router.push('/login')
   }

+ 1 - 1
htmldev/dashboard/src/login/index.vue

@@ -260,7 +260,7 @@ export default {
   textarea {
     width: 100%;
     height: 22px;
-    font-size: 15px;
+    font-size: 16px;
     color: #fff;
     word-break: break-all;
     resize: none;

+ 12 - 0
htmldev/dashboard/src/views/place/list/api/index.js

@@ -29,3 +29,15 @@ export const apiPlacePreOrder = (postData) => request({
   url: '/api/v1/user/preorder/create',
   data: postData
 })
+
+/**
+ * 获取公众号支付配置
+ */
+export const apiWxPayConfig = () => request({
+  method: 'GET',
+  url: '/api/wechat/account/config',
+  params: {
+    url: location.href,
+    officialAccountCode: 'tingbang' //  写死
+  }
+})

+ 34 - 17
htmldev/dashboard/src/views/place/list/index.vue

@@ -190,7 +190,7 @@
 
 <script>
 import { Tabs, Tab, Icon, Popup, Field, Toast, Button } from 'vant'
-import { apiBarList, apiPlaceList, apiPlacePreOrder } from './api'
+import { apiBarList, apiPlaceList, apiPlacePreOrder, apiWxPayConfig } from './api'
 import { getCookieValue } from '../../../utils'
 import { platform } from '../../../utils/platform'
 
@@ -329,7 +329,11 @@ export default {
             document.forms[0].submit()
           } else {
             // 微信支付
-            // window.location.replace
+            if (platform.isWeixin) {
+              this.weixinPay()
+            } else {
+              // window.location.replace()
+            }
           }
         } else {
           Toast(msg)
@@ -338,17 +342,27 @@ export default {
         this.booLock = false
       }
     },
-    weixinPay (data) {
+    async weixinPay () {
       var vm = this
-      if (typeof WeixinJSBridge === 'undefined') {
-        if (document.addEventListener) {
-          document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(data), false)
-        } else if (document.attachEvent) {
-          document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(data))
-          document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady(data))
+      try {
+        const { status, data, msg } = await apiWxPayConfig()
+        if (status) {
+          const officialOrderNumber = data.official_order_number
+          if (typeof WeixinJSBridge === 'undefined') {
+            if (document.addEventListener) {
+              document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(officialOrderNumber), false)
+            } else if (document.attachEvent) {
+              document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(officialOrderNumber))
+              document.attachEvent('onWeixinJSBridgeReady', vm.onBridgeReady(officialOrderNumber))
+            }
+          } else {
+            vm.onBridgeReady(officialOrderNumber)
+          }
+        } else {
+          Toast(msg)
         }
-      } else {
-        vm.onBridgeReady(data)
+      } catch (err) {
+        console.log(err)
       }
     },
     onBridgeReady (data) {
@@ -356,15 +370,18 @@ export default {
       WeixinJSBridge.invoke(
         'getBrandWCPayRequest',
         {
-          appId: data.appid,
-          timeStamp: data.timestamp,
+          appId: data.app_id,
+          timeStamp: data.time_stamp,
           nonceStr: data.nonce_str,
-          package: data.prepay_id,
-          signType: data.signType,
-          paySign: data.paySign
+          package: data.package,
+          signType: data.sign_type,
+          paySign: data.pay_sign
         },
         function (res) {
-          if (res.err_msg === 'get_brand_wcpay_request:ok') {
+          /* eslint-disable-next-line */
+          if (res.err_msg == 'get_brand_wcpay_request:ok') {
+            // 使用以上方式判断前端返回,微信团队郑重提示:
+            // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
           } else {
             Toast.fail('支付失败!')
           }