qinchaoyue 2 долоо хоног өмнө
parent
commit
96aaa75307

+ 2 - 1
src/Hotline.Api/Controllers/TestController.cs

@@ -254,7 +254,8 @@ public class TestController : BaseController
         var inDto = new ThirdTokenDto
         {
             AppId = _systemSettingCacheManager.WxOpenAppId,
-            Secret = _systemSettingCacheManager.WxOpenAppSecret
+            Secret = _systemSettingCacheManager.WxOpenAppSecret,
+            WebApiHost = "http://10.56.131.9:50200/wxapi/"
         };
         return await _thirdIdentiyService.GetPhoneNumberAsync(inDto, CancellationToken.None);
     }

+ 5 - 0
src/Hotline.Share/Dtos/Snapshot/ThirdTokenDto.cs

@@ -31,6 +31,11 @@ public class ThirdTokenInDto
     /// 3: 市民办件app
     /// </summary>
     public EAppType AppType { get; set; } = EAppType.Snapshot;
+
+    /// <summary>
+    /// 接口地址前缀
+    /// </summary>
+    public string? WebApiHost { get; set; }
 }
 
 public class ThirdPhoneInDto : ThirdTokenInDto { }

+ 9 - 0
src/Hotline.WeChat/WeChatService.cs

@@ -1,5 +1,6 @@
 using Hotline.Settings;
 using Hotline.Share.Dtos.Snapshot;
+using Hotline.Share.Tools;
 using Hotline.ThirdAccountDomainServices.Interfaces;
 using Microsoft.Extensions.Logging;
 using Senparc.CO2NET.Extensions;
@@ -27,6 +28,7 @@ public class WeChatService : IThirdIdentiyService, IScopeDependency
     {
         try
         {
+            GetWebApiHost(dto.WebApiHost);
             var result = await SnsApi.JsCode2JsonAsync(dto.AppId, dto.Secret, dto.LoginCode);
             _systemLog.Add("微信获取Token", dto, status: 1, executeResult: result.ToJson());
             if (result.errcode != ReturnCode.请求成功) throw UserFriendlyException.SameMessage("获取微信用户信息失败");
@@ -47,6 +49,7 @@ public class WeChatService : IThirdIdentiyService, IScopeDependency
     /// <returns></returns>
     public async Task<ThirdPhoneOutDto> GetPhoneNumberAsync(ThirdTokenDto dto, CancellationToken token)
     {
+        GetWebApiHost(dto.WebApiHost);
         await AccessTokenContainer.RegisterAsync(dto.AppId, dto.Secret);
         _logger.LogInformation($"GetPhoneNumberAsync: {dto.ToJson()}");
         var result = await BusinessApi.GetUserPhoneNumberAsync(dto.AppId, dto.TelCode);
@@ -61,4 +64,10 @@ public class WeChatService : IThirdIdentiyService, IScopeDependency
             PhoneNumber = result.phone_info?.phoneNumber,
         };
     }
+
+    private void GetWebApiHost(string? webApiHost)
+    {
+        if (webApiHost.NotNullOrEmpty())
+            Config.ApiMpHost = webApiHost;
+    }
 }

+ 4 - 3
test/Hotline.Tests/Infrastructure/WeiXinTest.cs

@@ -1,17 +1,18 @@
 using Hotline.Share.Dtos.Snapshot;
+using Hotline.ThirdAccountDomainServices.Interfaces;
 using Hotline.WeChat;
 
 namespace Hotline.Tests.Infrastructure;
 public class WeiXinTest
 {
-    private readonly WeChatService _weChatService;
+    private readonly IThirdIdentiyService _weChatService;
 
-    public WeiXinTest(WeChatService weChatService)
+    public WeiXinTest(IThirdIdentiyService weChatService)
     {
         _weChatService = weChatService;
     }
 
-    // [Fact]
+    [Fact]
     public async Task GetPhoneNumber_Test()
     {
         var result = await _weChatService.GetPhoneNumberAsync(new ThirdTokenDto { AppId = "12333", Secret = "4444444" }, CancellationToken.None);

+ 3 - 2
test/Hotline.Tests/Startup.cs

@@ -53,6 +53,7 @@ using Xunit.DependencyInjection.AspNetCoreTesting;
 using Hotline.Pdf;
 using Hotline.ThirdAccountDomainServices.Interfaces;
 using Hotline.Snapshot.IRepository;
+using Hotline.WeChat;
 
 namespace Hotline.Tests;
 public class Startup
@@ -146,8 +147,8 @@ public class Startup
                 .ToList()
                 .ForEach(d => ServiceRegister.Register(services, d));
 
-            // services.AddScoped<IThirdIdentiyService, WeChatService>();
-            services.AddScoped<IThirdIdentiyService, ThirdTestService>();
+            services.AddScoped<IThirdIdentiyService, WeChatService>();
+            //services.AddScoped<IThirdIdentiyService, ThirdTestService>();
 
             services.AddScoped<IUpdateDatabaseEvent<OrderVisitDetail>, OrderVisitDetailEventHandler>();