api.ashx.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. using System;
  2. using System.Reflection;
  3. using System.Web;
  4. using System.Web.SessionState;
  5. namespace iNethinkCMS.Web
  6. {
  7. public struct ResponseResult
  8. {
  9. private int code;
  10. public int Code
  11. {
  12. get { return code; }
  13. set { code = value; }
  14. }
  15. private string info;
  16. public string Info
  17. {
  18. get { return info; }
  19. set { info = value; }
  20. }
  21. private object data;
  22. public object Data
  23. {
  24. get { return data; }
  25. set { data = value; }
  26. }
  27. public ResponseResult(int code, string info, object data = null)
  28. {
  29. this.code = code;
  30. this.info = info;
  31. this.data = data;
  32. }
  33. }
  34. /// <summary>
  35. /// api 的摘要说明
  36. /// </summary>
  37. public class api : IHttpHandler, IRequiresSessionState
  38. {
  39. public bool IsReusable
  40. {
  41. get
  42. {
  43. throw new NotImplementedException();
  44. }
  45. }
  46. protected string json(ResponseResult rtndata)
  47. {
  48. return Newtonsoft.Json.JsonConvert.SerializeObject(rtndata);
  49. }
  50. public void ProcessRequest(HttpContext context)
  51. {
  52. context.Response.ContentType = "application/json";
  53. Type thisType = this.GetType();
  54. MethodInfo mi = thisType.GetMethod(context.Request.PathInfo.Split('/')[1]);
  55. try
  56. {
  57. context.Response.Write(
  58. json(
  59. (ResponseResult)
  60. mi.Invoke(this, new object[]{
  61. context
  62. })
  63. )
  64. );
  65. }
  66. catch (Exception e)
  67. {
  68. context.Response.Write(
  69. json(
  70. new ResponseResult(404, "Method invalid, info:" + e.Message)
  71. ));
  72. }
  73. }
  74. public ResponseResult sendVerificationCode(HttpContext context)
  75. {
  76. string tel = context.Request.QueryString["tel"];
  77. int code = Helper.VarifyCode.Next(tel);
  78. string result = Helper.Messager.Send(tel, $"欢迎试用利亚方舟影楼Erp管理软件,您的验证码是:{code}");
  79. return new ResponseResult(200, "Successed", code);
  80. }
  81. public ResponseResult isCodeValidate(HttpContext context)
  82. {
  83. string tel = context.Request.QueryString["tel"];
  84. int code = int.Parse(context.Request.QueryString["code"]);
  85. if (Helper.VarifyCode.isCodeValidate(tel, code))
  86. {
  87. return new ResponseResult(200, "Successed");
  88. }
  89. else
  90. {
  91. return new ResponseResult(403, "Failed");
  92. }
  93. }
  94. public ResponseResult ResponseConfirm(HttpContext context)
  95. {
  96. int id = Int32.Parse(context.Request.Form["id"]);
  97. string responsor = context.Request.Form["responsor"];
  98. string remark = context.Request.Form["remark"];
  99. BLL.BLL_Immediateuse.Responsed(id, responsor, remark);
  100. return new ResponseResult(200, "Successed");
  101. }
  102. public ResponseResult ApplicationForTrial(HttpContext context)
  103. {
  104. try
  105. {
  106. Model.Model_Immediateuse model = new Model.Model_Immediateuse();
  107. model.SJ = context.Request.Form["tel"];
  108. int code = int.Parse(context.Request.Form["code"]);
  109. if (BLL.BLL_Immediateuse.Exsits(model.SJ))
  110. {
  111. return new ResponseResult(-4, "号码已经成功提交,请不要重复提交,感谢您的支持");
  112. }
  113. else
  114. {
  115. if (Helper.VarifyCode.isCodeValidate(model.SJ, code))
  116. {
  117. model.Name = context.Request.Form["name"];
  118. model.lyName = context.Request.Form["lymc"];
  119. model.lyDZ = context.Request.Form["lydz"];
  120. model.lyGM = context.Request.Form["lygm"];
  121. model.ZW = context.Request.Form["zw"];
  122. model.date = DateTime.Now;
  123. BLL.BLL_Immediateuse bll = new BLL.BLL_Immediateuse();
  124. if (bll.Add(model) > 0)
  125. {
  126. Helper.Messager.Send("18602065722", $"通知:有新的用户({model.SJ})在官网登记了信息,请及时查询回复");
  127. Helper.Messager.Send("18607523124", $"通知:有新的用户({model.SJ})在官网登记了信息,请及时查询回复");
  128. return new ResponseResult(0, "Success!");
  129. }
  130. else
  131. {
  132. return new ResponseResult(-3, "系统异常,请直接与客服人员联系");
  133. }
  134. }
  135. else
  136. {
  137. return new ResponseResult(-1, "验证码不正确或已经失效!");
  138. }
  139. }
  140. }
  141. catch
  142. {
  143. return new ResponseResult(-2, "系统异常,请直接与客服人员联系");
  144. }
  145. }
  146. }
  147. }