初始化

main
gzydong 2020-12-01 22:50:43 +08:00
parent 1905a605fa
commit ffb0a0dd44
5 changed files with 26 additions and 15 deletions

View File

@ -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 配置 ----

View File

@ -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

View File

@ -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;
}
/**

View File

@ -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) {//群聊

View File

@ -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,