目录结构调整
parent
d55098f815
commit
68d65e6933
|
@ -17,7 +17,7 @@ use Hyperf\HttpServer\Annotation\Middleware;
|
||||||
use App\Middleware\JWTAuthMiddleware;
|
use App\Middleware\JWTAuthMiddleware;
|
||||||
use App\Model\User;
|
use App\Model\User;
|
||||||
use App\Support\SendEmailCode;
|
use App\Support\SendEmailCode;
|
||||||
use App\Helper\HashHelper;
|
use App\Helpers\HashHelper;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
use App\Service\SmsCodeService;
|
use App\Service\SmsCodeService;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace App\Exception\Handler;
|
||||||
|
|
||||||
use App\Cache\Repository\LockRedis;
|
use App\Cache\Repository\LockRedis;
|
||||||
use App\Constants\ResponseCode;
|
use App\Constants\ResponseCode;
|
||||||
use App\Support\MailerTemplate;
|
use App\Templates\MailerTemplate;
|
||||||
use Hyperf\Contract\StdoutLoggerInterface;
|
use Hyperf\Contract\StdoutLoggerInterface;
|
||||||
use Hyperf\ExceptionHandler\ExceptionHandler;
|
use Hyperf\ExceptionHandler\ExceptionHandler;
|
||||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Helper;
|
namespace App\Helpers;
|
||||||
|
|
||||||
class ArrayHelper
|
class ArrayHelper
|
||||||
{
|
{
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
||||||
* @link https://github.com/gzydong/hyperf-chat
|
* @link https://github.com/gzydong/hyperf-chat
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper;
|
namespace App\Helpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash 密码加密辅助类
|
* Hash 密码加密辅助类
|
|
@ -8,7 +8,7 @@
|
||||||
* @link https://github.com/gzydong/hyperf-chat
|
* @link https://github.com/gzydong/hyperf-chat
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper;
|
namespace App\Helpers;
|
||||||
|
|
||||||
use Hashids\Hashids;
|
use Hashids\Hashids;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Helper;
|
namespace App\Helpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 正则验证助手
|
* 正则验证助手
|
|
@ -9,7 +9,7 @@ declare(strict_types=1);
|
||||||
* @link https://github.com/gzydong/hyperf-chat
|
* @link https://github.com/gzydong/hyperf-chat
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper;
|
namespace App\Helpers;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 字符串助手类
|
* 字符串助手类
|
|
@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Helper\HashHelper;
|
use App\Helpers\HashHelper;
|
||||||
use App\Model\Talk\TalkRecords;
|
use App\Model\Talk\TalkRecords;
|
||||||
use App\Model\User;
|
use App\Model\User;
|
||||||
use Hyperf\Utils\Str;
|
use Hyperf\Utils\Str;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Helper\HashHelper;
|
use App\Helpers\HashHelper;
|
||||||
use App\Model\Robot;
|
use App\Model\Robot;
|
||||||
use App\Model\User;
|
use App\Model\User;
|
||||||
use Hyperf\DbConnection\Db;
|
use Hyperf\DbConnection\Db;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Helper\HashHelper;
|
use App\Helpers\HashHelper;
|
||||||
use App\Model\User;
|
use App\Model\User;
|
||||||
use App\Model\Article\ArticleClass;
|
use App\Model\Article\ArticleClass;
|
||||||
use App\Model\UsersFriend;
|
use App\Model\UsersFriend;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Support;
|
namespace App\Support;
|
||||||
|
|
||||||
|
@ -21,7 +22,7 @@ class Response
|
||||||
* @param $data
|
* @param $data
|
||||||
* @return PsrResponseInterface
|
* @return PsrResponseInterface
|
||||||
*/
|
*/
|
||||||
public function json($data)
|
public function json($data): PsrResponseInterface
|
||||||
{
|
{
|
||||||
return $this->response->json($data);
|
return $this->response->json($data);
|
||||||
}
|
}
|
||||||
|
@ -33,7 +34,7 @@ class Response
|
||||||
* @param string $message 响应提示
|
* @param string $message 响应提示
|
||||||
* @return PsrResponseInterface
|
* @return PsrResponseInterface
|
||||||
*/
|
*/
|
||||||
public function success(array $data = [], $message = 'success')
|
public function success(array $data = [], $message = 'success'): PsrResponseInterface
|
||||||
{
|
{
|
||||||
$code = ResponseCode::SUCCESS;
|
$code = ResponseCode::SUCCESS;
|
||||||
return $this->response->json(compact('code', 'message', 'data'));
|
return $this->response->json(compact('code', 'message', 'data'));
|
||||||
|
@ -47,7 +48,7 @@ class Response
|
||||||
* @param int $code 错误码
|
* @param int $code 错误码
|
||||||
* @return PsrResponseInterface
|
* @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'));
|
return $this->response->json(compact('code', 'message', 'data'));
|
||||||
}
|
}
|
||||||
|
@ -59,7 +60,7 @@ class Response
|
||||||
* @param int $code 错误码
|
* @param int $code 错误码
|
||||||
* @return PsrResponseInterface
|
* @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([
|
return $this->response->withStatus(500)->json([
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace App\Support;
|
namespace App\Support;
|
||||||
|
|
||||||
|
use App\Templates\MailerTemplate;
|
||||||
|
|
||||||
class SendEmailCode
|
class SendEmailCode
|
||||||
{
|
{
|
||||||
const FORGET_PASSWORD = 'forget_password';
|
const FORGET_PASSWORD = 'forget_password';
|
||||||
|
@ -16,7 +18,7 @@ class SendEmailCode
|
||||||
* @param string $mobile
|
* @param string $mobile
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private function getKey(string $type, string $mobile)
|
private function getKey(string $type, string $mobile): string
|
||||||
{
|
{
|
||||||
return "email_code:{$type}:{$mobile}";
|
return "email_code:{$type}:{$mobile}";
|
||||||
}
|
}
|
||||||
|
@ -29,7 +31,7 @@ class SendEmailCode
|
||||||
* @param string $code 验证码
|
* @param string $code 验证码
|
||||||
* @return bool
|
* @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));
|
$sms_code = redis()->get($this->getKey($type, $email));
|
||||||
if (!$sms_code) {
|
if (!$sms_code) {
|
||||||
|
@ -84,7 +86,7 @@ class SendEmailCode
|
||||||
* @param float|int $exp 过期时间
|
* @param float|int $exp 过期时间
|
||||||
* @return bool
|
* @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);
|
return redis()->setex($key, $exp, $sms_code);
|
||||||
}
|
}
|
||||||
|
@ -96,7 +98,7 @@ class SendEmailCode
|
||||||
* @param string $email 邮箱地址
|
* @param string $email 邮箱地址
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function delCode(string $type, string $email)
|
public function delCode(string $type, string $email): int
|
||||||
{
|
{
|
||||||
return redis()->del($this->getKey($type, $email));
|
return redis()->del($this->getKey($type, $email));
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Templates;
|
||||||
|
|
||||||
|
abstract class BaseTemplate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 获取模板信息
|
||||||
|
*
|
||||||
|
* @param string $engine 模板引擎
|
||||||
|
* @param string $template 模板名称
|
||||||
|
* @param array $params 模板参数
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function view(string $engine, string $template, $params = []): string
|
||||||
|
{
|
||||||
|
return di()->get($engine)->render($template, $params, config('view.config', []));
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,29 +1,17 @@
|
||||||
<?php
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Support;
|
namespace App\Templates;
|
||||||
|
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 邮件视图模板
|
* 邮件视图模板库
|
||||||
*
|
*
|
||||||
* @package App\Support
|
* @package App\Templates
|
||||||
*/
|
*/
|
||||||
class MailerTemplate
|
class MailerTemplate extends BaseTemplate
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* 获取模板信息
|
|
||||||
*
|
|
||||||
* @param string $engine 模板引擎
|
|
||||||
* @param string $template 模板名称
|
|
||||||
* @param array $params 模板参数
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
private function view(string $engine, string $template, $params = []): string
|
|
||||||
{
|
|
||||||
return di()->get($engine)->render($template, $params, config('view.config', []));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证码通知 - 邮件模板
|
* 验证码通知 - 邮件模板
|
||||||
*
|
*
|
||||||
|
@ -31,7 +19,7 @@ class MailerTemplate
|
||||||
* @param array $params 模板参数
|
* @param array $params 模板参数
|
||||||
* @return string
|
* @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', [
|
return $this->view(config('view.engine'), 'emails.verify-code', [
|
||||||
'service_name' => $params['service_name'] ?? "邮箱绑定",
|
'service_name' => $params['service_name'] ?? "邮箱绑定",
|
||||||
|
@ -46,7 +34,7 @@ class MailerTemplate
|
||||||
* @param Throwable $throwable
|
* @param Throwable $throwable
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function errorNotice(Throwable $throwable)
|
public function errorNotice(Throwable $throwable): string
|
||||||
{
|
{
|
||||||
return $this->view(config('view.engine'), 'emails.error-notice', [
|
return $this->view(config('view.engine'), 'emails.error-notice', [
|
||||||
'throwable' => $throwable->getTraceAsString(),
|
'throwable' => $throwable->getTraceAsString(),
|
|
@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Traits;
|
namespace App\Traits;
|
||||||
|
|
||||||
use App\Helper\ArrayHelper;
|
use App\Helpers\ArrayHelper;
|
||||||
use Hyperf\Database\Model\Builder;
|
use Hyperf\Database\Model\Builder;
|
||||||
use Hyperf\Database\Model\Model;
|
use Hyperf\Database\Model\Model;
|
||||||
use Hyperf\DbConnection\Db;
|
use Hyperf\DbConnection\Db;
|
||||||
|
|
|
@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||||
namespace HyperfTest\Cases\Helper;
|
namespace HyperfTest\Cases\Helper;
|
||||||
|
|
||||||
|
|
||||||
use App\Helper\ArrayHelper;
|
use App\Helpers\ArrayHelper;
|
||||||
use HyperfTest\HttpTestCase;
|
use HyperfTest\HttpTestCase;
|
||||||
|
|
||||||
class ArrayHelperTest extends HttpTestCase
|
class ArrayHelperTest extends HttpTestCase
|
||||||
|
|
|
@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace HyperfTest\Cases\Helper;
|
namespace HyperfTest\Cases\Helper;
|
||||||
|
|
||||||
use App\Helper\RegularHelper;
|
use App\Helpers\RegularHelper;
|
||||||
use HyperfTest\HttpTestCase;
|
use HyperfTest\HttpTestCase;
|
||||||
|
|
||||||
class RegularHelperTest extends HttpTestCase
|
class RegularHelperTest extends HttpTestCase
|
||||||
|
|
Loading…
Reference in New Issue