refactor 改用basic服务
This commit is contained in:
@@ -51,8 +51,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Constants", "Src\Dlhi
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Canteen.Api", "Src\Dlhis.Canteen.Api\Dlhis.Canteen.Api.csproj", "{7934BE46-9409-4D28-8B35-82A0F900DD01}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.Message.Api", "Src\Dlhis.Message.Api\Dlhis.Message.Api.csproj", "{78B80FBD-E7B0-4352-B7FD-B6DCE2D48AEE}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -131,10 +129,6 @@ Global
|
||||
{7934BE46-9409-4D28-8B35-82A0F900DD01}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7934BE46-9409-4D28-8B35-82A0F900DD01}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7934BE46-9409-4D28-8B35-82A0F900DD01}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{78B80FBD-E7B0-4352-B7FD-B6DCE2D48AEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{78B80FBD-E7B0-4352-B7FD-B6DCE2D48AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{78B80FBD-E7B0-4352-B7FD-B6DCE2D48AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{78B80FBD-E7B0-4352-B7FD-B6DCE2D48AEE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@@ -153,7 +147,6 @@ Global
|
||||
{841B7B43-5394-413F-9D68-A07EBDD6D4CD} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
|
||||
{E673CA04-3567-4E03-9A86-994F50291ACC} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
|
||||
{7934BE46-9409-4D28-8B35-82A0F900DD01} = {3D8A98C1-83C9-4375-AEAB-4F72AFAF365B}
|
||||
{78B80FBD-E7B0-4352-B7FD-B6DCE2D48AEE} = {65E76F97-E78A-4C95-B788-4091236B1A79}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0}
|
||||
|
||||
@@ -10,8 +10,4 @@
|
||||
<PackageReference Include="Kurisu.RemoteCall" Version="0.4.8" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Request\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Dlhis.Message.Api.Requests;
|
||||
using Dlhis.Basic.Api.Requests;
|
||||
using Kurisu.RemoteCall.Attributes;
|
||||
|
||||
namespace Dlhis.Message.Api;
|
||||
namespace Dlhis.Basic.Api;
|
||||
|
||||
[RequestLog]
|
||||
[RequestResultHandler]
|
||||
[EnableRemoteClient(Name = "message-service", BaseUrl = "${InternalRequest:MessageRequestUrl}")]
|
||||
[EnableRemoteClient(Name = "message-service", BaseUrl = "${InternalRequest:BasicRequestUrl}")]
|
||||
public interface IDingTalkApi
|
||||
{
|
||||
[Post("/api/messages/dingtalk/workmessage")]
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace Dlhis.Message.Api.Requests;
|
||||
namespace Dlhis.Basic.Api.Requests;
|
||||
|
||||
public class JinkoSendWorkMessageRequest
|
||||
{
|
||||
6
Src/Dlhis.Basic/Common/Message/IJinkoApiService.cs
Normal file
6
Src/Dlhis.Basic/Common/Message/IJinkoApiService.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Dlhis.Basic.Common.Message;
|
||||
|
||||
public interface IJinkoApiService : ISingletonDependency
|
||||
{
|
||||
Task SendWorkMessageAsync(JinkoSendWorkMessageRequest request);
|
||||
}
|
||||
99
Src/Dlhis.Basic/Common/Message/JinkoApiService.cs
Normal file
99
Src/Dlhis.Basic/Common/Message/JinkoApiService.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
using System.Text;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Dlhis.Basic.Common.Message;
|
||||
|
||||
public class JinkoApiService : IJinkoApiService
|
||||
{
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
|
||||
public JinkoApiService(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
public async Task<string> GetTokenAsync()
|
||||
{
|
||||
var token = string.Empty;
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient("jinko.httpclient");
|
||||
|
||||
var form = new FormUrlEncodedContent(new Dictionary<string, string>
|
||||
{
|
||||
{ "appkey", "dingumelppews6rah7x9" },
|
||||
{ "appsecret", "nsWfJTVjYesHVzrLiP-t1TQqMQvC1L_kZNfXfnIyzcXK4pCTfKprkjZcxAbsDR_l" }
|
||||
});
|
||||
|
||||
//appkey=dingumelppews6rah7x9&appsecret=nsWfJTVjYesHVzrLiP-t1TQqMQvC1L_kZNfXfnIyzcXK4pCTfKprkjZcxAbsDR_l
|
||||
var response = await httpClient.GetStringAsync($"/gettoken?{await form.ReadAsStringAsync()}");
|
||||
var jObj = JObject.Parse(response);
|
||||
(jObj.Value<string>("errcode") == "0").ThrowIfFalse(jObj.Value<string>("errmsg"));
|
||||
|
||||
token = jObj.Value<string>("access_token");
|
||||
}
|
||||
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
public async Task SendWorkMessageAsync(JinkoSendWorkMessageRequest request)
|
||||
{
|
||||
request.Content.IsEmpty().ThrowIfTrue("发送内容不能为空");
|
||||
var token = await GetTokenAsync();
|
||||
|
||||
var users = await GetJinkoOaInfoByWorkCodes(request.WorkCodes);
|
||||
var userStringIds = string.Join(",", users.Select(x => x.Id));
|
||||
(userStringIds.Length > 100).ThrowIfTrue("超出消息接受人数,length > 100");
|
||||
|
||||
var body = new
|
||||
{
|
||||
agent_id = "2768073678",
|
||||
userid_list = userStringIds,
|
||||
msg = new
|
||||
{
|
||||
msgtype = "text",
|
||||
text = new
|
||||
{
|
||||
content = request.Content
|
||||
},
|
||||
},
|
||||
}.ToJson();
|
||||
|
||||
var httpClient = _httpClientFactory.CreateClient("jinko.httpclient");
|
||||
var url = $"/topapi/message/corpconversation/asyncsend_v2?access_token={token}";
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = await httpClient.PostAsync(url, content);
|
||||
var jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
|
||||
//_logger.LogInformation("请求参数:{Request} \r\n 钉钉请求参数:{DingTalkRequest} \r\n 钉钉响应:{DingTalkResponse}", JsonConvert.SerializeObject(request), body, jsonResponse);
|
||||
|
||||
var jObj = JObject.Parse(jsonResponse);
|
||||
(jObj.Value<string>("errcode") == "0").ThrowIfFalse(jObj.Value<string>("errmsg"));
|
||||
}
|
||||
|
||||
|
||||
private async Task<List<JinkoOaInfo>> GetJinkoOaInfoByWorkCodes(List<string> codes)
|
||||
{
|
||||
var httpClient = _httpClientFactory.CreateClient("jinko.oa");
|
||||
|
||||
var body = new
|
||||
{
|
||||
token = "TTMlaplWIEjmJHiVShWybekyyNnJXDHD",
|
||||
type = "workCode",
|
||||
workCode = string.Join(",", codes)
|
||||
}.ToJson();
|
||||
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var response = await httpClient.PostAsync("http://oa.jinkosolar.com/api/commonRequestService/getUserByWorkCode/v2", content);
|
||||
var responseJson = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var oaInfo = JsonConvert.DeserializeObject<JinkoOaResponse<JinkoData<List<JinkoOaInfo>>>>(responseJson);
|
||||
(oaInfo.Code == 200).ThrowIfFalse(oaInfo.Message);
|
||||
|
||||
return oaInfo.Result.Data;
|
||||
}
|
||||
}
|
||||
22
Src/Dlhis.Basic/Common/Message/JinkoOaResponse.cs
Normal file
22
Src/Dlhis.Basic/Common/Message/JinkoOaResponse.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace Dlhis.Basic.Common.Message
|
||||
{
|
||||
public class JinkoOaResponse<T>
|
||||
{
|
||||
public int Code { get; set; }
|
||||
public string Message { get; set; }
|
||||
public T Result { get; set; }
|
||||
}
|
||||
|
||||
public class JinkoData<T>
|
||||
{
|
||||
public T Data { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public class JinkoOaInfo
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Lastname { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Dlhis.Basic.Common.Message;
|
||||
|
||||
public class JinkoSendWorkMessageRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 发送内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 工号
|
||||
/// </summary>
|
||||
public List<string> WorkCodes { get; set; }
|
||||
}
|
||||
23
Src/Dlhis.Basic/Common/Message/MessagesController.cs
Normal file
23
Src/Dlhis.Basic/Common/Message/MessagesController.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Dlhis.Basic.Common.Message;
|
||||
|
||||
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class MessagesController : ControllerBase
|
||||
{
|
||||
private readonly IJinkoApiService _jinkoApiService;
|
||||
|
||||
public MessagesController(IJinkoApiService jinkoApiService)
|
||||
{
|
||||
_jinkoApiService = jinkoApiService;
|
||||
}
|
||||
|
||||
|
||||
[HttpPost("dingtalk/workmessage")]
|
||||
public async Task SendWorkMessageAsync(JinkoSendWorkMessageRequest request)
|
||||
{
|
||||
await _jinkoApiService.SendWorkMessageAsync(request);
|
||||
}
|
||||
}
|
||||
50
Src/Dlhis.Basic/Common/Packs/MessagePack.cs
Normal file
50
Src/Dlhis.Basic/Common/Packs/MessagePack.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
|
||||
namespace Dlhis.Basic.Common.Packs;
|
||||
|
||||
public class MessagePack : BaseAppPack
|
||||
{
|
||||
public override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient("jinko.oa", (_, _) => { })
|
||||
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||
{
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
||||
};
|
||||
|
||||
return handler;
|
||||
});
|
||||
|
||||
services.AddHttpClient("jinko.httpclient", (sp, httpClient) =>
|
||||
{
|
||||
// "BaseUrl": "https://oapi.dingtalk.com",
|
||||
// "AgentId": "2768073678",
|
||||
// "AppId": "dingumelppews6rah7x9",
|
||||
// "AppSecret": "nsWfJTVjYesHVzrLiP-t1TQqMQvC1L_kZNfXfnIyzcXK4pCTfKprkjZcxAbsDR_l",
|
||||
|
||||
httpClient.BaseAddress = new Uri("https://oapi.dingtalk.com");
|
||||
httpClient.Timeout = TimeSpan.FromSeconds(30);
|
||||
})
|
||||
// .SetHandlerLifetime(TimeSpan.FromMinutes(5))
|
||||
// .addd((res) =>
|
||||
// {
|
||||
// return HttpPolicyExtensions
|
||||
// .HandleTransientHttpError()
|
||||
// .OrResult(msg => msg.StatusCode != HttpStatusCode.OK)
|
||||
// .WaitAndRetryAsync(6, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)));
|
||||
// })
|
||||
.ConfigurePrimaryHttpMessageHandler(() =>
|
||||
{
|
||||
var handler = new HttpClientHandler
|
||||
{
|
||||
ClientCertificateOptions = ClientCertificateOption.Manual,
|
||||
ServerCertificateCustomValidationCallback = (_, _, _, _) => true
|
||||
};
|
||||
|
||||
return handler;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -31,12 +31,10 @@
|
||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.InfoCheck.Api\Dlhis.InfoCheck.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Message.Api\Dlhis.Message.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Common\" />
|
||||
<Folder Include="Summary\Request\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Dlhis.Basic.Organization.Comparers;
|
||||
using Dlhis.Basic.Common.Message;
|
||||
using Dlhis.Basic.Organization.Comparers;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Entity.Sys.Entities;
|
||||
using Dlhis.Entity.Sys.Enums;
|
||||
using Dlhis.Jip.Api.Dto;
|
||||
using Dlhis.Message.Api;
|
||||
using Dlhis.Message.Api.Requests;
|
||||
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
@@ -18,14 +17,14 @@ public class GainfoUpdateService : IGainfoUpdateService
|
||||
private readonly ILogger<GainfoUpdateService> _logger;
|
||||
private readonly IJinkoSapService _jinkoSapService;
|
||||
private readonly IGainfoPermissionService _gainfoPermissionService;
|
||||
private readonly IDingTalkApi _dingTalkApi;
|
||||
private readonly IJinkoApiService _dingTalkApi;
|
||||
private readonly IIdentityUserSyncService _identityUserSyncService;
|
||||
|
||||
public GainfoUpdateService(IDbContext dbContext,
|
||||
ILogger<GainfoUpdateService> logger,
|
||||
IJinkoSapService jinkoSapService,
|
||||
IGainfoPermissionService gainfoPermissionService,
|
||||
IDingTalkApi dingTalkApi,
|
||||
IJinkoApiService dingTalkApi,
|
||||
IIdentityUserSyncService identityUserSyncService)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.RemoteCall" Version="0.4.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,12 +1,12 @@
|
||||
using Dlhis.Constants;
|
||||
using Dlhis.Basic.Api;
|
||||
using Dlhis.Basic.Api.Requests;
|
||||
using Dlhis.Constants;
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Basic.Enums;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using Dlhis.Jip.Api;
|
||||
using Dlhis.Jip.Api.Requests;
|
||||
using Dlhis.Message.Api;
|
||||
using Dlhis.Message.Api.Requests;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Request;
|
||||
using Dlhis.ScheduledTask.DeviceUploadLog.Response;
|
||||
using Kurisu.AspNetCore.Authentication.Abstractions;
|
||||
|
||||
@@ -32,7 +32,6 @@
|
||||
<ProjectReference Include="..\Dlhis.Constants\Dlhis.Constants.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Jip.Api\Dlhis.Jip.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Message.Api\Dlhis.Message.Api.csproj" />
|
||||
<ProjectReference Include="..\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"profiles": {
|
||||
"Dlhis.ScheduledTask": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": false,
|
||||
"launchUrl": "swagger/index.html",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
||||
Reference in New Issue
Block a user