在h5端,调用支付接口会返回openlink字段,这个后台配置的小程序scheme地址,通过window.location.href=openlink可跳转到小程序
that.$http.request.post(that.$http.api.PayBond, { type: that.pay_type, id: that.Info.id }).then(res => {
console.log(res, 'pay-bond');
uni.hideLoading();
let pay_info = res.data.pay_info;
// #ifdef MP-WEIXIN
that.$payment.pay(pay_info, that.pay_type, that.paySuccess);
// #endif
// #ifndef MP-WEIXIN
let openlink = res.data.openlink
console.log(openlink)
window.location.href = openlink
// #endif
});
在跳转的指定页面onload里面可以接收参数,我的就是在pages/index/index里的,因为有多个支付
onLoad(e) {
let that = this
console.log("=========")
console.log(e)
if(!!e.way){
let {type,amount,platform,way,address_id,id,money} = e
let fun = ''
switch(way){
// 充值
case 'recharge':
fun = 'Recharge';
break;
// 订单支付
case 'payorder':
fun = 'PayOrder';
break;
// 认证
case 'authandupgrade':
fun = 'UpgradePay';
break;
// 消保金
case 'payxiaobaojin':
fun = 'PayShopBond';
break;
// 保证金
case 'paybond':
fun = 'PayBond';
break;
default:
break;
}
console.log(fun)
let data = {type: type, amount: amount,address_id:address_id,id:id,money:money }
console.log(data)
that.$http.request.post(that.$http.api[fun], data).then(res => {
console.log(res, 'recharge');
// uni.hideLoading();
let pay_info = res.data.pay_info;
that.$payment.pay(pay_info, type,that.init);
})
}
console.log("========")
this.init();
},
其中this.$payment.pay是封装的调起支付函数
function pay(params, type = 1, callback) {
console.log('pay:', params, type);
if (type == 1) {
uni.showToast({
title: '支付成功'
});
setTimeout(() => {
callback()
}, 1500);
} else if (type == 2) {
// #ifdef MP-WEIXIN
uni.requestPayment({
provider: 'wxpay',
timeStamp: params.timeStamp,
nonceStr: params.nonceStr,
package: params.package,
signType: params.signType,
paySign: params.paySign,
success: function(res) {
console.log(res, 'paySuccess-wx');
uni.showToast({
title: '支付成功!'
});
setTimeout(() => {
callback()
}, 1500);
},
fail: function(err) {
console.log(err, 'payFail-wx');
uni.showToast({
title: '支付失败!',
icon: 'none'
});
}
});
// #endif
}
}