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:
john
2026-06-16 16:20:04 +08:00
parent bb70634a96
commit f818dd0307
15 changed files with 260 additions and 32 deletions
+49
View File
@@ -0,0 +1,49 @@
import type { JsapiPayParams } from '../types';
type WeixinJsBridge = {
invoke(
api: 'getBrandWCPayRequest',
params: JsapiPayParams,
callback: (result: { err_msg?: string }) => void,
): void;
};
declare global {
interface Window {
WeixinJSBridge?: WeixinJsBridge;
}
}
export function isWeChatBrowser() {
return /MicroMessenger/i.test(navigator.userAgent);
}
export function invokeWechatJsapiPay(params: JsapiPayParams): Promise<'ok' | 'cancel'> {
return new Promise((resolve, reject) => {
const invoke = () => {
const bridge = window.WeixinJSBridge;
if (!bridge) {
reject(new Error('当前环境不支持微信支付,请在微信内打开'));
return;
}
bridge.invoke('getBrandWCPayRequest', params, (result) => {
const message = result.err_msg ?? '';
if (message === 'get_brand_wcpay_request:ok') {
resolve('ok');
return;
}
if (message === 'get_brand_wcpay_request:cancel') {
resolve('cancel');
return;
}
reject(new Error(message || '微信支付失败'));
});
};
if (typeof window.WeixinJSBridge === 'undefined') {
document.addEventListener('WeixinJSBridgeReady', invoke, { once: true });
return;
}
invoke();
});
}