18年6月最新微信小程序获取用户名、授权弹窗方法

首先说下现在wx.getUserInfo接口已经废弃,也就是你不能通过该接口获取nickName等信息,更不必说授权的弹窗。

其次,新的方法是通过

<button open-type="getUserInfo" lang="zh_CN" bindgetuserinfo="onGotUserInfo"  class='login-button'>点击授权</button>

以一个按钮的形式,点击弹出弹窗,用户再进行授权。

我们只能通过改变button的样式进行美化了。

js部分参考:

onGotUserInfo: function (e) {
      if(e.detail.userInfo != null){    //用户点击允许授权
        app.imageUrl = e.detail.userInfo.avatarUrl,
        app.nickName = e.detail.userInfo.nickName,
        app.authorize = true;
      }
  },


猜你喜欢

转载自blog.csdn.net/qq_32117641/article/details/80554966