I also fumble a lot of times, the first attempt success, as a novice, published their fumble out of the new. I use silent authorization, and webpage authorization with SNSAPi_base as scope. In terms of silent authorization, users have no perception. Specifically, the webpage authorization process is divided into four steps: 1

Access_token (different from access_token in base support)

3. If necessary, developers can refresh the web license access_token to avoid expiration

4. Access user basic information through web authorization Access_token and OpenID (support UnionID mechanism)

Snsapi_base and snsapi_userinfo in the scope argument by default. {let appid = config. appid let redirect_uri = webUrl? encodeURIComponent(webUrl) : EncodeURIComponent (config.websiteurl) //appid Redirect to the configuration window. The location. Href = “open.weixin.qq.com/connect/oau…” ; }, code can be obtained after authorization is successful, openID can be obtained after code is passed in, and user information can be obtained after openID is passed in. A series of operations have been completed, but an error will be reported when code is obtained. Through the localStorage. SetItem () / / get the url into the information stored in the ginseng getQueryString (name) {let reg = new RegExp (” (^ | &) “+ name +” = (/ ^ & *) (& | $) “, “i”); let r = window.location.search.substr(1).match(reg); if (r ! = null) { return decodeURI(r[2]); } return “”; }, this method is to obtain the url into the reference method Specific can refer to this link address blog.csdn.net/zengyonglan… To note here is redirect configuration issues, specific can reference many things will to 10003 error code, the need to look at your configuration is wrong, you can consult this explanation blog.csdn.net/haoxuexiaol…

** To sum up, when the page loads, you should first check whether you have logged in before (have user information), if, etc., if, ** isAuthorize(){// 1. Check whether user information exists in the cache. Let userId = localstorage.getitem ("userId"); if(userId) { this.initUserInfo(); return; } If there is no user information, see if there is code. If there is code, directly obtain the user openID and call the user information interface. If there is no user information, conduct authorization. Let code = this.getQueryString("code"); If (code == ""){// let webUrl = window.location.href; this.toWXAuthorize(webUrl); } else {// when code has been obtained, Openid getWxAuth(code)}}, openID getWxAuth(code){let _this = this request({url: '/wx/xjjkt/xcUser/getWxAuth', data: { code: code } }).then(res => { if (res.code ! = 200) {console.log(" openID failed == ", res); return; } _this.setStorage(res.data); }).catch(err=>{ console.log(err) }) }, / / get the url parameter getQueryString (name) {let reg = new RegExp (" (^ | &) "+ name +" = (/ ^ & *) (& | $) "and" I "); let r = window.location.search.substr(1).match(reg); if (r ! = null) { return decodeURI(r[2]); } return ""; }, the above is my share, I am a novice, this is my slowly pondering, if there is something wrong, code redundancy, welcome to point outCopy the code