Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信小程序授权后使用 Taro.getUserInfo(option) 返回结果为空 #9176

Closed
twwch opened this issue Apr 24, 2021 · 3 comments
Closed
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@twwch
Copy link

twwch commented Apr 24, 2021

相关平台

微信小程序

小程序基础库: 2.1.16
使用框架: React

复现步骤

Taro.getUserInfo().then(res => {
console.log(res);
})

输出的userinfo为空
{errMsg: "getUserInfo:ok", rawData: "{"nickName":"微信用户","gender":0,"language":"","city"…GKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132"}", userInfo: {…}, signature: "87abb8b8385a04d830bf0f1eb1caa73f4458f370", encryptedData: "mEaVcoqPzTSFIPzLUvtpL8l25Dt3/30tuyPN4FNs1ozoLWuTpi…EUBCO90tg6Dj1mzcabtd8T1AQryi/pMyANkS0ijsY5ji69w==", …}
cloudID: "44_BBEQirmFizXKYgoCzBXP87RzGAi2hc2QGUajnKh5513xTO-55_sISBOmTc0"
encryptedData: "mEaVcoqPzTSFIPzLUvtpL8l25Dt3/30tuyPN4FNs1ozoLWuTpiRsQsT5bgl2tvy0Y1dBzniIHyAjpbqJGaxe O Nt059gy1mHHuTN6AaQJqwIw4Wj2jIyPDGdI5litMQnxEWC9a0zYwRUsampwdBmuAUv/tIF2sXB6fwSD 4KYcNZb8ECq72S9ACKfcDnQIWQbUz1HbqSbj8C4G36GMC6R63PpMxf3vKuxTkc Vj5nIpGFdxUhkaC4IkaxdFsyTSOajLauGa9q/PStk/OKPmP7VMYa2T90jh6gEjzFf0jeEBX/gNH3aIGnFD6mMMr2jrkjmR NY8Y4jtARZWzETMZZyZlW7dWuz8sqtK0gUQozI 3KIAR8htPl4bY9XzxUbmz0dLCMQ0PPSI4z2p7F1MUX71lzUS1dCECtj1KVLEUBCO90tg6Dj1mzcabtd8T1AQryi/pMyANkS0ijsY5ji69w=="
errMsg: "getUserInfo:ok"
iv: "LtL/pB7fF1wg7Rc U 6n A=="
rawData: "{"nickName":"微信用户","gender":0,"language":"","city":"","province":"","country":"","avatarUrl":"https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4nibH0KlMECNjjGxQUq24ZEaGT4poC6icRiccVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132"}"
signature: "87abb8b8385a04d830bf0f1eb1caa73f4458f370"
userInfo: {nickName: "微信用户", gender: 0, language: "", city: "", province: "", …}

期望结果

返回用户信息

实际结果

用户信息为空

环境信息

Taro CLI 3.2.1 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 12.16.1 - D:\devtools\nodejs\node.EXE
      npm: 6.13.4 - D:\devtools\nodejs\npm.CMD   

补充信息

@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Apr 24, 2021
@fangmd
Copy link

fangmd commented Apr 24, 2021

我也有这个问题:

          <Button className="btn" openType="getUserInfo" onGetUserInfo={this.onGetUserInfo} type="primary" lang="zh_CN">
            用户授权
          </Button>

发现 taro 文档更新了,可以用这个:

// 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认
// 开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
Taro.getUserProfile({
  desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  success: (res) => {
    this.setState({
      userInfo: res.userInfo,
      hasUserInfo: true
    })
  }
})

@iamxiyang
Copy link

这是微信小程序升级引起的,详见微信公告:https://developers.weixin.qq.com/community/develop/doc/000ecabcb642185cfdfb78fe056c01?blockType=1

你可以参照楼上提到的API Taro.getUserProfile 获取微信个人资料。建议平常多关注下微信公告、Taro更新动态,这项改动很久之前就已经发出公告了,而Taro也早就适配了新的API

@Chen-jj
Copy link
Contributor

Chen-jj commented Apr 25, 2021

楼上正解~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

4 participants