初始化
parent
1905a605fa
commit
f66b474cc6
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
use Hyperf\Command\Command as HyperfCommand;
|
|
||||||
use Hyperf\Command\Annotation\Command;
|
use Hyperf\Command\Annotation\Command;
|
||||||
|
use Hyperf\Command\Command as HyperfCommand;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use App\Service\SocketClientService;
|
use App\Service\SocketClientService;
|
||||||
|
|
||||||
|
|
|
@ -2,43 +2,41 @@
|
||||||
|
|
||||||
namespace App\Constants;
|
namespace App\Constants;
|
||||||
|
|
||||||
use Hyperf\Constants\AbstractConstants;
|
|
||||||
use Hyperf\Constants\Annotation\Constants;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebSocket 消息事件
|
* WebSocket 消息事件枚举
|
||||||
*
|
*
|
||||||
* @Constants
|
* Class SocketConstants
|
||||||
|
* @package App\Constants
|
||||||
*/
|
*/
|
||||||
class SocketConstants extends AbstractConstants
|
class SocketConstants
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @Message("对话消息通知 - 事件名)
|
* 对话消息通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_TALK = 'event_talk';
|
const EVENT_TALK = 'event_talk';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("键盘输入事件通知 - 事件名")
|
* 键盘输入事件通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_KEYBOARD = 'event_keyboard';
|
const EVENT_KEYBOARD = 'event_keyboard';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("用户在线状态通知 - 事件名")
|
* 用户在线状态通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_ONLINE_STATUS = 'event_online_status';
|
const EVENT_ONLINE_STATUS = 'event_online_status';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("聊天消息撤销通知 - 事件名")
|
* 聊天消息撤销通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_REVOKE_TALK = 'event_revoke_talk';
|
const EVENT_REVOKE_TALK = 'event_revoke_talk';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("好友申请消息通知 - 事件名")
|
* 好友申请消息通知 - 事件名
|
||||||
*/
|
*/
|
||||||
const EVENT_FRIEND_APPLY = 'event_friend_apply';
|
const EVENT_FRIEND_APPLY = 'event_friend_apply';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Message("WebSocket 消息消费队列交换机名称")
|
* WebSocket 消息消费队列交换机名称
|
||||||
*/
|
*/
|
||||||
const CONSUMER_MESSAGE_EXCHANGE = 'im.message.fanout';
|
const CONSUMER_MESSAGE_EXCHANGE = 'im.message.fanout';
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ use App\Service\MessageHandleService;
|
||||||
use App\Service\SocketRoomService;
|
use App\Service\SocketRoomService;
|
||||||
use App\Model\Group\UsersGroupMember;
|
use App\Model\Group\UsersGroupMember;
|
||||||
use App\Amqp\Producer\ChatMessageProducer;
|
use App\Amqp\Producer\ChatMessageProducer;
|
||||||
|
use App\Support\SocketIOParser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class WebSocketController
|
* Class WebSocketController
|
||||||
|
@ -77,6 +78,11 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
||||||
// 判断是否存在异地登录
|
// 判断是否存在异地登录
|
||||||
$isOnline = $this->socketClientService->isOnlineAll(intval($userInfo['user_id']));
|
$isOnline = $this->socketClientService->isOnlineAll(intval($userInfo['user_id']));
|
||||||
|
|
||||||
|
// 若开启单点登录,则主动关闭当前连接
|
||||||
|
if ($isOnline) {
|
||||||
|
// ... 预留
|
||||||
|
}
|
||||||
|
|
||||||
// 绑定fd与用户关系
|
// 绑定fd与用户关系
|
||||||
$this->socketClientService->bindRelation($request->fd, $userInfo['user_id']);
|
$this->socketClientService->bindRelation($request->fd, $userInfo['user_id']);
|
||||||
|
|
||||||
|
@ -109,12 +115,20 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
||||||
// 判断是否为心跳检测
|
// 判断是否为心跳检测
|
||||||
if ($frame->data == 'PING') return;
|
if ($frame->data == 'PING') return;
|
||||||
|
|
||||||
[$event, $data] = array_values(json_decode($frame->data, true));
|
$result = SocketIOParser::decode($frame->data);
|
||||||
|
if (!isset(self::EVENTS[$result['event']])) {
|
||||||
if (isset(self::EVENTS[$event])) {
|
|
||||||
call_user_func_array([$this->messageHandleService, self::EVENTS[$event]], [$server, $frame, $data]);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 回调事件处理函数
|
||||||
|
call_user_func_array([
|
||||||
|
$this->messageHandleService,
|
||||||
|
self::EVENTS[$result['event']]
|
||||||
|
], [
|
||||||
|
$server,
|
||||||
|
$frame,
|
||||||
|
$result['data']
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -429,8 +429,6 @@ class ArticleService extends BaseService
|
||||||
return $res->id;
|
return $res->id;
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Db::rollBack();
|
Db::rollBack();
|
||||||
|
|
||||||
var_dump($e->getMessage());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -122,7 +122,6 @@ class EmoticonService extends BaseService
|
||||||
return [false, []];
|
return [false, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$result = EmoticonDetail::where('user_id', $user_id)->where('url', $fileInfo->save_dir)->first();
|
$result = EmoticonDetail::where('user_id', $user_id)->where('url', $fileInfo->save_dir)->first();
|
||||||
if ($result) {
|
if ($result) {
|
||||||
return [false, []];
|
return [false, []];
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
|
||||||
use App\Model\User;
|
use App\Model\User;
|
||||||
use App\Model\UsersFriend;
|
use App\Model\UsersFriend;
|
||||||
use App\Model\UsersFriendsApply;
|
use App\Model\UsersFriendsApply;
|
||||||
|
|
|
@ -683,6 +683,7 @@ class TalkService extends BaseService
|
||||||
*
|
*
|
||||||
* @param $message
|
* @param $message
|
||||||
* @param $fileInfo
|
* @param $fileInfo
|
||||||
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function createImgMessage($message, $fileInfo)
|
public function createImgMessage($message, $fileInfo)
|
||||||
{
|
{
|
||||||
|
@ -715,6 +716,7 @@ class TalkService extends BaseService
|
||||||
*
|
*
|
||||||
* @param array $message
|
* @param array $message
|
||||||
* @param array $codeBlock
|
* @param array $codeBlock
|
||||||
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function createCodeMessage(array $message, array $codeBlock)
|
public function createCodeMessage(array $message, array $codeBlock)
|
||||||
{
|
{
|
||||||
|
@ -746,6 +748,7 @@ class TalkService extends BaseService
|
||||||
*
|
*
|
||||||
* @param array $message
|
* @param array $message
|
||||||
* @param array $emoticon
|
* @param array $emoticon
|
||||||
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function createEmoticonMessage(array $message, array $emoticon)
|
public function createEmoticonMessage(array $message, array $emoticon)
|
||||||
{
|
{
|
||||||
|
@ -777,6 +780,7 @@ class TalkService extends BaseService
|
||||||
*
|
*
|
||||||
* @param array $message
|
* @param array $message
|
||||||
* @param array $emoticon
|
* @param array $emoticon
|
||||||
|
* @return bool|int
|
||||||
*/
|
*/
|
||||||
public function createFileMessage(array $message, array $emoticon)
|
public function createFileMessage(array $message, array $emoticon)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use Hyperf\HttpMessage\Upload\UploadedFile;
|
use Hyperf\HttpMessage\Upload\UploadedFile;
|
||||||
use League\Flysystem\Filesystem;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件上传服务
|
* 文件上传服务
|
||||||
|
@ -22,7 +20,7 @@ class UploadService extends BaseService
|
||||||
/**
|
/**
|
||||||
* 创建文件夹
|
* 创建文件夹
|
||||||
*
|
*
|
||||||
* @param $dir
|
* @param string $dir 文件夹路径
|
||||||
*/
|
*/
|
||||||
public function makeDirectory($dir)
|
public function makeDirectory($dir)
|
||||||
{
|
{
|
||||||
|
@ -33,18 +31,21 @@ class UploadService extends BaseService
|
||||||
* 上传媒体图片
|
* 上传媒体图片
|
||||||
*
|
*
|
||||||
* @param UploadedFile $file
|
* @param UploadedFile $file
|
||||||
* @param string $dir
|
* @param string $dir 文件夹路径
|
||||||
* @param string $filename 文件夹名称
|
* @param string $filename 文件名称
|
||||||
|
*
|
||||||
|
* @return bool|string
|
||||||
*/
|
*/
|
||||||
public function media(UploadedFile $file, string $dir, string $filename)
|
public function media(UploadedFile $file, string $dir, string $filename)
|
||||||
{
|
{
|
||||||
$save_dir = $this->driver($dir);
|
$save_dir = $this->driver($dir);
|
||||||
|
|
||||||
$this->makeDirectory($save_dir);
|
$this->makeDirectory($save_dir);
|
||||||
|
|
||||||
$file->moveTo(sprintf('%s/%s', $save_dir, $filename));
|
$file->moveTo(sprintf('%s/%s', $save_dir, $filename));
|
||||||
|
|
||||||
if ($file->isMoved()) {
|
if ($file->isMoved()) {
|
||||||
// 修改文集权限
|
// 修改文件权限
|
||||||
@chmod(sprintf('%s/%s', $save_dir, $filename), 0644);
|
@chmod(sprintf('%s/%s', $save_dir, $filename), 0644);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,15 +23,14 @@ class SocketIOParser extends Packet
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decode message from websocket client.
|
* Decode message from websocket client.
|
||||||
* Define and return payload here.
|
|
||||||
*
|
*
|
||||||
* @param \Swoole\Websocket\Frame $frame
|
* @param string $string
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function decode($frame)
|
public static function decode($string)
|
||||||
{
|
{
|
||||||
$payload = Packet::getPayload($frame->data);
|
$payload = Packet::getPayload($string);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'event' => $payload['event'] ?? null,
|
'event' => $payload['event'] ?? null,
|
||||||
|
|
|
@ -10,6 +10,7 @@ date_default_timezone_set('Asia/Shanghai');
|
||||||
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
|
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
|
||||||
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
|
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
|
||||||
|
|
||||||
|
define('SWOOLE_SSL', 512);
|
||||||
require BASE_PATH . '/vendor/autoload.php';
|
require BASE_PATH . '/vendor/autoload.php';
|
||||||
|
|
||||||
// 设置服务运行ID
|
// 设置服务运行ID
|
||||||
|
|
|
@ -0,0 +1,76 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types = 1);
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| SMTP Host Address
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may provide the host address of the SMTP server used by your
|
||||||
|
| applications. A default option is provided that is compatible with
|
||||||
|
| the Mailgun mail service which will provide reliable deliveries.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| SMTP Host Port
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| This is the SMTP port used by your application to deliver e-mails to
|
||||||
|
| users of the application. Like the host we have set this value to
|
||||||
|
| stay compatible with the Mailgun e-mail application by default.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'port' => env('MAIL_PORT', 587),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| SMTP Server Username
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| If your SMTP server requires a username for authentication, you should
|
||||||
|
| set it here. This will get used to authenticate with your server on
|
||||||
|
| connection. You may also set the "password" value below this one.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'username' => env('MAIL_USERNAME'),
|
||||||
|
|
||||||
|
'password' => env('MAIL_PASSWORD'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Global "From" Address
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| You may wish for all e-mails sent by your application to be sent from
|
||||||
|
| the same address. Here, you may specify a name and address that is
|
||||||
|
| used globally for all e-mails that are sent by your application.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'from' => [
|
||||||
|
'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'),
|
||||||
|
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| E-Mail Encryption Protocol
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Here you may specify the encryption protocol that should be used when
|
||||||
|
| the application send e-mail messages. A sensible default using the
|
||||||
|
| transport layer security protocol should provide great security.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
|
||||||
|
];
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require './vendor/autoload.php';
|
||||||
|
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\SMTP;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
|
||||||
|
$config = [
|
||||||
|
'host' => 'smtp.163.com',
|
||||||
|
'port' => 465,
|
||||||
|
'username' => '18798276809@163.com',
|
||||||
|
'password' => 'RYD18798276809',
|
||||||
|
'from' => [
|
||||||
|
'address' => '18798276809@163.com',
|
||||||
|
'name' => 'Lumen IM 在线聊天',
|
||||||
|
],
|
||||||
|
'encryption' => 'ssl',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
$mail = new PHPMailer(true);
|
||||||
|
try {
|
||||||
|
//Server settings
|
||||||
|
$mail->CharSet = 'UTF-8'; //设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
|
||||||
|
$mail->IsSMTP(); // 设定使用SMTP服务
|
||||||
|
$mail->SMTPDebug = 0; // 关闭SMTP调试功能
|
||||||
|
$mail->SMTPAuth = true; // 启用 SMTP 验证功能
|
||||||
|
$mail->SMTPAutoTLS = false;
|
||||||
|
$mail->Host = $config['host']; // Set the SMTP server to send through
|
||||||
|
$mail->Port = intval($config['port']); // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
|
||||||
|
$mail->Username = $config['username']; // SMTP username
|
||||||
|
$mail->Password = $config['password']; // SMTP password
|
||||||
|
$mail->SMTPSecure = $config['encryption']; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
|
||||||
|
|
||||||
|
//Recipients
|
||||||
|
$mail->setFrom($config['from']['address'], $config['from']['name']);
|
||||||
|
|
||||||
|
$mail->addAddress('837215079@qq.com'); // Name is optional
|
||||||
|
|
||||||
|
// Content
|
||||||
|
$mail->isHTML(true); // Set email format to HTML
|
||||||
|
$mail->Subject = 'Here is the subject';
|
||||||
|
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
|
||||||
|
|
||||||
|
$mail->send();
|
||||||
|
echo 'Message has been sent';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
|
||||||
|
}
|
Loading…
Reference in New Issue