@@ -1,8 +1,14 @@
|
||||
import { goLogin } from './auth-nav';
|
||||
import { isLoggedIn } from './api';
|
||||
import { ensureWechatAuthForPay } from './wechat-auth';
|
||||
import { fetchClientConfig, fetchUserProfile, needsWechatAuthForPay } from './pay-wechat';
|
||||
|
||||
/** 支付前门禁:未登录/未验手机/未绑微信时跳转登录页 */
|
||||
/**
|
||||
* 支付前门禁:
|
||||
* - 未登录 / 未验手机 → 跳转登录页
|
||||
* - H5 微信内缺 openId → 尝试 OAuth(可能跳转微信授权页)
|
||||
* - 小程序缺绑定 → 跳转登录页 needWechat
|
||||
*/
|
||||
export async function ensurePayReady(returnPath: string): Promise<boolean> {
|
||||
if (!isLoggedIn()) {
|
||||
goLogin(returnPath);
|
||||
@@ -15,11 +21,23 @@ export async function ensurePayReady(returnPath: string): Promise<boolean> {
|
||||
goLogin(returnPath, { needPhone: '1' });
|
||||
return false;
|
||||
}
|
||||
if (needsWechatAuthForPay(config, profile)) {
|
||||
goLogin(returnPath, { needWechat: '1' });
|
||||
if (!needsWechatAuthForPay(config, profile)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (process.env.TARO_ENV === 'h5') {
|
||||
const auth = await ensureWechatAuthForPay();
|
||||
if (auth.ok) return true;
|
||||
if ('needBindPhone' in auth && auth.needBindPhone) {
|
||||
goLogin(returnPath, { bindMode: '1', wxSessionKey: auth.wxSessionKey });
|
||||
return false;
|
||||
}
|
||||
// redirecting:正在跳转微信 OAuth
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
goLogin(returnPath, { needWechat: '1' });
|
||||
return false;
|
||||
} catch {
|
||||
goLogin(returnPath);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user