初始化
parent
da44242310
commit
0a4b140253
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Model\Chat\ChatRecordsForward;
|
||||
use App\Model\UsersFriend;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Result;
|
||||
|
@ -191,6 +192,15 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
unset($notifyInfo, $userInfo, $membersIds);
|
||||
break;
|
||||
case 4://会话记录消息
|
||||
$forward = ['num' => 0,'list' => []];
|
||||
|
||||
$forwardInfo = ChatRecordsForward::where('record_id', $result->id)->first(['records_id', 'text']);
|
||||
if ($forwardInfo) {
|
||||
$forward = [
|
||||
'num' => substr_count($forwardInfo->records_id, ',') + 1,
|
||||
'list' => json_decode($forwardInfo->text, true) ?? []
|
||||
];
|
||||
}
|
||||
|
||||
break;
|
||||
case 5://代码块消息
|
||||
|
|
|
@ -9,7 +9,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
|
||||
/**
|
||||
* Class ArticleController
|
||||
|
@ -100,7 +100,7 @@ class ArticleController extends CController
|
|||
|
||||
return $this->response->success(
|
||||
$this->articleService->getArticleDetail(
|
||||
$this->request->input('article_id'),
|
||||
(int)$this->request->input('article_id'),
|
||||
$this->uid()
|
||||
)
|
||||
);
|
||||
|
@ -139,7 +139,7 @@ class ArticleController extends CController
|
|||
'class_id' => 'required|integer'
|
||||
]);
|
||||
|
||||
if (!$this->articleService->delArticleClass($this->uid(), $params['class_id'])) {
|
||||
if (!$this->articleService->delArticleClass($this->uid(), (int)$params['class_id'])) {
|
||||
return $this->response->fail('笔记分类删除失败...');
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ class ArticleController extends CController
|
|||
|
||||
// 获取Redis锁
|
||||
if (RedisLock::lock($lockKey, 0, 3)) {
|
||||
$isTrue = $this->articleService->articleClassSort($this->uid(), $params['class_id'], $params['sort_type']);
|
||||
$isTrue = $this->articleService->articleClassSort($this->uid(), (int)$params['class_id'], (int)$params['sort_type']);
|
||||
|
||||
// 释放Redis锁
|
||||
RedisLock::release($lockKey, 0);
|
||||
|
@ -189,7 +189,7 @@ class ArticleController extends CController
|
|||
'toid' => 'required|integer'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->mergeArticleClass($this->uid(), $params['class_id'], $params['toid']);
|
||||
$isTrue = $this->articleService->mergeArticleClass($this->uid(), (int)$params['class_id'], (int)$params['toid']);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '合并完成...')
|
||||
|
@ -211,7 +211,7 @@ class ArticleController extends CController
|
|||
|
||||
$id = $this->articleService->editArticleTag(
|
||||
$this->uid(),
|
||||
$this->request->post('tag_id', 0),
|
||||
(int)$this->request->post('tag_id', 0),
|
||||
$this->request->post('tag_name', '')
|
||||
);
|
||||
|
||||
|
@ -232,7 +232,7 @@ class ArticleController extends CController
|
|||
'tag_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->delArticleTags($this->uid(), $params['tag_id']);
|
||||
$isTrue = $this->articleService->delArticleTags($this->uid(), (int)$params['tag_id']);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记标签删除完成...')
|
||||
|
@ -255,7 +255,7 @@ class ArticleController extends CController
|
|||
'md_content' => 'required',
|
||||
]);
|
||||
|
||||
$id = $this->articleService->editArticle($this->uid(), $params['article_id'], [
|
||||
$id = $this->articleService->editArticle($this->uid(), (int)$params['article_id'], [
|
||||
'title' => $params['title'],
|
||||
'abstract' => mb_substr(strip_tags($params['content']), 0, 200),
|
||||
'class_id' => $params['class_id'],
|
||||
|
@ -281,7 +281,7 @@ class ArticleController extends CController
|
|||
'article_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->updateArticleStatus($this->uid(), $params['article_id'], 2);
|
||||
$isTrue = $this->articleService->updateArticleStatus($this->uid(), (int)$params['article_id'], 2);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记删除成功...')
|
||||
|
@ -300,7 +300,7 @@ class ArticleController extends CController
|
|||
'article_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->updateArticleStatus($this->uid(), $params['article_id'], 1);
|
||||
$isTrue = $this->articleService->updateArticleStatus($this->uid(), (int)$params['article_id'], 1);
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记恢复成功...')
|
||||
: $this->response->fail('笔记恢复失败...');
|
||||
|
@ -355,8 +355,8 @@ class ArticleController extends CController
|
|||
|
||||
$isTrue = $this->articleService->setAsteriskArticle(
|
||||
$this->uid(),
|
||||
$params['article_id'],
|
||||
$params['type']
|
||||
(int)$params['article_id'],
|
||||
(int)$params['type']
|
||||
);
|
||||
|
||||
return $isTrue
|
||||
|
@ -377,7 +377,7 @@ class ArticleController extends CController
|
|||
'tags' => 'required|array'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->updateArticleTag($this->uid(), $params['article_id'], $params['tags']);
|
||||
$isTrue = $this->articleService->updateArticleTag($this->uid(), (int)$params['article_id'], $params['tags']);
|
||||
return $isTrue
|
||||
? $this->response->success([], 'success...')
|
||||
: $this->response->fail('编辑失败...');
|
||||
|
@ -395,7 +395,7 @@ class ArticleController extends CController
|
|||
'article_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->foreverDelArticle($this->uid(), $params['article_id']);
|
||||
$isTrue = $this->articleService->foreverDelArticle($this->uid(), (int)$params['article_id']);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记删除成功...')
|
||||
|
@ -425,7 +425,7 @@ class ArticleController extends CController
|
|||
'annex_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->updateArticleAnnexStatus($this->uid(), $params['annex_id'], 2);
|
||||
$isTrue = $this->articleService->updateArticleAnnexStatus($this->uid(), (int)$params['annex_id'], 2);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记附件删除成功...')
|
||||
|
@ -444,7 +444,7 @@ class ArticleController extends CController
|
|||
'annex_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->updateArticleAnnexStatus($this->uid(), $params['annex_id'], 1);
|
||||
$isTrue = $this->articleService->updateArticleAnnexStatus($this->uid(), (int)$params['annex_id'], 1);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记附件恢复成功...')
|
||||
|
@ -487,7 +487,7 @@ class ArticleController extends CController
|
|||
'annex_id' => 'required|integer|min:0'
|
||||
]);
|
||||
|
||||
$isTrue = $this->articleService->foreverDelAnnex($this->uid(), $params['annex_id']);
|
||||
$isTrue = $this->articleService->foreverDelAnnex($this->uid(), (int)$params['annex_id']);
|
||||
|
||||
return $isTrue
|
||||
? $this->response->success([], '笔记附件删除成功...')
|
||||
|
|
|
@ -11,7 +11,7 @@ use Hyperf\HttpServer\Annotation\Middleware;
|
|||
use App\Service\UserService;
|
||||
use App\Service\SmsCodeService;
|
||||
use Phper666\JWTAuth\JWT;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
|
||||
/**
|
||||
* 授权相关控制器
|
||||
|
|
|
@ -9,7 +9,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
use App\Service\EmoticonService;
|
||||
|
||||
/**
|
||||
|
|
|
@ -9,7 +9,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
use App\Service\GroupService;
|
||||
use App\Model\UsersChatList;
|
||||
use App\Model\Group\UsersGroup;
|
||||
|
|
|
@ -17,7 +17,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
use Hyperf\Utils\Str;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use App\Amqp\Producer\ChatMessageProducer;
|
||||
|
|
|
@ -9,7 +9,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
|
||||
/**
|
||||
* 上传控制器
|
||||
|
@ -51,7 +51,7 @@ class UploadController extends CController
|
|||
@file_put_contents($this->uploadService->driver($path), $data);
|
||||
return $this->response->success(['avatar' => get_media_url($path)]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取拆分文件信息
|
||||
*
|
||||
|
|
|
@ -7,7 +7,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||
use Hyperf\HttpServer\Annotation\Controller;
|
||||
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||
use Hyperf\HttpServer\Annotation\Middleware;
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware;
|
||||
use App\Middleware\JWTAuthMiddleware;
|
||||
use App\Constants\ResponseCode;
|
||||
use App\Helper\Hash;
|
||||
use App\Model\User;
|
||||
|
|
|
@ -2,43 +2,70 @@
|
|||
|
||||
namespace App\Middleware;
|
||||
|
||||
use Phper666\JWTAuth\Middleware\JWTAuthMiddleware as BaseJWTAuthMiddleware;
|
||||
use Phper666\JWTAuth\Exception\TokenValidException;
|
||||
use Phper666\JWTAuth\Util\JWTUtil;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Hyperf\HttpServer\Contract\ResponseInterface as HttpResponse;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use Psr\SimpleCache\InvalidArgumentException;
|
||||
use Phper666\JWTAuth\JWT;
|
||||
use Phper666\JWTAuth\Util\JWTUtil;
|
||||
|
||||
class JWTAuthMiddleware extends BaseJWTAuthMiddleware
|
||||
/**
|
||||
* Http Token 授权验证中间件
|
||||
*
|
||||
* @package App\Middleware
|
||||
*/
|
||||
class JWTAuthMiddleware implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
* @param ServerRequestInterface $request
|
||||
* @param RequestHandlerInterface $handler
|
||||
* @return ResponseInterface
|
||||
* @throws InvalidArgumentException
|
||||
* @throws \Throwable
|
||||
* @var RequestInterface
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var HttpResponse
|
||||
*/
|
||||
protected $response;
|
||||
|
||||
/**
|
||||
* @var JWT
|
||||
*/
|
||||
protected $jwt;
|
||||
|
||||
public function __construct(HttpResponse $response, RequestInterface $request, JWT $jwt)
|
||||
{
|
||||
$this->response = $response;
|
||||
$this->request = $request;
|
||||
$this->jwt = $jwt;
|
||||
}
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$isValidToken = false;
|
||||
// 根据具体业务判断逻辑走向,这里假设用户携带的token有效
|
||||
$token = $request->getHeaderLine('Authorization') ?? '';
|
||||
if (strlen($token) > 0) {
|
||||
$isValidToken = true;
|
||||
|
||||
// 获取请求token
|
||||
$token = $request->getHeaderLine('Authorization') ?? $this->request->input('token', '');
|
||||
|
||||
if (!empty($token)) {
|
||||
try {
|
||||
$token = JWTUtil::handleToken($token);
|
||||
if ($token !== false && $this->jwt->checkToken($token)) {
|
||||
$isValidToken = true;
|
||||
}
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new TokenValidException('Token authentication does not pass', 401);
|
||||
} catch (\Exception $e) {
|
||||
$isValidToken = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($isValidToken) {
|
||||
return $handler->handle($request);
|
||||
if (!$isValidToken) {
|
||||
return $this->response->withStatus(401)->json([
|
||||
'code' => 401,
|
||||
'message' => 'Token authentication does not pass',
|
||||
'data' => []
|
||||
]);
|
||||
}
|
||||
|
||||
throw new TokenValidException('Token authentication does not pass', 401);
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ use Psr\Http\Server\MiddlewareInterface;
|
|||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
/**
|
||||
* WebSocket token 授权验证中间件
|
||||
*
|
||||
* @package App\Middleware
|
||||
*/
|
||||
class WebSocketAuthMiddleware implements MiddlewareInterface
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -164,11 +164,11 @@ class ArticleService extends BaseService
|
|||
* 编辑笔记分类
|
||||
*
|
||||
* @param int $uid 用户ID
|
||||
* @param int $class_id 分类ID
|
||||
* @param int|string $class_id 分类ID
|
||||
* @param string $class_name 分类名
|
||||
* @return bool|int
|
||||
*/
|
||||
public function editArticleClass(int $uid, int $class_id, string $class_name)
|
||||
public function editArticleClass(int $uid, $class_id, string $class_name)
|
||||
{
|
||||
if ($class_id) {
|
||||
if (!ArticleClass::where('id', $class_id)->where('user_id', $uid)->where('is_default', 0)->update(['class_name' => $class_name])) {
|
||||
|
|
|
@ -30,14 +30,14 @@ class RedisLock
|
|||
* -- 2、建议 timeout 设置为 0,避免 redis 因为阻塞导致性能下降。请根据实际需求进行设置。
|
||||
*
|
||||
* @param string $key 缓存KEY
|
||||
* @param string $requestId 客户端请求唯一ID
|
||||
* @param string|int $requestId 客户端请求唯一ID
|
||||
* @param integer $lockSecond 锁定时间 单位(秒)
|
||||
* @param integer $timeout 取锁超时时间。单位(秒)。等于0,如果当前锁被占用,则立即返回失败。如果大于0,则反复尝试获取锁直到达到该超时时间。
|
||||
* @param integer|float $sleep 取锁间隔时间 单位(秒)。当锁为占用状态时。每隔多久尝试去取锁。默认 0.1 秒一次取锁。
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function lock(string $key, string $requestId, $lockSecond = 20, $timeout = 0, $sleep = 0.1)
|
||||
public static function lock(string $key,$requestId, $lockSecond = 20, $timeout = 0, $sleep = 0.1)
|
||||
{
|
||||
if (empty($key)) {
|
||||
throw new \Exception('获取锁的KEY值没有设置');
|
||||
|
@ -66,10 +66,10 @@ class RedisLock
|
|||
* 释放锁
|
||||
*
|
||||
* @param string $key 被加锁的KEY
|
||||
* @param string $requestId 客户端请求唯一ID
|
||||
* @param string|int $requestId 客户端请求唯一ID
|
||||
* @return bool
|
||||
*/
|
||||
public static function release(string $key, string $requestId)
|
||||
public static function release(string $key,$requestId)
|
||||
{
|
||||
if (strlen($key) === 0) {
|
||||
return false;
|
||||
|
|
|
@ -19,6 +19,6 @@ return [
|
|||
CorsMiddleware::class
|
||||
],
|
||||
'ws' => [
|
||||
|
||||
WebSocketAuthMiddleware::class
|
||||
]
|
||||
];
|
||||
|
|
|
@ -46,7 +46,7 @@ return [
|
|||
],
|
||||
'settings' => [
|
||||
'enable_coroutine' => true,
|
||||
'worker_num' => swoole_cpu_num(),
|
||||
'worker_num' => 1,
|
||||
'pid_file' => BASE_PATH . '/runtime/hyperf.pid',
|
||||
'open_tcp_nodelay' => true,
|
||||
'max_coroutine' => 100000,
|
||||
|
|
Loading…
Reference in New Issue