feat;提交管理端和城市合伙人端
This commit is contained in:
@@ -19,12 +19,59 @@ export function needsWechatAuth(profile: PartnerProfile | null): boolean {
|
||||
return isWechatEnv() && !!profile && !profile.hasWechat;
|
||||
}
|
||||
|
||||
export function savePartnerWechatAuth(result: WechatLoginResult): boolean {
|
||||
/** 处理微信登录/绑定结果,返回是否已拿到 token 可进入首页 */
|
||||
export function handlePartnerWechatLoginResult(result: WechatLoginResult): boolean {
|
||||
if (!result.accessToken) return false;
|
||||
saveAuth({ accessToken: result.accessToken });
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function handlePartnerWechatCallback(): Promise<WechatLoginResult | null> {
|
||||
if (!isWechatEnv()) return null;
|
||||
return weixinSdk.handleOAuthCallback();
|
||||
}
|
||||
|
||||
let clientConfigCache: { mockWechat?: boolean } | null = null;
|
||||
|
||||
async function fetchClientConfig(): Promise<{ mockWechat?: boolean }> {
|
||||
if (clientConfigCache) return clientConfigCache;
|
||||
try {
|
||||
clientConfigCache = await request<{ mockWechat?: boolean }>('PARTNER_H5', '/common/client-config');
|
||||
} catch {
|
||||
clientConfigCache = {};
|
||||
}
|
||||
return clientConfigCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信授权登录(与 C 端一致:微信内走公众号 OAuth)。
|
||||
* 返回 true = 已登录;void = 已跳转授权页等待回调。
|
||||
*/
|
||||
export async function loginPartnerWithWechat(): Promise<boolean | void> {
|
||||
if (isWechatEnv()) {
|
||||
const result = await weixinSdk.login();
|
||||
if (result) return handlePartnerWechatLoginResult(result);
|
||||
return;
|
||||
}
|
||||
const cfg = await fetchClientConfig();
|
||||
if (!cfg.mockWechat) {
|
||||
throw new Error('请在微信内打开以使用微信一键授权');
|
||||
}
|
||||
const result = await request<WechatLoginResult>('PARTNER_H5', '/partner/auth/login/wechat', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ code: `mockcode_${Date.now()}`, platform: 'h5' }),
|
||||
});
|
||||
return handlePartnerWechatLoginResult(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信登录成功后于微信内自动发起 OAuth,将 openId 绑定到当前合伙人账号(便于同一微信后续免登)。
|
||||
*/
|
||||
export async function bindPartnerWechatAfterSmsLogin(): Promise<void> {
|
||||
if (!isWechatEnv()) return;
|
||||
await weixinSdk.login();
|
||||
}
|
||||
|
||||
export async function authorizePartnerWechat(): Promise<WechatLoginResult | void> {
|
||||
if (!isWechatEnv()) {
|
||||
throw new Error('请在微信内打开以完成授权');
|
||||
@@ -32,7 +79,7 @@ export async function authorizePartnerWechat(): Promise<WechatLoginResult | void
|
||||
return weixinSdk.login();
|
||||
}
|
||||
|
||||
export async function handlePartnerWechatCallback(): Promise<WechatLoginResult | null> {
|
||||
if (!isWechatEnv()) return null;
|
||||
return weixinSdk.handleOAuthCallback();
|
||||
/** @deprecated 使用 handlePartnerWechatLoginResult */
|
||||
export function savePartnerWechatAuth(result: WechatLoginResult): boolean {
|
||||
return handlePartnerWechatLoginResult(result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user