diff --git a/app/Controller/Api/V1/GroupController.php b/app/Controller/Api/V1/GroupController.php index 478a0ce..28a881b 100644 --- a/app/Controller/Api/V1/GroupController.php +++ b/app/Controller/Api/V1/GroupController.php @@ -2,6 +2,7 @@ namespace App\Controller\Api\V1; +use App\Constants\SocketConstants; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; @@ -81,7 +82,7 @@ class GroupController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($data['group_id']), //接收者ID 'source' => 2, //接收者类型 1:好友;2:群组 @@ -146,7 +147,7 @@ class GroupController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['group_id']), //接收者ID 'source' => 2, //接收者类型 1:好友;2:群组 @@ -180,7 +181,7 @@ class GroupController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['group_id']), //接收者ID 'source' => 2, //接收者类型 1:好友;2:群组 @@ -246,7 +247,7 @@ class GroupController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['group_id']), //接收者ID 'source' => 2, //接收者类型 1:好友;2:群组 diff --git a/app/Controller/Api/V1/TalkController.php b/app/Controller/Api/V1/TalkController.php index d771de3..4d16f1d 100644 --- a/app/Controller/Api/V1/TalkController.php +++ b/app/Controller/Api/V1/TalkController.php @@ -2,6 +2,7 @@ namespace App\Controller\Api\V1; +use App\Constants\SocketConstants; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; @@ -229,7 +230,7 @@ class TalkController extends CController [$isTrue, $message,] = $this->talkService->revokeRecord($this->uid(), $params['record_id']); if ($isTrue) { $this->producer->produce( - new ChatMessageProducer('event_revoke_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_REVOKE_TALK, [ 'record_id' => $params['record_id'] ]) ); @@ -326,7 +327,7 @@ class TalkController extends CController // ...消息推送队列 foreach ($ids as $value) { $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($value['receive_id']), //接收者ID 'source' => intval($value['source']), //接收者类型 1:好友;2:群组 @@ -526,7 +527,7 @@ class TalkController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['receive_id']), //接收者ID 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 @@ -571,7 +572,7 @@ class TalkController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['receive_id']), //接收者ID 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 @@ -586,6 +587,9 @@ class TalkController extends CController * 发送文件消息 * * @RequestMapping(path="send-file", methods="post") + * + * @param UploadService $uploadService + * @return ResponseInterface */ public function sendFile(UploadService $uploadService) { @@ -633,7 +637,7 @@ class TalkController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['receive_id']), //接收者ID 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 @@ -661,7 +665,7 @@ class TalkController extends CController $user_id = $this->uid(); $emoticon = EmoticonDetail::where('id', $params['emoticon_id'])->where('user_id', $user_id)->first([ - 'url','file_suffix','file_size' + 'url', 'file_suffix', 'file_size' ]); if (!$emoticon) { @@ -688,7 +692,7 @@ class TalkController extends CController // ...消息推送队列 $this->producer->produce( - new ChatMessageProducer('event_talk', [ + new ChatMessageProducer(SocketConstants::EVENT_TALK, [ 'sender' => $user_id, //发送者ID 'receive' => intval($params['receive_id']), //接收者ID 'source' => intval($params['source']), //接收者类型 1:好友;2:群组 diff --git a/app/Controller/Api/V1/UsersController.php b/app/Controller/Api/V1/UsersController.php index d391cf8..0005fb9 100644 --- a/app/Controller/Api/V1/UsersController.php +++ b/app/Controller/Api/V1/UsersController.php @@ -2,6 +2,7 @@ namespace App\Controller\Api\V1; +use App\Constants\SocketConstants; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; @@ -268,7 +269,7 @@ class UsersController extends CController //判断对方是否在线。如果在线发送消息通知 if ($this->socketClientService->isOnlineAll((int)$params['friend_id'])) { $this->producer->produce( - new ChatMessageProducer('event_friend_apply', [ + new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [ 'sender' => $user_id, 'receive' => (int)$params['friend_id'], 'type' => 1, @@ -304,7 +305,7 @@ class UsersController extends CController if ($this->socketClientService->isOnlineAll((int)$params['friend_id'])) { // 待修改 $this->producer->produce( - new ChatMessageProducer('event_friend_apply', [ + new ChatMessageProducer(SocketConstants::EVENT_FRIEND_APPLY, [ 'sender' => $user_id, 'receive' => (int)$params['friend_id'], 'type' => 1, diff --git a/app/Service/TalkService.php b/app/Service/TalkService.php index f3fcc38..e6da1ac 100644 --- a/app/Service/TalkService.php +++ b/app/Service/TalkService.php @@ -240,7 +240,7 @@ class TalkService extends BaseService * @param int $record_id 上一次查询的聊天记录ID * @param int $limit 查询数据长度 * @param array $msg_type 消息类型 - * @return mixed + * @return array */ public function getChatRecords(int $user_id, int $receive_id, int $source, int $record_id, $limit = 30, $msg_type = []) { @@ -417,7 +417,6 @@ class TalkService extends BaseService * @param int $record_id 转发消息的记录ID * @param array $receive_ids 接受者数组 例如:[['source' => 1,'id' => 3045],['source' => 1,'id' => 3046],['source' => 1,'id' => 1658]] 二维数组 * @return array - * @throws \Exception */ public function forwardRecords(int $user_id, int $record_id, array $receive_ids) { @@ -477,7 +476,7 @@ class TalkService extends BaseService 'save_dir' => $fileInfo->save_dir, 'created_at' => date('Y-m-d H:i:s') ])) { - throw new \Exception('插入文件消息记录失败'); + throw new Exception('插入文件消息记录失败'); } } else if ($result->msg_type == 5) { if (!ChatRecordsCode::create([ @@ -487,7 +486,7 @@ class TalkService extends BaseService 'code' => $codeBlock->code, 'created_at' => date('Y-m-d H:i:s') ])) { - throw new \Exception('插入代码消息记录失败'); + throw new Exception('插入代码消息记录失败'); } } } @@ -696,17 +695,17 @@ class TalkService extends BaseService $insert = ChatRecord::create($message); if (!$insert) { - throw new \Exception('插入聊天记录失败...'); + throw new Exception('插入聊天记录失败...'); } $fileInfo['record_id'] = $insert->id; $fileInfo['created_at'] = date('Y-m-d H:i:s'); if (!ChatRecordsFile::create($fileInfo)) { - throw new \Exception('插入聊天记录(文件消息)失败...'); + throw new Exception('插入聊天记录(文件消息)失败...'); } Db::commit(); - } catch (\Exception $e) { + } catch (Exception $e) { Db::rollBack(); return false; } @@ -728,17 +727,17 @@ class TalkService extends BaseService $message['created_at'] = date('Y-m-d H:i:s'); $insert = ChatRecord::create($message); if (!$insert) { - throw new \Exception('插入聊天记录失败...'); + throw new Exception('插入聊天记录失败...'); } $codeBlock['record_id'] = $insert->id; $codeBlock['created_at'] = date('Y-m-d H:i:s'); if (!ChatRecordsCode::create($codeBlock)) { - throw new \Exception('插入聊天记录(代码消息)失败...'); + throw new Exception('插入聊天记录(代码消息)失败...'); } Db::commit(); - } catch (\Exception $e) { + } catch (Exception $e) { Db::rollBack(); return false; } @@ -760,17 +759,17 @@ class TalkService extends BaseService $message['created_at'] = date('Y-m-d H:i:s'); $insert = ChatRecord::create($message); if (!$insert) { - throw new \Exception('插入聊天记录失败...'); + throw new Exception('插入聊天记录失败...'); } $emoticon['record_id'] = $insert->id; $emoticon['created_at'] = date('Y-m-d H:i:s'); if (!ChatRecordsFile::create($emoticon)) { - throw new \Exception('插入聊天记录(代码消息)失败...'); + throw new Exception('插入聊天记录(代码消息)失败...'); } Db::commit(); - } catch (\Exception $e) { + } catch (Exception $e) { Db::rollBack(); return false; } @@ -792,17 +791,17 @@ class TalkService extends BaseService $message['created_at'] = date('Y-m-d H:i:s'); $insert = ChatRecord::create($message); if (!$insert) { - throw new \Exception('插入聊天记录失败...'); + throw new Exception('插入聊天记录失败...'); } $emoticon['record_id'] = $insert->id; $emoticon['created_at'] = date('Y-m-d H:i:s'); if (!ChatRecordsFile::create($emoticon)) { - throw new \Exception('插入聊天记录(代码消息)失败...'); + throw new Exception('插入聊天记录(代码消息)失败...'); } Db::commit(); - } catch (\Exception $e) { + } catch (Exception $e) { Db::rollBack(); return false; } diff --git a/app/helper.php b/app/helper.php index 1f3ec3f..83df55e 100644 --- a/app/helper.php +++ b/app/helper.php @@ -112,7 +112,9 @@ function response() /** * 从HTML文本中提取所有图片 - * @param $content + * + * @param string $content HTML文本 + * * @return array */ function get_html_images($content) @@ -133,8 +135,9 @@ function get_html_images($content) /** * 获取两个日期相差多少天 * - * @param $day1 - * @param $day2 + * @param string $day1 日期1 + * @param string $day2 日期2 + * * @return float|int */ function diff_date($day1, $day2) @@ -153,6 +156,7 @@ function diff_date($day1, $day2) * 获取媒体文件url * * @param string $path 文件相对路径 + * * @return string */ function get_media_url(string $path) @@ -166,6 +170,7 @@ function get_media_url(string $path) * @param string $ext 图片后缀名 * @param int $width 图片宽度 * @param int $height 图片高度 + * * @return string */ function create_image_name(string $ext, int $width, int $height) @@ -176,7 +181,8 @@ function create_image_name(string $ext, int $width, int $height) /** * 替换文本中的url 为 a标签 * - * @param string $str + * @param string $str 字符串 + * * @return null|string|string[] */ function replace_url_link(string $str)