控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Sms.php 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2018 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | fastadmin: https://www.fastadmin.net/
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 手机短信接口
  13. // +----------------------------------------------------------------------
  14. namespace app\api\controller;
  15. use app\common\controller\Api;
  16. use app\common\library\Sms as Smslib;
  17. use app\member\model\Member;
  18. use think\facade\Hook;
  19. use think\facade\Validate;
  20. /**
  21. * @title 手机短信接口
  22. * @controller api\controller\Sms
  23. * @group base
  24. */
  25. class Sms extends Api
  26. {
  27. /**
  28. * @title 发送验证码
  29. * @desc 最基础的接口注释写法
  30. * @author 御宅男
  31. * @url /api/Sms/send
  32. * @method GET
  33. * @tag 手机 验证码
  34. * @param name:mobile type:string require:1 desc:手机号
  35. * @param name:event type:string require:1 desc:事件名称
  36. * @return name:data type:array ref:definitions\dictionary
  37. */
  38. public function send()
  39. {
  40. $mobile = $this->request->request("mobile");
  41. $event = $this->request->request("event");
  42. $event = $event ? $event : 'register';
  43. if (!$mobile || !Validate::isMobile($mobile)) {
  44. $this->error('手机号不正确');
  45. }
  46. $last = Smslib::get($mobile, $event);
  47. if ($last && time() - $last['create_time'] < 60) {
  48. $this->error('发送频繁');
  49. }
  50. $ipSendTotal = \app\common\model\Sms::where(['ip' => $this->request->ip()])->whereTime('create_time', '-1 hours')->count();
  51. if ($ipSendTotal >= 5) {
  52. $this->error('发送频繁');
  53. }
  54. if ($event) {
  55. $userinfo = Member::getByMobile($mobile);
  56. if ($event == 'register' && $userinfo) {
  57. $this->error('已被注册');
  58. } elseif (in_array($event, ['changemobile']) && $userinfo) {
  59. $this->error('已被占用');
  60. } elseif (in_array($event, ['changepwd', 'resetpwd']) && !$userinfo) {
  61. $this->error('未注册');
  62. }
  63. }
  64. if (!Hook::get('sms_send')) {
  65. $this->error('请在后台插件管理安装短信验证插件');
  66. }
  67. $ret = Smslib::send($mobile, null, $event);
  68. if ($ret) {
  69. $this->success('发送成功');
  70. } else {
  71. $this->error('发送失败');
  72. }
  73. }
  74. /**
  75. * @title 检测验证码
  76. * @desc 最基础的接口注释写法
  77. * @author 御宅男
  78. * @url /api/Sms/check
  79. * @method GET
  80. * @tag 手机 验证码
  81. * @param name:mobile type:string require:1 desc:手机号
  82. * @param name:event type:string require:1 desc:事件名称
  83. * @param name:captcha type:string require:1 desc:验证码
  84. * @return name:data type:array ref:definitions\dictionary
  85. */
  86. public function check()
  87. {
  88. }
  89. }