Просмотр исходного кода

😁公众号和小程序登录接口token增加有效期

zuohuaijun 2 лет назад
Родитель
Сommit
397d63ad75

+ 7 - 2
Admin.NET/Admin.NET.Core/Service/Wechat/SysWechatService.cs

@@ -18,13 +18,16 @@ public class SysWechatService : IDynamicApiController, ITransient
     private readonly SqlSugarRepository<SysWechatUser> _sysWechatUserRep;
     private readonly WechatApiClient _wechatApiClient;
     private readonly WechatApiHttpClient _wechatApiHttpClient;
+    private readonly SysConfigService _sysConfigService;
 
     public SysWechatService(SqlSugarRepository<SysWechatUser> sysWechatUserRep,
-        WechatApiHttpClient wechatApiHttpClient)
+        WechatApiHttpClient wechatApiHttpClient,
+        SysConfigService sysConfigService)
     {
         _sysWechatUserRep = sysWechatUserRep;
         _wechatApiClient = wechatApiHttpClient.CreateWechatClient();
         _wechatApiHttpClient = wechatApiHttpClient;
+        _sysConfigService = sysConfigService;
     }
 
     /// <summary>
@@ -91,6 +94,8 @@ public class SysWechatService : IDynamicApiController, ITransient
         var wxUser = await _sysWechatUserRep.GetFirstAsync(p => p.OpenId == input.OpenId);
         if (wxUser == null)
             throw Oops.Oh("微信用户登录OpenId错误");
+
+        var tokenExpire = await _sysConfigService.GetTokenExpire();
         return new
         {
             wxUser.Avatar,
@@ -99,7 +104,7 @@ public class SysWechatService : IDynamicApiController, ITransient
                 { ClaimConst.UserId, wxUser.Id },
                 { ClaimConst.NickName, wxUser.NickName },
                 { ClaimConst.LoginMode, LoginModeEnum.APP },
-            })
+            }, tokenExpire)
         };
     }
 

+ 7 - 2
Admin.NET/Admin.NET.Core/Service/Wechat/SysWxOpenService.cs

@@ -17,12 +17,15 @@ public class SysWxOpenService : IDynamicApiController, ITransient
 {
     private readonly SqlSugarRepository<SysWechatUser> _sysWechatUserRep;
     private readonly WechatApiClient _wechatApiClient;
+    private readonly SysConfigService _sysConfigService;
 
     public SysWxOpenService(SqlSugarRepository<SysWechatUser> sysWechatUserRep,
-        WechatApiHttpClient wechatApiHttpClient)
+        WechatApiHttpClient wechatApiHttpClient,
+        SysConfigService sysConfigService)
     {
         _sysWechatUserRep = sysWechatUserRep;
         _wechatApiClient = wechatApiHttpClient.CreateWxOpenClient();
+        _sysConfigService = sysConfigService;
     }
 
     /// <summary>
@@ -100,6 +103,8 @@ public class SysWxOpenService : IDynamicApiController, ITransient
         var wxUser = await _sysWechatUserRep.GetFirstAsync(p => p.OpenId == input.OpenId);
         if (wxUser == null)
             throw Oops.Oh("微信小程序登录失败");
+
+        var tokenExpire = await _sysConfigService.GetTokenExpire();
         return new
         {
             wxUser.Avatar,
@@ -108,7 +113,7 @@ public class SysWxOpenService : IDynamicApiController, ITransient
                 { ClaimConst.UserId, wxUser.Id },
                 { ClaimConst.RealName, wxUser.NickName },
                 { ClaimConst.LoginMode, LoginModeEnum.APP },
-            })
+            }, tokenExpire)
         };
     }