|
@@ -1,6 +1,6 @@
|
|
|
import request from '@/helpers/request'
|
|
|
import { browser, getUrlCode, moneyFormat } from '@/helpers/utils'
|
|
|
-import { goWechatAuth } from '@/state'
|
|
|
+import { goAliAuth, goWechatAuth } from '@/state'
|
|
|
import { Cell, CellGroup, Icon, Loading, showConfirmDialog, showToast } from 'vant'
|
|
|
import { defineComponent, onMounted, reactive } from 'vue'
|
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
@@ -15,20 +15,22 @@ export default defineComponent({
|
|
|
errorText: '',
|
|
|
browserStatus: false,
|
|
|
code: null as any,
|
|
|
+ paymentType: route.query.paymentType as any,
|
|
|
pay_channel: route.query.pay_channel as any,
|
|
|
wxAppId: route.query.wxAppId as any,
|
|
|
+ alipayAppId: route.query.alipayAppId as any,
|
|
|
body: route.query.body as any,
|
|
|
price: route.query.price as any,
|
|
|
orderNo: route.query.orderNo as any,
|
|
|
userId: route.query.userId as any,
|
|
|
- payInfo: {} as any
|
|
|
+ payInfo: {} as any,
|
|
|
+ isYeePay: false // 是否为易宝支付
|
|
|
})
|
|
|
|
|
|
- console.log(state.errorText)
|
|
|
-
|
|
|
const init = () => {
|
|
|
const query = route.query
|
|
|
console.log(query)
|
|
|
+ const isYeePay = state.paymentType.indexOf('yeepay') !== -1
|
|
|
// 判断是否有支付对象
|
|
|
if (!query.orderNo || !query.pay_channel) {
|
|
|
showConfirmDialog({
|
|
@@ -43,8 +45,19 @@ export default defineComponent({
|
|
|
state.browserStatus = true
|
|
|
getWxPay()
|
|
|
} else if (browser().alipay) {
|
|
|
- state.browserStatus = true
|
|
|
- getPayment()
|
|
|
+ if (isYeePay) {
|
|
|
+ const code = getUrlCode('auth_code')
|
|
|
+ if (code) {
|
|
|
+ state.code = code // 赋值code码
|
|
|
+ state.browserStatus = true
|
|
|
+ getPayment()
|
|
|
+ } else {
|
|
|
+ goAliAuth(state.alipayAppId)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ state.browserStatus = true
|
|
|
+ getPayment()
|
|
|
+ }
|
|
|
} else {
|
|
|
state.errorText = '请在微信或支付宝客户端打开'
|
|
|
document.title = 'ERROR'
|
|
@@ -74,6 +87,7 @@ export default defineComponent({
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+ state.isYeePay = data.paymentVender?.indexOf('yeepay') !== -1
|
|
|
console.log(data, 'payment', state.pay_channel)
|
|
|
scanCodePay(data.reqParams)
|
|
|
} catch (e) {
|
|
@@ -86,22 +100,63 @@ export default defineComponent({
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // 由于js的载入是异步的,所以可以通过该方法,当AlipayJSBridgeReady事件发生后,再执行callback方法
|
|
|
+ const ready = (callback: any) => {
|
|
|
+ if ((window as any).AlipayJSBridge) {
|
|
|
+ callback && callback()
|
|
|
+ } else {
|
|
|
+ document.addEventListener('AlipayJSBridgeReady', callback, false)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const tradePay = (tradeNO: any) => {
|
|
|
+ ready(function () {
|
|
|
+ // 通过传入交易号唤起快捷调用方式(注意tradeNO大小写严格)
|
|
|
+ ;(window as any).AlipayJSBridge.call(
|
|
|
+ 'tradePay',
|
|
|
+ {
|
|
|
+ tradeNO: tradeNO
|
|
|
+ },
|
|
|
+ function (data: any) {
|
|
|
+ if ('9000' == data.resultCode) {
|
|
|
+ window.location.replace(
|
|
|
+ location.origin + '/orchestra-student/#/payment-result?orderNo=' + state.orderNo
|
|
|
+ )
|
|
|
+ } else {
|
|
|
+ window.location.replace(
|
|
|
+ location.origin + '/orchestra-student/#/payment-result?orderNo=' + state.orderNo
|
|
|
+ )
|
|
|
+ }
|
|
|
+ //使用的支付宝内置api实现关闭H5
|
|
|
+ ;(window as any).AlipayJSBridge.call('closeWebview')
|
|
|
+ }
|
|
|
+ )
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
const scanCodePay = (data: any) => {
|
|
|
// 判断支付方式 如果是 test 模式 支付用测试url 否则用生产url
|
|
|
if (state.pay_channel == 'alipay_qr') {
|
|
|
- const url =
|
|
|
- data.prod_mode === 'false'
|
|
|
- ? data?.expend?.qrcode_url +
|
|
|
- '?payment_id=' +
|
|
|
- data.id +
|
|
|
- '&pay_channel=' +
|
|
|
- data.pay_channel
|
|
|
- : data?.expend?.qrcode_url
|
|
|
- window.location.href = url
|
|
|
+ if (state.isYeePay) {
|
|
|
+ tradePay(data.tradeNO)
|
|
|
+ } else {
|
|
|
+ const url =
|
|
|
+ data.prod_mode === 'false'
|
|
|
+ ? data?.expend?.qrcode_url +
|
|
|
+ '?payment_id=' +
|
|
|
+ data.id +
|
|
|
+ '&pay_channel=' +
|
|
|
+ data.pay_channel
|
|
|
+ : data?.expend?.qrcode_url
|
|
|
+ window.location.href = url
|
|
|
+ }
|
|
|
} else if (state.pay_channel == 'alipay_wap') {
|
|
|
window.location.href = data?.expend?.pay_info
|
|
|
} else if (state.pay_channel == 'wx_pub') {
|
|
|
- const tempPayInfo = data?.expend ? JSON.parse(data?.expend?.pay_info) : data
|
|
|
+ const tempPayInfo = state.isYeePay
|
|
|
+ ? JSON.parse(data.prePayTn)
|
|
|
+ : data?.expend
|
|
|
+ ? JSON.parse(data?.expend?.pay_info)
|
|
|
+ : data
|
|
|
state.payInfo = tempPayInfo
|
|
|
if (typeof (window as any).WeixinJSBridge == 'undefined') {
|
|
|
if (document.addEventListener) {
|