UploadParamsController.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Microsoft.Extensions.Logging;
  7. using Microsoft.Extensions.Options;
  8. using Microsoft.AspNetCore.Authorization;
  9. using System.Web;
  10. using MySystem.Models;
  11. using LitJson;
  12. using Library;
  13. namespace MySystem.Areas.Api.Controllers.v1
  14. {
  15. [Area("Api")]
  16. [Route("Api/v1/[controller]/[action]")]
  17. public class UploadParamsController : BaseController
  18. {
  19. public UploadParamsController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 通用-根据Base64返回图片地址
  23. [Authorize]
  24. public JsonResult Base64ToPic(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. Dictionary<string, object> Obj = Base64ToPicDo(value);
  29. return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
  30. }
  31. public Dictionary<string, object> Base64ToPicDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. string Base64 = data["Base64"].ToString(); //图片base64编码
  35. Dictionary<string, object> Obj = new Dictionary<string, object>();
  36. UploadParams query = new UploadParams();
  37. int Id = int.Parse(function.CheckInt(data["Id"].ToString()));
  38. query = new UploadParamsService().Query(Id);
  39. Obj.Add("PicUrl", ""); //图片地址
  40. return Obj;
  41. }
  42. #endregion
  43. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  44. /// <summary>
  45. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  46. /// </summary>
  47. /// <param name="value">请求的参数(json字符串)</param>
  48. /// <param name="signField">要签名的字段</param>
  49. /// <returns></returns>
  50. private string CheckSign(string value, string[] signField)
  51. {
  52. JsonData json = JsonMapper.ToObject(value);
  53. Dictionary<string, string> dic = new Dictionary<string, string>();
  54. for (int i = 0; i < signField.Length; i++)
  55. {
  56. dic.Add(signField[i], json[signField[i]].ToString());
  57. }
  58. string sign = json["sign"].ToString(); //客户端签名字符串
  59. return new Sign().sign(dic, sign);
  60. }
  61. #endregion
  62. }
  63. }