Sms.php 984 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by PhpStorm
  4. * User: 林志杰
  5. * Email: [email protected]
  6. * Time: 2020/1/11 17:54
  7. */
  8. declare(strict_types=1);
  9. namespace app\api\controller;
  10. use app\common\business\Sms AS SmsBus;
  11. use app\api\validate\User;
  12. use app\BaseController;
  13. use think\exception\ValidateException;
  14. class Sms extends BaseController
  15. {
  16. public function code(): object
  17. {
  18. $phoneNumber = input('param.phone_number', '', 'trim');
  19. halt($phoneNumber);
  20. $data = [
  21. 'phoneNumber' => $phoneNumber
  22. ];
  23. try {
  24. validate(User::class)->scene('send_code')->check($data);
  25. } catch (ValidateException $e) {
  26. return show(config('status.error'), $e->getError());
  27. }
  28. // 调用business层
  29. if (SmsBus::sendCode($phoneNumber, 6, 'jd')) {
  30. return show(config('status.success'), '发送验证码成功');
  31. }
  32. return show(config('status.success'), '发送验证码失败');
  33. }
  34. }