小程序修改
This commit is contained in:
@@ -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 {
|
||||
/* 用户拒绝或上报失败时不阻断主流程 */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user