web-retail-h5/pages/wechatPay/bfPay.vue

95 lines
2.2 KiB
Vue
Raw Permalink Normal View History

2025-03-23 09:29:40 +08:00
<!--
* @Descripttion:
* @version:
* @Author: 王三华
* @Date: 2023-06-16 09:43:05
-->
<template>
<div class="contain">
<img src="@/static/images/pay_i2.png"
alt="" />
<div>宝付支付中...</div>
</div>
</template>
<script>
import wx from 'weixin-js-sdk'
import * as pay from '@/config/pay.js'
export default {
data() {
return {
code: '',
state: '',
}
},
mounted() {
let allData = decodeURIComponent(window.location.href).split('=')
console.log(
'%c [ allData ]-34',
'font-size:13px; background:#a3905c; color:#e7d4a0;',
allData
)
this.code = allData[1].split('&')[0]
this.state = allData[2].split('#')[0]
this.getFiveCode()
},
methods: {
getFiveCode() {
pay
.baoFuPay({
code: this.code,
state: this.state,
})
.then((res) => {
let obj = res.data
this.onBridgeReady(obj)
})
},
onBridgeReady(data) {
console.log('调用微信支付WeixinJSBridge')
var vm = this
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
{
// 下面参数内容都是后台返回的
appId: data.appId, // 公众号名称,由商户传入
timeStamp: data.timeStamp, // 时间戳
nonceStr: data.nonceStr, // 随机串
package: data.package, // 预支付id
signType: data.signType, // 微信签名方式
paySign: data.paySign, // 微信签名
},
function (res) {
// 使用以上方式判断前端返回,微信团队郑重提示res.err_msg将在用户支付成功后返回ok但并不保证它绝对可靠。
if (res.err_msg === 'get_brand_wcpay_request:ok') {
uni.showToast({
title: this.$t('w_0335'),
icon: 'none',
})
} else {
uni.showToast({
title: '支付失败',
icon: 'none',
})
}
}
)
},
},
}
</script>
<style lang="scss" scoped>
.contain {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 200px;
font-size: 16px;
img {
width: 60px;
height: 60px;
margin-bottom: 20px;
}
}
</style>