微信公众号支付:接入 100%

pull/32/MERGE
YunaiV 2023-12-24 11:41:17 +08:00
parent f90096e20a
commit b548999e89
4 changed files with 21 additions and 11 deletions

View File

@ -159,13 +159,14 @@ export default {
}); });
}, },
//微信支付 TODO 芋艿:未测试 // 微信支付
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 位
package: data.package, // 统一支付接口返回的prepay_id参数值提交格式如prepay_id=\*\*\* package: data.packageValue, // 统一支付接口返回的prepay_id参数值提交格式如prepay_id=\*\*\*
signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5' signType: data.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: data.paySign, // 支付签名 paySign: data.paySign, // 支付签名
success: function (res) { success: function (res) {

View File

@ -105,9 +105,12 @@ export default class SheepPay {
// 成功时 // 成功时
res.code === 0 && resolve(res); res.code === 0 && resolve(res);
// 失败时 // 失败时
// TODO 芋艿:这块需要在测试下哈; if (res.code !== 0 && res.msg.indexOf('无效的openid') >= 0) {
if (res.code !== 0 && res.msg === 'miss_openid') { // 特殊逻辑:微信公众号、小程序支付时,必须传入 openid 不正确的情况
this.bindWeixin(); if (res.msg.indexOf('无效的openid') >= 0 // 获取的 openid 不正确时,或者随便输入了个 openid
|| res.msg.indexOf('下单账号与支付账号不一致') >= 0) { // https://developers.weixin.qq.com/community/develop/doc/00008c53c347804beec82aed051c00
this.bindWeixin();
}
} }
}); });
}); });
@ -119,15 +122,19 @@ export default class SheepPay {
if (code !== 0) { if (code !== 0) {
return; return;
} }
// let that = this; const payConfig = JSON.parse(data.displayContent);
$wxsdk.wxpay(data, { $wxsdk.wxpay(payConfig, {
success: () => { success: () => {
this.payResult('success'); this.payResult('success');
}, },
cancel: () => { cancel: () => {
this.$helper.toast('支付已手动取消'); sheep.$helper.toast('支付已手动取消');
}, },
fail: () => { fail: (error) => {
if (error.errMsg.indexOf('chooseWXPay:没有此SDK或暂不支持此SDK模拟') >= 0) {
sheep.$helper.toast('发起微信支付失败,原因:可能是微信开发者工具不支持,建议使用微信打开网页后支付');
return
}
this.payResult('fail'); this.payResult('fail');
}, },
}); });

View File

@ -220,7 +220,8 @@ const request = (config) => {
// TODO 芋艿:额外拼接 // TODO 芋艿:额外拼接
if (config.url.indexOf('/app-api/') >= 0) { if (config.url.indexOf('/app-api/') >= 0) {
// config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】 // config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】 // config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
config.url = 'http://yunai.natapp1.cc' + config.url; // 调用【natapp】
} }
return http.middleware(config); return http.middleware(config);
}; };

View File

@ -217,7 +217,8 @@ const request = (config) => {
// 设置接口地址 // 设置接口地址
// config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】 // config.url = 'http://api-dashboard.yudao.iocoder.cn' + config.url; // 调用【云端】
// config.url = 'https://app.test.huizhizao.vip/prod-api' + config.url; // 调用【云端】 // config.url = 'https://app.test.huizhizao.vip/prod-api' + config.url; // 调用【云端】
config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】 // config.url = 'http://127.0.0.1:48080' + config.url; // 调用【本地】
config.url = 'http://yunai.natapp1.cc' + config.url; // 调用【natapp】
} }
return http.middleware(config); return http.middleware(config);
}; };