debug: silenceAuth 增加成功/失败响应日志,验证新用户 openid 获取

This commit is contained in:
2026-07-31 12:09:35 +08:00
parent a600dc05f7
commit 45aade9a7a

12
App.vue
View File

@@ -108,16 +108,20 @@
// #endif // #endif
// #ifdef MP // #ifdef MP
// 小程序静默授权 // 小程序静默授权
console.log('[auth-flow] App onLaunch: isLogin=' + this.$store.getters.isLogin + ', expired=' + this.getExpired());
if (!this.$store.getters.isLogin) { if (!this.$store.getters.isLogin) {
Routine.getCode().then(code => { Routine.getCode().then(code => {
console.log('[auth-flow] App onLaunch: wx.login 拿到 code=' + (code ? code.substring(0, 10) + '...' : '(空)'));
this.silenceAuth(code); this.silenceAuth(code);
}).catch(res => { }).catch(res => {
console.warn('[auth-flow] App onLaunch: wx.login 失败', res);
uni.hideLoading(); uni.hideLoading();
}); });
}else if(this.$store.getters.isLogin && this.getExpired()){ }else if(this.$store.getters.isLogin && this.getExpired()){
//处理小程序有token情况下但是静默授权失败 //处理小程序有token情况下但是静默授权失败
this.$Cache.clear(LOGIN_STATUS); this.$Cache.clear(LOGIN_STATUS);
Routine.getCode().then(code => { Routine.getCode().then(code => {
console.log('[auth-flow] App onLaunch: token过期,重新静默授权 code=' + (code ? code.substring(0, 10) + '...' : '(空)'));
this.silenceAuth(code); this.silenceAuth(code);
}) })
} }
@@ -222,12 +226,14 @@
silenceAuth(code) { silenceAuth(code) {
let that = this; let that = this;
let spid = that.globalData.spid ? that.globalData.spid : ''; let spid = that.globalData.spid ? that.globalData.spid : '';
console.log('[auth-flow] silenceAuth 发起, code=' + (code ? code.substring(0, 10) + '...' : '(空)'));
silenceAuth({ silenceAuth({
code: code, code: code,
spread_spid: spid, spread_spid: spid,
spread_code: that.globalData.code spread_code: that.globalData.code
}) })
.then(res => { .then(res => {
console.log('[auth-flow] silenceAuth 响应:', JSON.stringify(res.data || res).substring(0, 200));
if (res.data.token !== undefined && res.data.token) { if (res.data.token !== undefined && res.data.token) {
uni.hideLoading(); uni.hideLoading();
let time = res.data.expires_time - this.$Cache.time(); let time = res.data.expires_time - this.$Cache.time();
@@ -237,10 +243,14 @@
}); });
that.$store.commit('SETUID', res.data.userInfo.uid); that.$store.commit('SETUID', res.data.userInfo.uid);
that.$store.commit('UPDATE_USERINFO', res.data.userInfo); that.$store.commit('UPDATE_USERINFO', res.data.userInfo);
console.log('[auth-flow] ✅ silenceAuth 成功, token 已存 store (含 openid)');
} else {
console.warn('[auth-flow] ⚠️ silenceAuth 返回无 token:', JSON.stringify(res.data || res).substring(0, 200));
} }
}).catch(err => { }).catch(err => {
console.warn('[auth-flow] ❌ silenceAuth 失败:', JSON.stringify(err).substring(0, 300));
return that.$util.Tips({ return that.$util.Tips({
title:err title: err
}) })
}); });
}, },