xf 1 年之前
父節點
當前提交
7bae1fe4db

+ 14 - 0
Hotline.sln

@@ -41,6 +41,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Wex.Sdk", "src\Wex.Sdk\Wex.
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hotline.Wex", "src\Hotline.Wex\Hotline.Wex.csproj", "{40B6FBEC-0524-430C-8B28-22229681D0F8}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tr.Sdk", "src\Tr.Sdk\Tr.Sdk.csproj", "{BB901B26-EA97-4D6F-8CAC-14DB321E1733}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hotline.Tr", "src\Hotline.Tr\Hotline.Tr.csproj", "{42A37A81-9B4A-4A05-8EBC-90D1E580E1DD}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -99,6 +103,14 @@ Global
 		{40B6FBEC-0524-430C-8B28-22229681D0F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{40B6FBEC-0524-430C-8B28-22229681D0F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{40B6FBEC-0524-430C-8B28-22229681D0F8}.Release|Any CPU.Build.0 = Release|Any CPU
+		{BB901B26-EA97-4D6F-8CAC-14DB321E1733}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{BB901B26-EA97-4D6F-8CAC-14DB321E1733}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{BB901B26-EA97-4D6F-8CAC-14DB321E1733}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{BB901B26-EA97-4D6F-8CAC-14DB321E1733}.Release|Any CPU.Build.0 = Release|Any CPU
+		{42A37A81-9B4A-4A05-8EBC-90D1E580E1DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{42A37A81-9B4A-4A05-8EBC-90D1E580E1DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{42A37A81-9B4A-4A05-8EBC-90D1E580E1DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{42A37A81-9B4A-4A05-8EBC-90D1E580E1DD}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -121,6 +133,8 @@ Global
 		{F68F9925-E184-47C4-88EE-73A09CF4F61E} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
 		{F2E2E925-39FF-41BB-B199-34E50A3AC1FB} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
 		{40B6FBEC-0524-430C-8B28-22229681D0F8} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
+		{BB901B26-EA97-4D6F-8CAC-14DB321E1733} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
+		{42A37A81-9B4A-4A05-8EBC-90D1E580E1DD} = {D041C554-B78E-4AAF-B597-E309DC8EEF4F}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {4B8EA790-BD13-4422-8D63-D6DBB77B823F}

+ 60 - 0
src/Hotline.Api/Program.cs

@@ -1,5 +1,9 @@
+using System.Text.Json.Serialization;
 using Hotline.Api;
+using Newtonsoft.Json;
+using RestSharp;
 using Serilog;
+using Tr.Sdk;
 
 Log.Logger = new LoggerConfiguration()
     .WriteTo.Console()
@@ -7,6 +11,51 @@ Log.Logger = new LoggerConfiguration()
 
 Log.Information("Hotline service is Starting up");
 
+//var a = "http://internal.ttf-cti.com:8080";
+////var r = await a
+////    .AppendPathSegment("api/login")
+////    .SetQueryParams(new { username = "yscs", password = "123456" })
+////    .GetAsync();
+////var h = r.Headers.FirstOrDefault(d => d.Name == "X-Auth-Token");
+
+//var p = new Pa { Phone = "13312341234", SpecialFlag = 4 };
+//var njp = Newtonsoft.Json.JsonConvert.SerializeObject(p);
+//var jp = System.Text.Json.JsonSerializer.Serialize(p);
+
+//FlurlHttp.GlobalSettings.JsonSerializer = new TrUrlEncodedSerializer();
+
+//var r1 = await a
+//    .AppendPathSegment("api/special_phone/insert")
+//    //.WithHeader(h.Name, h.Value)
+//    .WithHeader("X-Auth-Token", "8352d42165d7cf6821e53e926d66adba54c309e6")
+//    //.PostUrlEncodedAsync(new { phone = "13312341234", special_flag = 4 });
+//    //.PostUrlEncodedAsync(p);
+//    //.ConfigureRequest(s =>
+//    //{
+//    //    s.JsonSerializer = new Tr.Sdk.TrUrlEncodedSerializer();
+//    //})
+//    .BeforeCall(d =>
+//    {
+//        var b = d.RequestBody;
+//        var c = d.Request;
+//    })
+//    .PostUrlEncodedAsync(p);
+
+//var r2 = await r1;
+
+//var options = new RestClientOptions("http://internal.ttf-cti.com:8080");
+
+//var client = new RestClient(options);
+//client.AddDefaultHeader("X-Auth-Token", "8352d42165d7cf6821e53e926d66adba54c309e6");
+
+//var reqToken = new RestRequest("api/login")
+//    .AddObject(new { username = "yscs", password = "123456" });
+
+//var r1 = await client.GetAsync(reqToken);
+//var h = r1.Headers.FirstOrDefault(d => d.Name == "X-Auth-Token");
+//7a906970b1ce06a503807e75762da323782f4a29
+
+
 try
 {
     var builder = WebApplication.CreateBuilder(args);
@@ -46,4 +95,15 @@ finally
 {
     Log.Information("Shut down complete");
     Log.CloseAndFlush();
+}
+
+class Pa
+{
+    [JsonProperty(PropertyName = "phone")]
+    [JsonPropertyName("phone")]
+    public string Phone { get; set; }
+
+    [JsonProperty(PropertyName = "special_flag")]
+    [JsonPropertyName("special_flag")]
+    public int SpecialFlag { get; set; }
 }

+ 5 - 2
src/Hotline.Api/StartupExtensions.cs

@@ -14,6 +14,8 @@ using Microsoft.AspNetCore.Identity;
 using Serilog;
 using System.Text.Json;
 using Fw.Utility.Client;
+using Mapster;
+using MapsterMapper;
 using XF.Domain.Dependency;
 using XF.Domain.Filters;
 using XF.Domain.Options;
@@ -94,7 +96,8 @@ internal static class StartupExtensions
         //cache
         services.AddCache(d =>
             {
-                d.ConnectionString = configuration.GetConnectionString("Redis") ?? string.Empty;
+                var cacheConfig = configuration.GetSection("Cache").Get<CacheOptions>();
+                cacheConfig.Adapt(d);
                 d.Prefix = "Hotline";
                 d.TopicName = "hotline-topic";
             });
@@ -118,7 +121,7 @@ internal static class StartupExtensions
     internal static WebApplication ConfigurePipelines(this WebApplication app)
     {
         app.UseSerilogRequestLogging();
-        
+
         // Configure the HTTP request pipeline.
         var swaggerEnable = app.Configuration.GetSection("Swagger").Get<bool>();
         if (swaggerEnable)

+ 13 - 2
src/Hotline.Api/config/appsettings.Development.json

@@ -1,7 +1,7 @@
 {
   "AllowedHosts": "*",
   "CallCenterConfiguration": {
-    "CallCenterType": "WeiErXin", //XunShi、WeiErXin
+    "CallCenterType": "WeiErXin", //XunShi、WeiErXin、TianRun
     "DeviceConfigs": {
       "Address": "http://192.168.100.100/xml",
       "Authorize": true,
@@ -13,14 +13,25 @@
       "Address": "http://222.212.82.225:8083",
       "Username": "admin",
       "Password": "Wex@12345"
+    },
+    "Tr": {
+      "Address": "http://internal.ttf-cti.com:8080",
+      "Username": "yscs",
+      "Password": "123456"
     }
   },
   "ConnectionStrings": {
     "Hotline": "PORT=5432;DATABASE=hotline;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
-    "Redis": "110.188.24.182",
+    "Redis": "110.188.24.182:50179,password=fengwo22@@",
     "MongoDB": "mongodb://192.168.100.121:27017",
     "Wex": "server=222.212.82.225;Port=4509;Database=fs_kft;Uid=root;Pwd=Wex@12345;"
   },
+  "Cache": {
+    "Host": "110.188.24.182",
+    "Port": 50179,
+    "Password": "fengwo22@@",
+    "Database": 1
+  },
   "Swagger": true,
   "Cors": {
     "Origins": [ "http://localhost:8888", "http://admin.hotline.fw.com", "http://hotline.fw.com" ]

+ 12 - 1
src/Hotline.Api/config/appsettings.json

@@ -13,14 +13,25 @@
       "Address": "http://222.212.82.225:8083",
       "Username": "admin",
       "Password": "Wex@12345"
+    },
+    "Tr": {
+      "Address": "http://internal.ttf-cti.com:8080",
+      "Username": "yscs",
+      "Password": "123456"
     }
   },
   "ConnectionStrings": {
     "Hotline": "PORT=5432;DATABASE=hotline;HOST=110.188.24.182;PASSWORD=fengwo11!!;USER ID=dev;",
-    "Redis": "110.188.24.182",
+    "Redis": "110.188.24.182:50179,password=fengwo22@@",
     "MongoDB": "mongodb://192.168.100.121:27017",
     "Wex": "server=222.212.82.225;Port=4509;Database=fs_kft;Uid=root;Pwd=Wex@12345;"
   },
+  "Cache": {
+    "Host": "110.188.24.182",
+    "Port": 50179,
+    "Password": "fengwo22@@",
+    "Database": 1
+  },
   "Swagger": true,
   "Cors": {
     "Origins": [ "http://localhost:8888", "http://hotline.12345lm.cn", "http://hotline.fw.com", "http://110.188.24.28:50101", "http://110.188.24.28:50102" ]

+ 1 - 0
src/Hotline.Application/Hotline.Application.csproj

@@ -14,6 +14,7 @@
     <ProjectReference Include="..\Hotline.Application.Contracts\Hotline.Application.Contracts.csproj" />
     <ProjectReference Include="..\Hotline.NewRock\Hotline.NewRock.csproj" />
     <ProjectReference Include="..\Hotline.Repository.SqlSugar\Hotline.Repository.SqlSugar.csproj" />
+    <ProjectReference Include="..\Hotline.Tr\Hotline.Tr.csproj" />
     <ProjectReference Include="..\Hotline.Wex\Hotline.Wex.csproj" />
     <ProjectReference Include="..\Hotline\Hotline.csproj" />
     <ProjectReference Include="..\XF.EasyCaching\XF.EasyCaching.csproj" />

+ 7 - 0
src/Hotline.Tr/Class1.cs

@@ -0,0 +1,7 @@
+namespace Hotline.Tr
+{
+    public class Class1
+    {
+
+    }
+}

+ 14 - 0
src/Hotline.Tr/Hotline.Tr.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="..\Hotline\Hotline.csproj" />
+    <ProjectReference Include="..\Tr.Sdk\Tr.Sdk.csproj" />
+  </ItemGroup>
+
+</Project>

+ 12 - 0
src/Hotline/CallCenter/Devices/CallCenterConfiguration.cs

@@ -0,0 +1,12 @@
+namespace Hotline.CallCenter.Devices;
+
+public class CallCenterConfiguration
+{
+    public string CallCenterType { get; set; }
+
+    public DeviceConfigs DeviceConfigs { get; set; }
+
+    public WexConfiguration Wex { get; set; }
+
+    public TrConfiguration Tr { get; set; }
+}

+ 0 - 9
src/Hotline/CallCenter/Devices/DeviceConfigs.cs

@@ -12,13 +12,4 @@
         /// </summary>
         public int Expired { get; set; }
     }
-
-    public class CallCenterConfiguration
-    {
-        public string CallCenterType { get; set; }
-
-        public DeviceConfigs DeviceConfigs { get; set; }
-
-        public WexConfiguration Wex { get; set; }
-    }
 }

+ 8 - 0
src/Hotline/CallCenter/Devices/TrConfiguration.cs

@@ -0,0 +1,8 @@
+namespace Hotline.CallCenter.Devices;
+
+public class TrConfiguration
+{
+    public string Address { get; set; }
+    public string Username { get; set; }
+    public string Password { get; set; }
+}

+ 6 - 0
src/Tr.Sdk/Defaults.cs

@@ -0,0 +1,6 @@
+namespace Tr.Sdk;
+
+internal class Defaults
+{
+    internal static readonly string ServiceName = "Tr";
+}

+ 52 - 0
src/Tr.Sdk/ITrClient.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.Json.Serialization;
+using System.Threading.Tasks;
+
+namespace Tr.Sdk
+{
+    public interface ITrClient
+    {
+        /// <summary>
+        /// 执行操作呼叫中心请求
+        /// </summary>
+        /// <typeparam name="TRequest"></typeparam>
+        /// <typeparam name="TResponse"></typeparam>
+        /// <param name="request"></param>
+        /// <param name="cancellationToken"></param>
+        /// <returns></returns>
+        Task<TResponse?> ExecuteAsync<TRequest, TResponse>(
+            TRequest request,
+            CancellationToken cancellationToken) where TRequest : ITrRequest;
+
+        Task<string> GetTokenAsync(TokenRequest request, CancellationToken cancellationToken);
+    }
+
+    public class TokenRequest : ITrRequest
+    {
+        public TokenRequest()
+        {
+            Url = "login/token";
+            Method = HttpMethod.Get;
+        }
+
+        public string Url { get; init; }
+
+        public HttpMethod Method { get; init; }
+
+        public string Username { get; set; }
+
+        public string Password { get; set; }
+    }
+
+    public interface ITrRequest
+    {
+        [JsonIgnore]
+        string Url { get; }
+
+        [JsonIgnore]
+        HttpMethod Method { get; }
+    }
+}

+ 14 - 0
src/Tr.Sdk/Tr.Sdk.csproj

@@ -0,0 +1,14 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+    <TargetFramework>net7.0</TargetFramework>
+    <ImplicitUsings>enable</ImplicitUsings>
+    <Nullable>enable</Nullable>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
+    <PackageReference Include="RestSharp" Version="110.2.0" />
+  </ItemGroup>
+
+</Project>

+ 75 - 0
src/Tr.Sdk/TrClient.cs

@@ -0,0 +1,75 @@
+//using System.Net.Http.Json;
+//using System.Text.Json;
+
+//namespace Tr.Sdk;
+
+//public partial class TrClient : ITrClient
+//{
+//    private readonly IHttpClientFactory _httpClientFactory;
+
+//    public TrClient(IHttpClientFactory httpClientFactory)
+//    {
+//        _httpClientFactory = httpClientFactory;
+//    }
+
+//    /// <summary>
+//    /// 执行操作呼叫中心请求
+//    /// </summary>
+//    /// <typeparam name="TRequest"></typeparam>
+//    /// <typeparam name="TResponse"></typeparam>
+//    /// <param name="request"></param>
+//    /// <param name="cancellationToken"></param>
+//    /// <returns></returns>
+//    public async Task<TResponse?> ExecuteAsync<TRequest, TResponse>(TRequest request, CancellationToken cancellationToken) where TRequest : ITrRequest
+//    {
+//        //var httpClient = _httpClientFactory.CreateClient(Defaults.ServiceName);
+//        //var token = await _tokenManager.GetTokenAsync(cancellationToken);
+//        //httpClient.DefaultRequestHeaders.Add("X-Auth-Token", token);
+//        //try
+//        //{
+//        //    if (request.Method == HttpMethod.Get)
+//        //    {
+//        //        return await httpClient.GetFromJsonAsync<TResponse>(request.Url, cancellationToken);
+//        //    }
+//        //    else if (request.Method == HttpMethod.Post)
+//        //    {
+//        //        using var content = new FormUrlEncodedContent
+//        //        await httpClient.PostAsync(request.Url, new FormUrlEncodedContent(), cancellationToken);
+//        //    }
+//        //    else
+//        //    {
+//        //        throw new ArgumentOutOfRangeException();
+//        //    }
+
+//        //    var rsp = await httpClient.PostAsJsonAsync(request.Url, request, cancellationToken: cancellationToken);
+//        //    if (!rsp.IsSuccessStatusCode)
+//        //        throw new HttpRequestException("请求呼叫中心服务失败");
+//        //    var response = await rsp.Content.ReadFromJsonAsync<TResponse>(new JsonSerializerOptions
+//        //    {
+//        //        PropertyNamingPolicy = JsonNamingPolicy.CamelCase
+//        //    }, cancellationToken);
+//        //    if (response?.Code == 401)
+//        //    {
+//        //        await _tokenManager.RefreshTokenAsync(cancellationToken);
+//        //        response = await rsp.Content.ReadFromJsonAsync<TResponse>(new JsonSerializerOptions
+//        //        {
+//        //            PropertyNamingPolicy = JsonNamingPolicy.CamelCase
+//        //        }, cancellationToken);
+//        //    }
+//        //    if (response?.Code != 200)
+//        //        throw new HttpRequestException(response?.Msg);
+//        //    return response;
+//        //}
+//        //catch (Exception)
+//        //{
+//        //    throw;
+//        //}
+
+//        throw new NotImplementedException();
+//    }
+
+//    public async Task<string> GetTokenAsync(TokenRequest request, CancellationToken cancellationToken)
+//    {
+//        throw new NotImplementedException();
+//    }
+//}

+ 6 - 3
src/XF.EasyCaching/StartupExtensions.cs

@@ -21,8 +21,9 @@ namespace XF.EasyCaching
 
                 d.UseRedis(config =>
                 {
-                    config.DBConfig.Endpoints.Add(new ServerEndPoint(options.ConnectionString, options.Port));
+                    config.DBConfig.Endpoints.Add(new ServerEndPoint(options.Host, options.Port));
                     config.DBConfig.Database = options.Database;
+                    config.DBConfig.Password = options.Password;
                     config.SerializerName = "xjson";
                 }, "r1");
 
@@ -40,7 +41,7 @@ namespace XF.EasyCaching
                     // use redis bus
                     .WithRedisBus(busConf =>
                     {
-                        busConf.Endpoints.Add(new ServerEndPoint(options.ConnectionString, options.Port));
+                        busConf.Endpoints.Add(new ServerEndPoint(options.Host, options.Port));
 
                         // do not forget to set the SerializerName for the bus here !!
                         busConf.SerializerName = "xjson";
@@ -56,10 +57,12 @@ namespace XF.EasyCaching
 
     public class CacheOptions
     {
-        public string ConnectionString { get; set; }
+        public string Host { get; set; }
 
         public int Port { get; set; }
 
+        public string Password { get; set; }
+
         public int Database { get; set; } = 1;
 
         public string Prefix { get; set; }