|
@@ -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('支付失败!')
|
|
|
}
|