MobileCodeCheckController.cs 3.1 KB

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