1
0

SendSmsValidate.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\api\validate;
  15. use app\common\validate\BaseValidate;
  16. /**
  17. * 短信验证
  18. * Class SmsValidate
  19. * @package app\api\validate
  20. */
  21. class SendSmsValidate extends BaseValidate
  22. {
  23. protected $rule = [
  24. 'mobile' => 'require|mobile',
  25. 'scene' => 'require',
  26. 'verifyCode' => 'require|checkVerifyCode',
  27. ];
  28. protected $message = [
  29. 'mobile.require' => '请输入手机号',
  30. 'mobile.mobile' => '请输入正确手机号',
  31. 'scene.require' => '请输入场景值',
  32. 'verifyCode.require' => '请输入图形验证码',
  33. ];
  34. /**
  35. * @notes 发送短信
  36. */
  37. public function sceneSendCode()
  38. {
  39. return $this->only(['mobile','scene','verifyCode']);
  40. }
  41. /**
  42. * @notes 图形验证码
  43. */
  44. public function sceneVerifyCode()
  45. {
  46. return $this->only(['mobile']);
  47. }
  48. /**
  49. * @notes 校验图形验证码
  50. */
  51. public function checkVerifyCode($scene, $rule, $data)
  52. {
  53. $captcha = cache('verifyCode_'.$data['mobile']);
  54. if (empty($captcha)) {
  55. return '图形验证码已失效,请重新获取';
  56. }
  57. if ($captcha != $data['verifyCode']) {
  58. return '图形验证码错误';
  59. }
  60. // 验证成功后删除验证码
  61. cache('verifyCode_'.$data['mobile'],null);
  62. return true;
  63. }
  64. }