MobileCodeCheckController.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 LitJson;
  11. using Library;
  12. namespace MySystem.Areas.Api.Controllers.v1
  13. {
  14. [Area("Api")]
  15. [Route("Api/v1/[controller]/[action]")]
  16. public class MobileCodeCheckController : BaseController
  17. {
  18. public MobileCodeCheckController(IHttpContextAccessor accessor) : base(accessor)
  19. {
  20. }
  21. #region 我的-发送验证码
  22. // [Authorize]
  23. public JsonResult SendSms(string value)
  24. {
  25. value = DesDecrypt(value);
  26. JsonData data = JsonMapper.ToObject(value);
  27. AppResultJson result = SendSmsDo(value);
  28. return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
  29. }
  30. public AppResultJson SendSmsDo(string value)
  31. {
  32. JsonData data = JsonMapper.ToObject(value);
  33. Dictionary<string, object> Obj = new Dictionary<string, object>();
  34. string Mobile = data["Mobile"].ToString(); //手机号
  35. string check = RedisDbconn.Instance.Get<string>("MobileCodeCheck:" + Mobile);
  36. if (check == "")
  37. {
  38. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  39. }
  40. string CheckCode = function.get_Random(6);
  41. RedisDbconn.Instance.Set("MobileCodeCheck:" + Mobile, CheckCode);
  42. RedisDbconn.Instance.SetExpire("MobileCodeCheck:" + Mobile, 300);
  43. SendSMS.Instance.Do(Mobile, CheckCode); //发送短信
  44. return new AppResultJson() { Status = "1", Info = "", Data = Obj };
  45. }
  46. #endregion
  47. }
  48. }