wangxinhui
2025-10-26 733c975cd8647f6d006736f1863bad731e32e6fb
ÏîÄ¿´úÂë/WMS/WMSServices/WIDESEA_Core/Helper/HttpMesHelper.cs
@@ -11,7 +11,7 @@
{
    public class HttpMesHelper
    {
        public static string Post(string serviceAddress, string requestJson = null, string contentType = "application/json", Dictionary<string, string>? headers = null)
        public static string Post(string serviceAddress, string requestJson = "", string contentType = "application/json", Dictionary<string, string>? headers = null)
        {
            string result = string.Empty;
            DateTime beginDate = DateTime.Now;
@@ -22,20 +22,14 @@
                    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    
                    using HttpClient httpClient = new HttpClient();
                    httpClient.Timeout = new TimeSpan(0, 0, 60);
                    //正式
                    string authorization = "AppKey 1830415116987195392";
                    //测试
                    //string authorization = "AppKey 1773317109539201024";
                    httpClient.Timeout = new TimeSpan(0, 0, 30);
                    string LoginToken = AppSettings.Get("MESLoginToken");
                    headers = new Dictionary<string, string>
                    {
                        { "Authorization", authorization },
                        //正式
                        { "Site_tenant_id", "0dc2d164-8a62-417e-8a00-808007464feb" }
                        { "LoginToken", LoginToken }
                        //测试
                        //{ "Site_tenant_id", "ced19269-2b83-4577-be43-8cc2f700251e" }
                        //{ "LoginToken", "Z6_BusModel_LLD:5_92e848cf-b0b8-4f7e-9ac4-41e015c1fca3" }
                    };
                    if (headers != null)
                    {
@@ -55,37 +49,6 @@
            {
                Logger.Add(serviceAddress, requestJson == null ? "" : requestJson, result, beginDate);
            }
        }
        public static string GetStr(string textToEncrypt)
        {
            string publicKey;
            string privateKey;
            GenerateRSAKeyPair(out publicKey, out privateKey);
            byte[] encryptedBytes = RSAEncrypt(textToEncrypt, publicKey);
            // å¯ä»¥å°†åŠ å¯†åŽçš„å­—èŠ‚æ•°ç»„è½¬æ¢ä¸ºBase64字符串方便后续处理,例如传输等
            string encryptedBase64 = Convert.ToBase64String(encryptedBytes);
            return encryptedBase64;
        }
        public static void GenerateRSAKeyPair(out string publicKey, out string privateKey)
        {
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048))
            {
                publicKey = rsa.ToXmlString(false);
                privateKey = rsa.ToXmlString(true);
            }
        }
        public static byte[] RSAEncrypt(string plainText, string publicKey)
        {
            byte[] encryptedData;
            using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
            {
                rsa.FromXmlString(publicKey);
                // å°†æ–‡æœ¬è½¬æ¢ä¸ºUTF8编码的字节数组
                byte[] plainBytes = Encoding.UTF8.GetBytes(plainText);
                // ä½¿ç”¨SHA1哈希算法以及Pkcs1填充规则进行加密
                encryptedData = rsa.Encrypt(plainBytes, true);
            }
            return encryptedData;
        }
    }
}