|
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Options;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
+using OpenXmlPowerTools;
|
|
using System;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Dynamic;
|
|
using System.Dynamic;
|
|
@@ -12,10 +13,13 @@ using System.Linq;
|
|
using System.Net;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Json;
|
|
using System.Net.Http.Json;
|
|
|
|
+using System.Security.Policy;
|
|
using System.Text;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
|
+using TEAMModelOS.Models;
|
|
using TEAMModelOS.SDK.DI;
|
|
using TEAMModelOS.SDK.DI;
|
|
|
|
+using TEAMModelOS.SDK.DI.CoreAPI;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Extension;
|
|
using TEAMModelOS.SDK.Models;
|
|
using TEAMModelOS.SDK.Models;
|
|
|
|
|
|
@@ -50,12 +54,19 @@ namespace TEAMModelOS.SDK
|
|
private SnowflakeId _snowflakeId;
|
|
private SnowflakeId _snowflakeId;
|
|
private readonly HttpClient _httpClient;
|
|
private readonly HttpClient _httpClient;
|
|
public readonly IOptionsMonitor<CoreAPIHttpServiceOptions> options;
|
|
public readonly IOptionsMonitor<CoreAPIHttpServiceOptions> options;
|
|
- public CoreAPIHttpService(HttpClient httpClient, IOptionsMonitor<CoreAPIHttpServiceOptions> optionsMonitor, IWebHostEnvironment environment,SnowflakeId snowflakeId)
|
|
|
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
|
+ private readonly DI.DingDing _dingDing;
|
|
|
|
+ public readonly Option _option;
|
|
|
|
+ public CoreAPIHttpService(IOptionsSnapshot<Option> option, DingDing dingDing,IConfiguration configuration,HttpClient httpClient, IOptionsMonitor<CoreAPIHttpServiceOptions> optionsMonitor, IWebHostEnvironment environment,SnowflakeId snowflakeId)
|
|
{
|
|
{
|
|
_httpClient = httpClient;
|
|
_httpClient = httpClient;
|
|
options = optionsMonitor;
|
|
options = optionsMonitor;
|
|
_environment = environment;
|
|
_environment = environment;
|
|
_snowflakeId= snowflakeId;
|
|
_snowflakeId= snowflakeId;
|
|
|
|
+ _option = option?.Value;
|
|
|
|
+ _configuration = configuration;
|
|
|
|
+ _dingDing = dingDing;
|
|
|
|
+
|
|
}
|
|
}
|
|
/*
|
|
/*
|
|
hubName string Optional 指定要傳送到哪個訊息中樞,若沒給則不傳送端外通知,只會發送端內通知。(目前只有"hita"及"hita5"能使用)
|
|
hubName string Optional 指定要傳送到哪個訊息中樞,若沒給則不傳送端外通知,只會發送端內通知。(目前只有"hita"及"hita5"能使用)
|
|
@@ -97,61 +108,77 @@ namespace TEAMModelOS.SDK
|
|
/// <param name="_configuration"></param>
|
|
/// <param name="_configuration"></param>
|
|
/// <param name="_dingDing"></param>
|
|
/// <param name="_dingDing"></param>
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
- public (HttpStatusCode code, string content) PushNotify(List<IdNameCode> toTeachers , string notifyCode,Dictionary<string, object> replaceData, string location, IConfiguration _configuration, DI.DingDing _dingDing) {
|
|
|
|
|
|
+ public void PushNotify(List<IdNameCode> toTeachers , string notifyCode,string notifyType,Dictionary<string, object> replaceData) {
|
|
/*
|
|
/*
|
|
|
|
+ * IES5_Management shift-assist_school DelBeforeCopyAbility-mark_start copyAbility-mark_finish copyAbility-mark_start
|
|
|
|
+ * transfer-admin_school invite-join_school invite_school request_school request-join_school remove_school scan-join_school
|
|
|
|
+ * IES5_Course submitanswer_homework scan-join_groupList expire-school_lessonRecord
|
|
|
|
+ * IES5_Task scoring-mark_school scoring-arb_school scoring-err_school
|
|
|
|
+ * IES5_Contect coedit_syllabus share_syllabus
|
|
{
|
|
{
|
|
"hubName":"hita5",
|
|
"hubName":"hita5",
|
|
"sender":"ies5",
|
|
"sender":"ies5",
|
|
- "tags":["1595321354_ies5"]
|
|
|
|
|
|
+ "tags":["1595321354_IES5_Management"]
|
|
"title":"",
|
|
"title":"",
|
|
"body":"",
|
|
"body":"",
|
|
"eventId":"",
|
|
"eventId":"",
|
|
"eventName":"",
|
|
"eventName":"",
|
|
- "data":""
|
|
|
|
|
|
+ "data":""action":{"type":"click\link","tokenbindtype":1,"url":"http://xxxx"}"
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
- string lang = location.Contains("China") ? "zh-cn" : "en-us";
|
|
|
|
|
|
+ string lang = _option.Location.Contains("China") ? "zh-cn" : "en-us";
|
|
toTeachers.FindAll(x => string.IsNullOrWhiteSpace(x.code)||(!x.code.Equals("zh-cn")&& !x.code.Equals("zh-tw")&& !x.code.Equals("en-us"))).ForEach(x => { x.code = lang; });
|
|
toTeachers.FindAll(x => string.IsNullOrWhiteSpace(x.code)||(!x.code.Equals("zh-cn")&& !x.code.Equals("zh-tw")&& !x.code.Equals("en-us"))).ForEach(x => { x.code = lang; });
|
|
var groups = toTeachers.GroupBy(x => x.code).Select(x => new { x.Key, list = x.ToList() });
|
|
var groups = toTeachers.GroupBy(x => x.code).Select(x => new { x.Key, list = x.ToList() });
|
|
-
|
|
|
|
- foreach(var group in groups)
|
|
|
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
|
+ var token = CoreTokenExtensions.CreateAccessToken(clientID, clientSecret,_option.Location).Result;
|
|
|
|
+ _httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
|
|
|
|
+ foreach (var group in groups)
|
|
{
|
|
{
|
|
- string path = $"{_environment.ContentRootPath}/JsonFile/Core/Lang/{group.Key}.json";
|
|
|
|
|
|
+ string path = $"{_environment.ContentRootPath}/Lang/{group.Key}.json";
|
|
var sampleJson = File.ReadAllBytes(path).AsSpan();
|
|
var sampleJson = File.ReadAllBytes(path).AsSpan();
|
|
Utf8JsonReader reader = new Utf8JsonReader(sampleJson);
|
|
Utf8JsonReader reader = new Utf8JsonReader(sampleJson);
|
|
if (JsonDocument.TryParseValue(ref reader, out JsonDocument jsonDoc) && jsonDoc.RootElement.TryGetProperty(notifyCode, out JsonElement json )) {
|
|
if (JsonDocument.TryParseValue(ref reader, out JsonDocument jsonDoc) && jsonDoc.RootElement.TryGetProperty(notifyCode, out JsonElement json )) {
|
|
List<string> msgs = json.ToObject<List<string>>();
|
|
List<string> msgs = json.ToObject<List<string>>();
|
|
if (msgs.IsNotEmpty()) {
|
|
if (msgs.IsNotEmpty()) {
|
|
- var tags= group.list.Select(x => $"{x.id}_ies5");
|
|
|
|
- dynamic notifyData = new ExpandoObject();
|
|
|
|
|
|
+ var tags= group.list.Select(x => $"{x.id}_{notifyType}");
|
|
|
|
+ NotifyData notifyData = new NotifyData
|
|
|
|
+ {
|
|
|
|
+ hubName = "hita5",
|
|
|
|
+ sender = "ies5",
|
|
|
|
+ tags = tags.ToList(),
|
|
|
|
+ title = msgs[0],
|
|
|
|
+ eventId = $"{notifyCode}-{_snowflakeId.NextId()}",
|
|
|
|
+ eventName = $"{msgs[0]}",
|
|
|
|
+ data = new { value = replaceData }.ToJsonString()
|
|
|
|
+ };
|
|
if (msgs.Count == 1)
|
|
if (msgs.Count == 1)
|
|
{
|
|
{
|
|
- notifyData.hubName = "hita5";
|
|
|
|
- notifyData.sender = "ies5";
|
|
|
|
- notifyData.tags = tags;
|
|
|
|
- notifyData.title = msgs[0];
|
|
|
|
notifyData.body = msgs[0];
|
|
notifyData.body = msgs[0];
|
|
- notifyData.eventId = $"{notifyCode}-{_snowflakeId.NextId()}";
|
|
|
|
- notifyData.eventName = $"{msgs[0]}";
|
|
|
|
- notifyData.data = replaceData;
|
|
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- notifyData.hubName = "hita5";
|
|
|
|
- notifyData.sender = "ies5";
|
|
|
|
- notifyData.tags = tags;
|
|
|
|
- notifyData.title = msgs[0];
|
|
|
|
- notifyData.body =replaceData.Keys.Select(x => msgs[1].Replace("{"+x+"}", $"{replaceData[x]}"));
|
|
|
|
- notifyData.eventId = $"{notifyCode}-{_snowflakeId.NextId()}";
|
|
|
|
- notifyData.eventName = $"{msgs[0]}";
|
|
|
|
- notifyData.data = replaceData;
|
|
|
|
|
|
+ replaceData.Keys.ToList().ForEach(x => {
|
|
|
|
+ msgs[1]= msgs[1].Replace("{" + x + "}", $"{replaceData[x]}");
|
|
|
|
+ });
|
|
|
|
+ notifyData.body = msgs[1];
|
|
}
|
|
}
|
|
|
|
+ _ = _httpClient.PostAsJsonAsync(url, notifyData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return (HttpStatusCode.BadRequest, null);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ public class NotifyData {
|
|
|
|
+ public string hubName { get; set; }
|
|
|
|
+ public string sender { get; set; }
|
|
|
|
+ public List<string> tags { get; set; } = new List<string>();
|
|
|
|
+ public string title { get; set; }
|
|
|
|
+ public string body { get; set; }
|
|
|
|
+ public string eventId { get; set; }
|
|
|
|
+ public string eventName { get; set; }
|
|
|
|
+ public string data { get; set; }
|
|
|
|
+ }
|
|
/// <summary>
|
|
/// <summary>
|
|
/// 发送短信验证码
|
|
/// 发送短信验证码
|
|
/// </summary>
|
|
/// </summary>
|