wxr
2022-08-17 d6578b10542226650e263815dea75e598a7090f9
HDL_ON/Common/ImageUtlis.cs
@@ -4,6 +4,8 @@
using System.IO;
using HDL_ON.Common;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace HDL_ON
{
@@ -179,19 +181,26 @@
        /// </summary>
        public byte[] GetImageDownloadUrl(string imageKey)
        {
            var requestJson = HttpUtil.GetSignRequestJson(new GetImageUrlObj()
            if (imageKey.StartsWith("https:"))
            {
                imageKey = imageKey,
            });
            var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetImageUrl, requestJson);
            if (revertObj.Code == StateCode.SUCCESS)
                return HttpUtil.HttpsDownload(imageKey);
            }
            else
            {
                if (revertObj.Data != null)
                var requestJson = HttpUtil.GetSignRequestJson(new GetImageUrlObj()
                {
                    if (!string.IsNullOrEmpty(revertObj.Data.ToString()))
                    imageKey = imageKey,
                });
                var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_GetImageUrl, requestJson);
                if (revertObj.Code == StateCode.SUCCESS)
                {
                    if (revertObj.Data != null)
                    {
                        var url = revertObj.Data.ToString();
                        return HttpUtil.HttpsDownload(url);
                        if (!string.IsNullOrEmpty(revertObj.Data.ToString()))
                        {
                            var url = revertObj.Data.ToString();
                            return HttpUtil.HttpsDownload(url);
                        }
                    }
                }
            }
@@ -294,6 +303,34 @@
            }
        }
        string strKey = "abcdefgh";//注意:这里的密钥sKey必须能转为8个byte,即输入密钥为8半角个字符或者4个全角字符或者4个汉字的字符串
        string strIV = "ijklmnop";
        // 加密
        private string Encrypt(string _strQ)
        {
            byte[] buffer = Encoding.UTF8.GetBytes(_strQ);
            MemoryStream ms = new MemoryStream();
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            CryptoStream encStream = new CryptoStream(ms, des.CreateEncryptor(Encoding.UTF8.GetBytes(strKey), Encoding.UTF8.GetBytes(strIV)), CryptoStreamMode.Write);
            encStream.Write(buffer, 0, buffer.Length);
            encStream.FlushFinalBlock();
            return Convert.ToBase64String(ms.ToArray());
        }
        // 解密
        private string Decrypt(string _strQ)
        {
            byte[] buffer = Convert.FromBase64String(_strQ);
            MemoryStream ms = new MemoryStream();
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            CryptoStream encStream = new CryptoStream(ms, des.CreateDecryptor(Encoding.UTF8.GetBytes(strKey), Encoding.UTF8.GetBytes(strIV)), CryptoStreamMode.Write);
            encStream.Write(buffer, 0, buffer.Length);
            encStream.FlushFinalBlock();
            return Encoding.UTF8.GetString(ms.ToArray());
        }
        /// <summary>
        /// 2020-12-03
        /// 检测加载图片
@@ -306,6 +343,13 @@
        {
            try
            {
                var imageUrl = imageKey;
                if (imageUrl.StartsWith("http"))
                {
                    imageKey = Encrypt(imageKey);
                }
                //1.本地默认图库图片,直接加载本地
                if (imageKey.Contains("Classification/Room/Roombg") || imageKey.Contains("Intelligence/Gallery/scenebg"))
                {
@@ -333,7 +377,7 @@
                        //2.2 本地没缓存,开启线程云端下载然后缓存
                        System.Threading.Tasks.Task.Run(() =>
                        {
                            byte[] imageBytes = GetImageDownloadUrl(imageKey);
                            byte[] imageBytes = GetImageDownloadUrl(imageUrl);
                            if (imageBytes != null)
                            {
                                WriteFileByBytes(imageKey, imageBytes);
@@ -343,14 +387,14 @@
                                    if (frameLayout != null)
                                    {
                                        frameLayout.BackgroundImagePath = imageKey;
                                        //Utlis.WriteLine("imageKey 加载云端下载图片成功");
                                        Utlis.WriteLine("imageKey 加载云端下载图片成功");
                                    }
                                });
                            }
                            else
                            {
                                //2.4 下载是否,是否使用默认图片
                                //Utlis.WriteLine("imageKey 加载云端图片失败");
                                Utlis.WriteLine("imageKey 加载云端图片失败");
                            }
                        });
                    }