|
@@ -48,7 +48,7 @@ declare const JyObj: any
|
|
|
methods: {
|
|
|
...mapActions({
|
|
|
getOrderDetail: 'pay/orderDetail',
|
|
|
- getAppPayInfo: 'pay/appPay',
|
|
|
+ getPaySign: 'pay/paySign',
|
|
|
isPaySuccess: 'pay/isPaySuccess'
|
|
|
})
|
|
|
}
|
|
@@ -56,7 +56,7 @@ declare const JyObj: any
|
|
|
|
|
|
export default class Pay extends Vue {
|
|
|
protected getOrderDetail!: any
|
|
|
- protected getAppPayInfo!: any
|
|
|
+ protected getPaySign!: any
|
|
|
protected isPaySuccess!: any
|
|
|
|
|
|
orderInfo = {
|
|
@@ -115,9 +115,7 @@ export default class Pay extends Vue {
|
|
|
toast.clear()
|
|
|
if (res.error_code === 0) {
|
|
|
if (res.data.status === 1) {
|
|
|
- for (const key in this.orderInfo) {
|
|
|
- this.orderInfo.paymoney = res.data.paymoney
|
|
|
- }
|
|
|
+ this.orderInfo.paymoney = res.data.paymoney
|
|
|
} else {
|
|
|
this.$toast(res.error_msg || '查询订单信息失败')
|
|
|
}
|
|
@@ -127,22 +125,98 @@ export default class Pay extends Vue {
|
|
|
|
|
|
// 确认支付
|
|
|
confirmPay () {
|
|
|
- if (this.env.isWeiXinBrowser) {
|
|
|
- this.wxPayCallBack()
|
|
|
- } else {
|
|
|
- this.appPayCallBack()
|
|
|
+ this.$toast.loading({
|
|
|
+ message: '加载中...',
|
|
|
+ forbidClick: true,
|
|
|
+ duration: 0
|
|
|
+ })
|
|
|
+ const data = {
|
|
|
+ payway: this.payWay,
|
|
|
+ ordercode: this.orderInfo.ordercode
|
|
|
}
|
|
|
+ this.getPaySign(data).then(res => {
|
|
|
+ if (res.error_code === 0) {
|
|
|
+ this.$toast.clear()
|
|
|
+ if (res.status === 1) {
|
|
|
+ // 获取参数成功,判断是微信h5还是非微信h5
|
|
|
+ if (this.env.isWeiXinBrowser) {
|
|
|
+ this.wxPayCallBack(res.data.payStr)
|
|
|
+ } else {
|
|
|
+ this.appPayCallBack(res.data.payStr)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.$toast(res.error_msg || '获取支付信息失败')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
- // 微信支付逻辑
|
|
|
- wxPayCallBack () {
|
|
|
+ // 微信h5支付逻辑
|
|
|
+ wxPayCallBack (paySign) {
|
|
|
console.log('wxPay')
|
|
|
+ console.log(paySign)
|
|
|
+ if (!this.$wxSdk) {
|
|
|
+ return this.$toast({
|
|
|
+ message: '微信Sdk初始化失败',
|
|
|
+ forbidClick: true,
|
|
|
+ duration: 1000
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const sign = {
|
|
|
+ timestamp: '',
|
|
|
+ nonceStr: '',
|
|
|
+ package: '',
|
|
|
+ signType: '',
|
|
|
+ paySign: '',
|
|
|
+ appId: ''
|
|
|
+ }
|
|
|
+ // 进行支付
|
|
|
+ console.log(this.$wxSdk)
|
|
|
+ this.$wxSdk.chooseWXPay({
|
|
|
+ config: {
|
|
|
+ timestamp: sign.timestamp,
|
|
|
+ nonceStr: sign.nonceStr,
|
|
|
+ package: sign.package,
|
|
|
+ signType: sign.signType,
|
|
|
+ paySign: sign.paySign,
|
|
|
+ appId: sign.appId
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// app支付逻辑
|
|
|
- appPayCallBack () {
|
|
|
+ appPayCallBack (paySign) {
|
|
|
console.log('appPay')
|
|
|
- console.log(this.payWay)
|
|
|
+ if (this.payWay === 'wx_app') {
|
|
|
+ // 调微信支付
|
|
|
+ try {
|
|
|
+ JyObj.wxPay(paySign)
|
|
|
+ } catch (error) {
|
|
|
+ console.log('请在指定环境运行', error)
|
|
|
+ }
|
|
|
+ } else if (this.payWay === 'ali_app') {
|
|
|
+ // 调支付宝支付
|
|
|
+ try {
|
|
|
+ JyObj.aliPay(paySign)
|
|
|
+ } catch (error) {
|
|
|
+ console.log('请在指定环境运行', error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.checkAppPaySuccess()
|
|
|
+ }
|
|
|
+
|
|
|
+ // 开启定时任务,3s查询一次是否支付成功
|
|
|
+ checkAppPaySuccess () {
|
|
|
+ const ordercode = this.orderInfo.ordercode
|
|
|
+ const checkPaySuccessTimer = setInterval(() => {
|
|
|
+ this.isPaySuccess({ ordercode }).then(res => {
|
|
|
+ if (res.error_code === 0 && res.data.status === 1) {
|
|
|
+ // 支付完成订单,关闭定时器
|
|
|
+ clearInterval(checkPaySuccessTimer)
|
|
|
+ this.$router.push(`/pay-success/${ordercode}`)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, 3000)
|
|
|
}
|
|
|
}
|
|
|
</script>
|