import type { WechatLoginResult } from '@dukang/shared-types'; import { isWechatEnv, weixinSdk } from './weixin'; import { request, saveAuth } from './api'; export type PartnerProfile = { id: string; name: string; phone: string; companyName: string; hasWechat?: boolean; }; export async function fetchPartnerProfile(): Promise { return request('PARTNER_H5', '/partner/me'); } /** 微信内上传照片前需完成公众号授权绑定 */ export function needsWechatAuth(profile: PartnerProfile | null): boolean { return isWechatEnv() && !!profile && !profile.hasWechat; } export function savePartnerWechatAuth(result: WechatLoginResult): boolean { if (!result.accessToken) return false; saveAuth({ accessToken: result.accessToken }); return true; } export async function authorizePartnerWechat(): Promise { if (!isWechatEnv()) { throw new Error('请在微信内打开以完成授权'); } return weixinSdk.login(); } export async function handlePartnerWechatCallback(): Promise { if (!isWechatEnv()) return null; return weixinSdk.handleOAuthCallback(); }