wxr
2022-07-08 f16e7e4df7e7813e4a3052dae752aae3e6937b30
HDL_ON/Common/ImageUtlis.cs
@@ -147,9 +147,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();
                }
@@ -440,7 +440,7 @@
            try
            {
                if (string.IsNullOrEmpty(imageKey)) return null;
                byte[] imageBytes;
                if (!ignoreCache && Exists(imageKey))
                {
@@ -451,12 +451,12 @@
                {
                    //云端下载
                    imageBytes = GetImageDownloadUrlWithRegionUrl(imageKey, regionUrl);
                    if(imageBytes != null)
                    if (imageBytes != null)
                    {
                        //保存到本地
                        WriteFileByBytes(imageKey, imageBytes);
                    }
                }
                return imageBytes;
            }
@@ -466,6 +466,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
    }
}