✨ 微信公小程序支付:接入 100%
parent
b548999e89
commit
d60d552bb1
|
@ -162,7 +162,6 @@ export default {
|
||||||
// 微信支付
|
// 微信支付
|
||||||
wxpay(data, callback) {
|
wxpay(data, callback) {
|
||||||
this.isReady(() => {
|
this.isReady(() => {
|
||||||
debugger
|
|
||||||
jweixin.chooseWXPay({
|
jweixin.chooseWXPay({
|
||||||
timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
timestamp: data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||||
nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
|
nonceStr: data.nonceStr, // 支付签名随机串,不长于 32 位
|
||||||
|
|
|
@ -92,7 +92,7 @@ export default class SheepPay {
|
||||||
channelExtras: {}
|
channelExtras: {}
|
||||||
};
|
};
|
||||||
// 特殊逻辑:微信公众号、小程序支付时,必须传入 openid
|
// 特殊逻辑:微信公众号、小程序支付时,必须传入 openid
|
||||||
if (['wx_pub'].includes(channel)) {
|
if (['wx_pub', 'wx_lite'].includes(channel)) {
|
||||||
const openid = await sheep.$platform.useProvider('wechat').getOpenid();
|
const openid = await sheep.$platform.useProvider('wechat').getOpenid();
|
||||||
// 如果获取不到 openid,微信无法发起支付,此时需要引导
|
// 如果获取不到 openid,微信无法发起支付,此时需要引导
|
||||||
if (!openid) {
|
if (!openid) {
|
||||||
|
@ -101,6 +101,7 @@ export default class SheepPay {
|
||||||
}
|
}
|
||||||
data.channelExtras.openid = openid;
|
data.channelExtras.openid = openid;
|
||||||
}
|
}
|
||||||
|
// 发起预支付 API 调用
|
||||||
PayOrderApi.submitOrder(data).then((res) => {
|
PayOrderApi.submitOrder(data).then((res) => {
|
||||||
// 成功时
|
// 成功时
|
||||||
res.code === 0 && resolve(res);
|
res.code === 0 && resolve(res);
|
||||||
|
@ -144,8 +145,7 @@ export default class SheepPay {
|
||||||
async wechatWapPay() {
|
async wechatWapPay() {
|
||||||
const { error, data } = await this.prepay();
|
const { error, data } = await this.prepay();
|
||||||
if (error === 0) {
|
if (error === 0) {
|
||||||
const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment
|
const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment}&orderType=${this.orderType}`;
|
||||||
}&orderType=${this.orderType}`;
|
|
||||||
location.href = `${data.pay_data.h5_url}&redirect_url=${encodeURIComponent(redirect_url)}`;
|
location.href = `${data.pay_data.h5_url}&redirect_url=${encodeURIComponent(redirect_url)}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -154,29 +154,37 @@ export default class SheepPay {
|
||||||
async redirectPay() {
|
async redirectPay() {
|
||||||
let { error, data } = await this.prepay();
|
let { error, data } = await this.prepay();
|
||||||
if (error === 0) {
|
if (error === 0) {
|
||||||
const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment
|
const redirect_url = `${getRootUrl()}pages/pay/result?id=${this.id}&payment=${this.payment}&orderType=${this.orderType}`;
|
||||||
}&orderType=${this.orderType}`;
|
|
||||||
location.href = data.pay_data + encodeURIComponent(redirect_url);
|
location.href = data.pay_data + encodeURIComponent(redirect_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #endif
|
// #endif
|
||||||
|
|
||||||
// 微信小程序支付 TODO 芋艿:待接入
|
// 微信小程序支付
|
||||||
async wechatMiniProgramPay() {
|
async wechatMiniProgramPay() {
|
||||||
let that = this;
|
// let that = this;
|
||||||
let result = await this.prepay();
|
let { code, data } = await this.prepay('wx_lite');
|
||||||
|
if (code !== 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 调用微信小程序支付
|
||||||
|
const payConfig = JSON.parse(data.displayContent);
|
||||||
uni.requestPayment({
|
uni.requestPayment({
|
||||||
provider: 'wxpay',
|
provider: 'wxpay',
|
||||||
...result.data.pay_data,
|
timeStamp: payConfig.timeStamp,
|
||||||
|
nonceStr: payConfig.nonceStr,
|
||||||
|
package: payConfig.packageValue,
|
||||||
|
signType: payConfig.signType,
|
||||||
|
paySign: payConfig.paySign,
|
||||||
success: (res) => {
|
success: (res) => {
|
||||||
that.payResult('success');
|
this.payResult('success');
|
||||||
},
|
},
|
||||||
fail: (err) => {
|
fail: (err) => {
|
||||||
if (err.errMsg === 'requestPayment:fail cancel') {
|
if (err.errMsg === 'requestPayment:fail cancel') {
|
||||||
sheep.$helper.toast('支付已手动取消');
|
sheep.$helper.toast('支付已手动取消');
|
||||||
} else {
|
} else {
|
||||||
that.payResult('fail');
|
this.payResult('fail');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -115,7 +115,6 @@ http.interceptors.response.use(
|
||||||
}
|
}
|
||||||
// TODO 芋艿:如果是登录的 API,则自动设置 token
|
// TODO 芋艿:如果是登录的 API,则自动设置 token
|
||||||
if (response.data?.data?.accessToken) {
|
if (response.data?.data?.accessToken) {
|
||||||
debugger
|
|
||||||
$store('user').setToken(response.data.data.accessToken);
|
$store('user').setToken(response.data.data.accessToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue