Files
digital_doctor/digital_doctor/application/api/controller/Wsspush.php
2024-07-10 17:40:31 +08:00

81 lines
1.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*
* description
* authorwh
* email
* createTime{2024/4/5} {19:51}
*/
namespace app\api\controller;
use app\api\logic\StatisticsLogic;
use app\common\model\TabConf;
use GatewayWorker\Lib\Gateway;
use think\Db;
use wanghua\general_utility_tools_php\Date;
use wanghua\general_utility_tools_php\tool\Tools;
/**
* socket 主动推送
*
* Class Wsspush
* @package app\api\controller
*/
class Wsspush extends BaseWssApi
{
public function index()
{
$socketTaskId = input('socketTaskId');
Gateway::sendToClient($socketTaskId,json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE));
}
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
/**
* desc向客户端推送消息
*
* 接收一维数组表单
*
* /api/wsspush/pushMessageToClient
*
* authorwh
*/
function pushMessageToClient(){
$socketTaskId = input('clientid');
if(empty($socketTaskId)){
return json(Tools::set_fail('客户端id必须'));
}
$action = input('action');
if(empty($action)){
return json(Tools::set_fail('ACTION MUST'));
}
$msg = input('msg');
if(empty($msg)){
return json(Tools::set_fail('MSG MUST'));
}
$all_params = [];
foreach (input() as $key=>$item){
if(in_array($key, ['clientid','action','msg'])){
continue;
}
$all_params[$key] = $item;
}
//json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE);
$json = self::json_wss($action,$msg,$all_params);
Gateway::sendToClient($socketTaskId, $json);
return json(Tools::set_ok('向指定客户端发送信息成功。'));
}
}