uni-app app内微信支付
if(this.paytype == 'wechat'){
//订单对象,从服务器获取
var orderInfo = {
"appid": authRes.result.appid, // 应用ID(AppID)
"partnerid": authRes.result.partnerid, // 商户号(PartnerID)
"prepayid": authRes.result.prepayid, // 预支付交易会话ID
"package": authRes.result.package, // 固定值
"noncestr": authRes.result.noncestr, // 随机字符串
"timestamp": authRes.result.timestamp, // 时间戳(单位:秒)
"sign": authRes.result.sign // 签名,这里用的 MD5 签名
};
uni.requestPayment({
provider: "wxpay",
orderInfo: orderInfo,
success(res) {
uni.showToast({
title: '支付成功',
icon: 'success'
});
setTimeout(()=>{
uni.navigateBack()
},1000)
},
fail(err) {
that.showToast('支付失败')
console.log('fail:' + JSON.stringify(err));
console.log("支付失败");
}
});
}
vue pc网页 微信&支付宝支付
提交参数,走接口获取跳转链接。
接口参数
/api/user/submit?level='+ this.level + '&days=' + this.days + '&paytype=wechat&method=web
//获取到跳转链接
window.location.replace(res.data)
uni-app 移动h5&微信内支付
提交参数获取预支付订单细信息
code获取?
appid为绑定微信商户号的appid
redirect_uri为支付完成或支付失败或取消支付返回跳转链接。
scope=snsapi_base 静默授权 详细可见微信开发文档
let local = window.location.href;
window.location.href =
"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
this.appid +
"&redirect_uri=" +
encodeURIComponent(local) +
"&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
// snsapi_userinfo
}
/api/user/submit?level='+ this.level + '&days=' + this.days + '&paytype=wechat&method=mp&code=' + this.code + '&method=mp'
//解决微信内置对象报错
weixinPay(data){
var vm= this;
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', vm.onBridgeReady(data), false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', vm.onBridgeReady(data));
document.attachEvent('onWeixinJSBridgeReady',vm.onBridgeReady(data));
}
}else{
vm.onBridgeReady();
}
},
//微信内置浏览器类,weChatParameter对象是后台返回的预支付订单数据
onBridgeReady(){
var vm = this;
var timestamp=Math.round(vm.weChatParameter.timeStamp).toString();
WeixinJSBridge.invoke(
'getBrandWCPayRequest',{
debug:true,
"appId":vm.weChatParameter.appId, //公众号名称,由商户传入
// "appId": vm.appid, //公众号名称,由商户传入
"timeStamp": vm.weChatParameter.timeStamp, //时间戳,自1970年以来的秒数
"timeStamp": timestamp, //时间戳,自1970年以来的秒数
"nonceStr": vm.weChatParameter.nonceStr, //随机串
"package": vm.weChatParameter.package,
"signType": vm.weChatParameter.signType, //微信签名方式:
"paySign": vm.weChatParameter.paySign, //微信签名
jsApiList: ['chooseWXPay']
},
function(res){
// 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
if(res.err_msg == "get_brand_wcpay_request:ok" ){
vm.$message({
type: 'success',
message: '支付成功'
});
// window.history.go(-1);
}else{
vm.$message({
type: 'error',
message: '支付失败'
});
}
}
);
},