@@ -203,7 +203,7 @@ export class WechatService extends SocialService {
203203
204204 migrationQrCode ( type : 'new' | 'old' = 'new' ) {
205205 const isOld = type === 'old' ;
206- const state = this . setState ( 'open_weixin' ) ;
206+ const state = this . setState ( 'open_weixin' , type ) ;
207207 this . cleanExpiresState ( ) ;
208208 return {
209209 state,
@@ -215,7 +215,7 @@ export class WechatService extends SocialService {
215215
216216 migrationAuthUrl ( type : 'new' | 'old' = 'new' ) : string {
217217 const isOld = type === 'old' ;
218- const state = this . setState ( 'weixin' ) ;
218+ const state = this . setState ( 'weixin' , type ) ;
219219 this . cleanExpiresState ( ) ;
220220 return `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${ isOld ? this . oldAppId : this . appId } &redirect_uri=${ encodeURIComponent ( this . migrationRedirectUri ) } &response_type=code&scope=snsapi_userinfo&state=${ state } #wechat_redirect` ;
221221 }
@@ -228,9 +228,14 @@ export class WechatService extends SocialService {
228228 if ( ! stateInfo ) {
229229 throw new UnauthorizedException ( 'Invalid state identifier' ) ;
230230 }
231+ const isOld = state . startsWith ( 'old_' ) ;
231232 const isWeixin = stateInfo . type === 'weixin' ;
232- const appId = isWeixin ? this . oldAppId : this . oldOpenAppId ;
233- const appSecret = isWeixin ? this . oldAppSecret : this . oldOpenAppSecret ;
233+ const rawAppid = isOld ? this . oldAppId : this . appId ;
234+ const rawAppsecret = isOld ? this . oldAppSecret : this . appSecret ;
235+ const rawOpenAppid = isOld ? this . oldOpenAppId : this . openAppId ;
236+ const rawOpenAppsecret = isOld ? this . oldOpenAppSecret : this . openAppSecret ;
237+ const appId = isWeixin ? rawAppid : rawOpenAppid ;
238+ const appSecret = isWeixin ? rawAppsecret : rawOpenAppsecret ;
234239 const accessTokenResponse = await fetch (
235240 `https://api.weixin.qq.com/sns/oauth2/access_token?appid=${ appId } &secret=${ appSecret } &code=${ code } &grant_type=authorization_code` ,
236241 ) ;
0 commit comments