合伙人端验证是否已经绑定手机号,否则不支持微信一键登录

This commit is contained in:
2026-07-12 21:18:10 +08:00
parent b5235dedef
commit 236a2a87a5
7 changed files with 80 additions and 9 deletions
+34 -1
View File
@@ -1,8 +1,12 @@
import type { ClientRuntimeConfig, WechatLoginResult } from '@dukang/shared-types';
import type { PartnerPhoneCheckResponse } from '@dukang/shared-types';
import { isWxAuthorizeEnabled } from '@dukang/shared-types';
import { WECHAT_INAPP_REQUIRED_MSG } from '@dukang/weixin-sdk';
import { isWechatEnv, weixinSdk } from './weixin';
import { request, saveWechatSession, type PartnerSessionPayload } from './api';
import { getPartnerProfile, request, saveWechatSession, type PartnerSessionPayload, type PartnerSessionProfile } from './api';
export const PARTNER_WECHAT_LOGIN_HINT =
'请先使用手机验证码登录,登录后将自动关联微信';
export type PartnerProfile = {
id: string;
@@ -13,6 +17,35 @@ export type PartnerProfile = {
isPrimary?: boolean;
};
export function partnerHasWechatBinding(
profile: PartnerProfile | PartnerSessionProfile | null | undefined,
): boolean {
return !!profile?.hasWechat;
}
/** 微信一键登录前:账号须已绑定 wxOpenId(本地缓存或手机号校验) */
export async function canPartnerUseWechatLogin(options: {
profile?: PartnerProfile | PartnerSessionProfile | null;
phone?: string;
}): Promise<boolean> {
const cached = options.profile ?? getPartnerProfile();
if (partnerHasWechatBinding(cached)) return true;
const normalized = options.phone?.trim() ?? '';
if (!/^1\d{10}$/.test(normalized)) return false;
try {
const res = await request<PartnerPhoneCheckResponse>('PARTNER_H5', '/partner/auth/phone/check', {
method: 'POST',
body: JSON.stringify({ phone: normalized }),
silent: true,
});
return !!res.hasWechat;
} catch {
return false;
}
}
export async function fetchClientConfig(): Promise<ClientRuntimeConfig> {
return request<ClientRuntimeConfig>('PARTNER_H5', '/common/client-config');
}