WeChat applet gets the mobile phone number authorized user login function

There are many places in the applet to use the registered user information. Users need to fill in the mobile phone number. With this component, this component can quickly get the WeChat binding mobile phone number, and no user is filled in.

1.Getphonenumber This component is implemented by Button (other label invalid). Bring the open-type = “getphone” in Button, and bind the BindgetPhoneNumber event to get the callback.

      App ({ONLAUNCH: Function () {wx.login ({Success: Function (RES) {if (res.) {// initiate network request console. Log (res.}}} {console.log ('Get user login state failed!' + res. hydrsg)}}});}}) 

3 Get the callback by binding events bound by BindgetPhonenumber. There are three parameters of the callback,
Errmsg: The user clicks the information callback of cancellation or authorization.
  IV: The initial vector of the encryption algorithm (if the user does not agree to authorize the undefined).  EncryptedData:User information encrypted data (if the user did not agree to authorize the same returned) 

GetPhoneNumber: Function (E) {Console.log e.detail.errmsg) console.log (e.detail.EncryptedData) if (e.detail.errmsg == ‘getPhonenumber: fail user deny’) {wx.showmodal ({Title : ‘Tip’, ShowCancel: False, Content: ‘Unauthorized’, Success: Function (RES) {}}}} else {wx.showmodal ({Title: ‘prompt’, showcancel: false, content: ‘agreed to authorize , Success: Function (RES) {}}}}

Finally, we need to process according to your business logic. If the user does not agree to authorize, we may There will be an interface that makes him manually entered. If it is not forced to get the mobile phone number, you can directly jump the page for the next step. (User does not agree to authorize errmsg to return ‘getPhoneNumber: fail user deny’)

微信小程序获取手机号授权用户登录功能 5. We can obtain session_Key through the background according to the Code obtained by Login, and we can get session_Key through the background and WeChat processing. Over the app_ID, session_key, iv, encrypteddata (user agreed authorized errmsg Returning ‘getphoneEnumber: ok’)

The above is a small text that Xiaobian introduced WeChat small The program acquires the mobile phone number authorized user login function, I hope to help everyone. If you have any questions, please leave a message, Xiaobian will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website!
                     
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment