ajax_sys.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // by 请勿倒卖,已申请软著,否则追究法律责任
  3. include "source/pack/dingxianginc/CaptchaClient.php";
  4. include "include/function/alisms.function.php";
  5. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  6. header("Cache-Control: no-cache, must-revalidate");
  7. header("Pragma: no-cache");
  8. header("content-type:application/json");
  9. $ac = SafeRequest("ac", "get");
  10. if ($ac == "send_sms") {
  11. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  12. $mobile = SafeRequest("phone", "post");
  13. $token = SafeRequest("token", "post");
  14. if (IN_DXINCAPPID == "") {
  15. if (strlen($token) > 100) {
  16. $check = "ok";
  17. } else {
  18. $check = "no";
  19. }
  20. } else {
  21. $appId = IN_DXINCAPPID;
  22. $appSecret = IN_DXINCAPPSECRET;
  23. $client = new CaptchaClient($appId, $appSecret);
  24. $client->setTimeOut(5);
  25. $response = $client->verifyToken($token);
  26. if ($response->result) {
  27. $check = "ok";
  28. } else {
  29. $check = "no";
  30. }
  31. }
  32. if ($check == 'ok') {
  33. $code = rand(100000, 999999);
  34. $ipcount = $GLOBALS["db"]->getone("select count(*) from " . tname("mobile") . " where in_ip='" . getonlineip() . "'");
  35. $mmcount = $GLOBALS["db"]->getone("select count(*) from " . tname("mobile") . " where in_mobile='" . $mobile . "'");
  36. if (!preg_match("/0?[1][0-9][0-9]{9}/", $mobile)) {
  37. exit(json_encode(array("code" => "404", "msg" => "手机号码不正确!")));
  38. } elseif ($GLOBALS["db"]->getone("select in_userid from " . tname("user") . " where in_mobile='" . $mobile . "'")) {
  39. exit(json_encode(array("code" => "404", "msg" => "手机号码已存在!")));
  40. } elseif (9 <= $ipcount) {
  41. exit(json_encode(array("code" => "404", "msg" => "当前IP超出短信发送限制!")));
  42. } elseif (9 <= $mmcount) {
  43. exit(json_encode(array("code" => "404", "msg" => "当前手机超出短信发送限制!")));
  44. } elseif (!empty($_COOKIE[$cookie])) {
  45. exit(json_encode(array("code" => "404", "msg" => "发送时间限制,请稍后再次发送!")));
  46. } else {
  47. $result = SENDALISMS($mobile, $code);
  48. if ($result) {
  49. if ($result == "OK") {
  50. $setarr = array("in_mobile" => $mobile, "in_code" => $code, "in_ip" => getonlineip(), "in_addtime" => date("Y-m-d H:i:s"), "in_timeout" => strtotime("+10 minute"));
  51. inserttable("mobile", $setarr, 1);
  52. exit(json_encode(array("code" => "200", "msg" => "短信验证码发送成功")));
  53. } else {
  54. exit(json_encode(array("code" => "404", "msg" => $result)));
  55. }
  56. } else {
  57. exit(json_encode(array("code" => "404", "msg" => "请求发送短信失败")));
  58. }
  59. }
  60. } else {
  61. exit(json_encode(array("code" => "404", "msg" => "验证码失效,请刷新后重试!")));
  62. }
  63. } else {
  64. exit(json_encode(array("code" => "404", "msg" => "参数错误")));
  65. }
  66. } elseif ($ac == "send_lostsms") {
  67. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  68. $mobile = SafeRequest("phone", "post");
  69. $token = SafeRequest("token", "post");
  70. if (IN_DXINCAPPID == "") {
  71. if (strlen($token) > 100) {
  72. $check = "ok";
  73. } else {
  74. $check = "no";
  75. }
  76. } else {
  77. $appId = IN_DXINCAPPID;
  78. $appSecret = IN_DXINCAPPSECRET;
  79. $client = new CaptchaClient($appId, $appSecret);
  80. $client->setTimeOut(5);
  81. $response = $client->verifyToken($token);
  82. if ($response->result) {
  83. $check = "ok";
  84. } else {
  85. $check = "no";
  86. }
  87. }
  88. if ($check == 'ok') {
  89. $code = rand(100000, 999999);
  90. $ipcount = $GLOBALS["db"]->getone("select count(*) from " . tname("mobile") . " where in_ip='" . getonlineip() . "'");
  91. $mmcount = $GLOBALS["db"]->getone("select count(*) from " . tname("mobile") . " where in_mobile='" . $mobile . "'");
  92. $uid = $GLOBALS["db"]->getone("select in_userid from " . tname("user") . " where in_mobile='" . $mobile . "'");
  93. $uid || exit(json_encode(array("code" => "404", "msg" => "手机号码不存在!")));
  94. if (!preg_match("/0?[1][0-9][0-9]{9}/", $mobile)) {
  95. exit(json_encode(array("code" => "404", "msg" => "手机号码不正确!")));
  96. } elseif (9 <= $ipcount) {
  97. exit(json_encode(array("code" => "404", "msg" => "当前IP超出短信发送限制!")));
  98. } elseif (9 <= $mmcount) {
  99. exit(json_encode(array("code" => "404", "msg" => "当前手机超出短信发送限制!")));
  100. } elseif (!empty($_COOKIE[$cookie])) {
  101. exit(json_encode(array("code" => "404", "msg" => "发送时间限制,请稍后再次发送!")));
  102. } else {
  103. $result = SENDALISMS($mobile, $code);
  104. if ($result) {
  105. if ($result == "OK") {
  106. $setarr = array("in_mobile" => $mobile, "in_code" => $code, "in_uid" => $uid, "in_ip" => getonlineip(), "in_addtime" => date("Y-m-d H:i:s"), "in_timeout" => strtotime("+10 minute"));
  107. inserttable("mobile", $setarr, 1);
  108. exit(json_encode(array("code" => "200", "msg" => "短信验证码发送成功")));
  109. } else {
  110. exit(json_encode(array("code" => $error_code, "msg" => $result)));
  111. }
  112. } else {
  113. exit(json_encode(array("code" => "404", "msg" => "请求发送短信失败")));
  114. }
  115. }
  116. } else {
  117. exit(json_encode(array("code" => "404", "msg" => "验证码验证失败!")));
  118. }
  119. } else {
  120. exit(json_encode(array("code" => "404", "msg" => "参数错误")));
  121. }
  122. }