Merge branch 'main' of github.com:gzydong/hyperf-chat into main

main
gzydong 2020-12-02 15:14:50 +08:00
commit 09b09bbc14
6 changed files with 35 additions and 16 deletions

View File

@ -35,10 +35,10 @@ IP_ADDRESS=0.0.0.0
MAIL_DRIVER=smtp MAIL_DRIVER=smtp
MAIL_HOST=smtp.163.com MAIL_HOST=smtp.163.com
MAIL_PORT=465 MAIL_PORT=465
MAIL_USERNAME=18798276809@163.com MAIL_USERNAME=xxxxx
MAIL_PASSWORD=RYD18798276809 MAIL_PASSWORD=xxxx
MAIL_FROM_ADDRESS=18798276809@163.com MAIL_FROM_ADDRESS=xxxx@163.com
MAIL_FROM_NAME="Lumen IM 在线聊天" MAIL_FROM_NAME="xxxxx"
MAIL_ENCRYPTION=ssl MAIL_ENCRYPTION=ssl
# ---- Rabbit MQ 配置 ---- # ---- Rabbit MQ 配置 ----

View File

@ -1,9 +1,17 @@
# Hyperf-Chat # Lumen-IM
## 1、简介 ## 1、简介
这是一个使用Hyperf框架的开发的IM后端应用程序。此项目是 [LumenIM-Serve](https://github.com/gzydong/LumenIM-Serve) 的重构版本。 这是一个使用Hyperf框架的开发的IM后端应用程序。此项目是 [LumenIM-Serve](https://github.com/gzydong/LumenIM-Serve) 的重构版本。
Lumen-IM 是一个网页版在线即时聊天项目,前端使用 Element-ui + Vue ,后端使用 PHP+Swoole 进行开发。项目后端采用 Hyperf 框架。
- 基于Swoole WebSocket服务做消息即时推送
- 支持私聊及群聊
- 支持聊天消息类型有文本、代码块、图片及其它类型文件,并支持文件下载
- 支持聊天消息撤回、删除或批量删除、转发消息(逐条转发、合并转发)
- 支持编写个人笔记、支持笔记分享(好友或群)
## 2、项目Demo ## 2、项目Demo
- 地址: [http://im.gzydong.club](http://im.gzydong.club) - 地址: [http://im.gzydong.club](http://im.gzydong.club)

View File

@ -201,7 +201,7 @@ class ChatMessageConsumer extends ConsumerMessage
$invite = [ $invite = [
'type' => $notifyInfo->type, 'type' => $notifyInfo->type,
'operate_user' => ['id' => $userInfo->id, 'nickname' => $userInfo->nickname], 'operate_user' => ['id' => $userInfo->id, 'nickname' => $userInfo->nickname],
'users' => User::select('id', 'nickname')->whereIn('id', parse_ids($notifyInfo->user_ids))->get()->toArray() 'users' => User::whereIn('id', parse_ids($notifyInfo->user_ids))->get(['id', 'nickname'])->toArray()
]; ];
unset($notifyInfo, $userInfo); unset($notifyInfo, $userInfo);
@ -212,7 +212,7 @@ class ChatMessageConsumer extends ConsumerMessage
$forwardInfo = ChatRecordsForward::where('record_id', $result->id)->first(['records_id', 'text']); $forwardInfo = ChatRecordsForward::where('record_id', $result->id)->first(['records_id', 'text']);
if ($forwardInfo) { if ($forwardInfo) {
$forward = [ $forward = [
'num' => substr_count($forwardInfo->records_id, ',') + 1, 'num' => count(parse_ids($forwardInfo->records_id)),
'list' => json_decode($forwardInfo->text, true) ?? [] 'list' => json_decode($forwardInfo->text, true) ?? []
]; ];
} }
@ -361,7 +361,7 @@ class ChatMessageConsumer extends ConsumerMessage
* @param array $data 对话的消息 * @param array $data 对话的消息
* @return array * @return array
*/ */
private function formatTalkMessage(array $data) private function formatTalkMessage(array $data): array
{ {
$message = [ $message = [
"id" => 0,//消息记录ID "id" => 0,//消息记录ID

View File

@ -93,16 +93,27 @@ SQL;
* *
* @param int $user_id1 用户1 * @param int $user_id1 用户1
* @param int $user_id2 用户2 * @param int $user_id2 用户2
* @param bool $cache 是否读取缓存
* @return bool * @return bool
*/ */
public static function isFriend(int $user_id1, int $user_id2) public static function isFriend(int $user_id1, int $user_id2, bool $cache = false)
{ {
// 比较大小交换位置 // 比较大小交换位置
if ($user_id1 > $user_id2) { if ($user_id1 > $user_id2) {
[$user_id1, $user_id2] = [$user_id2, $user_id1]; [$user_id1, $user_id2] = [$user_id2, $user_id1];
} }
return self::where('user1', $user_id1)->where('user2', $user_id2)->where('status', 1)->exists(); $cacheKey = "good_friends:{$user_id1}_$user_id2";
if ($cache && redis()->get($cacheKey)) {
return true;
}
$isTrue = self::where('user1', $user_id1)->where('user2', $user_id2)->where('status', 1)->exists();
if ($isTrue) {
redis()->setex($cacheKey, 60 * 5, 1);
}
return $isTrue;
} }
/** /**

View File

@ -57,7 +57,7 @@ class MessageHandleService
//验证发送消息用户与接受消息用户之间是否存在好友或群聊关系(后期走缓存) //验证发送消息用户与接受消息用户之间是否存在好友或群聊关系(后期走缓存)
if ($data['source_type'] == 1) {//私信 if ($data['source_type'] == 1) {//私信
//判断发送者和接受者是否是好友关系 //判断发送者和接受者是否是好友关系
if (!UsersFriend::isFriend(intval($data['send_user']), intval($data['receive_user']))) { if (!UsersFriend::isFriend((int)$data['send_user'], (int)$data['receive_user'], true)) {
return; return;
} }
} else if ($data['source_type'] == 2) {//群聊 } else if ($data['source_type'] == 2) {//群聊

View File

@ -11,11 +11,11 @@ declare(strict_types=1);
*/ */
return [ return [
'default' => [ 'default' => [
'host' => '47.105.180.123', 'host' => env('AMQP_HOST','127.0.0.1'),
'port' => 5672, 'port' => intval(env('AMQP_PORT',5672)),
'user' => 'yuandong', 'user' => env('AMQP_USER','guest'),
'password' => 'yuandong', 'password' => env('AMQP_PASSWORD','guest'),
'vhost' => 'im', 'vhost' => env('AMQP_VHOST','/'),
'pool' => [ 'pool' => [
'min_connections' => 1, 'min_connections' => 1,
'max_connections' => 10, 'max_connections' => 10,