Add WeChat in-app JSAPI recharge for g2.tkmind.cn.
Use JSAPI with bound openid inside WeChat instead of QR long-press, and include related auth redirect and admin UX fixes. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+25
-2
@@ -141,12 +141,34 @@ export function createRechargeService(pool, { userAuth, wechatPay, config = load
|
||||
const outTradeNo = createOutTradeNo();
|
||||
const expireAt = now + config.orderTtlMs;
|
||||
const description = `TKMind账户充值¥${(amount / 100).toFixed(2)}`;
|
||||
const mode = payScene === 'h5' ? 'h5' : 'native';
|
||||
const mode =
|
||||
payScene === 'jsapi' ? 'jsapi' : payScene === 'h5' ? 'h5' : 'native';
|
||||
|
||||
let codeUrl = null;
|
||||
let h5Url = null;
|
||||
let jsapiParams = null;
|
||||
try {
|
||||
if (mode === 'h5') {
|
||||
if (mode === 'jsapi') {
|
||||
const appId = wechatPay.appId;
|
||||
if (!appId) {
|
||||
return { ok: false, message: '微信支付 AppID 未配置' };
|
||||
}
|
||||
const openid = await userAuth.getWechatOpenidForUser(userId, appId);
|
||||
if (!openid) {
|
||||
return {
|
||||
ok: false,
|
||||
message: '请先用微信登录并绑定账号后再充值',
|
||||
};
|
||||
}
|
||||
const result = await wechatPay.createJsapiOrder({
|
||||
outTradeNo,
|
||||
description,
|
||||
amountCents: amount,
|
||||
clientIp,
|
||||
openid,
|
||||
});
|
||||
jsapiParams = result.jsapiParams;
|
||||
} else if (mode === 'h5') {
|
||||
const result = await wechatPay.createH5Order({
|
||||
outTradeNo,
|
||||
description,
|
||||
@@ -200,6 +222,7 @@ export function createRechargeService(pool, { userAuth, wechatPay, config = load
|
||||
expireAt,
|
||||
codeUrl,
|
||||
h5Url,
|
||||
jsapiParams,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user