New version of access to user information authorization

Include the user’s nickname, avatar, and so on

<button bindtap="bindGetUserInfo" class="btnPhone {{wechat_name ! = ' '? 'btnPhoneActive':'}}">Copy the code
BindGetUserInfo: function(res) {var that = this // getUserProfile wx.getUserProfile({desc: 'display of user information, / / can't be empty success (res) {the console. The log (" xinban for user information, "res) that. SetData ({wechat_name: res. The userInfo. NickName, headimgurl:res.userInfo.avatarUrl, province:res.userInfo.province, country:res.userInfo.country, Gender: res. The userInfo. Gender, city: res. The userInfo. City,}) that. PostInfo () wx. ShowToast ({title: 'authorization success! ', // title icon: 'success', // icon type, default success duration: 1500 // Prompt window duration, default 1500ms})}}) console.log(res); }, // pop authorization endCopy the code

Wechat mini program to obtain mobile phone number authorization

<button open-type="getPhoneNumber" bindgetphonenumber="getPhoneNumber" class="btnPhone {{mobile ! = ' '? 'btnPhoneActive':'}}">Copy the code
GetPhoneNumber: function (e) { console.log(e) var ivObj = e.detail.iv var telObj = e.detail.encryptedData var codeObj = ""; var that = this; / / -- -- -- -- -- - to perform the Login -- -- -- -- -- -- -- -- - wx. Login ({success: res = > {the console. The log (' code conversion, res. Code). UserGetMobile ({vcode: res.code, encryptedData: telObj, iv: encryptedData: telObj; IvObj}). Then (res = > {the console. The log (" phone number "success, res). The console log (" res. Data. The data. The phoneNumber," res. Data. The data. The phoneNumber) that.setData({ mobile:res.data.data.phoneNumber, openid:res.data.data.openid, unionid:res.data.data.unionid, }) / / the console. The log (" mobile number = ", res. Data. The data. The phoneNumber) / / post request that the postInfo () wx. ShowToast ({title: 'access to success in mobile phone number! ', // title icon: 'success', // icon type, default success duration: 1500 / / prompt window residence time, the default 1500 ms})}) / / -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- whether authorization, authorized by to enter the main page, If (e.dail. errMsg == 'getPhoneNumber:user deny') {// wx.navigateTo({// url: '.. / index/index ', / /})} else {/ / allows authorized to perform jump. / / wx navigateTo ({/ / url: '.. /test/test', // }) } } }); }, // Get the phone numberCopy the code

Applets location authorization

<button bindtap="getLocation" class="btnPhone {{lng ! = ' '? 'btnPhoneActive':'}}">Copy the code
GetLocation () {var that = this wx.getLocation({success: Function (res) {console.log(" location ",res) app.globaldata.lat = res.latitude; function(res) {console.log(" location ",res) app.globaldata.lat = res.latitude; app.globalData.lon = res.longitude; SetData ({LNG :res.longitude, lat:res.latitude}) // post request that.postinfo () wx.showtoast ({title: 'Obtain position successfully! ', // title icon: 'success', // icon type, default success duration: 1500 // Prompt window duration, default 1500ms})}, fail() {wx.showmodal ({title: 'Reminder ', content: 'You have refused location authorization and will not be able to use most features, Click OK to re-license ', Success (res) {if (res.confirm) {wx.opensetting ({success(res) {userLocation=true if (res. AuthSetting [" scope. UserLocation "]) {/ / that the onLoad ()}}}}}}}}}))), / / to get end locationCopy the code

Check whether the user is authorized

Wx.getsetting ({success: function(res) {if (res.authSetting[' scope.userinfo ']) {console.log(" user authorized "); console.log(res); wx.getUserInfo({ success: Res => {console.log(" User authorization information ",res) app.globaldata.userInfo = res.userinfo // service code}})} else {// The user is not authorized Console. log(" user is not authorized "); } console.log("res.authSetting",res.authSetting) if (res.authSetting['scope.userLocation']) {console.log(" user authorized location ");  } else {console.log(" user has no authorized location "); }}}); // Authorization endsCopy the code

Scan code to add group or get information