小程序修改

This commit is contained in:
2026-07-12 19:44:36 +08:00
parent 3b4833b51a
commit e2dfb08de3
45 changed files with 2028 additions and 347 deletions
@@ -0,0 +1,34 @@
import Taro from '@tarojs/taro';
import { request } from './api';
type MiniProfilePayload = {
nickname?: string;
avatarUrl?: string;
};
/** 小程序授权后拉取微信昵称/头像并上报服务端 */
export async function syncMiniWechatProfile(): Promise<void> {
if (process.env.TARO_ENV !== 'weapp') return;
let profile: MiniProfilePayload | null = null;
try {
const res = await Taro.getUserProfile({ desc: '用于完善会员资料' });
profile = {
nickname: res.userInfo?.nickName,
avatarUrl: res.userInfo?.avatarUrl,
};
} catch {
return;
}
if (!profile.nickname && !profile.avatarUrl) return;
try {
await request('/auth/wechat/mini-profile', {
method: 'POST',
data: profile,
});
} catch {
/* 用户拒绝或上报失败时不阻断主流程 */
}
}