Sms.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. //
  3. //namespace app\api\controller;
  4. //
  5. //use app\common\controller\Api;
  6. //use app\common\library\Sms as Smslib;
  7. //use app\common\model\User;
  8. //use think\Hook;
  9. //
  10. ///**
  11. // * 手机短信接口
  12. // */
  13. //class Sms extends Api
  14. //{
  15. // protected $noNeedLogin = '*';
  16. // protected $noNeedRight = '*';
  17. //
  18. // /**
  19. // * 发送验证码
  20. // *
  21. // * @param string $mobile 手机号
  22. // * @param string $event 事件名称
  23. // */
  24. // public function send()
  25. // {
  26. // $mobile = $this->request->request("mobile");
  27. // $event = $this->request->request("event");
  28. // $event = $event ? $event : 'register';
  29. //
  30. // if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
  31. // $this->error(__('手机号不正确'));
  32. // }
  33. // $last = Smslib::get($mobile, $event);
  34. // if ($last && time() - $last['createtime'] < 60) {
  35. // $this->error(__('发送频繁'));
  36. // }
  37. // $ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('createtime', '-1 hours')->count();
  38. // if ($ipSendTotal >= 5) {
  39. // $this->error(__('发送频繁'));
  40. // }
  41. // if ($event) {
  42. // $userinfo = User::getByMobile($mobile);
  43. // if ($event == 'register' && $userinfo) {
  44. // //已被注册
  45. // $this->error(__('已被注册'));
  46. // } elseif (in_array($event, ['changemobile']) && $userinfo) {
  47. // //被占用
  48. // $this->error(__('已被占用'));
  49. // } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
  50. // //未注册
  51. // $this->error(__('未注册'));
  52. // }
  53. // }
  54. // if (!Hook::get('sms_send')) {
  55. // $this->error(__('请在后台插件管理安装短信验证插件'));
  56. // }
  57. // $ret = Smslib::send($mobile, null, $event);
  58. // if ($ret) {
  59. // $this->success(__('发送成功'));
  60. // } else {
  61. // $this->error(__('发送失败,请检查短信配置是否正确'));
  62. // }
  63. // }
  64. //
  65. // /**
  66. // * 检测验证码
  67. // *
  68. // * @param string $mobile 手机号
  69. // * @param string $event 事件名称
  70. // * @param string $captcha 验证码
  71. // */
  72. // public function check()
  73. // {
  74. // $mobile = $this->request->request("mobile");
  75. // $event = $this->request->request("event");
  76. // $event = $event ? $event : 'register';
  77. // $captcha = $this->request->request("captcha");
  78. //
  79. // if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
  80. // $this->error(__('手机号不正确'));
  81. // }
  82. // if ($event) {
  83. // $userinfo = User::getByMobile($mobile);
  84. // if ($event == 'register' && $userinfo) {
  85. // //已被注册
  86. // $this->error(__('已被注册'));
  87. // } elseif (in_array($event, ['changemobile']) && $userinfo) {
  88. // //被占用
  89. // $this->error(__('已被占用'));
  90. // } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
  91. // //未注册
  92. // $this->error(__('未注册'));
  93. // }
  94. // }
  95. // $ret = Smslib::check($mobile, $captcha, $event);
  96. // if ($ret) {
  97. // $this->success(__('成功'));
  98. // } else {
  99. // $this->error(__('验证码不正确'));
  100. // }
  101. // }
  102. //}