UserBackController.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 MySystem.MainModels;
  10. using LitJson;
  11. using Library;
  12. namespace MySystem.Areas.Api.Controllers.v1
  13. {
  14. [Area("Api")]
  15. [Route("Api/v1/[controller]/[action]")]
  16. public class UserBackController : BaseController
  17. {
  18. public UserBackController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  19. {
  20. }
  21. #region 商户-提交意见反馈
  22. [Authorize]
  23. public JsonResult Add(string value)
  24. {
  25. value = DesDecrypt(value);
  26. JsonData data = JsonMapper.ToObject(value);
  27. AppResultJson result = AddDo(value);
  28. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  29. }
  30. public AppResultJson AddDo(string value)
  31. {
  32. JsonData data = JsonMapper.ToObject(value);
  33. string Content = data["Content"].ToString(); //回复内容
  34. int BackKind = int.Parse(function.CheckInt(data["BackKind"].ToString())); //反馈类型
  35. int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); //商户Id
  36. if (string.IsNullOrEmpty(data["Content"].ToString()))
  37. {
  38. return new AppResultJson() { Status = "-1", Info = "请填写回复内容" };
  39. }
  40. if (data["Content"].ToString().Length > 100)
  41. {
  42. return new AppResultJson() { Status = "-1", Info = "回复内容最多100个字符" };
  43. }
  44. Dictionary<string, object> Obj = new Dictionary<string, object>();
  45. maindb.UserBack.Add(new UserBack()
  46. {
  47. CreateDate = DateTime.Now, //创建时间
  48. UpdateDate = DateTime.Now, //修改时间
  49. Content = Content, //回复内容
  50. BackKind = BackKind, //反馈类型
  51. UserId = UserId,
  52. });
  53. maindb.SaveChanges();
  54. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  55. }
  56. #endregion
  57. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  58. /// <summary>
  59. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  60. /// </summary>
  61. /// <param name="value">请求的参数(json字符串)</param>
  62. /// <param name="signField">要签名的字段</param>
  63. /// <returns></returns>
  64. private string CheckSign(string value, string[] signField)
  65. {
  66. JsonData json = JsonMapper.ToObject(value);
  67. Dictionary<string, string> dic = new Dictionary<string, string>();
  68. for (int i = 0; i < signField.Length; i++)
  69. {
  70. dic.Add(signField[i], json[signField[i]].ToString());
  71. }
  72. string sign = json["sign"].ToString(); //客户端签名字符串
  73. return new Sign().sign(dic, sign);
  74. }
  75. #endregion
  76. }
  77. }