Merge branch 'main' of github.com:gzydong/hyperf-chat into main
commit
09b09bbc14
|
@ -35,10 +35,10 @@ IP_ADDRESS=0.0.0.0
|
|||
MAIL_DRIVER=smtp
|
||||
MAIL_HOST=smtp.163.com
|
||||
MAIL_PORT=465
|
||||
MAIL_USERNAME=18798276809@163.com
|
||||
MAIL_PASSWORD=RYD18798276809
|
||||
MAIL_FROM_ADDRESS=18798276809@163.com
|
||||
MAIL_FROM_NAME="Lumen IM 在线聊天"
|
||||
MAIL_USERNAME=xxxxx
|
||||
MAIL_PASSWORD=xxxx
|
||||
MAIL_FROM_ADDRESS=xxxx@163.com
|
||||
MAIL_FROM_NAME="xxxxx"
|
||||
MAIL_ENCRYPTION=ssl
|
||||
|
||||
# ---- Rabbit MQ 配置 ----
|
||||
|
|
10
README.md
10
README.md
|
@ -1,9 +1,17 @@
|
|||
# Hyperf-Chat
|
||||
# Lumen-IM
|
||||
|
||||
## 1、简介
|
||||
|
||||
这是一个使用Hyperf框架的开发的IM后端应用程序。此项目是 [LumenIM-Serve](https://github.com/gzydong/LumenIM-Serve) 的重构版本。
|
||||
|
||||
Lumen-IM 是一个网页版在线即时聊天项目,前端使用 Element-ui + Vue ,后端使用 PHP+Swoole 进行开发。项目后端采用 Hyperf 框架。
|
||||
|
||||
- 基于Swoole WebSocket服务做消息即时推送
|
||||
- 支持私聊及群聊
|
||||
- 支持聊天消息类型有文本、代码块、图片及其它类型文件,并支持文件下载
|
||||
- 支持聊天消息撤回、删除或批量删除、转发消息(逐条转发、合并转发)
|
||||
- 支持编写个人笔记、支持笔记分享(好友或群)
|
||||
|
||||
## 2、项目Demo
|
||||
|
||||
- 地址: [http://im.gzydong.club](http://im.gzydong.club)
|
||||
|
|
|
@ -201,7 +201,7 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
$invite = [
|
||||
'type' => $notifyInfo->type,
|
||||
'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);
|
||||
|
@ -212,7 +212,7 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
$forwardInfo = ChatRecordsForward::where('record_id', $result->id)->first(['records_id', 'text']);
|
||||
if ($forwardInfo) {
|
||||
$forward = [
|
||||
'num' => substr_count($forwardInfo->records_id, ',') + 1,
|
||||
'num' => count(parse_ids($forwardInfo->records_id)),
|
||||
'list' => json_decode($forwardInfo->text, true) ?? []
|
||||
];
|
||||
}
|
||||
|
@ -361,7 +361,7 @@ class ChatMessageConsumer extends ConsumerMessage
|
|||
* @param array $data 对话的消息
|
||||
* @return array
|
||||
*/
|
||||
private function formatTalkMessage(array $data)
|
||||
private function formatTalkMessage(array $data): array
|
||||
{
|
||||
$message = [
|
||||
"id" => 0,//消息记录ID
|
||||
|
|
|
@ -93,16 +93,27 @@ SQL;
|
|||
*
|
||||
* @param int $user_id1 用户1
|
||||
* @param int $user_id2 用户2
|
||||
* @param bool $cache 是否读取缓存
|
||||
* @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) {
|
||||
[$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -57,7 +57,7 @@ class MessageHandleService
|
|||
//验证发送消息用户与接受消息用户之间是否存在好友或群聊关系(后期走缓存)
|
||||
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;
|
||||
}
|
||||
} else if ($data['source_type'] == 2) {//群聊
|
||||
|
|
|
@ -11,11 +11,11 @@ declare(strict_types=1);
|
|||
*/
|
||||
return [
|
||||
'default' => [
|
||||
'host' => '47.105.180.123',
|
||||
'port' => 5672,
|
||||
'user' => 'yuandong',
|
||||
'password' => 'yuandong',
|
||||
'vhost' => 'im',
|
||||
'host' => env('AMQP_HOST','127.0.0.1'),
|
||||
'port' => intval(env('AMQP_PORT',5672)),
|
||||
'user' => env('AMQP_USER','guest'),
|
||||
'password' => env('AMQP_PASSWORD','guest'),
|
||||
'vhost' => env('AMQP_VHOST','/'),
|
||||
'pool' => [
|
||||
'min_connections' => 1,
|
||||
'max_connections' => 10,
|
||||
|
|
Loading…
Reference in New Issue