chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: ywxapp<admin@ywxapp.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace addon\wxchat\worker;
|
||||
|
||||
use addon\wxchat\worker\Message;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use addon\wxchat\worker\enum\MsgFrame;
|
||||
use addon\wxchat\worker\enum\MsgType;
|
||||
|
||||
/**
|
||||
* 统一的消息下发工具
|
||||
*/
|
||||
class MsgReply
|
||||
{
|
||||
/**
|
||||
* 发送错误消息给指定客户端
|
||||
*/
|
||||
public static function sendError($client_id, $payload)
|
||||
{
|
||||
$message = new Message();
|
||||
$message->header->frame = MsgFrame::ERROR->value;
|
||||
$message->header->type = MsgType::ERROR->value;
|
||||
$message->payload->content = $payload;
|
||||
Gateway::sendToClient($client_id, json_encode($message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条通用消息给指定客户端
|
||||
* @param string $frame 帧类型(MsgFrame 值)
|
||||
* @param string $type 消息类型(MsgType 值)
|
||||
*/
|
||||
public static function send($client_id, $frame, $type, $content, $extra = [])
|
||||
{
|
||||
$message = new Message();
|
||||
$message->header->frame = $frame;
|
||||
$message->header->type = $type;
|
||||
$message->payload->content = $content;
|
||||
foreach ($extra as $k => $v) {
|
||||
$message->payload->$k = $v;
|
||||
}
|
||||
Gateway::sendToClient($client_id, json_encode($message));
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送给某用户(若在线)
|
||||
*/
|
||||
public static function sendToUid($uid, $frame, $type, $content, $extra = [])
|
||||
{
|
||||
if (! Gateway::isUidOnline($uid)) {
|
||||
return false;
|
||||
}
|
||||
$message = new Message();
|
||||
$message->header->frame = $frame;
|
||||
$message->header->type = $type;
|
||||
$message->payload->content = $content;
|
||||
foreach ($extra as $k => $v) {
|
||||
$message->payload->$k = $v;
|
||||
}
|
||||
Gateway::sendToUid($uid, json_encode($message));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user