提交 bfc564ac authored 作者: zyx's avatar zyx

update

上级 53a467ab
...@@ -79,24 +79,24 @@ export default { ...@@ -79,24 +79,24 @@ export default {
methods: { methods: {
onBridgeReady () { onBridgeReady () {
this.VueEvent.$off('pay-wx-h5').$on('pay-wx-h5', (obj) => { this.VueEvent.$off('pay-wx-h5').$on('pay-wx-h5', (obj) => {
const _callback = obj.callback || function () {} this.goToPay()
const _obj = this.goToPay()
_callback(_obj)
}) })
}, },
async goToPay () { goToPay () {
const obj = { code: 0, msg: '', data: {} } const obj = { code: 0, msg: '', data: {} }
if (!this.requestParam.product_id) { if (!this.requestParam.product_id) {
obj.code = 3001 obj.code = 3001
obj.msg = '没有商品ID' obj.msg = '没有商品ID'
return obj this.VueEvent.$emit('pay-wx-h5-callback', obj)
return false
} }
if (!this.requestParam.open_id) { if (!this.requestParam.open_id) {
obj.code = 3002 obj.code = 3002
obj.msg = '没有小程序用户openid' obj.msg = '没有小程序用户openid'
return obj this.VueEvent.$emit('pay-wx-h5-callback', obj)
return false
} }
return await Pay.getOrderId(this.requestParam).then(res => { Pay.getOrderId(this.requestParam).then(res => {
if (res.code) { if (res.code) {
// this.requestParam.product_id // this.requestParam.product_id
// this.requestParam.open_id // this.requestParam.open_id
...@@ -110,14 +110,19 @@ export default { ...@@ -110,14 +110,19 @@ export default {
this.requestParam.paySign = res.data.options.paySign this.requestParam.paySign = res.data.options.paySign
this.wxWakeUpToPay(obj) this.wxWakeUpToPay(obj)
} else {
obj.code = 3003
obj.msg = '获取订单ID失败'
this.VueEvent.$emit('pay-wx-h5-callback', obj)
} }
}).catch(e => { }).catch(e => {
obj.code = 5001 obj.code = 5001
obj.msg = e.message obj.msg = e.message
this.VueEvent.$emit('pay-wx-h5-callback', obj)
return obj return obj
}) })
}, },
async wxWakeUpToPay (obj) { wxWakeUpToPay (obj) {
/* 直接调用微信支付 */ /* 直接调用微信支付 */
// const timestamp = parseInt(new Date().getTime() / 1000) // const timestamp = parseInt(new Date().getTime() / 1000)
// const noncestr = parseInt(Math.random() * 10000000000000000) // const noncestr = parseInt(Math.random() * 10000000000000000)
...@@ -131,12 +136,15 @@ export default { ...@@ -131,12 +136,15 @@ export default {
paySign: this.requestParam.paySign // 微信签名 paySign: this.requestParam.paySign // 微信签名
}, },
function (res) { function (res) {
/* 小程序调用失败 */
obj.code = 4000
obj.msg = res.err_msg obj.msg = res.err_msg
return obj if (res.err_msg === 'get_brand_wcpay_request:ok') {
// if (res.err_msg === 'get_brand_wcpay_request:ok') { // 使用以上方式判断前端返回,微信团队郑重提示:
// // 使用以上方式判断前端返回,微信团队郑重提示: // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
// // res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。 obj.code = 200
// } }
this.VueEvent.$emit('pay-wx-h5-callback', obj)
} }
) )
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论