uniapp 实现支付宝支付
1、首先要勾选支持支付宝支付。2、根据后台返回参数作处理。
·
1、首先要勾选支持支付宝支付。
2、根据后台返回参数作处理。
//获取URL字段
getparams(url, field){
let url2 = url.split('#');
let txt = "";
url2.forEach((res,i)=>{
if(res.includes('=')){
let val = res.split('=');
if(val[0]==field){
txt = val[1]
}
}
})
return txt;
},
//APP支付宝支付
appAliPay(data){
let url = data.url;
let params = {
alipay_sdk:'alipay-sdk-java-4.35.37.ALL',
app_id: this.getparams(url,'app_id'),
biz_content: this.getparams(url,'biz_content'),
charset:'UTF-8',
format:'json',
method:'alipay.trade.app.pay',
notify_url: this.getparams(url,'notify_url'),
return_url: this.getparams(url,'return_url'),
sign_type:'RSA2',
timestamp: this.getparams(url,'timestamp'),
version: this.getparams(url,'version'),
sign: this.getparams(url,'sign')
}
console.log(params,11)
let payurl = "";
for(let o in params){ payurl += `${o}=${params[o]}&`; }
let orderInfo = payurl.substring(0, payurl.length-1)
console.log(orderInfo,22)
uni.requestPayment({
"provider": "alipay", //固定值为"alipay"
"orderInfo": orderInfo, //此处为服务器返回的订单信息字符串
success: function (res) {
that.payComplete();
},
fail: function (err) {
uni.redirectTo({url:'/pages/my/order/index'})
}
});
},
更多推荐
已为社区贡献5条内容
所有评论(0)