You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.1 KiB
81 lines
2.1 KiB
/*
|
|
* @Author: ch
|
|
* @Date: 2022-04-29 14:26:10
|
|
* @LastEditors: ch
|
|
* @LastEditTime: 2022-05-07 17:07:08
|
|
* @Description: file content
|
|
*/
|
|
|
|
import { ApiPostWxH5Pay, ApiPostWxJsApiPay, ApiPostWxAppPay } from '@/common/api/wx';
|
|
export const Wxpay = async ({orderId,openId})=>{
|
|
|
|
// #ifdef APP-PLUS
|
|
const {error, result} = await ApiPostWxAppPay({orderId});
|
|
if(error){
|
|
uni.$u.toast(error.message);
|
|
return false;
|
|
}
|
|
const par = result.dataInfo;
|
|
uni.requestPayment({
|
|
provider: 'wxpay',
|
|
orderInfo :{
|
|
"appid": par.appId, // 微信开放平台 - 应用 - AppId
|
|
"noncestr": par.nonceStr, // 随机字符串
|
|
"package": par.packageValue, // 固定值
|
|
"partnerid": par.partnerId, // 微信支付商户号
|
|
"prepayid": par.prepayId, // 统一下单订单号
|
|
"timestamp": par.timeStamp ,// 时间戳(单位:秒)
|
|
"sign": par.sign // 签名,这里用的 MD5 签名
|
|
},
|
|
success(res) {
|
|
uni.navigateTo({
|
|
url : `/payResult?orderId=${orderId}&payType=appWx`
|
|
});
|
|
},
|
|
fail(e) {
|
|
uni.navigateTo({
|
|
url : `/payResult?orderId=${orderId}&payType=appWx`
|
|
});
|
|
}
|
|
}).then(res => {
|
|
console.log('res',res);
|
|
})
|
|
// #endif
|
|
|
|
// #ifdef H5
|
|
// 有openId则判断在微信浏览器内
|
|
if(openId) {
|
|
// 微信JSAPI
|
|
const {error, result} = await ApiPostWxJsApiPay({orderId,openId});
|
|
if(error){
|
|
uni.$u.toast(error.message);
|
|
return false;
|
|
}
|
|
const par = result.dataInfo;
|
|
WeixinJSBridge.invoke('getBrandWCPayRequest', {
|
|
appId : par.appId,
|
|
timeStamp : par.timeStamp,
|
|
nonceStr : par.nonceStr,
|
|
package : par.packageValue,
|
|
signType : par.signType,
|
|
paySign : par.paySign
|
|
}, res => {
|
|
if(res.err_msg !== 'get_brand_wcpay_request:cancel'){
|
|
uni.navigateTo({
|
|
url : `/payResult?orderId=${orderId}&payType=wxjsapi`
|
|
});
|
|
}
|
|
})
|
|
}else{
|
|
// h5支付
|
|
const {error, result} = await ApiPostWxH5Pay({orderId});
|
|
if(error){
|
|
uni.$u.toast(error.message);
|
|
return false;
|
|
}
|
|
const redirect_url = decodeURIComponent(`https://you-app.mashibing.com/payResult?orderId=${orderId}&payType=wxh5`);
|
|
window.location.href = `${result.dataInfo.payUrl}&redirect_url=${redirect_url}`;
|
|
}
|
|
// #endif
|
|
|
|
} |