using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Net.Http; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Security.Cryptography; using System.Net.Http.Json; using System.Text.Json; using System.IO; using TEAMModelOS.SDK.Extension; using System.Net; using TEAMModelOS.SDK.Models; namespace TEAMModelOS.SDK.DI { public class HttpTrigger { private readonly HttpClient _httpClient; public HttpTrigger(HttpClient httpClient) { _httpClient = httpClient; } // /// 请求信息 /// /// 釘釘Robot發送Url /// 加簽密鑰 /// 發送訊息 /// public async Task<(int status, string json)> RequestHttpTrigger(object data, string location, string url) { var keys = HttpTriggerUrl.HttpTrigger地址.GetDescriptionText().Split(','); string domain = ""; if (location.Equals("China-Dep")) { domain = keys[0]; } else if (location.Equals("China-Test")) { domain = keys[1]; } else if (location.Equals("China")) { domain = keys[2]; } else if (location.Equals("Global-Dep")) { domain = keys[3]; } else if (location.Equals("Global-Test")) { domain = keys[3]; } else if (location.Equals("Global")) { domain = keys[4]; } string link = domain.Contains("localhost") ? $"http://{domain}/api/{url}" : $"https://{domain}/api/{url}"; HttpContent httpContent = new StringContent(data.ToJsonString()); HttpResponseMessage responseMessage = await _httpClient.PostAsync(link, httpContent); if (responseMessage.StatusCode == HttpStatusCode.OK) { string Content = await responseMessage.Content.ReadAsStringAsync(); if (string.IsNullOrWhiteSpace(Content)) { return (200, null) ; } else { Content.ToObject().TryGetProperty("data", out JsonElement content); return (200, $"{content}"); } } else { string Content = await responseMessage.Content?.ReadAsStringAsync(); return (500, Content); } } } public enum HttpTriggerUrl { [Description("localhost:7071,teammodelosfunction-test.chinacloudsites.cn,teammodelosfunction.chinacloudsites.cn,localhost:7071,teammodelfunction.azurewebsites.net")] HttpTrigger地址, } }