From 68d65e6933d1b3dfd05de8fb34d0f81de22c00ec Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Tue, 31 Aug 2021 22:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9B=AE=E5=BD=95=E7=BB=93=E6=9E=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/Api/V1/UsersController.php | 2 +- app/Exception/Handler/AppExceptionHandler.php | 2 +- app/{Helper => Helpers}/ArrayHelper.php | 2 +- app/{Helper => Helpers}/HashHelper.php | 2 +- app/{Helper => Helpers}/HashIdsHelper.php | 2 +- app/{Helper => Helpers}/RegularHelper.php | 2 +- app/{Helper => Helpers}/StringHelper.php | 2 +- app/Repository/ExampleRepository.php | 2 +- app/Service/RobotService.php | 2 +- app/Service/UserService.php | 2 +- app/Support/Response.php | 9 ++++--- app/Support/SendEmailCode.php | 10 ++++--- app/Templates/BaseTemplate.php | 20 ++++++++++++++ app/{Support => Templates}/MailerTemplate.php | 26 +++++-------------- app/Traits/RepositoryTrait.php | 2 +- test/Cases/Helper/ArrayHelperTest.php | 2 +- test/Cases/Helper/RegularHelperTest.php | 2 +- 17 files changed, 51 insertions(+), 40 deletions(-) rename app/{Helper => Helpers}/ArrayHelper.php (94%) rename app/{Helper => Helpers}/HashHelper.php (97%) rename app/{Helper => Helpers}/HashIdsHelper.php (98%) rename app/{Helper => Helpers}/RegularHelper.php (97%) rename app/{Helper => Helpers}/StringHelper.php (95%) create mode 100644 app/Templates/BaseTemplate.php rename app/{Support => Templates}/MailerTemplate.php (60%) diff --git a/app/Controller/Api/V1/UsersController.php b/app/Controller/Api/V1/UsersController.php index 25c4d8d..d657f87 100644 --- a/app/Controller/Api/V1/UsersController.php +++ b/app/Controller/Api/V1/UsersController.php @@ -17,7 +17,7 @@ use Hyperf\HttpServer\Annotation\Middleware; use App\Middleware\JWTAuthMiddleware; use App\Model\User; use App\Support\SendEmailCode; -use App\Helper\HashHelper; +use App\Helpers\HashHelper; use App\Service\UserService; use App\Service\SmsCodeService; use Psr\Http\Message\ResponseInterface; diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php index 0074952..eee2de2 100644 --- a/app/Exception/Handler/AppExceptionHandler.php +++ b/app/Exception/Handler/AppExceptionHandler.php @@ -6,7 +6,7 @@ namespace App\Exception\Handler; use App\Cache\Repository\LockRedis; use App\Constants\ResponseCode; -use App\Support\MailerTemplate; +use App\Templates\MailerTemplate; use Hyperf\Contract\StdoutLoggerInterface; use Hyperf\ExceptionHandler\ExceptionHandler; use Hyperf\HttpMessage\Stream\SwooleStream; diff --git a/app/Helper/ArrayHelper.php b/app/Helpers/ArrayHelper.php similarity index 94% rename from app/Helper/ArrayHelper.php rename to app/Helpers/ArrayHelper.php index fb776fd..c84d7d1 100644 --- a/app/Helper/ArrayHelper.php +++ b/app/Helpers/ArrayHelper.php @@ -1,7 +1,7 @@ response->json($data); } @@ -33,7 +34,7 @@ class Response * @param string $message 响应提示 * @return PsrResponseInterface */ - public function success(array $data = [], $message = 'success') + public function success(array $data = [], $message = 'success'): PsrResponseInterface { $code = ResponseCode::SUCCESS; return $this->response->json(compact('code', 'message', 'data')); @@ -47,7 +48,7 @@ class Response * @param int $code 错误码 * @return PsrResponseInterface */ - public function fail($message = 'fail', $data = [], $code = ResponseCode::FAIL) + public function fail($message = 'fail', $data = [], $code = ResponseCode::FAIL): PsrResponseInterface { return $this->response->json(compact('code', 'message', 'data')); } @@ -59,7 +60,7 @@ class Response * @param int $code 错误码 * @return PsrResponseInterface */ - public function error($message = '', $code = ResponseCode::SERVER_ERROR) + public function error($message = '', $code = ResponseCode::SERVER_ERROR): PsrResponseInterface { return $this->response->withStatus(500)->json([ 'code' => $code, diff --git a/app/Support/SendEmailCode.php b/app/Support/SendEmailCode.php index db7f413..d79151e 100644 --- a/app/Support/SendEmailCode.php +++ b/app/Support/SendEmailCode.php @@ -2,6 +2,8 @@ namespace App\Support; +use App\Templates\MailerTemplate; + class SendEmailCode { const FORGET_PASSWORD = 'forget_password'; @@ -16,7 +18,7 @@ class SendEmailCode * @param string $mobile * @return string */ - private function getKey(string $type, string $mobile) + private function getKey(string $type, string $mobile): string { return "email_code:{$type}:{$mobile}"; } @@ -29,7 +31,7 @@ class SendEmailCode * @param string $code 验证码 * @return bool */ - public function check(string $type, string $email, string $code) + public function check(string $type, string $email, string $code): bool { $sms_code = redis()->get($this->getKey($type, $email)); if (!$sms_code) { @@ -84,7 +86,7 @@ class SendEmailCode * @param float|int $exp 过期时间 * @return bool */ - public function setCode(string $key, string $sms_code, $exp = 60 * 15) + public function setCode(string $key, string $sms_code, $exp = 60 * 15): bool { return redis()->setex($key, $exp, $sms_code); } @@ -96,7 +98,7 @@ class SendEmailCode * @param string $email 邮箱地址 * @return int */ - public function delCode(string $type, string $email) + public function delCode(string $type, string $email): int { return redis()->del($this->getKey($type, $email)); } diff --git a/app/Templates/BaseTemplate.php b/app/Templates/BaseTemplate.php new file mode 100644 index 0000000..6156612 --- /dev/null +++ b/app/Templates/BaseTemplate.php @@ -0,0 +1,20 @@ +get($engine)->render($template, $params, config('view.config', [])); + } +} diff --git a/app/Support/MailerTemplate.php b/app/Templates/MailerTemplate.php similarity index 60% rename from app/Support/MailerTemplate.php rename to app/Templates/MailerTemplate.php index 7efe43a..c0ab484 100644 --- a/app/Support/MailerTemplate.php +++ b/app/Templates/MailerTemplate.php @@ -1,29 +1,17 @@ get($engine)->render($template, $params, config('view.config', [])); - } - /** * 验证码通知 - 邮件模板 * @@ -31,7 +19,7 @@ class MailerTemplate * @param array $params 模板参数 * @return string */ - public function emailCode(string $sms_code, array $params = []) + public function emailCode(string $sms_code, array $params = []): string { return $this->view(config('view.engine'), 'emails.verify-code', [ 'service_name' => $params['service_name'] ?? "邮箱绑定", @@ -46,7 +34,7 @@ class MailerTemplate * @param Throwable $throwable * @return string */ - public function errorNotice(Throwable $throwable) + public function errorNotice(Throwable $throwable): string { return $this->view(config('view.engine'), 'emails.error-notice', [ 'throwable' => $throwable->getTraceAsString(), diff --git a/app/Traits/RepositoryTrait.php b/app/Traits/RepositoryTrait.php index 3519aa5..493c578 100644 --- a/app/Traits/RepositoryTrait.php +++ b/app/Traits/RepositoryTrait.php @@ -3,7 +3,7 @@ declare(strict_types=1); namespace App\Traits; -use App\Helper\ArrayHelper; +use App\Helpers\ArrayHelper; use Hyperf\Database\Model\Builder; use Hyperf\Database\Model\Model; use Hyperf\DbConnection\Db; diff --git a/test/Cases/Helper/ArrayHelperTest.php b/test/Cases/Helper/ArrayHelperTest.php index 8c5549c..10765a3 100644 --- a/test/Cases/Helper/ArrayHelperTest.php +++ b/test/Cases/Helper/ArrayHelperTest.php @@ -4,7 +4,7 @@ declare(strict_types=1); namespace HyperfTest\Cases\Helper; -use App\Helper\ArrayHelper; +use App\Helpers\ArrayHelper; use HyperfTest\HttpTestCase; class ArrayHelperTest extends HttpTestCase diff --git a/test/Cases/Helper/RegularHelperTest.php b/test/Cases/Helper/RegularHelperTest.php index b2a5c6d..e94081f 100644 --- a/test/Cases/Helper/RegularHelperTest.php +++ b/test/Cases/Helper/RegularHelperTest.php @@ -3,7 +3,7 @@ declare(strict_types=1); namespace HyperfTest\Cases\Helper; -use App\Helper\RegularHelper; +use App\Helpers\RegularHelper; use HyperfTest\HttpTestCase; class RegularHelperTest extends HttpTestCase