Auth.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace app\common\controller;
  3. use app\BaseController;
  4. use app\common\model\MessageRecord;
  5. use think\Facade\Cache;
  6. class Auth extends BaseController
  7. {
  8. public function register(){
  9. $msg = "";
  10. if($this->request->isPost()){
  11. }
  12. return view("", ["msg" => $msg]);
  13. }
  14. public function verificationCode()
  15. {
  16. $phone = $this->request["phone"];
  17. $type = $this->request["type"];
  18. //校验手机号码是否为空
  19. if(\StrUtil::isEmpOrNull($phone)) {
  20. return json(["msg" => "请填写手机号码!"],500);
  21. }
  22. if (\StrUtil::isEmpOrNull($type)) {
  23. return json(["msg" => "请填写手机号码!"],500);
  24. }
  25. //校验手机号码格式是否正确
  26. if(\StrUtil::isMoblePhone($phone)) {
  27. return json(["msg" => "请填写正确的手机号码!"],500);
  28. }
  29. $record = Cache::get("verify_{$type}_{$phone}");
  30. if($record){
  31. $time = time();
  32. if($time - $record <= 60){
  33. return json(["msg" => "一分钟内请勿频繁发送短信!"],500);
  34. }
  35. }
  36. $code = '';
  37. for ($i = 1;$i <= 6;$i++){
  38. $code .= rand(0,9);
  39. }
  40. $template = "【晋江市人才服务平台】尊敬的用户,您的短信验证码为{$code},5分钟内有效。若非本人操作请忽略。";
  41. }
  42. }