初始化
parent
1905a605fa
commit
f66b474cc6
|
@ -4,8 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Command;
|
||||
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use App\Service\SocketClientService;
|
||||
|
||||
|
|
|
@ -2,43 +2,41 @@
|
|||
|
||||
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';
|
||||
|
||||
/**
|
||||
* @Message("键盘输入事件通知 - 事件名")
|
||||
* 键盘输入事件通知 - 事件名
|
||||
*/
|
||||
const EVENT_KEYBOARD = 'event_keyboard';
|
||||
|
||||
/**
|
||||
* @Message("用户在线状态通知 - 事件名")
|
||||
* 用户在线状态通知 - 事件名
|
||||
*/
|
||||
const EVENT_ONLINE_STATUS = 'event_online_status';
|
||||
|
||||
/**
|
||||
* @Message("聊天消息撤销通知 - 事件名")
|
||||
* 聊天消息撤销通知 - 事件名
|
||||
*/
|
||||
const EVENT_REVOKE_TALK = 'event_revoke_talk';
|
||||
|
||||
/**
|
||||
* @Message("好友申请消息通知 - 事件名")
|
||||
* 好友申请消息通知 - 事件名
|
||||
*/
|
||||
const EVENT_FRIEND_APPLY = 'event_friend_apply';
|
||||
|
||||
/**
|
||||
* @Message("WebSocket 消息消费队列交换机名称")
|
||||
* WebSocket 消息消费队列交换机名称
|
||||
*/
|
||||
const CONSUMER_MESSAGE_EXCHANGE = 'im.message.fanout';
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ use App\Service\MessageHandleService;
|
|||
use App\Service\SocketRoomService;
|
||||
use App\Model\Group\UsersGroupMember;
|
||||
use App\Amqp\Producer\ChatMessageProducer;
|
||||
use App\Support\SocketIOParser;
|
||||
|
||||
/**
|
||||
* Class WebSocketController
|
||||
|
@ -77,6 +78,11 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
// 判断是否存在异地登录
|
||||
$isOnline = $this->socketClientService->isOnlineAll(intval($userInfo['user_id']));
|
||||
|
||||
// 若开启单点登录,则主动关闭当前连接
|
||||
if ($isOnline) {
|
||||
// ... 预留
|
||||
}
|
||||
|
||||
// 绑定fd与用户关系
|
||||
$this->socketClientService->bindRelation($request->fd, $userInfo['user_id']);
|
||||
|
||||
|
@ -109,12 +115,20 @@ class WebSocketController implements OnMessageInterface, OnOpenInterface, OnClos
|
|||
// 判断是否为心跳检测
|
||||
if ($frame->data == 'PING') return;
|
||||
|
||||
[$event, $data] = array_values(json_decode($frame->data, true));
|
||||
|
||||
if (isset(self::EVENTS[$event])) {
|
||||
call_user_func_array([$this->messageHandleService, self::EVENTS[$event]], [$server, $frame, $data]);
|
||||
$result = SocketIOParser::decode($frame->data);
|
||||
if (!isset(self::EVENTS[$result['event']])) {
|
||||
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;
|
||||
} catch (Exception $e) {
|
||||
Db::rollBack();
|
||||
|
||||
var_dump($e->getMessage());
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -122,7 +122,6 @@ class EmoticonService extends BaseService
|
|||
return [false, []];
|
||||
}
|
||||
|
||||
|
||||
$result = EmoticonDetail::where('user_id', $user_id)->where('url', $fileInfo->save_dir)->first();
|
||||
if ($result) {
|
||||
return [false, []];
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace App\Service;
|
||||
|
||||
|
||||
use App\Model\User;
|
||||
use App\Model\UsersFriend;
|
||||
use App\Model\UsersFriendsApply;
|
||||
|
|
|
@ -683,6 +683,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param $message
|
||||
* @param $fileInfo
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createImgMessage($message, $fileInfo)
|
||||
{
|
||||
|
@ -715,6 +716,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param array $message
|
||||
* @param array $codeBlock
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createCodeMessage(array $message, array $codeBlock)
|
||||
{
|
||||
|
@ -746,6 +748,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param array $message
|
||||
* @param array $emoticon
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createEmoticonMessage(array $message, array $emoticon)
|
||||
{
|
||||
|
@ -777,6 +780,7 @@ class TalkService extends BaseService
|
|||
*
|
||||
* @param array $message
|
||||
* @param array $emoticon
|
||||
* @return bool|int
|
||||
*/
|
||||
public function createFileMessage(array $message, array $emoticon)
|
||||
{
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -33,18 +31,21 @@ class UploadService extends BaseService
|
|||
* 上传媒体图片
|
||||
*
|
||||
* @param UploadedFile $file
|
||||
* @param string $dir
|
||||
* @param string $filename 文件夹名称
|
||||
* @param string $dir 文件夹路径
|
||||
* @param string $filename 文件名称
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
public function media(UploadedFile $file, string $dir, string $filename)
|
||||
{
|
||||
$save_dir = $this->driver($dir);
|
||||
|
||||
$this->makeDirectory($save_dir);
|
||||
|
||||
$file->moveTo(sprintf('%s/%s', $save_dir, $filename));
|
||||
|
||||
if ($file->isMoved()) {
|
||||
// 修改文集权限
|
||||
// 修改文件权限
|
||||
@chmod(sprintf('%s/%s', $save_dir, $filename), 0644);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,15 +23,14 @@ class SocketIOParser extends Packet
|
|||
|
||||
/**
|
||||
* Decode message from websocket client.
|
||||
* Define and return payload here.
|
||||
*
|
||||
* @param \Swoole\Websocket\Frame $frame
|
||||
* @param string $string
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function decode($frame)
|
||||
public static function decode($string)
|
||||
{
|
||||
$payload = Packet::getPayload($frame->data);
|
||||
$payload = Packet::getPayload($string);
|
||||
|
||||
return [
|
||||
'event' => $payload['event'] ?? null,
|
||||
|
|
|
@ -10,6 +10,7 @@ date_default_timezone_set('Asia/Shanghai');
|
|||
! defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
|
||||
! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
|
||||
|
||||
define('SWOOLE_SSL', 512);
|
||||
require BASE_PATH . '/vendor/autoload.php';
|
||||
|
||||
// 设置服务运行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