通过微信链接重定向获取code


const Appid='appid' 

const code = theRequest.code

const redirect_uri =encodeURIComponent('http://192.168.10.90:8080/#/login') //重定向的地址并且进行编码

if (code == null ||code ==='') { 

    window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + Appid +     '&redirect_uri='+redirect_uri+'&response_type=code&scope=snsapi_base&state=123#wechat_redirect'

}

//重定向以后code会出现在链接上

获取链接中code

var userip=returnCitySN["cip"]

var url = location.search; //获取url中"?"符后的字符串

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]);

  }

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容