diff --git a/app/Controller/Api/V1/AuthController.php b/app/Controller/Api/V1/AuthController.php index 1765aed..77c227e 100644 --- a/app/Controller/Api/V1/AuthController.php +++ b/app/Controller/Api/V1/AuthController.php @@ -43,7 +43,7 @@ class AuthController extends CController { $params = $this->request->inputs(['mobile', 'password', 'platform']); $this->validate($params, [ - 'mobile' => "required|regex:/^1[345789][0-9]{9}$/", + 'mobile' => "required|phone", 'password' => 'required', 'platform' => 'required|in:h5,ios,windows,mac,web', ]); @@ -94,7 +94,7 @@ class AuthController extends CController $params = $this->request->all(); $this->validate($params, [ 'nickname' => "required|max:20", - 'mobile' => "required|regex:/^1[345789][0-9]{9}$/", + 'mobile' => "required|phone", 'password' => 'required|max:16', 'sms_code' => 'required|digits:6', 'platform' => 'required|in:h5,ios,windows,mac,web', @@ -128,7 +128,7 @@ class AuthController extends CController { $params = $this->request->inputs(['mobile', 'password', 'sms_code']); $this->validate($params, [ - 'mobile' => "required|regex:/^1[345789][0-9]{9}$/", + 'mobile' => "required|phone", 'password' => 'required|max:16', 'sms_code' => 'required|digits:6', ]); @@ -175,7 +175,7 @@ class AuthController extends CController $params = $this->request->inputs(['type', 'mobile']); $this->validate($params, [ 'type' => "required", - 'mobile' => "required|regex:/^1[345789][0-9]{9}$/" + 'mobile' => "required|phone" ]); if (!$this->smsCodeService->isUsages($params['type'])) { diff --git a/app/Controller/Api/V1/UsersController.php b/app/Controller/Api/V1/UsersController.php index 5b989fb..86916b8 100644 --- a/app/Controller/Api/V1/UsersController.php +++ b/app/Controller/Api/V1/UsersController.php @@ -184,7 +184,7 @@ class UsersController extends CController { $params = $this->request->inputs(['mobile', 'password', 'sms_code']); $this->validate($params, [ - 'mobile' => "required|regex:/^1[345789][0-9]{9}$/", + 'mobile' => "required|phone", 'password' => 'required', 'sms_code' => 'required|digits:6' ]); @@ -256,7 +256,7 @@ class UsersController extends CController { $params = $this->request->inputs(['mobile']); $this->validate($params, [ - 'mobile' => "present|regex:/^1[345789][0-9]{9}$/" + 'mobile' => "present|phone" ]); $user_id = $this->uid(); diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php new file mode 100644 index 0000000..814d7b7 --- /dev/null +++ b/app/Controller/TestController.php @@ -0,0 +1,25 @@ +response->json([ + 'code' => 200 + ]); + } +} diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php index 30b4e8e..6c808d1 100644 --- a/app/Exception/Handler/AppExceptionHandler.php +++ b/app/Exception/Handler/AppExceptionHandler.php @@ -57,6 +57,10 @@ class AppExceptionHandler extends ExceptionHandler */ public function sendAdminEmail(Throwable $throwable) { + if (config('app_env') != 'dev') { + return; + } + $error = implode(':', [ 'error', md5($throwable->getFile() . $throwable->getCode() . $throwable->getLine()), diff --git a/app/Listener/ValidatorFactoryResolvedListener.php b/app/Listener/ValidatorFactoryResolvedListener.php index a86c38d..762095a 100644 --- a/app/Listener/ValidatorFactoryResolvedListener.php +++ b/app/Listener/ValidatorFactoryResolvedListener.php @@ -26,17 +26,21 @@ class ValidatorFactoryResolvedListener implements ListenerInterface $validatorFactory = $event->validatorFactory; // 注册了 ids 验证器(验证英文逗号拼接的整形数字字符串 例如:[1,2,3,4,5]) - $validatorFactory->extend('ids', function ($attribute, $value, $parameters, $validator) { - if (!is_string($value)) { - return false; - } + $validatorFactory->extend('ids', function ($attribute, $value) { + if (!is_string($value)) return false; - $arr = explode(',', $value); - foreach ($arr as $id) { + foreach (explode(',', $value) as $id) { if (!check_int($id)) return false; } return true; }); + + // 注册手机号验证器 + $validatorFactory->extend('phone', function ($attribute, $value) { + if (!is_string($value)) return false; + + return (bool)preg_match('/^1[345789][0-9]{9}$/', $value); + }); } } diff --git a/storage/languages/en/validation.php b/storage/languages/en/validation.php index 6ba00d1..6e9e0de 100644 --- a/storage/languages/en/validation.php +++ b/storage/languages/en/validation.php @@ -176,4 +176,5 @@ return [ 'sequential_array' => 'The :attribute must be sequential array', 'ids' => ' :attribute 字段 ids 格式不正确', + 'phone' => 'The :attribute must be a valid phone number', ]; diff --git a/storage/languages/zh_CN/validation.php b/storage/languages/zh_CN/validation.php index 7610b33..5454935 100644 --- a/storage/languages/zh_CN/validation.php +++ b/storage/languages/zh_CN/validation.php @@ -176,4 +176,5 @@ return [ 'sequential_array' => ':attribute 必须是一个有序数组', 'ids' => ' :attribute 字段 ids 格式不正确', + 'phone' => ':attribute 必须为一个有效的电话号码', ];