jsapi支付

msb_prod
ch 3 years ago
parent fa53e0f058
commit 661aaa874a

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-07-08 11:46:30
* @LastEditors: ch
* @LastEditTime: 2022-07-12 10:57:40
* @LastEditTime: 2022-07-12 11:09:38
* @Description: file content
*/
@ -20,7 +20,7 @@ if (ua.includes('micromessenger')) {
const openId = localStorage.getItem('payOpenId');
if (!openId) {
let query = FormatSearchJson(window.location.search);
// 通过订单No获取APPID
ApiGetOrderInfo({ payOrderNo: query.payOrderNo }).then(({ result }) => {
const appid = result.prepayWxApp.prepayAppId;
if (query.code) {
@ -29,25 +29,18 @@ if (ua.includes('micromessenger')) {
appid
}).then(({ error, result }) => {
if (error) {
// uni.$u.toast(error.message);
return false;
}
localStorage.setItem('payOpenId', result.openId);
})
} else {
ApiGetAuthUrl({
appid,
redirectUrl: window.location.href,
scope: 'snsapi_base'
}).then(({ result, error }) => {
if (error) {
// uni.$u.toast(error.message);
uni.showToast({
title: error.message,
icon: 'none',
duration: 2000
})
uni._$oast(error.message)
return false;
}
window.location.replace(result);

@ -2,7 +2,7 @@
* @Author: ch
* @Date: 2022-07-08 11:46:30
* @LastEditors: ch
* @LastEditTime: 2022-07-09 18:34:53
* @LastEditTime: 2022-07-12 11:37:13
* @Description: file content
-->
<template>
@ -66,35 +66,70 @@ const ENV = process.env;
},
pay(){
if(this.payType === 'wxpay'){
this.wxPay();
if(localStorage.getItem('payOpenId') && WeixinJSBridge){
this.wxJsapiPay()
}else{
this.wxH5Pay();
}
}else{
this.aliPay();
}
},
async wxPay(){
// h5
const {error, result} = await ApiPostH5Pay({
payOrderNo : this.orderInfo.payOrderNo,
payCode : 'WX_H5',
appCode : this.orderInfo.prepayWxApp.prepayAppCode
/**
* 微信APP内部点击支付
*/
async wxJsapiPay(){
const {result} = await this.getOrderInfo('WX_JSAPI');
if(result){
const par = result.payDataInfo;
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'){
if(this.orderInfo.returnUrl){
window.location.replace(this.orderInfo.returnUrl);
}else{
uni.redirectTo({
url : `/pages/wapResult?payOrderNo=${this.payOrderNo}`
});
if(error){
uni._$toast(error.message);
return false;
}
}
})
}
},
/**
* h5唤起微信支付
*/
async wxH5Pay(){
const {error, result} = await this.getOrderInfo('WX_H5');
if(result){
// h5windowAPI
window.location.replace(data.payDataInfo.h5Url);
}
},
async aliPay(){
const {error, result} = await this.getOrderInfo('ALI_WAP');
if(result){
// h5windowAPI
window.location.replace(data.payDataInfo.payUrl);
}
},
async getPayData(payCode){
const {error, result} = await ApiPostH5Pay({
payOrderNo : this.orderInfo.payOrderNo,
payCode : 'ALI_WAP',
payCode,
appCode : this.orderInfo.prepayAliApp.prepayAppCode
});
if(error){
uni._$toast(error.message);
return false;
}
window.location.replace(data.payDataInfo.payUrl);
return {error, result};
}
}
}

Loading…
Cancel
Save