Loading…

WeChat Mini Program One-click login with mobile phone number

First, you need to use the login api of `WeChat Mini Program` to obtain the temporary `code` of the current user: ["WeChat Mini Program login api instructions"](https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html) After getting the `code`, call the WeChat Mini Program's mobile phone number acquisition interface: ["Get mobile phone number"](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html) Complete login: ```javascript WXAPI.loginWxaMobileV3({ code: '', codeMobile: '', autoReg: true, postJsonString: '', referrer: '', pwd: '' }) ``` + code The user temporary code of WeChat Mini Program obtained in the previous step + codeMobile returns the code after clicking the button. For details, see [https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html](https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/getPhoneNumber.html) + If autoReg is true, it will automatically register when the user does not exist, otherwise it will directly return an error that the user does not exist. + postJsonString If the user does not exist, autoReg is true, and the json data of the user's extended attributes is saved when registering a new user (requires a string) + referrer If the user does not exist, autoReg is true, and the inviter information is saved when registering a new user. + pwd If the user does not exist, autoReg is true, set this login password when registering a new user ```json { "code": 0, "data": { "uid": 1351478, "openid": "om3AQ0YaRp3RZtFuZ1Wgk0OdQjvA", "mobile": "1860000062", "token": "83065b5e-9a75-4e64-8692-4f03eaa90348" }, "msg": "success" } ``` + uid After successful login, return the user number + openid is the openid of the current WeChat user corresponding to the current mini program + mobile is the current user’s mobile phone number + token is the token returned after the user logs in. Many subsequent user-related operations require the token to be operated.