微博三方登录功能
2022-04-07 本文已影响0人
秀萝卜
1.基本代码
微博pc端和h5的三方登录都一样,超级简单
举个例子:
let redirect_url = "http://www.xxxxxxx.com/login";
let url = "https://api.weibo.com/oauth2/authorize?client_id=11*****&redirect_uri=" + redirect_url;
window.location.href = url
页面跳转到新浪微博的登录页面,授权登录后,跳转回redirect_url页面,并且带上参数code(code只可以用一次并且有时间限制)我们获取该code。
this.code = this.$route.query.code
this.state = this.$route.query.state(state是用来区分微信的)
// 微博
if (this.code && !this.state) {
this.weibo_config()
}
使用该code调用后台接口,获取openId
var url = 'front/thirdparty/getWBConfig?code=' + this.code
Util.showLoading()
var data = await Util.fetch(url)
......
2.实际使用问题:
h5三方登录,打开微博app,点击授权登录后,不能跳转回原本的浏览器页面
ios直接不能打开微博app