Wechat public number H5 to obtain the user code, the following is a copy of all the code can be used to fill in their own AppID and redirect_URI, URL needs to encodeURIComponent processing

GetUrlCode () {var url = window.location.href this.winurl = url // If (url.indexof ("?") )! = 1) {let obj = this.urltoobj (url) console.log(1111,obj.code)} else {// if not, call getCode below to getCode this.getcode ()} }, getCode method getCode() {this.code = "var appid =" // own appid var redirect_uri = 'http://devotc-m.ydjk5.com/#/pages/Login/Login' // own callback URL redirect_uri = (redirect_uri + ").tostring (); // redirect_uri = encodeURIComponent(redirect_uri).replace(/! /g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28'). replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');  history.pushState(null, null, "/"); window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${redirect_uri}&response_type=code&scop e= snsapi_userinfo&state=123&component_appid=wxfd4a6038404bd033#wechat_redirect` }, UrlToObj (STR) {var obj = {}; var arr1 = str.split("?" ); var arr2 = arr1[1].split("&"); for (var i = 0; i < arr2.length; i++) { var res = arr2[i].split("="); obj[res[0]] = res[1]; } return obj; },Copy the code