收藏
回答

在登录页获取code, redirect_uri 配置的连接 导致项目来回跳转,首页登录页来回跳转

框架类型 问题类型 操作系统版本 手机型号 微信版本
小程序 Bug Windows 11 家庭版 iphone 13pro 1.06.2404020

// 检查URL中是否包含code参数

checkCode() {

const urlParams = new URLSearchParams(window.location.search);

const code = urlParams.get('code');

const state = urlParams.get('state');

if (code && state) {

// 如果有code,则存起来

if (this.codeUsed) {

this.wxLogin()

} else {

this.wxCode = code

this.state = state

}

} else {

// 如果没有code,可能是授权失败,给出提示或处理

this.wxLogin()

}

},

// 通过type / 域名 获取code

wxLogin() {

getSocialRedirect({

type: 31, // 31:微信公众号 34:微信小程序

redirectUri: BASEURL, // BASEURL,

}).then(res => {

window.location.href = res.data // 去获取code

this.getUrlCode(res.data)

this.codeUsed = false

}).catch(err => {

uni.showToast({

title: err.msg,

icon: 'none'

})

})

},

回答关注问题邀请回答
收藏
登录 后发表内容