|
|
|
@ -2,13 +2,48 @@
|
|
|
|
|
* @Author: ch
|
|
|
|
|
* @Date: 2022-04-29 14:26:10
|
|
|
|
|
* @LastEditors: ch
|
|
|
|
|
* @LastEditTime: 2022-05-05 19:16:29
|
|
|
|
|
* @LastEditTime: 2022-05-06 21:23:48
|
|
|
|
|
* @Description: file content
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { ApiPostWxH5Pay, ApiPostWxJsApiPay } from '@/common/api/wx';
|
|
|
|
|
import { ApiPostWxH5Pay, ApiPostWxJsApiPay, ApiPostWxAppPay } from '@/common/api/wx';
|
|
|
|
|
export const Wxpay = async ({orderId,openId})=>{
|
|
|
|
|
// 有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});
|
|
|
|
@ -16,14 +51,6 @@ export const Wxpay = async ({orderId,openId})=>{
|
|
|
|
|
uni.$u.toast(error.message);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* 公众号id appId 是 String(16) wx8888888888888888
|
|
|
|
|
时间戳 timeStamp 是 String(32) 1414561699 当前的时间
|
|
|
|
|
随机字符串 nonceStr 是 String(32) 5K8264ILTKCH16CQ2502SI8ZNMTM67VS 随机字符串,不长于32位。推荐随机数生成算法
|
|
|
|
|
订单详情扩展字符串 package 是 String(128) prepay_id=123456789 统一下单接口返回的prepay_id参数值,提交格式如:prepay_id=***
|
|
|
|
|
签名方式 signType 是 String(32) MD5 签名类型,默认为MD5,支持HMAC-SHA256和MD5。注意此处需与统一下单的签名类型一致
|
|
|
|
|
签名 paySign 是 String(64) C380BEC2BFD727A4B6845133519F3AD6 签名
|
|
|
|
|
*/
|
|
|
|
|
const par = result.dataInfo;
|
|
|
|
|
WeixinJSBridge.invoke('getBrandWCPayRequest', {
|
|
|
|
|
appId : par.appId,
|
|
|
|
@ -49,4 +76,6 @@ export const Wxpay = async ({orderId,openId})=>{
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
}
|