From c7a3e8bb30ed5c89ef3f25b7316b4f2335bcf118 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Sat, 11 Sep 2021 12:41:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Bootstrap/ServerStart.php | 2 + app/Command/ClearFileCommand.php | 1 + app/Command/InstallCommand.php | 9 ++ app/Command/RemoveWsCacheCommand.php | 1 + app/Constants/MediaTypeConstant.php | 1 + app/Constants/RedisSubscribeChan.php | 1 + app/Constants/ResponseCode.php | 1 + app/Constants/RobotConstant.php | 3 +- app/Constants/TalkEventConstant.php | 1 + app/Constants/TalkModeConstant.php | 1 + app/Controller/AbstractController.php | 9 +- app/Controller/Api/V1/ArticleController.php | 118 +++++++----------- app/Controller/Api/V1/AuthController.php | 10 +- .../Api/V1/ContactsApplyController.php | 2 + app/Controller/Api/V1/ContactsController.php | 35 ++---- app/Controller/Api/V1/DownloadController.php | 8 -- app/Controller/Api/V1/EmoticonController.php | 33 ++--- app/Controller/Api/V1/GroupController.php | 69 +++------- app/Controller/Api/V1/TalkController.php | 42 ++----- .../Api/V1/TalkMessageController.php | 51 +++++--- app/Controller/Api/V1/UploadController.php | 8 -- app/Controller/Api/V1/UsersController.php | 40 +++--- app/Controller/WebSocketController.php | 1 + app/Exception/Handler/AppExceptionHandler.php | 1 - .../Handler/JwtAuthExceptionHandler.php | 1 + .../Handler/ValidateExceptionHandler.php | 1 + .../Handler/WebSocketExceptionHandler.php | 1 + app/Exception/ValidateException.php | 9 +- app/Helpers/HashHelper.php | 9 -- app/Helpers/HashIdsHelper.php | 9 +- app/Helpers/StringHelper.php | 9 -- app/Middleware/JWTAuthMiddleware.php | 2 + app/Middleware/WebSocketAuthMiddleware.php | 1 + app/Process/AsyncQueueConsumer.php | 2 +- app/Process/RedisExpiredSubscribe.php | 1 - app/Process/RedisWebsocketSubscribe.php | 1 - app/Service/SplitUploadService.php | 1 + app/Service/TalkMessageService.php | 11 +- app/Service/UserFriendService.php | 4 +- app/Service/UserService.php | 8 +- message.php => doc/message.php | 0 41 files changed, 191 insertions(+), 327 deletions(-) rename message.php => doc/message.php (100%) diff --git a/app/Bootstrap/ServerStart.php b/app/Bootstrap/ServerStart.php index 5e34267..6b2b1d1 100644 --- a/app/Bootstrap/ServerStart.php +++ b/app/Bootstrap/ServerStart.php @@ -1,4 +1,6 @@ + * @link https://github.com/gzydong/hyperf-chat + */ + namespace App\Command; use Hyperf\Command\Command as HyperfCommand; diff --git a/app/Command/RemoveWsCacheCommand.php b/app/Command/RemoveWsCacheCommand.php index ad7a051..1e4aadd 100644 --- a/app/Command/RemoveWsCacheCommand.php +++ b/app/Command/RemoveWsCacheCommand.php @@ -1,5 +1,6 @@ validationFactory->make(...$arg); + $validator = di()->get(ValidatorFactoryInterface::class)->make(...$arg); if ($validator->fails()) { throw new ValidateException($validator->errors()->first(), ResponseCode::VALIDATION_ERROR); } diff --git a/app/Controller/Api/V1/ArticleController.php b/app/Controller/Api/V1/ArticleController.php index 1511729..c4b08a4 100644 --- a/app/Controller/Api/V1/ArticleController.php +++ b/app/Controller/Api/V1/ArticleController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller\Api\V1; @@ -39,11 +31,10 @@ class ArticleController extends CController /** * 获取笔记分类列表 - * @RequestMapping(path="classifys", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="classifys", methods="get") */ - public function getArticleClass() + public function getArticleClass(): ResponseInterface { $rows = $this->articleService->getUserClass($this->uid()); foreach ($rows as &$row) { @@ -55,11 +46,10 @@ class ArticleController extends CController /** * 获取笔记标签列表 - * @RequestMapping(path="tags", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="tags", methods="get") */ - public function getArticleTags() + public function getArticleTags(): ResponseInterface { return $this->response->success([ 'tags' => $this->articleService->getUserTags($this->uid()) @@ -68,11 +58,10 @@ class ArticleController extends CController /** * 获取笔记列表 - * @RequestMapping(path="search", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="search", methods="get") */ - public function getArticleList() + public function getArticleList(): ResponseInterface { $params1 = $this->request->inputs(['keyword', 'find_type', 'cid', 'page']); $this->validate($params1, [ @@ -102,11 +91,10 @@ class ArticleController extends CController /** * 获取笔记详情 - * @RequestMapping(path="detail", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="detail", methods="get") */ - public function getArticleDetail() + public function getArticleDetail(): ResponseInterface { $params = $this->request->inputs(['article_id']); $this->validate($params, [ @@ -120,11 +108,10 @@ class ArticleController extends CController /** * 添加或编辑笔记分类 - * @RequestMapping(path="classify/editor", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="classify/editor", methods="post") */ - public function editArticleClass() + public function editArticleClass(): ResponseInterface { $params = $this->request->inputs(['class_id', 'class_name']); $this->validate($params, [ @@ -142,12 +129,12 @@ class ArticleController extends CController /** * 删除笔记分类 - * @RequestMapping(path="classify/delete", methods="post") * + * @RequestMapping(path="classify/delete", methods="post") * @return ResponseInterface * @throws \Exception */ - public function delArticleClass() + public function delArticleClass(): ResponseInterface { $params = $this->request->inputs(['class_id']); $this->validate($params, [ @@ -163,12 +150,12 @@ class ArticleController extends CController /** * 笔记分类列表排序接口 - * @RequestMapping(path="classify/sort", methods="post") * + * @RequestMapping(path="classify/sort", methods="post") * @return ResponseInterface * @throws \Exception */ - public function articleClassSort() + public function articleClassSort(): ResponseInterface { $params = $this->request->inputs(['class_id', 'sort_type']); $this->validate($params, [ @@ -194,11 +181,10 @@ class ArticleController extends CController /** * 笔记分类合并接口 - * @RequestMapping(path="classify/merge", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="classify/merge", methods="post") */ - public function mergeArticleClass() + public function mergeArticleClass(): ResponseInterface { $params = $this->request->inputs(['class_id', 'toid']); $this->validate($params, [ @@ -215,11 +201,10 @@ class ArticleController extends CController /** * 添加或编辑笔记标签 - * @RequestMapping(path="tag/editor", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="tag/editor", methods="post") */ - public function editArticleTags() + public function editArticleTags(): ResponseInterface { $params = $this->request->inputs(['tag_id', 'tag_name']); $this->validate($params, [ @@ -236,11 +221,10 @@ class ArticleController extends CController /** * 删除笔记标签 - * @RequestMapping(path="del-article-tag", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="del-article-tag", methods="post") */ - public function delArticleTags() + public function delArticleTags(): ResponseInterface { $params = $this->request->inputs(['tag_id']); $this->validate($params, [ @@ -256,11 +240,10 @@ class ArticleController extends CController /** * 添加或编辑笔记 - * @RequestMapping(path="editor", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="editor", methods="post") */ - public function editArticle() + public function editArticle(): ResponseInterface { $params = $this->request->all(); $this->validate($params, [ @@ -287,11 +270,10 @@ class ArticleController extends CController /** * 删除笔记 - * @RequestMapping(path="delete", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="delete", methods="post") */ - public function deleteArticle() + public function deleteArticle(): ResponseInterface { $params = $this->request->inputs(['article_id']); $this->validate($params, [ @@ -307,11 +289,10 @@ class ArticleController extends CController /** * 恢复删除笔记 - * @RequestMapping(path="recover", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="recover", methods="post") */ - public function recoverArticle() + public function recoverArticle(): ResponseInterface { $params = $this->request->inputs(['article_id']); $this->validate($params, [ @@ -327,12 +308,12 @@ class ArticleController extends CController /** * 笔记图片上传接口 - * @RequestMapping(path="upload-image", methods="post") * + * @RequestMapping(path="upload-image", methods="post") * @param Filesystem $filesystem * @return ResponseInterface */ - public function uploadArticleImage(Filesystem $filesystem) + public function uploadArticleImage(Filesystem $filesystem): ResponseInterface { $file = $this->request->file('image'); if (!$file || !$file->isValid()) { @@ -358,11 +339,10 @@ class ArticleController extends CController /** * 移动笔记至指定分类 - * @RequestMapping(path="move", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="move", methods="post") */ - public function moveArticle() + public function moveArticle(): ResponseInterface { $params = $this->request->inputs(['article_id', 'class_id']); $this->validate($params, [ @@ -383,11 +363,10 @@ class ArticleController extends CController /** * 笔记标记星号接口 - * @RequestMapping(path="asterisk", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="asterisk", methods="post") */ - public function setAsterisk() + public function setAsterisk(): ResponseInterface { $params = $this->request->inputs(['article_id', 'type']); $this->validate($params, [ @@ -408,11 +387,10 @@ class ArticleController extends CController /** * 更新笔记关联标签ID - * @RequestMapping(path="update-tag", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="update-tag", methods="post") */ - public function updateArticleTag() + public function updateArticleTag(): ResponseInterface { $params = $this->request->inputs(['article_id', 'tags']); $this->validate($params, [ @@ -429,12 +407,12 @@ class ArticleController extends CController /** * 永久删除笔记文章 - * @RequestMapping(path="forever-delete", methods="post") * + * @RequestMapping(path="forever-delete", methods="post") * @return ResponseInterface * @throws \Exception */ - public function foreverDelArticle() + public function foreverDelArticle(): ResponseInterface { $params = $this->request->inputs(['article_id']); $this->validate($params, [ @@ -450,11 +428,12 @@ class ArticleController extends CController /** * 上传笔记附件 - * @RequestMapping(path="annex/upload", methods="post") * + * @RequestMapping(path="annex/upload", methods="post") + * @param Filesystem $filesystem * @return ResponseInterface */ - public function uploadArticleAnnex(Filesystem $filesystem) + public function uploadArticleAnnex(Filesystem $filesystem): ResponseInterface { $params = $this->request->inputs(['article_id']); $this->validate($params, [ @@ -492,11 +471,10 @@ class ArticleController extends CController /** * 删除笔记附件 - * @RequestMapping(path="annex/delete", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="annex/delete", methods="post") */ - public function deleteArticleAnnex() + public function deleteArticleAnnex(): ResponseInterface { $params = $this->request->inputs(['annex_id']); $this->validate($params, [ @@ -512,11 +490,10 @@ class ArticleController extends CController /** * 恢复笔记附件 - * @RequestMapping(path="annex/recover", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="annex/recover", methods="post") */ - public function recoverArticleAnnex() + public function recoverArticleAnnex(): ResponseInterface { $params = $this->request->inputs(['annex_id']); $this->validate($params, [ @@ -532,11 +509,10 @@ class ArticleController extends CController /** * 获取附件回收站列表 - * @RequestMapping(path="annex/recover-list", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="annex/recover-list", methods="get") */ - public function recoverAnnexList() + public function recoverAnnexList(): ResponseInterface { $rows = $this->articleService->recoverAnnexList($this->uid()); if ($rows) { @@ -556,12 +532,12 @@ class ArticleController extends CController /** * 永久删除笔记附件(从已删除附件中永久删除) - * @RequestMapping(path="annex/forever-delete", methods="post") * + * @RequestMapping(path="annex/forever-delete", methods="post") * @return ResponseInterface * @throws \Exception */ - public function foreverDelAnnex() + public function foreverDelAnnex(): ResponseInterface { $params = $this->request->inputs(['annex_id']); $this->validate($params, [ diff --git a/app/Controller/Api/V1/AuthController.php b/app/Controller/Api/V1/AuthController.php index 36b77a5..c077a21 100644 --- a/app/Controller/Api/V1/AuthController.php +++ b/app/Controller/Api/V1/AuthController.php @@ -1,15 +1,6 @@ - * @link https://github.com/gzydong/hyperf-chat - */ - namespace App\Controller\Api\V1; use App\Event\LoginEvent; @@ -161,6 +152,7 @@ class AuthController extends CController /** * 授权刷新接口 + * * @RequestMapping(path="refresh", methods="post") */ public function refresh(): ResponseInterface diff --git a/app/Controller/Api/V1/ContactsApplyController.php b/app/Controller/Api/V1/ContactsApplyController.php index 5200efb..7077727 100644 --- a/app/Controller/Api/V1/ContactsApplyController.php +++ b/app/Controller/Api/V1/ContactsApplyController.php @@ -30,6 +30,8 @@ class ContactsApplyController extends CController private $service; /** + * 添加联系人申请接口 + * * @RequestMapping(path="create", methods="post") * @param UserService $userService * @return ResponseInterface diff --git a/app/Controller/Api/V1/ContactsController.php b/app/Controller/Api/V1/ContactsController.php index 8e72a84..b0bde60 100644 --- a/app/Controller/Api/V1/ContactsController.php +++ b/app/Controller/Api/V1/ContactsController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller\Api\V1; @@ -42,11 +34,10 @@ class ContactsController extends CController /** * 获取用户联系人列表 - * @RequestMapping(path="list", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="list", methods="get") */ - public function getContacts(UserService $service) + public function getContacts(UserService $service): ResponseInterface { $rows = $service->getUserFriends($this->uid()); if ($rows) { @@ -61,11 +52,10 @@ class ContactsController extends CController /** * 删除联系人 - * @RequestMapping(path="delete", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="delete", methods="post") */ - public function deleteContact() + public function deleteContact(): ResponseInterface { $params = $this->request->inputs(['friend_id']); $this->validate($params, [ @@ -86,11 +76,10 @@ class ContactsController extends CController /** * 获取联系人申请未读数 - * @RequestMapping(path="apply-unread-num", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="apply-unread-num", methods="get") */ - public function getContactApplyUnreadNum() + public function getContactApplyUnreadNum(): ResponseInterface { return $this->response->success([ 'unread_num' => (int)FriendApply::getInstance()->get(strval($this->uid())) @@ -99,11 +88,10 @@ class ContactsController extends CController /** * 搜索联系人 - * @RequestMapping(path="search", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="search", methods="get") */ - public function searchContacts() + public function searchContacts(): ResponseInterface { $params = $this->request->inputs(['mobile']); $this->validate($params, [ @@ -116,11 +104,10 @@ class ContactsController extends CController /** * 编辑联系人备注 - * @RequestMapping(path="edit-remark", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="edit-remark", methods="post") */ - public function editContactRemark() + public function editContactRemark(): ResponseInterface { $params = $this->request->inputs(['friend_id', 'remarks']); $this->validate($params, [ @@ -129,7 +116,7 @@ class ContactsController extends CController ]); $user_id = $this->uid(); - $isTrue = $this->service->editRemark($user_id, intval($params['friend_id']), $params['remarks']); + $isTrue = $this->service->editRemark($user_id, intval($params['friend_id']), $params['remarks']); if (!$isTrue) { return $this->response->fail('备注修改失败!'); } diff --git a/app/Controller/Api/V1/DownloadController.php b/app/Controller/Api/V1/DownloadController.php index be8a454..442416d 100644 --- a/app/Controller/Api/V1/DownloadController.php +++ b/app/Controller/Api/V1/DownloadController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller\Api\V1; diff --git a/app/Controller/Api/V1/EmoticonController.php b/app/Controller/Api/V1/EmoticonController.php index ecbfea4..c49fa06 100644 --- a/app/Controller/Api/V1/EmoticonController.php +++ b/app/Controller/Api/V1/EmoticonController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller\Api\V1; @@ -39,11 +31,10 @@ class EmoticonController extends CController /** * 获取用户表情包列表 - * @RequestMapping(path="list", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="list", methods="get") */ - public function list() + public function list(): ResponseInterface { $emoticonList = []; $user_id = $this->uid(); @@ -74,11 +65,10 @@ class EmoticonController extends CController /** * 获取系统表情包 - * @RequestMapping(path="system", methods="get") * - * @return ResponseInterface + * @RequestMapping(path="system", methods="get") */ - public function system() + public function system(): ResponseInterface { $items = Emoticon::get(['id', 'name', 'icon'])->toArray(); if ($items) { @@ -94,11 +84,10 @@ class EmoticonController extends CController /** * 安装或移除系统表情包 - * @RequestMapping(path="set-user-emoticon", methods="post") * - * @return ResponseInterface + * @RequestMapping(path="set-user-emoticon", methods="post") */ - public function setUserEmoticon() + public function setUserEmoticon(): ResponseInterface { $params = $this->request->all(); $this->validate($params, [ @@ -142,12 +131,12 @@ class EmoticonController extends CController /** * 自定义上传表情包 - * @RequestMapping(path="upload", methods="post") * + * @RequestMapping(path="upload", methods="post") * @param Filesystem $filesystem * @return ResponseInterface */ - public function upload(Filesystem $filesystem) + public function upload(Filesystem $filesystem): ResponseInterface { $file = $this->request->file('emoticon'); if (!$file->isValid()) { @@ -192,12 +181,10 @@ class EmoticonController extends CController /** * 移除收藏的表情包 - * @RequestMapping(path="del-collect-emoticon", methods="post") * - * @return ResponseInterface - * @throws \Exception + * @RequestMapping(path="del-collect-emoticon", methods="post") */ - public function delCollectEmoticon() + public function delCollectEmoticon(): ResponseInterface { $params = $this->request->inputs(['ids']); $this->validate($params, [ diff --git a/app/Controller/Api/V1/GroupController.php b/app/Controller/Api/V1/GroupController.php index e168389..21c5c43 100644 --- a/app/Controller/Api/V1/GroupController.php +++ b/app/Controller/Api/V1/GroupController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller\Api\V1; @@ -51,10 +43,8 @@ class GroupController extends CController /** * 创建群组 * @RequestMapping(path="create", methods="post") - * - * @return ResponseInterface */ - public function create() + public function create(): ResponseInterface { $params = $this->request->inputs(['group_name', 'uids']); $this->validate($params, [ @@ -78,10 +68,8 @@ class GroupController extends CController /** * 解散群组接口 * @RequestMapping(path="dismiss", methods="post") - * - * @return ResponseInterface */ - public function dismiss() + public function dismiss(): ResponseInterface { $params = $this->request->inputs(['group_id']); $this->validate($params, [ @@ -99,10 +87,8 @@ class GroupController extends CController /** * 邀请好友加入群组接口 * @RequestMapping(path="invite", methods="post") - * - * @return ResponseInterface */ - public function invite() + public function invite(): ResponseInterface { $params = $this->request->inputs(['group_id', 'uids']); $this->validate($params, [ @@ -121,10 +107,8 @@ class GroupController extends CController /** * 退出群组接口 * @RequestMapping(path="secede", methods="post") - * - * @return ResponseInterface */ - public function secede() + public function secede(): ResponseInterface { $params = $this->request->inputs(['group_id']); $this->validate($params, [ @@ -141,10 +125,8 @@ class GroupController extends CController /** * 编辑群组信息 * @RequestMapping(path="edit", methods="post") - * - * @return ResponseInterface */ - public function editDetail() + public function editDetail(): ResponseInterface { $params = $this->request->inputs(['group_id', 'group_name', 'profile', 'avatar']); $this->validate($params, [ @@ -162,10 +144,8 @@ class GroupController extends CController /** * 移除指定成员(管理员权限) * @RequestMapping(path="remove-members", methods="post") - * - * @return ResponseInterface */ - public function removeMembers() + public function removeMembers(): ResponseInterface { $params = $this->request->inputs(['group_id', 'members_ids']); $this->validate($params, [ @@ -191,10 +171,8 @@ class GroupController extends CController /** * 获取群信息接口 * @RequestMapping(path="detail", methods="get") - * - * @return ResponseInterface */ - public function detail(TalkListService $service) + public function detail(TalkListService $service): ResponseInterface { $group_id = $this->request->input('group_id', 0); $user_id = $this->uid(); @@ -231,10 +209,8 @@ class GroupController extends CController /** * 设置群名片 * @RequestMapping(path="set-group-card", methods="post") - * - * @return ResponseInterface */ - public function editGroupCard() + public function editGroupCard(): ResponseInterface { $params = $this->request->inputs(['group_id', 'visit_card']); $this->validate($params, [ @@ -252,10 +228,8 @@ class GroupController extends CController /** * 获取可邀请加入群组的好友列表 * @RequestMapping(path="invite-friends", methods="get") - * - * @return ResponseInterface */ - public function getInviteFriends(UserService $service) + public function getInviteFriends(UserService $service): ResponseInterface { $group_id = $this->request->input('group_id', 0); $friends = $service->getUserFriends($this->uid()); @@ -275,10 +249,8 @@ class GroupController extends CController /** * 获取群组列表 * @RequestMapping(path="list", methods="get") - * - * @return ResponseInterface */ - public function getGroups() + public function getGroups(): ResponseInterface { return $this->response->success( $this->groupService->getUserGroups($this->uid()) @@ -288,10 +260,8 @@ class GroupController extends CController /** * 获取群组成员列表 * @RequestMapping(path="members", methods="get") - * - * @return ResponseInterface */ - public function getGroupMembers() + public function getGroupMembers(): ResponseInterface { $user_id = $this->uid(); $group_id = $this->request->input('group_id', 0); @@ -323,10 +293,8 @@ class GroupController extends CController /** * 获取群组公告列表 * @RequestMapping(path="notices", methods="get") - * - * @return ResponseInterface */ - public function getGroupNotice(GroupNoticeService $service) + public function getGroupNotice(GroupNoticeService $service): ResponseInterface { $user_id = $this->uid(); $group_id = $this->request->input('group_id', 0); @@ -342,12 +310,13 @@ class GroupController extends CController /** * 创建/编辑群公告 * @RequestMapping(path="edit-notice", methods="post") - * - * @return ResponseInterface */ - public function editNotice(GroupNoticeService $service) + public function editNotice(GroupNoticeService $service): ResponseInterface { - $params = $this->request->inputs(['group_id', 'notice_id', 'title', 'content', 'is_top', 'is_confirm']); + $params = $this->request->inputs([ + 'group_id', 'notice_id', 'title', 'content', 'is_top', 'is_confirm' + ]); + $this->validate($params, [ 'notice_id' => 'required|integer', 'group_id' => 'required|integer', @@ -381,10 +350,8 @@ class GroupController extends CController /** * 删除群公告(软删除) * @RequestMapping(path="delete-notice", methods="post") - * - * @return ResponseInterface */ - public function deleteNotice(GroupNoticeService $service) + public function deleteNotice(GroupNoticeService $service): ResponseInterface { $params = $this->request->inputs(['group_id', 'notice_id']); $this->validate($params, [ diff --git a/app/Controller/Api/V1/TalkController.php b/app/Controller/Api/V1/TalkController.php index de7da0c..1d0d55c 100644 --- a/app/Controller/Api/V1/TalkController.php +++ b/app/Controller/Api/V1/TalkController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller\Api\V1; @@ -57,7 +49,7 @@ class TalkController extends CController * * @return ResponseInterface */ - public function list() + public function list(): ResponseInterface { $user_id = $this->uid(); @@ -74,10 +66,8 @@ class TalkController extends CController /** * 新增对话列表 * @RequestMapping(path="create", methods="post") - * - * @return ResponseInterface */ - public function create(UserFriendService $service) + public function create(UserFriendService $service): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id']); $this->validate($params, [ @@ -135,10 +125,8 @@ class TalkController extends CController /** * 删除对话列表 * @RequestMapping(path="delete", methods="post") - * - * @return ResponseInterface */ - public function delete() + public function delete(): ResponseInterface { $params = $this->request->inputs(['list_id']); $this->validate($params, [ @@ -153,10 +141,8 @@ class TalkController extends CController /** * 对话列表置顶 * @RequestMapping(path="topping", methods="post") - * - * @return ResponseInterface */ - public function topping() + public function topping(): ResponseInterface { $params = $this->request->inputs(['list_id', 'type']); $this->validate($params, [ @@ -172,10 +158,8 @@ class TalkController extends CController /** * 设置消息免打扰状态 * @RequestMapping(path="disturb", methods="post") - * - * @return ResponseInterface */ - public function disturb() + public function disturb(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'is_disturb']); $this->validate($params, [ @@ -192,10 +176,8 @@ class TalkController extends CController /** * 更新对话列表未读数 * @RequestMapping(path="update-unread-num", methods="post") - * - * @return ResponseInterface */ - public function updateUnreadNum() + public function updateUnreadNum(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id']); $this->validate($params, [ @@ -214,10 +196,8 @@ class TalkController extends CController /** * 获取对话面板中的聊天记录 * @RequestMapping(path="records", methods="get") - * - * @return ResponseInterface */ - public function getChatRecords() + public function getChatRecords(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']); $this->validate($params, [ @@ -251,10 +231,8 @@ class TalkController extends CController /** * 获取转发记录详情 * @RequestMapping(path="get-forward-records", methods="get") - * - * @return ResponseInterface */ - public function getForwardRecords() + public function getForwardRecords(): ResponseInterface { $params = $this->request->inputs(['record_id']); $this->validate($params, [ @@ -269,10 +247,8 @@ class TalkController extends CController /** * 查询聊天记录 * @RequestMapping(path="find-chat-records", methods="get") - * - * @return ResponseInterface */ - public function findChatRecords() + public function findChatRecords(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id', 'msg_type']); $this->validate($params, [ diff --git a/app/Controller/Api/V1/TalkMessageController.php b/app/Controller/Api/V1/TalkMessageController.php index 0d79829..5253e72 100644 --- a/app/Controller/Api/V1/TalkMessageController.php +++ b/app/Controller/Api/V1/TalkMessageController.php @@ -20,6 +20,7 @@ use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\Middleware; use App\Middleware\JWTAuthMiddleware; use League\Flysystem\Filesystem; +use Psr\Http\Message\ResponseInterface; /** * Class TalkController @@ -44,9 +45,10 @@ class TalkMessageController extends CController /** * 发送文本消息 + * * @RequestMapping(path="text", methods="post") */ - public function text() + public function text(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'text']); $this->validate($params, [ @@ -55,7 +57,7 @@ class TalkMessageController extends CController 'text' => 'required|max:65535', ]); - di()->get(TalkMessageService::class)->insertTextMessage([ + di()->get(TalkMessageService::class)->insertText([ 'talk_type' => $params['talk_type'], 'user_id' => $this->uid(), 'receiver_id' => $params['receiver_id'], @@ -67,9 +69,10 @@ class TalkMessageController extends CController /** * 发送代码块消息 + * * @RequestMapping(path="code", methods="post") */ - public function code() + public function code(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'lang', 'code']); $this->validate($params, [ @@ -84,7 +87,7 @@ class TalkMessageController extends CController return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); } - $isTrue = $this->talkMessageService->insertCodeMessage([ + $isTrue = $this->talkMessageService->insertCode([ 'talk_type' => $params['talk_type'], 'user_id' => $user_id, 'receiver_id' => $params['receiver_id'], @@ -101,9 +104,10 @@ class TalkMessageController extends CController /** * 发送图片消息 + * * @RequestMapping(path="image", methods="post") */ - public function image(Filesystem $filesystem) + public function image(Filesystem $filesystem): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id']); $this->validate($params, [ @@ -134,7 +138,7 @@ class TalkMessageController extends CController } // 创建图片消息记录 - $isTrue = $this->talkMessageService->insertFileMessage([ + $isTrue = $this->talkMessageService->insertFile([ 'talk_type' => $params['talk_type'], 'user_id' => $user_id, 'receiver_id' => $params['receiver_id'], @@ -153,9 +157,10 @@ class TalkMessageController extends CController /** * 发送文件消息 + * * @RequestMapping(path="file", methods="post") */ - public function file(Filesystem $filesystem) + public function file(Filesystem $filesystem): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'hash_name']); $this->validate($params, [ @@ -181,7 +186,7 @@ class TalkMessageController extends CController return $this->response->fail('文件不存在...'); } - $isTrue = $this->talkMessageService->insertFileMessage([ + $isTrue = $this->talkMessageService->insertFile([ 'talk_type' => $params['talk_type'], 'user_id' => $user_id, 'receiver_id' => $params['receiver_id'] @@ -201,9 +206,10 @@ class TalkMessageController extends CController /** * 发送投票消息 + * * @RequestMapping(path="vote", methods="post") */ - public function vote() + public function vote(): ResponseInterface { $params = $this->request->all(); $this->validate($params, [ @@ -218,7 +224,7 @@ class TalkMessageController extends CController return $this->response->fail('暂不属于好友关系或群聊成员,无法发送聊天消息!'); } - $isTrue = $this->talkMessageService->insertVoteMessage([ + $isTrue = $this->talkMessageService->insertVote([ 'talk_type' => TalkModeConstant::GROUP_CHAT, 'user_id' => $user_id, 'receiver_id' => $params['receiver_id'], @@ -236,9 +242,10 @@ class TalkMessageController extends CController /** * 投票处理 + * * @RequestMapping(path="vote/handle", methods="post") */ - public function handleVote() + public function handleVote(): ResponseInterface { $params = $this->request->inputs(['record_id', 'options']); $this->validate($params, [ @@ -260,9 +267,10 @@ class TalkMessageController extends CController /** * 发送表情包消息 + * * @RequestMapping(path="emoticon", methods="post") */ - public function emoticon() + public function emoticon(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'emoticon_id']); $this->validate($params, [ @@ -280,7 +288,7 @@ class TalkMessageController extends CController if (!$emoticon) return $this->response->fail('表情不存在!'); - $isTrue = $this->talkMessageService->insertFileMessage([ + $isTrue = $this->talkMessageService->insertFile([ 'talk_type' => $params['talk_type'], 'user_id' => $user_id, 'receiver_id' => $params['receiver_id'], @@ -299,11 +307,15 @@ class TalkMessageController extends CController /** * 转发消息记录 + * * @RequestMapping(path="forward", methods="post") */ - public function forward(TalkForwardService $forwardService) + public function forward(TalkForwardService $forwardService): ResponseInterface { - $params = $this->request->inputs(['talk_type', 'receiver_id', 'records_ids', 'forward_mode', 'receive_user_ids', 'receive_group_ids']); + $params = $this->request->inputs([ + 'talk_type', 'receiver_id', 'records_ids', 'forward_mode', 'receive_user_ids', 'receive_group_ids' + ]); + $this->validate($params, [ 'talk_type' => 'required|in:1,2', 'receiver_id' => 'required|integer|min:1', @@ -366,9 +378,10 @@ class TalkMessageController extends CController /** * 收藏聊天图片 + * * @RequestMapping(path="collect", methods="post") */ - public function collect(EmoticonService $service) + public function collect(EmoticonService $service): ResponseInterface { $params = $this->request->inputs(['record_id']); $this->validate($params, [ @@ -386,9 +399,10 @@ class TalkMessageController extends CController /** * 撤销聊天记录 + * * @RequestMapping(path="revoke", methods="post") */ - public function revoke() + public function revoke(): ResponseInterface { $params = $this->request->inputs(['record_id']); $this->validate($params, [ @@ -403,9 +417,10 @@ class TalkMessageController extends CController /** * 删除聊天记录 + * * @RequestMapping(path="delete", methods="post") */ - public function delete() + public function delete(): ResponseInterface { $params = $this->request->inputs(['talk_type', 'receiver_id', 'record_id']); $this->validate($params, [ diff --git a/app/Controller/Api/V1/UploadController.php b/app/Controller/Api/V1/UploadController.php index 33b5af3..97446c1 100644 --- a/app/Controller/Api/V1/UploadController.php +++ b/app/Controller/Api/V1/UploadController.php @@ -1,12 +1,4 @@ - * @link https://github.com/gzydong/hyperf-chat - */ declare(strict_types=1); namespace App\Controller\Api\V1; diff --git a/app/Controller/Api/V1/UsersController.php b/app/Controller/Api/V1/UsersController.php index 28db3ce..882663c 100644 --- a/app/Controller/Api/V1/UsersController.php +++ b/app/Controller/Api/V1/UsersController.php @@ -1,15 +1,6 @@ - * @link https://github.com/gzydong/hyperf-chat - */ - namespace App\Controller\Api\V1; use Hyperf\Di\Annotation\Inject; @@ -103,11 +94,11 @@ class UsersController extends CController 'avatar' => 'present|url' ]); - $isTrue = User::where('id', $this->uid())->update($params); + $params['updated_at'] = date("Y-m-d H:i:s"); - return $isTrue - ? $this->response->success([], '个人信息修改成功...') - : $this->response->fail('个人信息修改失败!'); + User::where('id', $this->uid())->update($params); + + return $this->response->success([], '个人信息修改成功...'); } /** @@ -123,11 +114,12 @@ class UsersController extends CController 'avatar' => 'required|url' ]); - $isTrue = User::where('id', $this->uid())->update(['avatar' => $params['avatar']]); + User::where('id', $this->uid())->update([ + 'avatar' => $params['avatar'], + 'updated_at' => date("Y-m-d H:i:s") + ]); - return $isTrue - ? $this->response->success([], '头像修改成功...') - : $this->response->fail('头像修改失败!'); + return $this->response->success([], '头像修改成功...'); } /** @@ -165,14 +157,16 @@ class UsersController extends CController $userInfo = $this->user(); // 验证密码是否正确 - if (!HashHelper::check($this->request->post('old_password'), $userInfo->password)) { + if (!HashHelper::check($params['old_password'], $userInfo->password)) { return $this->response->fail('旧密码验证失败!'); } $isTrue = $this->userService->resetPassword($userInfo->mobile, $params['new_password']); - return $isTrue - ? $this->response->success([], '密码修改成功...') - : $this->response->fail('密码修改失败!'); + if (!$isTrue) { + return $this->response->fail('密码修改失败!'); + } + + return $this->response->success([], '密码修改成功...'); } /** @@ -191,7 +185,7 @@ class UsersController extends CController 'sms_code' => 'required|digits:6' ]); - if (!$smsCodeService->check('change_mobile', $params['mobile'], $params['sms_code'])) { + if (!$smsCodeService->check('change_mobile', $params['mobile'], (string)$params['sms_code'])) { return $this->response->fail('验证码填写错误!'); } @@ -226,7 +220,7 @@ class UsersController extends CController ]); $sendEmailCode = new SendEmailCode(); - if (!$sendEmailCode->check(SendEmailCode::CHANGE_EMAIL, $params['email'], $params['email_code'])) { + if (!$sendEmailCode->check(SendEmailCode::CHANGE_EMAIL, $params['email'], (string)$params['email_code'])) { return $this->response->fail('验证码填写错误!'); } diff --git a/app/Controller/WebSocketController.php b/app/Controller/WebSocketController.php index ad996f4..f09849d 100644 --- a/app/Controller/WebSocketController.php +++ b/app/Controller/WebSocketController.php @@ -1,5 +1,6 @@ - * @link https://github.com/gzydong/hyperf-chat - */ +declare(strict_types=1); namespace App\Exception; diff --git a/app/Helpers/HashHelper.php b/app/Helpers/HashHelper.php index 82b6cb7..0600714 100644 --- a/app/Helpers/HashHelper.php +++ b/app/Helpers/HashHelper.php @@ -1,15 +1,6 @@ - * @link https://github.com/gzydong/hyperf-chat - */ - namespace App\Helpers; /** diff --git a/app/Helpers/HashIdsHelper.php b/app/Helpers/HashIdsHelper.php index a66de3e..3abe5b6 100644 --- a/app/Helpers/HashIdsHelper.php +++ b/app/Helpers/HashIdsHelper.php @@ -1,12 +1,5 @@ - * @link https://github.com/gzydong/hyperf-chat - */ +declare(strict_types=1); namespace App\Helpers; diff --git a/app/Helpers/StringHelper.php b/app/Helpers/StringHelper.php index 95164ec..d2e1295 100644 --- a/app/Helpers/StringHelper.php +++ b/app/Helpers/StringHelper.php @@ -1,15 +1,6 @@ - * @link https://github.com/gzydong/hyperf-chat - */ - namespace App\Helpers; /** diff --git a/app/Middleware/JWTAuthMiddleware.php b/app/Middleware/JWTAuthMiddleware.php index 2d67f64..2bd9b20 100644 --- a/app/Middleware/JWTAuthMiddleware.php +++ b/app/Middleware/JWTAuthMiddleware.php @@ -1,4 +1,6 @@ where('is_quit', 0)->count(); @@ -294,7 +293,7 @@ class TalkMessageService * @param array $loginParams * @return bool */ - public function insertLoginMessage(array $message, array $loginParams): bool + public function insertLogin(array $message, array $loginParams): bool { Db::beginTransaction(); try { diff --git a/app/Service/UserFriendService.php b/app/Service/UserFriendService.php index dd63d2c..575aa0e 100644 --- a/app/Service/UserFriendService.php +++ b/app/Service/UserFriendService.php @@ -14,7 +14,7 @@ class UserFriendService * @param int $friend_id 好友ID * @return string */ - public function getFriendRemark(int $user_id, int $friend_id) + public function getFriendRemark(int $user_id, int $friend_id): string { $remark = FriendRemark::getInstance()->read($user_id, $friend_id); if ($remark) return $remark; @@ -33,7 +33,7 @@ class UserFriendService * @param bool $is_mutual 相互互为好友 * @return bool */ - public function isFriend(int $user_id, int $friend_id, $is_mutual = false) + public function isFriend(int $user_id, int $friend_id, $is_mutual = false): bool { $isTrue1 = UsersFriend::where('user_id', $user_id)->where('friend_id', $friend_id)->where('status', 1)->exists(); diff --git a/app/Service/UserService.php b/app/Service/UserService.php index ebfb613..c3c91c5 100644 --- a/app/Service/UserService.php +++ b/app/Service/UserService.php @@ -16,9 +16,9 @@ class UserService extends BaseService * * @param int $user_id 用户ID * @param array $field 查询字段 - * @return User + * @return User|object|null */ - public function findById(int $user_id, $field = ['*']) + public function findById(int $user_id, $field = ['*']): ?User { return User::where('id', $user_id)->first($field); } @@ -149,7 +149,7 @@ class UserService extends BaseService * @param int $user_id 用户ID * @return array */ - public function getUserFriends(int $user_id) + public function getUserFriends(int $user_id): array { return UsersFriend::leftJoin('users', 'users.id', '=', 'users_friends.friend_id') ->where('user_id', $user_id)->where('users_friends.status', 1) @@ -169,7 +169,7 @@ class UserService extends BaseService * @param int $user_id 指定用户ID * @return array */ - public function getFriendIds(int $user_id) + public function getFriendIds(int $user_id): array { return UsersFriend::where('user_id', $user_id)->where('status', 1)->pluck('friend_id')->toArray(); } diff --git a/message.php b/doc/message.php similarity index 100% rename from message.php rename to doc/message.php