ajax 微信code获取_vue 获取微信授权成功code值
Category:前端Views:669Comments:2Posted on:2019-06-12export default {name: 'app',mounted() {let script1 = document.createElement("script");script1.type = "text/javascript";script1.src = "http://r...
Category : 前端
Views : 669
Comments : 2
Posted on : 2019-06-12
export default {
name: 'app',
mounted() {
let script1 = document.createElement("script");
script1.type = "text/javascript";
script1.src = "http://res.wx.qq.com/open/js/jweixin-1.2.0.js";
document.body.appendChild(script1);
let ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i) == "micromessenger") {
if(window.location.search.indexOf('code') < 0) {
window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx71c3c2414bc6ab7b&redirect_uri=' + encodeURIComponent(location.href) + '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
} else if(window.location.search.indexOf('code') > -1) {
let code = this.getUrlKey("code");
alert('前端获取到的code为:' + code);
localStorage.setItem('wechatcode', code);
}
}
},
methods: {
getUrlKey(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null;
}
}
}
Posted by : 雨落秋垣
Tags : 本文未设置标签
您可以自由的转载和修改,但请务必注明文章来源并且不可用于商业目的。
本站部分内容收集于互联网,如果有侵权内容、不妥之处,请联系我们删除。敬请谅解!
已有 2 条评论
回复 小白: 这个是线上的代码。我直接复制出来的。一个商城的商品使用微信商户付款中,需要获取code的代码。没有改过哦
添加新评论
提交评论

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐
所有评论(0)