|
@@ -7,6 +7,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
+using Newtonsoft.Json;
|
|
|
using OpenXmlPowerTools;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
@@ -16,6 +17,7 @@ using System.IO;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
|
+using System.Net.Http.Headers;
|
|
|
using System.Net.Http.Json;
|
|
|
using System.Security.Policy;
|
|
|
using System.Text;
|
|
@@ -27,6 +29,7 @@ using TEAMModelOS.SDK.DI;
|
|
|
using TEAMModelOS.SDK.Extension;
|
|
|
using TEAMModelOS.SDK.Models;
|
|
|
using TEAMModelOS.SDK.Models.Cosmos.BI;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
using static TEAMModelOS.SDK.CoreAPIHttpService;
|
|
|
|
|
|
namespace TEAMModelOS.SDK
|
|
@@ -35,7 +38,8 @@ namespace TEAMModelOS.SDK
|
|
|
public class CoreAPIHttpServiceOptions
|
|
|
{
|
|
|
public string location { get; set; }
|
|
|
- public string url { get; set; }
|
|
|
+ public string coreUrl { get; set; }
|
|
|
+ public string bbUrl { get; set; }
|
|
|
public string clientID { get; set; }
|
|
|
public string clientSecret { get; set; }
|
|
|
|
|
@@ -55,12 +59,14 @@ namespace TEAMModelOS.SDK
|
|
|
_httpClient = httpClient;
|
|
|
string location = _configuration.GetValue<string>("Option:Location");
|
|
|
string url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
+ string bburl = _configuration.GetValue<string>("HaBookAuth:CoreBBAPI");
|
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
options = new CoreAPIHttpServiceOptions
|
|
|
{
|
|
|
location=location,
|
|
|
- url=url,
|
|
|
+ coreUrl=url,
|
|
|
+ bbUrl=bburl,
|
|
|
clientID=clientID,
|
|
|
clientSecret=clientSecret
|
|
|
};
|
|
@@ -79,11 +85,60 @@ namespace TEAMModelOS.SDK
|
|
|
public string token_type { get; set; }
|
|
|
}
|
|
|
|
|
|
+ public async Task<(HttpStatusCode code,string msg )> AdminChange(AdminChange data, string location, IConfiguration _configuration, DI.DingDing _dingDing)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ string url = _configuration.GetValue<string>("HaBookAuth:CoreBBAPI") + "/ies5/admin-change";
|
|
|
+
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ if (location.Contains("China"))
|
|
|
+ {
|
|
|
+ location = "China";
|
|
|
+ }
|
|
|
+ else if (location.Contains("Global"))
|
|
|
+ {
|
|
|
+ location = "Global";
|
|
|
+ }
|
|
|
+ var client = _httpClient;
|
|
|
+ var token = await CoreTokenExtensions.CreateAccessToken(clientID, clientSecret, location);
|
|
|
+ if (client.DefaultRequestHeaders.Contains("Authorization"))
|
|
|
+ {
|
|
|
+ client.DefaultRequestHeaders.Remove("Authorization");
|
|
|
+ }
|
|
|
+ client.DefaultRequestHeaders.Add("Authorization", $"Bearer {token.AccessToken}");
|
|
|
+ HttpResponseMessage responseMessage = await client.PostAsJsonAsync(url, data);
|
|
|
+ if (responseMessage.Content != null)
|
|
|
+ {
|
|
|
+ string content = await responseMessage.Content.ReadAsStringAsync();
|
|
|
+ if (!string.IsNullOrWhiteSpace(content))
|
|
|
+ {
|
|
|
+
|
|
|
+ return (responseMessage.StatusCode, content);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return (responseMessage.StatusCode, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return (responseMessage.StatusCode, null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ await _dingDing.SendBotMsg($"{location},管理员或管理权限变更通知BB处理相关通知异常\n{data.ToJsonString()}{ex.Message},\n{ex.StackTrace}", GroupNames.成都开发測試群組);
|
|
|
+ return (HttpStatusCode.InternalServerError, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
public async Task<(HttpStatusCode code , CoreAPIToken token )> GetCoreAPIoAuth2Token(Dictionary<string,object> data, string location, IConfiguration _configuration, DI.DingDing _dingDing) {
|
|
|
try
|
|
|
{
|
|
|
var url = _configuration.GetValue<string>("HaBookAuth:CoreAPI");
|
|
|
- //url = "https://api2-rc.teammodel.cn";
|
|
|
+ //coreUrl = "https://api2-rc.teammodel.cn";
|
|
|
url = $"{url}/oauth2/token";
|
|
|
var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
@@ -332,8 +387,8 @@ namespace TEAMModelOS.SDK
|
|
|
result = $"{responseMessage.StatusCode},推送返回的状态码。";
|
|
|
|
|
|
}
|
|
|
- // _dingDing.SendBotMsg($"{location}站点发送消息:\n{url}/service/PushNotify \nheader: {token.AccessToken} \nresult:{result}\n params:{notifyData.ToJsonString()}", GroupNames.成都开发測試群組).GetAwaiter().GetResult();
|
|
|
-
|
|
|
+ // _dingDing.SendBotMsg($"{location}站点发送消息:\n{url}/service/PushNotify \nheader: {token.AccessToken} \nresult:{result}\n params:{notifyData.ToJsonString()}", GroupNames.成都开发測試群組).GetAwaiter().GetResult();
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -692,7 +747,7 @@ namespace TEAMModelOS.SDK
|
|
|
var clientID = options.clientID;
|
|
|
var clientSecret = options.clientSecret;
|
|
|
var location = options.location;
|
|
|
- var url = options.url;
|
|
|
+ var url = options.coreUrl;
|
|
|
if (location.Contains("China"))
|
|
|
{ url =string.IsNullOrWhiteSpace(url)? "https://api2.teammodel.cn":url;
|
|
|
location = "China";
|