| | |
| | | </template> |
| | | |
| | | <script setup lang="ts"> |
| | | import IconWeixin from '../../../assets/icon-weixin-pay.png'; |
| | | import IconAliPay from '../../../assets/icon-alipay.png'; |
| | | import IconWeixin from '../../assets/icon-weixin-pay.png'; |
| | | import IconAliPay from '../../assets/icon-alipay.png'; |
| | | import { |
| | | useLifeRechargeContext, |
| | | SetLifePayOrderPayTypeInput, |
| | |
| | | } from '@life-payment/core-vue'; |
| | | import { useQuery } from '@tanstack/vue-query'; |
| | | import { Toast as NutToast } from '@nutui/nutui-taro'; |
| | | import { reactive } from 'vue'; |
| | | import { onMounted, reactive, ref, computed } from 'vue'; |
| | | import Taro from '@tarojs/taro'; |
| | | |
| | | defineOptions({ |
| | | name: 'SelectPayTypeView', |
| | |
| | | isInWeChat?: boolean; |
| | | isH5?: boolean; |
| | | appId?: string; |
| | | isFocus?: boolean; |
| | | }; |
| | | |
| | | const props = withDefaults(defineProps<Props>(), { |
| | |
| | | state.msg = '请在微信中打开'; |
| | | state.show = true; |
| | | } |
| | | } else if (Taro.getEnv() === Taro.ENV_TYPE.WEAPP) { |
| | | handleWeixinPayByMini(); |
| | | } |
| | | } |
| | | |
| | | async function handleWeixinPayByJsApi() { |
| | | async function getPayOrderForJsAPI() { |
| | | try { |
| | | let params: GetPayOrderForJsAPIInput = { |
| | | orderNo: props.orderNo, |
| | |
| | | attach: Date.now().toString(), |
| | | }; |
| | | let res = await blLifeRecharge.services.getPayOrderForJsAPI(params); |
| | | //@ts-ignore |
| | | if (res && WeixinJSBridge) { |
| | | return res; |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function handleWeixinPayByJsApi() { |
| | | try { |
| | | let res = await getPayOrderForJsAPI(); |
| | | |
| | | if (res) { |
| | | //@ts-ignore |
| | | WeixinJSBridge.invoke( |
| | | 'getBrandWCPayRequest', |
| | | { |
| | | appId: props.appId, //公众号ID,由商户传入 |
| | | timeStamp: res.timestamp, //时间戳,自1970年以来的秒数 |
| | | nonceStr: res.nonceStr, //随机串 |
| | | package: res.package, |
| | | signType: res.signType, //微信签名方式: |
| | | paySign: res.paySign, //微信签名 |
| | | }, |
| | | function (res) { |
| | | if (res.err_msg == 'get_brand_wcpay_request:ok') { |
| | | // 使用以上方式判断前端返回,微信团队郑重提示: |
| | | //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠,商户需进一步调用后端查单确认支付结果。 |
| | | if (WeixinJSBridge) { |
| | | //@ts-ignore |
| | | WeixinJSBridge.invoke( |
| | | 'getBrandWCPayRequest', |
| | | { |
| | | appId: props.appId, //公众号ID,由商户传入 |
| | | timeStamp: res.timestamp, //时间戳,自1970年以来的秒数 |
| | | nonceStr: res.nonceStr, //随机串 |
| | | package: res.package, |
| | | signType: res.signType, //微信签名方式: |
| | | paySign: res.paySign, //微信签名 |
| | | }, |
| | | function (res) { |
| | | if (res.err_msg == 'get_brand_wcpay_request:ok') { |
| | | // 使用以上方式判断前端返回,微信团队郑重提示: |
| | | //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠,商户需进一步调用后端查单确认支付结果。 |
| | | } else if (res.err_msg == 'system:access_denied') { |
| | | state.msg = '请在手机微信中打开'; |
| | | state.show = true; |
| | | } else { |
| | | // state.msg = res.err_msg; |
| | | // state.show = true; |
| | | } |
| | | } |
| | | } |
| | | ); |
| | | ); |
| | | } |
| | | } |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function handleWeixinPayByMini() { |
| | | try { |
| | | let res = await getPayOrderForJsAPI(); |
| | | |
| | | if (res) { |
| | | Taro.requestPayment({ |
| | | timeStamp: res.timestamp, |
| | | nonceStr: res.nonceStr, |
| | | package: res.package, |
| | | signType: res.signType as any, |
| | | paySign: res.paySign, |
| | | success: function (res) { |
| | | console.log('res: ', res); |
| | | // if(res.errMsg) |
| | | }, |
| | | fail: function (res) {}, |
| | | }); |
| | | } |
| | | } catch (error) {} |
| | | } |
| | |
| | | ); |
| | | }, |
| | | onSuccess(data) { |
| | | if (data === blLifeRecharge.constants.LifePayStatusEnum.已支付) { |
| | | if (data !== blLifeRecharge.constants.LifePayStatusEnum.未支付) { |
| | | emit('paySuccess', props.orderNo, props.lifePayOrderType); |
| | | } |
| | | }, |
| | | refetchInterval: 1000 * 3, |
| | | enabled: computed(() => props.isFocus), |
| | | }); |
| | | </script> |