Micro-channel applets to obtain the user nickname, avatar

Some time ago a small micro-channel program to get the user nicknames and avatars methods have been updated, many online articles are no longer applicable, briefly summarize here, first of all, the effect of traditional interfaces wx.getUserInfo will bring up a pop to the user, need user authorization, tested traditional wx.getUserInfo is still usable, but there will be in use when the official log to remind you that this approach needs to be upgraded. Then is the latest method Open-data provided by the official label, the label can not use direct access to authorized users avatars and nicknames

example:

<Open Data-type = " userAvatarUrl " > </ Open-Data>     // Get user avatar displayed directly in the applet 
<Open Data-type = " userNickName " lang = " zh_CN " > </ Open-Data>     // nickname get displayed directly in the applet

The final step is flexible Open-data use

<button open-type='getUserInfo' lang="zh_CN" bindgetuserinfo="onGotUserInfo"></button>

Button will be written into the tag as a property of open-data, so the effect becomes nickname acquisition head and clicks

The method of obtaining the function obtained in like

onGotUserInfo: function (e) {
    console.log("nickname=" + e.detail.userInfo.nickName);
  }

Specifically how to use the analysis is different in different circumstances, like a little flexible

Guess you like

Origin www.cnblogs.com/xubao/p/12164507.html