This commit is contained in:
abearxiong 2025-03-29 20:33:06 +08:00
parent 865cd3fee3
commit f09549b61e
3 changed files with 12 additions and 3 deletions

View File

@ -3,7 +3,6 @@ import path from 'path';
export const env = dotenv.config({ export const env = dotenv.config({
path: [path.resolve(process.cwd(), '.env'), path.resolve(process.cwd(), '.env.wxopen')], path: [path.resolve(process.cwd(), '.env'), path.resolve(process.cwd(), '.env.wxopen')],
}); });
console.log(env.parsed);
export const config = { export const config = {
domain: env.parsed?.DOMAIN, domain: env.parsed?.DOMAIN,

View File

@ -109,7 +109,6 @@ export const refreshToken = async (refreshToken: string): Promise<RefreshToken>
const refreshUrl = `https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=${appId}&grant_type=refresh_token&refresh_token=${refreshToken}`; const refreshUrl = `https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=${appId}&grant_type=refresh_token&refresh_token=${refreshToken}`;
const res = await fetch(refreshUrl); const res = await fetch(refreshUrl);
const data = await res.json(); const data = await res.json();
console.log(data);
return data; return data;
}; };

View File

@ -30,6 +30,16 @@ export class WxServices {
}, },
}, },
}); });
// @ts-ignore
if (user && user.data.wxOpenid !== token.openid) {
user.data = {
...user.data,
// @ts-ignore
wxOpenid: token.openid,
};
await user.update({ data: user.data });
console.log('mp-user login openid update=============', token.openid, token.unionid);
}
if (!user) { if (!user) {
user = await User.createUser(unionid, unionid.slice(0, 8)); user = await User.createUser(unionid, unionid.slice(0, 8));
user.data = { user.data = {
@ -38,9 +48,10 @@ export class WxServices {
wxOpenid: token.openid, wxOpenid: token.openid,
wxUnionId: unionid, wxUnionId: unionid,
}; };
await user.save({ fields: ['data'] });
this.isNew = true; this.isNew = true;
} }
console.log('mp-user login=============', token.openid, token.unionid);
const tokenInfo = await user.createToken(null, 'plugin', { const tokenInfo = await user.createToken(null, 'plugin', {
wx: { wx: {
openid: token.openid, openid: token.openid,