|  | @@ -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 numeral from 'numeral';
 | 
	
		
			
				|  |  |  import { Button, Cell, CellGroup, Icon, showToast } from 'vant';
 | 
	
		
			
				|  |  |  import { defineComponent, onMounted, reactive } from 'vue';
 | 
	
	
		
			
				|  | @@ -17,11 +17,14 @@ export default defineComponent({
 | 
	
		
			
				|  |  |        code: null as any,
 | 
	
		
			
				|  |  |        pay_channel: route.query.pay_channel as any,
 | 
	
		
			
				|  |  |        wxAppId: route.query.wxAppId as any,
 | 
	
		
			
				|  |  | +      paymentType: route.query.paymentType 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 // 是否为易宝支付
 | 
	
		
			
				|  |  |      });
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      const getPayment = async () => {
 | 
	
	
		
			
				|  | @@ -39,7 +42,6 @@ export default defineComponent({
 | 
	
		
			
				|  |  |          if (state.pay_channel == 'wx_pub') {
 | 
	
		
			
				|  |  |            payMap.code = state.code;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        console.log(payMap, 'payMap');
 | 
	
		
			
				|  |  |          const { data } = await request.post(
 | 
	
		
			
				|  |  |            '/edu-app/open/userOrder/executePayment',
 | 
	
		
			
				|  |  |            {
 | 
	
	
		
			
				|  | @@ -50,7 +52,7 @@ export default defineComponent({
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |          );
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        console.log(data, 'payment');
 | 
	
		
			
				|  |  | +        state.isYeePay = data.paymentVender?.indexOf('yeepay') !== -1;
 | 
	
		
			
				|  |  |          scanCodePay(data.reqParams);
 | 
	
		
			
				|  |  |        } catch (e) {
 | 
	
		
			
				|  |  |          //
 | 
	
	
		
			
				|  | @@ -61,17 +63,23 @@ export default defineComponent({
 | 
	
		
			
				|  |  |      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 == 'wx_pub') {
 | 
	
		
			
				|  |  | -        const tempPayInfo = JSON.parse(data.expend.pay_info);
 | 
	
		
			
				|  |  | +        const tempPayInfo = state.isYeePay
 | 
	
		
			
				|  |  | +          ? JSON.parse(data.prePayTn)
 | 
	
		
			
				|  |  | +          : JSON.parse(data.expend.pay_info);
 | 
	
		
			
				|  |  |          state.payInfo = tempPayInfo;
 | 
	
		
			
				|  |  |          if (typeof (window as any).WeixinJSBridge == 'undefined') {
 | 
	
		
			
				|  |  |            if (document.addEventListener) {
 | 
	
	
		
			
				|  | @@ -94,6 +102,42 @@ 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 +
 | 
	
		
			
				|  |  | +                  '/classroom-app/#/payment-result?orderNo=' +
 | 
	
		
			
				|  |  | +                  state.orderNo
 | 
	
		
			
				|  |  | +              );
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +              window.location.replace(
 | 
	
		
			
				|  |  | +                location.origin +
 | 
	
		
			
				|  |  | +                  '/classroom-app/#/payment-result?orderNo=' +
 | 
	
		
			
				|  |  | +                  state.orderNo
 | 
	
		
			
				|  |  | +              );
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //使用的支付宝内置api实现关闭H5
 | 
	
		
			
				|  |  | +            (window as any).AlipayJSBridge.call('closeWebview');
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  | +        );
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    };
 | 
	
		
			
				|  |  |      const onBridgeReady = () => {
 | 
	
		
			
				|  |  |        const payInfo = state.payInfo;
 | 
	
		
			
				|  |  |        // let orderNo = state.orderNo
 | 
	
	
		
			
				|  | @@ -146,15 +190,14 @@ export default defineComponent({
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      const init = () => {
 | 
	
		
			
				|  |  |        const pay_channel = state.pay_channel;
 | 
	
		
			
				|  |  | +      const isYeePay = state.paymentType.indexOf('yeepay') !== -1;
 | 
	
		
			
				|  |  |        if (browser().weixin) {
 | 
	
		
			
				|  |  |          if (pay_channel === 'wx_pub') {
 | 
	
		
			
				|  |  |            //授权
 | 
	
		
			
				|  |  |            const code = getUrlCode();
 | 
	
		
			
				|  |  | -          console.log(code);
 | 
	
		
			
				|  |  |            if (code) {
 | 
	
		
			
				|  |  |              state.code = code; // 赋值code码
 | 
	
		
			
				|  |  |            } else {
 | 
	
		
			
				|  |  | -            // goAuth()
 | 
	
		
			
				|  |  |              goWechatAuth(state.wxAppId);
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |            state.browserStatus = true;
 | 
	
	
		
			
				|  | @@ -167,6 +210,13 @@ export default defineComponent({
 | 
	
		
			
				|  |  |            state.errorText = '请使用微信扫码';
 | 
	
		
			
				|  |  |          } else if (pay_channel == 'alipay_qr') {
 | 
	
		
			
				|  |  |            // 支付宝支付
 | 
	
		
			
				|  |  | +          //授权
 | 
	
		
			
				|  |  | +          const code = getUrlCode('auth_code');
 | 
	
		
			
				|  |  | +          if (code) {
 | 
	
		
			
				|  |  | +            state.code = code; // 赋值code码
 | 
	
		
			
				|  |  | +          } else {
 | 
	
		
			
				|  |  | +            goAliAuth(state.alipayAppId);
 | 
	
		
			
				|  |  | +          }
 | 
	
		
			
				|  |  |            state.browserStatus = true;
 | 
	
		
			
				|  |  |            document.title = '支付宝支付';
 | 
	
		
			
				|  |  |          }
 |