const base_url = encodeURIComponent('xxxxxx/wx/index.html')// 前端域名
const wx_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=xxxxxx+'&redirect_uri='+base_url+'&response_type=code&scope=snsapi_base&state=123#wechat_redirect'
onLoad() {
// 获取URL 上code
if(!this.isWechat()){
window.location.href="http://www." ;
return
}
const code = this.getUrlParam('code')
// 判断是否存在code
if(code == null || code == '') {
// 重新获取code
// console.log(code)
window.location.href = wx_url
} else {
// 发送code
this.postCode(code)
}
this.init()
var uanew = window.navigator.userAgent.toLowerCase();
if (uanew.match(/micromessenger/i) == 'micromessenger') {
//console.log('是微信客户端')
this.iswechat=false
} else {
//console.log('不是微信客户端')
this.iswechat=true
}
},
method:{
// 解析URL 参数
getUrlParam(name) {
let reg = new RegExp('(^|&)'+ name + '=([^&]*)(&|$)')
let r = window.location.search.substr(1).match(reg)
if(r!=null){
return unescape(r[2])
}
return null
},
//判断是否在微信中
isWechat() {
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/micromessenger/i) == 'micromessenger') {
//console.log('是微信客户端')
return true;
} else {
//console.log('不是微信客户端')
return false;
}
},
}
不懂的联系我(找昵称)
3 个评论
要回复文章请先登录或注册
王翔
2***@qq.com
6***@qq.com