For the public number development, this is already a very old topic, before it is also done a little, but write is the back end interface, for the front end of the operation of some process is not very clear, such as a very important entry function, authorization process.

Poke me 👉 quick registration certification applet, the development version of the public number online, authorized login process code description

Speaking of authorized login, WeChat applet also has authorized login. Both of them have the same authorized login process. In both cases, the code is exchanged for openID (the user’s unique identification of the current public account or applet) and access_token. Note that access_token here is different from the access_token in the underlying support, where the access_token is generated on a per-user basis and each user is different, and the underlying access_token is the identifier for the call to the interface. Then, the front end of the small program can directly get the user information (WeChat avatar, nickname, region and gender information), while the public account needs to get the basic user information through the OpenID and Access_Token call interface.

User authorization of public accounts is divided into silent authorization (scope is snsapi_base) and non-silent authorization (scope is snsapi_userinfo) based on different scope scope. Silent authorization means that the user is authorized without awareness, but can only jump without popping up the authorization page, and can only obtain the user’s OpenID. Non-silent authorization will pop up the authorization page, and the user can get the profile picture, nickname, gender and location through OpenID. And, even in the absence of attention, as long as the user is authorized to access their information.

The effect of the public number authorized login is probably like the following, is a pop-up on entering the home page to allow users to authorize the pop-up window (non-silent authorization).

The main front-end page authorization steps are as follows

// code toreDirect () {let redirect_uri = encodeUricomponent (this.$redirect_uri); let url = this.$auth_url.replace('REDIRECT_URI',redirect_uri); if (this.wechatCode == null || this.wechatCode === '') { window.location.href = url; } else { this.saveOpenID(); }}, getUrlCode() {var url = Location.Search var ThereQuest = new Object() if (Url.IndexOf ("?"); )! = -1) { var str = url.substr(1) var strs = str.split("&") for (var i = 0; i < strs.length; i++) { theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1]) } } return theRequest }, SaveOpenId () {if(this.wechatCode) {this.getOpenId(); } }, getOpenId() { let url = this.$api_url + this.$access_token_uri + '/' + this.wechatCode; uni.request({ async: false, url: url, method: 'GET', success: (res) => { console.log('getOpenId:',res); this.userOpenid =; this.accessToken =; uni.setStorage({ key: 'user_openid', data: this.userOpenid }); this.login(); }})}, $api_url + this.$user_info_uri + '/' + this.accesstoken + '/' + this.userOpenId; uni.request({ async: false, url: url, method: 'GET', success: (res) => { console.log('login:',res); uni.setStorage({ key: 'user_info', data: }) } }) }, onLoad() { if (! this.userOpenid) { this.wechatCode = ''; this.wechatCode = this.getUrlCode().code; this.toRedirect(); }; },

Quick registration certification small procedures, free 300 yuan certification fee