代码
onLoad(e) {
if(e.scene){
this.regcode = e.scene;
}
if(e.regcode){
this.regcode = e.regcode;
}
var app_type = this.isWeiXin() ? 'wechat' : 'h5';
var app_type_name = this.isWeiXin() ? '微信公众号' : 'H5';
if(app_type == 'wechat'){
console.log('微信公众号环境')
this.checkWeChatCode();
}
},
methods: {
checkWeChatCode() {
this.code = this.$u.comFun.getUrlCode('code')
if (this.code) {
this.getLogin(this.code)
} else {
let url = {
redirect_url:window.location.href
}
this.$u.api.getAuthUrl(url).then(res=>{
if(res.code == 1){
window.location.href = res.data.url
}
});
}
},
async getLogin(code){
let data = {
code:code,
regcode:this.regcode
}
const res = await this.$u.api.authByCode(data);
if (res.code == 1) {
this.$u.vuex('vuex_token', res.data.token.access_token)
this.$u.vuex('vuex_userInfo', res.data.member)
this.$store.dispatch('material').then(m => {
this.$refs.uToast.show({
message: res.msg,
type: 'success',
complete: () => {
this.$u.comFun.losePageUrl()
}
})
})
}
},
isWeiXin() {
return false;
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == "micromessenger") {
return true;
} else {
return false;
}
},
}
配置
- 登录微信公众号后台 https://mp.weixin.qq.com/
- 关注相关项目 公众号
- 设置网页授权域名,把文件下载下来发给后端,把text文件上传到服务器根目录下


