1、将 Taro CLI 版本及相关依赖更新到3.2.1版本
cnpm install -g @tarojs/cli@3.2.1
2、根据用户授权获取微信头像昵称等信息
<AtButton circle type='secondary' onClick={() => this.handleGetUserProfile()}>微信快捷注册</AtButton>
// 通过getUserProfile获取微信用户信息
handleGetUserProfile = () => {
Taro.getUserProfile({
lang: 'zh_CN',
desc: "获取你的昵称、头像、地区及性别",
success: response => {
const wxUserInfo = response.userInfo;
const { openId } = this.state;
console.log('getUserProfile', wxUserInfo);
const from_url = Taro.getCurrentInstance().router?.params["from_url"];
Taro.navigateTo({url: `${ROUTER_ENUM.PAGE_USER_REGISTER}?userInfo=${JSON.stringify(wxUserInfo)}&openId=${openId || ''}&from_url=${from_url}`})
},
fail: () => {
//拒绝授权
console.error("您拒绝了请求");
return;
}
})
};