SendSmsValidate.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. return $this->only(['mobile','scene']);
  41. }
  42. /**
  43. * @notes 图形验证码
  44. */
  45. public function sceneVerifyCode()
  46. {
  47. return $this->only(['mobile']);
  48. }
  49. /**
  50. * @notes 校验图形验证码
  51. */
  52. public function checkVerifyCode($scene, $rule, $data)
  53. {
  54. $captcha = cache('verifyCode_'.$data['mobile']);
  55. if (empty($captcha)) {
  56. return '图形验证码已失效,请重新获取';
  57. }
  58. if ($captcha != $data['verifyCode']) {
  59. return '图形验证码错误';
  60. }
  61. // 验证成功后删除验证码
  62. cache('verifyCode_'.$data['mobile'],null);
  63. return true;
  64. }
  65. }