PublicMethodController.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Mvc;
  6. using Microsoft.AspNetCore.Http;
  7. using Microsoft.Extensions.Logging;
  8. using Microsoft.Extensions.Options;
  9. using System.DrawingCore.Imaging;
  10. using System.IO;
  11. using Library;
  12. using System.Collections;
  13. using LitJson;
  14. using System.Globalization;
  15. using System.Web;
  16. // For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
  17. namespace MySystem.Areas.Api.Controllers
  18. {
  19. [Area("Api")]
  20. [Route("Api/[controller]/[action]")]
  21. public class PublicMethodController : BaseController
  22. {
  23. public PublicMethodController(IHttpContextAccessor accessor) : base(accessor)
  24. {
  25. }
  26. #region 系统-上传图片
  27. public JsonResult UploadPhotoByBase64(string value)
  28. {
  29. try
  30. {
  31. value = value.Replace("data:image/png;base64,", "");
  32. string base64str = HttpUtility.UrlDecode(value).Replace(" ", "+");
  33. string dummyData = base64str.Replace("%", "").Replace(",", "").Replace(" ", "+");
  34. if (dummyData.Length % 4 > 0)
  35. {
  36. dummyData = dummyData.PadRight(dummyData.Length + 4 - dummyData.Length % 4, '=');
  37. }
  38. string Icon = function.base64StringToImage(dummyData, "/static/upload/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/", "MT" + function.MD5_16(Guid.NewGuid().ToString()) + ".png");
  39. return Json(new AppResultJson() { Status = "1", Info = "", Data = Icon });
  40. }
  41. catch (Exception ex)
  42. {
  43. LogHelper.Instance.WriteLog(DateTime.Now + ":" + ex.ToString(), "系统上传图片异常");
  44. return Json(new AppResultJson() { Status = "1", Info = "", Data = "" });
  45. }
  46. }
  47. #endregion
  48. }
  49. }