fix 消息记录保存日志
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Dlhis.Basic.Common.ApiLog.Services;
|
||||||
|
using Dlhis.Entity.Common.Enums;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
@@ -8,16 +10,18 @@ namespace Dlhis.Basic.Common.Message;
|
|||||||
public class JinkoApiService : IJinkoApiService
|
public class JinkoApiService : IJinkoApiService
|
||||||
{
|
{
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
private readonly IServiceProvider _serviceProvider;
|
||||||
private const string _agentId = "2984453842";
|
private const string _agentId = "2984453842";
|
||||||
private const string _appKey = "dingppvj6wvtgbagwpsw";
|
private const string _appKey = "dingppvj6wvtgbagwpsw";
|
||||||
private const string _appSecret = "k9mxYwilZgQiuhV_RVYRueoIAWHCQWrUdhbj6DAmiEiqMzSQE4igt0kAj97rmLaS";
|
private const string _appSecret = "k9mxYwilZgQiuhV_RVYRueoIAWHCQWrUdhbj6DAmiEiqMzSQE4igt0kAj97rmLaS";
|
||||||
|
|
||||||
public JinkoApiService(IHttpClientFactory httpClientFactory)
|
public JinkoApiService(IHttpClientFactory httpClientFactory, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
|
_serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetTokenAsync()
|
private async Task<string> GetTokenAsync()
|
||||||
{
|
{
|
||||||
var token = string.Empty;
|
var token = string.Empty;
|
||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
@@ -76,6 +80,11 @@ public class JinkoApiService : IJinkoApiService
|
|||||||
|
|
||||||
var jObj = JObject.Parse(jsonResponse);
|
var jObj = JObject.Parse(jsonResponse);
|
||||||
(jObj.Value<string>("errcode") == "0").ThrowIfFalse(jObj.Value<string>("errmsg"));
|
(jObj.Value<string>("errcode") == "0").ThrowIfFalse(jObj.Value<string>("errmsg"));
|
||||||
|
|
||||||
|
|
||||||
|
using var scope = _serviceProvider.CreateScope();
|
||||||
|
var ol = scope.ServiceProvider.GetService<IOperateLog>();
|
||||||
|
await ol.LogAsync(OperateLogType.WorkGrid, $"dingtalk消息推送:{request.ToJson()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
Src/Dlhis.Message/Options/DingTalkOption.cs
Normal file
11
Src/Dlhis.Message/Options/DingTalkOption.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using Kurisu.AspNetCore.ConfigurableOptions.Attributes;
|
||||||
|
|
||||||
|
namespace Dlhis.Message.Options;
|
||||||
|
|
||||||
|
[Configuration]
|
||||||
|
public class DingTalkOption
|
||||||
|
{
|
||||||
|
public string AgentId { get; set; }
|
||||||
|
public string AppKey { get; set; }
|
||||||
|
public string AppSecret { get; set; }
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Dlhis.Message.Options;
|
||||||
using Kurisu.AspNetCore.Utils.Extensions;
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
@@ -8,13 +10,15 @@ namespace Dlhis.Message.Services;
|
|||||||
public class JinkoApiService : IJinkoApiService
|
public class JinkoApiService : IJinkoApiService
|
||||||
{
|
{
|
||||||
private readonly IHttpClientFactory _httpClientFactory;
|
private readonly IHttpClientFactory _httpClientFactory;
|
||||||
|
private readonly DingTalkOption _dingTalkOption;
|
||||||
|
|
||||||
public JinkoApiService(IHttpClientFactory httpClientFactory)
|
public JinkoApiService(IHttpClientFactory httpClientFactory, IOptions<DingTalkOption> options)
|
||||||
{
|
{
|
||||||
_httpClientFactory = httpClientFactory;
|
_httpClientFactory = httpClientFactory;
|
||||||
|
_dingTalkOption = options.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> GetTokenAsync()
|
private async Task<string> GetTokenAsync()
|
||||||
{
|
{
|
||||||
var token = string.Empty;
|
var token = string.Empty;
|
||||||
if (string.IsNullOrEmpty(token))
|
if (string.IsNullOrEmpty(token))
|
||||||
@@ -23,11 +27,10 @@ public class JinkoApiService : IJinkoApiService
|
|||||||
|
|
||||||
var form = new FormUrlEncodedContent(new Dictionary<string, string>
|
var form = new FormUrlEncodedContent(new Dictionary<string, string>
|
||||||
{
|
{
|
||||||
{ "appkey", "dingumelppews6rah7x9" },
|
{ "appkey", _dingTalkOption.AppKey },
|
||||||
{ "appsecret", "nsWfJTVjYesHVzrLiP-t1TQqMQvC1L_kZNfXfnIyzcXK4pCTfKprkjZcxAbsDR_l" }
|
{ "appsecret", _dingTalkOption.AppSecret }
|
||||||
});
|
});
|
||||||
|
|
||||||
//appkey=dingumelppews6rah7x9&appsecret=nsWfJTVjYesHVzrLiP-t1TQqMQvC1L_kZNfXfnIyzcXK4pCTfKprkjZcxAbsDR_l
|
|
||||||
var response = await httpClient.GetStringAsync($"/gettoken?{await form.ReadAsStringAsync()}");
|
var response = await httpClient.GetStringAsync($"/gettoken?{await form.ReadAsStringAsync()}");
|
||||||
var jObj = JObject.Parse(response);
|
var jObj = JObject.Parse(response);
|
||||||
(jObj.Value<string>("errcode") == "0").ThrowIfFalse(jObj.Value<string>("errmsg"));
|
(jObj.Value<string>("errcode") == "0").ThrowIfFalse(jObj.Value<string>("errmsg"));
|
||||||
@@ -50,7 +53,7 @@ public class JinkoApiService : IJinkoApiService
|
|||||||
|
|
||||||
var body = new
|
var body = new
|
||||||
{
|
{
|
||||||
agent_id = "2768073678",
|
agent_id = _dingTalkOption.AgentId,
|
||||||
userid_list = userStringIds,
|
userid_list = userStringIds,
|
||||||
msg = new
|
msg = new
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,6 +24,11 @@
|
|||||||
"yikatong": "yikatong"
|
"yikatong": "yikatong"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"DingTalkOption":{
|
||||||
|
"AgentId":"2984453842",
|
||||||
|
"AppKey":"dingppvj6wvtgbagwpsw",
|
||||||
|
"AppSecret":"k9mxYwilZgQiuhV_RVYRueoIAWHCQWrUdhbj6DAmiEiqMzSQE4igt0kAj97rmLaS"
|
||||||
|
},
|
||||||
"IdentityServerOptions": {
|
"IdentityServerOptions": {
|
||||||
"Authority": "http://identity.oauth.svc.cluster.local",
|
"Authority": "http://identity.oauth.svc.cluster.local",
|
||||||
"RequireHttpsMetadata": false,
|
"RequireHttpsMetadata": false,
|
||||||
|
|||||||
Reference in New Issue
Block a user