MobileCodeCheckController.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.MainModels;
  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 MobileCodeCheckController : BaseController
  18. {
  19. public MobileCodeCheckController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
  20. {
  21. }
  22. #region 我的-发送验证码
  23. // [Authorize]
  24. public JsonResult SendSms(string value)
  25. {
  26. value = DesDecrypt(value);
  27. JsonData data = JsonMapper.ToObject(value);
  28. AppResultJson result = SendSmsDo(value);
  29. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  30. }
  31. public AppResultJson SendSmsDo(string value)
  32. {
  33. JsonData data = JsonMapper.ToObject(value);
  34. Dictionary<string, object> Obj = new Dictionary<string, object>();
  35. string Mobile = data["Mobile"].ToString(); //手机号
  36. MobileCodeCheck check = RedisDbconn.Instance.Get<MobileCodeCheck>("MobileCodeCheck:" + Mobile);
  37. if (check != null)
  38. {
  39. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  40. }
  41. // string CheckCode = "111111";
  42. string CheckCode = function.get_Random(6);
  43. MobileCodeCheck query = new MobileCodeCheck()
  44. {
  45. Mobile = Mobile, //手机号
  46. CheckCode = CheckCode,
  47. };
  48. RedisDbconn.Instance.Set("MobileCodeCheck:" + Mobile, query);
  49. RedisDbconn.Instance.SetExpire("MobileCodeCheck:" + Mobile, 300);
  50. SendSMS.Instance.Do(Mobile, CheckCode); //发送短信
  51. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  52. }
  53. #endregion
  54. #region 检查签名是否合法,合法返回1,不合法返回提示信息
  55. /// <summary>
  56. /// 检查签名是否合法,合法返回1,不合法返回提示信息
  57. /// </summary>
  58. /// <param name="value">请求的参数(json字符串)</param>
  59. /// <param name="signField">要签名的字段</param>
  60. /// <returns></returns>
  61. private string CheckSign(string value, string[] signField)
  62. {
  63. JsonData json = JsonMapper.ToObject(value);
  64. Dictionary<string, string> dic = new Dictionary<string, string>();
  65. for (int i = 0; i < signField.Length; i++)
  66. {
  67. dic.Add(signField[i], json[signField[i]].ToString());
  68. }
  69. string sign = json["sign"].ToString(); //客户端签名字符串
  70. return new Sign().sign(dic, sign);
  71. }
  72. #endregion
  73. }
  74. }