截流自动化的商城平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

SmsSend.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace app\api\validate;
  3. use app\api\logic\LoginLogic;
  4. use app\common\basics\Validate;
  5. use app\common\enum\NoticeEnum;
  6. use app\common\model\Client_;
  7. use app\common\model\shop\Shop;
  8. use app\common\model\SmsLog;
  9. use app\common\model\user\User;
  10. use app\common\server\sms\Driver;
  11. use think\facade\Db;
  12. class SmsSend extends Validate
  13. {
  14. protected $rule = [
  15. 'mobile' => 'require|mobile|checkSms',
  16. 'key' => 'checkMobile',
  17. ];
  18. protected $message = [
  19. 'mobile.require' => '请输入手机号码',
  20. 'mobile.mobile' => '请输入正确的手机号码',
  21. ];
  22. //限制验证码发送频率
  23. protected function checkSms($value, $rule, $data)
  24. {
  25. $message_key = NoticeEnum::SMS_SCENE[$data['key']];
  26. $send_time = SmsLog::where(['message_key' => $message_key, 'mobile' => $value, 'is_verify' => 0])
  27. ->order('id desc')
  28. ->value('send_time');
  29. //一分钟内不能频繁发送
  30. if ($send_time && $send_time + 60 > time()) {
  31. return '验证码发送频繁,请稍后在发送';
  32. }
  33. return true;
  34. }
  35. //验证手机号
  36. protected function checkMobile($value, $rule, $data)
  37. {
  38. if($data['client'] == Client_::pc && $data['key'] == 'BGSJHM'){
  39. $data['new_mobile'] = $data['mobile'];
  40. $mobile = Db::name('user')->where(['id' => $data['user_id']])->value('mobile');
  41. $data['mobile'] = $mobile;
  42. }
  43. $user = User::where(['mobile' => $data['mobile'], 'del' => 0])->findOrEmpty();
  44. switch ($value) {
  45. case 'ZCYZ': //注册验证
  46. case 'BDSJHM': //绑定手机号码
  47. if (!$user->isEmpty()) {
  48. return '该手机号码已存在';
  49. }
  50. break;
  51. case 'YZMDL': //验证码登录
  52. if ($user->isEmpty()) { //账号不存在, 给他注册
  53. $post = request()->post();
  54. $post['password'] = '';
  55. LoginLogic::register($post);
  56. }
  57. break;
  58. case 'ZHMM': //找回密码
  59. case 'BGSJHM': //变更手机号码
  60. case 'ZHZFMM': // 找回支付密码
  61. if ($user->isEmpty()) {
  62. return '手机号码不存在';
  63. }
  64. break;
  65. case 'SJSQYZ': //商家入驻
  66. $shop = Shop::where(['mobile' => $data['mobile'], 'del' => 0])->findOrEmpty();
  67. if(!$shop->isEmpty()) {
  68. return '该手机号码已存在!';
  69. }
  70. break;
  71. default:
  72. return '场景错误';
  73. }
  74. return true;
  75. }
  76. }