jsapi支付

msb_prod
ch 3 years ago
parent fa53e0f058
commit 661aaa874a

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

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

Loading…
Cancel
Save