微信公衆番号のホームページはurlパラメータを取得することを許可します

5029 ワード

微信公衆番号のホームページの授権

// 1. 
window.location.href
// 2. 
var querys = url.substring(url.indexOf('?') + 1).split('&')
var result = []
 for (var i = 0; i < querys.length; i++) {
   var temp = querys[i].split('=')
   if (temp.length < 2) {
     result[temp[0]] = ''
   } else {
     result[temp[0]] = temp[1]
   }
 }
 console.log(result)
 // 3.  
const local = 'http%3a%2f%2flocal.natsabdjii.top%2f%23%2ftext' //  UrlEncode 
const AppId = 'wx9999a55309df2545' // appid
const state = result.tenantForm + '/' + result.btntype + '/' + result.record_id
window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + AppId + '&redirect_uri=' + local + '&response_type=code&scope=snsapi_userinfo&state=' + state + '#wechat_redirect'