wxr
2022-07-25 f7d3739023f4d04a4ed2c30c13d9abf8da210da7
HDL_ON/Common/ImageUtlis.cs
@@ -3,6 +3,7 @@
using HDL_ON.DAL.Server;
using System.IO;
using HDL_ON.Common;
using System.Collections.Generic;
namespace HDL_ON
{
@@ -147,9 +148,9 @@
        {
            var requestJson = HttpUtil.GetSignRequestJson(uploadImageObj);
            var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.API_POST_UploadImage, requestJson);
            if(revertObj.Code == StateCode.SUCCESS)
            if (revertObj.Code == StateCode.SUCCESS)
            {
                if(revertObj.Data != null)
                if (revertObj.Data != null)
                {
                    return revertObj.Data.ToString();
                }
@@ -159,6 +160,17 @@
                IMessageCommon.Current.ShowErrorInfoAlter(revertObj.Code);
            }
            return "";
        }
        /// <summary>
        /// 获取场景默认图库列表
        /// </summary>
        /// <returns></returns>
        public ResponsePackNew GetSceneDefaultIconList()
        {
            var d = new Dictionary<string, object>();
            var requestJson = HttpUtil.GetSignRequestJson(d);
            var revertObj = HttpUtil.RequestHttpsPostFroHome(NewAPI.Api_Post_GetSceneDefaultIconList, requestJson);
            return revertObj;
        }
        /// <summary>
@@ -440,7 +452,7 @@
            try
            {
                if (string.IsNullOrEmpty(imageKey)) return null;
                byte[] imageBytes;
                if (!ignoreCache && Exists(imageKey))
                {
@@ -451,12 +463,12 @@
                {
                    //云端下载
                    imageBytes = GetImageDownloadUrlWithRegionUrl(imageKey, regionUrl);
                    if(imageBytes != null)
                    if (imageBytes != null)
                    {
                        //保存到本地
                        WriteFileByBytes(imageKey, imageBytes);
                    }
                }
                return imageBytes;
            }
@@ -466,6 +478,47 @@
            }
        }
        /// <summary>
        /// 下载用户头像
        /// </summary>
        /// <param name="imageUrl"></param>
        /// <param name="ignoreCache">忽略缓存</param>
        /// <param name="regionUrl">指定服务器域名,传空为使用当前用户地址</param>
        /// <returns></returns>
        public byte[] DownImageByImageUrl(string imageUrl, bool ignoreCache = false)
        {
            try
            {
                if (string.IsNullOrEmpty(imageUrl)) return null;
                byte[] imageBytes;
                if (!ignoreCache && Exists(imageUrl))
                {
                    //本地有缓存
                    imageBytes = ReadFile(imageUrl);
                }
                else
                {
                    //下载
                    imageBytes = HttpUtil.HttpsDownload(imageUrl);
                    if (imageBytes != null)
                    {
                        //保存到本地
                        WriteFileByBytes(imageUrl, imageBytes);
                    }
                }
                return imageBytes;
            }
            catch
            {
                return null;
            }
        }
        #endregion
    }
}