From 1140a30aa8167a8a17b011dd1bfe74f6d0011245 Mon Sep 17 00:00:00 2001 From: gzydong <837215079@qq.com> Date: Thu, 22 Apr 2021 16:54:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/Api/V1/ArticleController.php | 3 +- app/Controller/Api/V1/AuthController.php | 1 - app/Controller/Api/V1/ContactsController.php | 9 +-- app/Controller/Api/V1/EmoticonController.php | 1 + app/Controller/Api/V1/GroupController.php | 6 +- app/Controller/Api/V1/TalkController.php | 80 +++++++++---------- app/Controller/Api/V1/UploadController.php | 1 + app/Controller/Api/V1/UsersController.php | 2 + app/Controller/IndexController.php | 14 ---- app/Controller/WebSocketController.php | 2 +- app/Exception/Handler/AppExceptionHandler.php | 2 +- .../Handler/JwtAuthExceptionHandler.php | 1 + app/Model/User.php | 2 + app/Service/ArticleService.php | 1 + app/Service/ContactsService.php | 1 - app/Service/MailerService.php | 12 +-- app/Service/MessageHandleService.php | 22 ++--- app/Service/TalkService.php | 16 ++-- app/Support/Mail.php | 26 +++--- app/Support/RedisLock.php | 8 +- 20 files changed, 97 insertions(+), 113 deletions(-) diff --git a/app/Controller/Api/V1/ArticleController.php b/app/Controller/Api/V1/ArticleController.php index 036185d..a8732f3 100644 --- a/app/Controller/Api/V1/ArticleController.php +++ b/app/Controller/Api/V1/ArticleController.php @@ -167,6 +167,7 @@ class ArticleController extends CController * @RequestMapping(path="article-class-sort", methods="post") * * @return ResponseInterface + * @throws \Exception */ public function articleClassSort() { @@ -344,7 +345,6 @@ class ArticleController extends CController return $this->response->fail('图片格式错误,目前仅支持jpg、png、jpeg、gif和webp'); } - //获取图片信息 $imgInfo = getimagesize($file->getRealPath()); $path = $this->uploadService->media($file, 'media/images/notes/', create_image_name($ext, $imgInfo[0], $imgInfo[1])); @@ -433,6 +433,7 @@ class ArticleController extends CController * @RequestMapping(path="forever-delete-article", methods="post") * * @return ResponseInterface + * @throws \Exception */ public function foreverDelArticle() { diff --git a/app/Controller/Api/V1/AuthController.php b/app/Controller/Api/V1/AuthController.php index 161c3db..dcb6baf 100644 --- a/app/Controller/Api/V1/AuthController.php +++ b/app/Controller/Api/V1/AuthController.php @@ -15,7 +15,6 @@ use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\Middleware; use App\Middleware\JWTAuthMiddleware; -use App\Constants\ResponseCode; use App\Model\User; use App\Service\UserService; use App\Service\SmsCodeService; diff --git a/app/Controller/Api/V1/ContactsController.php b/app/Controller/Api/V1/ContactsController.php index 68097a3..36c320a 100644 --- a/app/Controller/Api/V1/ContactsController.php +++ b/app/Controller/Api/V1/ContactsController.php @@ -102,10 +102,9 @@ class ContactsController extends CController // 好友申请未读消息数自增 ApplyNumCache::setInc(intval($params['friend_id'])); - //判断对方是否在线。如果在线发送消息通知 + // 判断对方是否在线。如果在线发送消息通知 if ($this->socketClientService->isOnlineAll(intval($params['friend_id']))) { $this->producer->produce( - // 消息待完善 new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [ 'sender' => $user_id, 'receive' => intval($params['friend_id']), @@ -137,11 +136,11 @@ class ContactsController extends CController return $this->response->fail('好友关系解除失败...'); } - //删除好友会话列表 + // 删除好友会话列表 UsersChatList::delItem($user_id, $params['friend_id'], 2); UsersChatList::delItem($params['friend_id'], $user_id, 2); - // ... 推送消息(待完善) + // ... TODO 推送消息(待完善) return $this->response->success([], '好友关系解除成功...'); } @@ -170,7 +169,7 @@ class ContactsController extends CController ->where('friend_id', $user_id) ->value('user_id'); - //判断对方是否在线。如果在线发送消息通知 + // 判断对方是否在线。如果在线发送消息通知 if ($this->socketClientService->isOnlineAll($friend_id)) { // 待完善 $this->producer->produce( diff --git a/app/Controller/Api/V1/EmoticonController.php b/app/Controller/Api/V1/EmoticonController.php index 1fd374d..e80943f 100644 --- a/app/Controller/Api/V1/EmoticonController.php +++ b/app/Controller/Api/V1/EmoticonController.php @@ -222,6 +222,7 @@ class EmoticonController extends CController * @RequestMapping(path="del-collect-emoticon", methods="post") * * @return ResponseInterface + * @throws \Exception */ public function delCollectEmoticon() { diff --git a/app/Controller/Api/V1/GroupController.php b/app/Controller/Api/V1/GroupController.php index 97ce10e..f16b0fd 100644 --- a/app/Controller/Api/V1/GroupController.php +++ b/app/Controller/Api/V1/GroupController.php @@ -122,7 +122,7 @@ class GroupController extends CController $this->socketRoomService->delRoom($params['group_id']); - // ... 推送群消息(预留) + // ... TODO 推送群消息(预留) return $this->response->success([], '群组解散成功...'); } @@ -224,7 +224,7 @@ class GroupController extends CController 'avatar' => $params['avatar'] ]); - // ... 推送消息通知(预留) + // ... TODO 推送消息通知(预留) return $result ? $this->response->success([], '群组信息修改成功...') @@ -496,7 +496,7 @@ class GroupController extends CController return $this->response->fail('添加群公告信息失败...'); } - // ... 推送群消息(预留) + // ... TODO 推送群消息(预留) return $this->response->success([], '添加群公告信息成功...'); } diff --git a/app/Controller/Api/V1/TalkController.php b/app/Controller/Api/V1/TalkController.php index f9b5dd6..7b07668 100644 --- a/app/Controller/Api/V1/TalkController.php +++ b/app/Controller/Api/V1/TalkController.php @@ -267,7 +267,7 @@ class TalkController extends CController { $params = $this->request->inputs(['source', 'record_id', 'receive_id']); $this->validate($params, [ - 'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息) + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'record_id' => 'required|ids', 'receive_id' => 'required|integer|min:0' ]); @@ -296,17 +296,17 @@ class TalkController extends CController { $params = $this->request->inputs(['source', 'records_ids', 'receive_id', 'forward_mode', 'receive_user_ids', 'receive_group_ids']); $this->validate($params, [ - //消息来源[1:好友消息 2:群聊消息] + // 消息来源[1:好友消息;2:群聊消息;] 'source' => 'required|in:1,2', - //聊天记录ID,多个逗号拼接 + // 聊天记录ID,多个逗号拼接 'records_ids' => 'required', - //接收者ID(好友ID或者群聊ID) + // 接收者ID(好友ID或者群聊ID) 'receive_id' => 'required|integer|min:0', - //转发方方式[1:逐条转发;2:合并转发] + // 转发方方式[1:逐条转发;2:合并转发;] 'forward_mode' => 'required|in:1,2', - //转发的好友的ID + // 转发的好友的ID //'receive_user_ids' => 'array', - //转发的群聊ID + // 转发的群聊ID //'receive_group_ids' => 'array', ]); @@ -326,9 +326,9 @@ class TalkController extends CController $items = array_merge($receive_user_ids, $receive_group_ids); $user_id = $this->uid(); - if ($params['forward_mode'] == 1) {//单条转发 + if ($params['forward_mode'] == 1) {// 单条转发 $ids = $this->talkService->forwardRecords($user_id, $params['receive_id'], $params['records_ids']); - } else {//合并转发 + } else {// 合并转发 $ids = $this->talkService->mergeForwardRecords($user_id, $params['receive_id'], $params['source'], $params['records_ids'], $items); } @@ -342,13 +342,13 @@ class TalkController extends CController } } - // ...消息推送队列 + // ... 消息推送队列 foreach ($ids as $value) { $this->producer->produce( new ChatMessageProducer(SocketConstants::EVENT_TALK, [ - 'sender' => $user_id, //发送者ID - 'receive' => intval($value['receive_id']), //接收者ID - 'source' => intval($value['source']), //接收者类型 1:好友;2:群组 + 'sender' => $user_id, // 发送者ID + 'receive' => intval($value['receive_id']), // 接收者ID + 'source' => intval($value['source']), // 接收者类型 1:好友;2:群组 'record_id' => $value['record_id'] ]) ); @@ -367,7 +367,7 @@ class TalkController extends CController { $params = $this->request->inputs(['record_id', 'source', 'receive_id']); $this->validate($params, [ - 'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息) + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'record_id' => 'required|integer|min:0', 'receive_id' => 'required|integer|min:1', ]); @@ -412,10 +412,7 @@ class TalkController extends CController 'records_id' => 'required|integer|min:0' ]); - $rows = $this->talkService->getForwardRecords( - $this->uid(), - $params['records_id'] - ); + $rows = $this->talkService->getForwardRecords($this->uid(), $params['records_id']); return $this->response->success(['rows' => $rows]); } @@ -430,7 +427,7 @@ class TalkController extends CController { $params = $this->request->inputs(['record_id', 'source', 'receive_id', 'msg_type']); $this->validate($params, [ - 'source' => 'required|in:1,2',//消息来源(1:好友消息 2:群聊消息) + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'record_id' => 'required|integer|min:0', 'receive_id' => 'required|integer|min:1', 'msg_type' => 'required|in:0,1,2,3,4,5,6', @@ -503,8 +500,7 @@ class TalkController extends CController { $params = $this->request->inputs(['source', 'receive_id']); $this->validate($params, [ - //消息来源(1:好友消息 2:群聊消息) - 'source' => 'required|in:1,2', + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'receive_id' => 'required|integer|min:1' ]); @@ -518,7 +514,7 @@ class TalkController extends CController return $this->response->fail('图片格式错误,目前仅支持jpg、png、jpeg、gif和webp'); } - //获取图片信息 + // 获取图片信息 $imgInfo = getimagesize($file->getRealPath()); $path = $uploadService->media($file, 'media/images/talks', create_image_name($ext, $imgInfo[0], $imgInfo[1])); @@ -547,12 +543,12 @@ class TalkController extends CController return $this->response->fail('图片上传失败'); } - // ...消息推送队列 + // ... 消息推送队列 $this->producer->produce( new ChatMessageProducer(SocketConstants::EVENT_TALK, [ - 'sender' => $user_id, //发送者ID - 'receive' => intval($params['receive_id']), //接收者ID - 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 + 'sender' => $user_id, // 发送者ID + 'receive' => intval($params['receive_id']), // 接收者ID + 'source' => intval($params['source']), // 接收者类型[1:好友;2:群组;] 'record_id' => $record_id ]) ); @@ -575,8 +571,7 @@ class TalkController extends CController { $params = $this->request->inputs(['source', 'receive_id', 'lang', 'code']); $this->validate($params, [ - //消息来源(1:好友消息 2:群聊消息) - 'source' => 'required|in:1,2', + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'receive_id' => 'required|integer|min:1', 'lang' => 'required', 'code' => 'required' @@ -601,9 +596,9 @@ class TalkController extends CController // ...消息推送队列 $this->producer->produce( new ChatMessageProducer(SocketConstants::EVENT_TALK, [ - 'sender' => $user_id, //发送者ID - 'receive' => intval($params['receive_id']), //接收者ID - 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 + 'sender' => $user_id, // 发送者ID + 'receive' => intval($params['receive_id']), // 接收者ID + 'source' => intval($params['source']), // 接收者类型[1:好友;2:群组;] 'record_id' => $record_id ]) ); @@ -627,8 +622,7 @@ class TalkController extends CController { $params = $this->request->inputs(['hash_name', 'receive_id', 'source']); $this->validate($params, [ - //消息来源(1:好友消息 2:群聊消息) - 'source' => 'required|in:1,2', + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'receive_id' => 'required|integer|min:1', 'hash_name' => 'required', ]); @@ -645,7 +639,6 @@ class TalkController extends CController $uploadService->makeDirectory($uploadService->driver("files/talks/" . date('Ymd'))); - // Copy Files @copy($uploadService->driver($file->save_dir), $uploadService->driver($save_dir)); $record_id = $this->talkService->createFileMessage([ @@ -667,12 +660,12 @@ class TalkController extends CController return $this->response->fail('表情发送失败'); } - // ...消息推送队列 + // ... 消息推送队列 $this->producer->produce( new ChatMessageProducer(SocketConstants::EVENT_TALK, [ - 'sender' => $user_id, //发送者ID - 'receive' => intval($params['receive_id']), //接收者ID - 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 + 'sender' => $user_id, // 发送者ID + 'receive' => intval($params['receive_id']), // 接收者ID + 'source' => intval($params['source']), // 接收者类型[1:好友;2:群组;] 'record_id' => $record_id ]) ); @@ -695,8 +688,7 @@ class TalkController extends CController { $params = $this->request->inputs(['source', 'receive_id', 'emoticon_id']); $this->validate($params, [ - //消息来源(1:好友消息 2:群聊消息) - 'source' => 'required|in:1,2', + 'source' => 'required|in:1,2',// 消息来源[1:好友消息;2:群聊消息;] 'receive_id' => 'required|integer|min:1', 'emoticon_id' => 'required|integer|min:1', ]); @@ -728,12 +720,12 @@ class TalkController extends CController return $this->response->fail('表情发送失败'); } - // ...消息推送队列 + // ... 消息推送队列 $this->producer->produce( new ChatMessageProducer(SocketConstants::EVENT_TALK, [ - 'sender' => $user_id, //发送者ID - 'receive' => intval($params['receive_id']), //接收者ID - 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 + 'sender' => $user_id, // 发送者ID + 'receive' => intval($params['receive_id']), // 接收者ID + 'source' => intval($params['source']), // 接收者类型[1:好友;2:群组;] 'record_id' => $record_id ]) ); diff --git a/app/Controller/Api/V1/UploadController.php b/app/Controller/Api/V1/UploadController.php index bc6fda7..fcd7604 100644 --- a/app/Controller/Api/V1/UploadController.php +++ b/app/Controller/Api/V1/UploadController.php @@ -56,6 +56,7 @@ class UploadController extends CController $path = '/media/images/avatar/' . date('Ymd') . '/' . uniqid() . date('His') . '.png'; $this->uploadService->makeDirectory($this->uploadService->driver('/media/images/avatar/' . date('Ymd') . '/')); @file_put_contents($this->uploadService->driver($path), $data); + return $this->response->success(['avatar' => get_media_url($path)]); } diff --git a/app/Controller/Api/V1/UsersController.php b/app/Controller/Api/V1/UsersController.php index 8d80f4a..5439599 100644 --- a/app/Controller/Api/V1/UsersController.php +++ b/app/Controller/Api/V1/UsersController.php @@ -46,6 +46,7 @@ class UsersController extends CController public function getUserDetail() { $userInfo = $this->userService->findById($this->uid(), ['mobile', 'nickname', 'avatar', 'motto', 'email', 'gender']); + return $this->response->success([ 'mobile' => $userInfo->mobile, 'nickname' => $userInfo->nickname, @@ -65,6 +66,7 @@ class UsersController extends CController public function getUserSetting() { $userInfo = $this->userService->findById($this->uid(), ['id', 'nickname', 'avatar', 'motto', 'gender']); + return $this->response->success([ 'user_info' => [ 'uid' => $userInfo->id, diff --git a/app/Controller/IndexController.php b/app/Controller/IndexController.php index adf3ace..c6129ce 100644 --- a/app/Controller/IndexController.php +++ b/app/Controller/IndexController.php @@ -1,28 +1,14 @@ - * @link https://github.com/gzydong/hyperf-chat - */ namespace App\Controller; -use App\Model\UsersEmoticon; use Hyperf\HttpServer\Contract\ResponseInterface; class IndexController extends AbstractController { public function index(ResponseInterface $response) { - - $res = (bool)UsersEmoticon::where('user_id', 9999999)->delete(); - - var_dump($res); - $user = $this->request->input('user', 'Hyperf'); $method = $this->request->getMethod(); diff --git a/app/Controller/WebSocketController.php b/app/Controller/WebSocketController.php index 3f1d0ab..50034fc 100644 --- a/app/Controller/WebSocketController.php +++ b/app/Controller/WebSocketController.php @@ -156,7 +156,7 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos stdout_log()->notice("客户端FD:{$fd} 已关闭连接 ,用户ID为【{$user_id}】,关闭时间:" . date('Y-m-d H:i:s')); - // 解除fd关系 + // 删除 fd 绑定关系 $this->socketClientService->removeRelation($fd); // 判断是否存在异地登录 diff --git a/app/Exception/Handler/AppExceptionHandler.php b/app/Exception/Handler/AppExceptionHandler.php index 32a8c66..9ca8855 100644 --- a/app/Exception/Handler/AppExceptionHandler.php +++ b/app/Exception/Handler/AppExceptionHandler.php @@ -33,7 +33,7 @@ class AppExceptionHandler extends ExceptionHandler 'message' => 'Internal Server Error.' ], JSON_UNESCAPED_UNICODE); - return $response->withHeader('Server', 'Hyperf')->withStatus(500)->withBody(new SwooleStream($data)); + return $response->withHeader('Server', 'Lumen IM')->withStatus(500)->withBody(new SwooleStream($data)); } /** diff --git a/app/Exception/Handler/JwtAuthExceptionHandler.php b/app/Exception/Handler/JwtAuthExceptionHandler.php index 01e2516..a24a308 100644 --- a/app/Exception/Handler/JwtAuthExceptionHandler.php +++ b/app/Exception/Handler/JwtAuthExceptionHandler.php @@ -29,6 +29,7 @@ class JwtAuthExceptionHandler extends ExceptionHandler // 阻止异常冒泡 $this->stopPropagation(); + return $response->withAddedHeader('content-type', 'application/json; charset=utf-8')->withStatus(401)->withBody(new SwooleStream($data)); } diff --git a/app/Model/User.php b/app/Model/User.php index 3671de1..4f62b00 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -10,9 +10,11 @@ namespace App\Model; * @property integer $id 用户ID * @property string $nickname 用户昵称 * @property string $mobile 登录手机号 + * @property string $email 邮箱地址 * @property string $password 登录密码 * @property string $avatar 头像 * @property integer $gender 性别 + * @property string $motto 座右铭 * @property integer $created_at 注册时间 * @package App\Model */ diff --git a/app/Service/ArticleService.php b/app/Service/ArticleService.php index 7d4178f..417676a 100644 --- a/app/Service/ArticleService.php +++ b/app/Service/ArticleService.php @@ -213,6 +213,7 @@ class ArticleService extends BaseService * @param int $uid 用户ID * @param int $class_id 分类ID * @return bool + * @throws Exception */ public function delArticleClass(int $uid, int $class_id) { diff --git a/app/Service/ContactsService.php b/app/Service/ContactsService.php index 7a06e0f..c75612a 100644 --- a/app/Service/ContactsService.php +++ b/app/Service/ContactsService.php @@ -153,7 +153,6 @@ SQL; $active = ($friendResult->user1 == $info->user_id && $friendResult->user2 == $info->friend_id) ? 1 : 2; UsersFriend::where('id', $friendResult->id)->update(['active' => $active, 'status' => 1]); } else { - //好友昵称 $friend_nickname = User::where('id', $info->friend_id)->value('nickname'); UsersFriend::create([ diff --git a/app/Service/MailerService.php b/app/Service/MailerService.php index b9055a2..ed43328 100644 --- a/app/Service/MailerService.php +++ b/app/Service/MailerService.php @@ -27,7 +27,7 @@ class MailerService * @param string $template 对应邮件模板 * @return bool */ - public function send($email, $subject, $template) + public function send(string $email, string $subject, string $template) { if ($this->queueSwitch) { @@ -44,7 +44,7 @@ class MailerService * @param string $template 对应邮件模板 * @return bool */ - public function realSend($email, $subject, $template) + public function realSend(string $email, string $subject, string $template) { try { return $this->mail($email, $subject, $template); @@ -67,10 +67,10 @@ class MailerService $config = config('mail'); $mail = new PHPMailer(); $mail->CharSet = 'UTF-8'; - $mail->IsSMTP(); // 设定使用SMTP服务 - $mail->SMTPDebug = 0; // 关闭SMTP调试功能 - $mail->SMTPAuth = true; // 启用 SMTP 验证功能 - $mail->SMTPSecure = 'ssl'; // 使用安全协议 + $mail->IsSMTP(); // 设定使用SMTP服务 + $mail->SMTPDebug = 0; // 关闭SMTP调试功能 + $mail->SMTPAuth = true; // 启用 SMTP 验证功能 + $mail->SMTPSecure = 'ssl'; // 使用安全协议 $mail->Host = $config['host']; $mail->Port = $config['port']; $mail->Username = $config['username']; diff --git a/app/Service/MessageHandleService.php b/app/Service/MessageHandleService.php index 9a6583f..9dd72c7 100644 --- a/app/Service/MessageHandleService.php +++ b/app/Service/MessageHandleService.php @@ -49,19 +49,19 @@ class MessageHandleService return; } - //验证消息类型 私聊|群聊 + // 验证消息类型 私聊|群聊 if (!in_array($data['source_type'], [1, 2])) { return; } - //验证发送消息用户与接受消息用户之间是否存在好友或群聊关系(后期走缓存) - if ($data['source_type'] == 1) {//私信 - //判断发送者和接受者是否是好友关系 + // 验证发送消息用户与接受消息用户之间是否存在好友或群聊关系(后期走缓存) + if ($data['source_type'] == 1) {// 私信 + // 判断发送者和接受者是否是好友关系 if (!UsersFriend::isFriend((int)$data['send_user'], (int)$data['receive_user'], true)) { return; } - } else if ($data['source_type'] == 2) {//群聊 - //判断是否属于群成员 + } else if ($data['source_type'] == 2) {// 群聊 + // 判断是否属于群成员 if (!Group::isMember((int)$data['receive_user'], (int)$data['send_user'])) { return; } @@ -94,9 +94,9 @@ class MessageHandleService $this->producer->produce( new ChatMessageProducer('event_talk', [ - 'sender' => intval($data['send_user']), //发送者ID - 'receive' => intval($data['receive_user']), //接收者ID - 'source' => intval($data['source_type']), //接收者类型 1:好友;2:群组 + 'sender' => intval($data['send_user']), // 发送者ID + 'receive' => intval($data['receive_user']), // 接收者ID + 'source' => intval($data['source_type']), // 接收者类型[1:好友;2:群组;] 'record_id' => $result->id ]) ); @@ -113,8 +113,8 @@ class MessageHandleService { $this->producer->produce( new ChatMessageProducer('event_keyboard', [ - 'send_user' => intval($data['send_user']), //发送者ID - 'receive_user' => intval($data['receive_user']), //接收者ID + 'send_user' => intval($data['send_user']), // 发送者ID + 'receive_user' => intval($data['receive_user']), // 接收者ID ]) ); } diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index fc97039..8281bc4 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -175,13 +175,13 @@ class TalkService extends BaseService $rows[$k]['invite'] = []; switch ($row['msg_type']) { - case 2://2:文件消息 + case 2:// 文件消息 $rows[$k]['file'] = $files[$row['id']] ?? []; if ($rows[$k]['file']) { $rows[$k]['file']['file_url'] = get_media_url($rows[$k]['file']['save_dir']); } break; - case 3://3:入群消息/退群消息 + case 3:// 入群消息/退群消息 if (isset($invites[$row['id']])) { $rows[$k]['invite'] = [ 'type' => $invites[$row['id']]['type'], @@ -199,7 +199,7 @@ class TalkService extends BaseService } } break; - case 4://4:会话记录消息 + case 4:// 会话记录消息 if (isset($forwards[$row['id']])) { $rows[$k]['forward'] = [ 'num' => substr_count($forwards[$row['id']]['records_id'], ',') + 1, @@ -207,7 +207,7 @@ class TalkService extends BaseService ]; } break; - case 5://5:代码块消息 + case 5:// 代码块消息 $rows[$k]['code_block'] = $codes[$row['id']] ?? []; if ($rows[$k]['code_block']) { $rows[$k]['code_block']['code'] = htmlspecialchars_decode($rows[$k]['code_block']['code']); @@ -298,7 +298,7 @@ class TalkService extends BaseService 'id', 'source', 'msg_type', 'user_id', 'receive_id', 'content', 'is_revoke', 'created_at' ]); - //判断是否有权限查看 + // 判断是否有权限查看 if ($result->source == 1 && ($result->user_id != $user_id && $result->receive_id != $user_id)) { return []; } else if ($result->source == 2 && !Group::isMember($result->receive_id, $user_id)) { @@ -338,11 +338,11 @@ class TalkService extends BaseService */ public function removeRecords(int $user_id, int $source, int $receive_id, array $record_ids) { - if ($source == 1) {//私聊信息 + if ($source == 1) {// 私聊信息 $ids = ChatRecord::whereIn('id', $record_ids)->where(function ($query) use ($user_id, $receive_id) { $query->where([['user_id', '=', $user_id], ['receive_id', '=', $receive_id]])->orWhere([['user_id', '=', $receive_id], ['receive_id', '=', $user_id]]); })->where('source', 1)->pluck('id'); - } else {//群聊信息 + } else {// 群聊信息 $ids = ChatRecord::whereIn('id', $record_ids)->where('source', 2)->pluck('id'); } @@ -379,7 +379,7 @@ class TalkService extends BaseService $result = ChatRecord::where('id', $record_id)->first(['id', 'source', 'user_id', 'receive_id', 'created_at']); if (!$result) return [false, '消息记录不存在']; - //判断是否在两分钟之内撤回消息,超过2分钟不能撤回消息 + // 判断是否在两分钟之内撤回消息,超过2分钟不能撤回消息 if ((time() - strtotime($result->created_at) > 120)) { return [false, '已超过有效的撤回时间', []]; } diff --git a/app/Support/Mail.php b/app/Support/Mail.php index aca917a..a28850b 100644 --- a/app/Support/Mail.php +++ b/app/Support/Mail.php @@ -45,17 +45,17 @@ class Mail private function mail(string $address, string $subject, string $view): bool { $config = config('mail'); - $mail = new PHPMailer(); // PHPMailer对象 - $mail->CharSet = 'UTF-8'; // 设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 - $mail->IsSMTP(); // 设定使用SMTP服务 - $mail->SMTPDebug = 0; // 关闭SMTP调试功能 - $mail->SMTPAuth = true; // 启用 SMTP 验证功能 - $mail->SMTPSecure = 'ssl'; // 使用安全协议 - $mail->Host = $config['host']; // SMTP 服务器 - $mail->Port = $config['port']; // SMTP服务器的端口号 - $mail->Username = $config['username']; // SMTP服务器用户名 - $mail->Password = $config['password']; // SMTP服务器密码 - $mail->SetFrom($config['from'], $config['name']); // 邮箱,昵称 + $mail = new PHPMailer(); // PHPMailer对象 + $mail->CharSet = 'UTF-8'; // 设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码 + $mail->IsSMTP(); // 设定使用SMTP服务 + $mail->SMTPDebug = 0; // 关闭SMTP调试功能 + $mail->SMTPAuth = true; // 启用 SMTP 验证功能 + $mail->SMTPSecure = 'ssl'; // 使用安全协议 + $mail->Host = $config['host']; // SMTP 服务器 + $mail->Port = $config['port']; // SMTP服务器的端口号 + $mail->Username = $config['username']; // SMTP服务器用户名 + $mail->Password = $config['password']; // SMTP服务器密码 + $mail->SetFrom($config['from'], $config['name']); // 邮箱,昵称 $mail->Subject = $subject; $mail->MsgHTML($view); $mail->AddAddress($address); // 收件人 @@ -64,11 +64,11 @@ class Mail /** * @param string $engine - * @param $template + * @param string $template * @param array $params * @return string */ - private function view(string $engine, $template, $params = []): string + private function view(string $engine, string $template, array $params = []): string { $config = config('view.config', []); return container()->get($engine)->render($template, $params, $config); diff --git a/app/Support/RedisLock.php b/app/Support/RedisLock.php index c80fa10..4a0b995 100644 --- a/app/Support/RedisLock.php +++ b/app/Support/RedisLock.php @@ -18,7 +18,7 @@ class RedisLock /** * 获取Redis连接 * - * @return mixed|\Redis + * @return \Hyperf\Redis\Redis */ public static function getRedis() { @@ -27,8 +27,8 @@ class RedisLock /** * 获得锁,如果锁被占用,阻塞,直到获得锁或者超时。 - * -- 1、如果 $timeout 参数为 0,则立即返回锁。 - * -- 2、建议 timeout 设置为 0,避免 redis 因为阻塞导致性能下降。请根据实际需求进行设置。 + * 1、如果 $timeout 参数为 0,则立即返回锁。 + * 2、建议 timeout 设置为 0,避免 redis 因为阻塞导致性能下降。请根据实际需求进行设置。 * * @param string $key 缓存KEY * @param string|int $requestId 客户端请求唯一ID @@ -60,7 +60,7 @@ class RedisLock \Swoole\Coroutine\System::sleep($sleep); } while (!is_numeric($timeout) || (self::getMicroTime()) < ($start + ($timeout * 1000000))); - return $acquired ? true : false; + return (bool)$acquired; } /**