公司需求:微博,qq和微信三方登录
微信只支持微信内置浏览器
qq授权登录pc端和h5端是一样的。需要先申请qq互联,
入门参考资料:https://blog.csdn.net/m0_46846526/article/details/119243300
1.在index.html中引入
<script type="text/javascript"src="https://qzonestyle.gtimg.cn/qzone/openapi/qc_loader.js" charset="utf-8"></script>
2.使用
QC.Login.showPopup({
appId: "1********5",
redirectURI: "http://wx.xxxxx.com/login", //登录成功后会自动跳往该地址
});
3.获取回调地址的内容,得到openId,使用openId请求后台接口
回调的格式类似:
mounted() {
this.code = this.$route.query.code
this.state = this.$route.query.state
// 微博
if (this.code && !this.state) {
this.weibo_login_redirect()
} else if (this.$route.hash.indexOf("#access_token") != -1) {
this.qq_login_redirect()
} else if (this.code && !this.state) {
this.weixin_login_redirect(obj)
}
}
qq_login_redirect() {
let that = this;
// 检查是否登录
if (QC.Login.check()) {
QC.Login.getMe(function (openId, accessToken) {
if (openId) {
that.openId = openId;
that.qq_login_redirect_confim()
}
});
} else {
console.log("未登录!");
}
},
// 调用后台接口,判断是否已绑定,如果已经绑定,那么返回用户登录信息
async qq_login_redirect_confim() {
let obj = {
openID: this.openId,
thirdType: "qq",
};
var url = 'front/thirdparty/login'
Util.showLoading()
var data = await Util.post(url, obj, 1)
if (data.status == '200') {
// ifReg需要绑定账号
if (data.data.ifReg) {
var query = {
openId: this.openId,
thirdType: 'qq'
}
this.$router.push({ path: '/thirdBind', query })
} else {
// 返回用户的信息data.data
this.publicData(data.data);
}
}
},
网友评论