正在显示
5 个修改的文件
包含
42 行增加
和
34 行删除
| @@ -8,30 +8,44 @@ | @@ -8,30 +8,44 @@ | ||
| 8 | */ | 8 | */ |
| 9 | 9 | ||
| 10 | namespace App\Helper; | 10 | namespace App\Helper; |
| 11 | - | 11 | +require __DIR__ . '/vendor/autoload.php'; |
| 12 | +use WebSocket\Client; | ||
| 12 | class Socket | 13 | class Socket |
| 13 | { | 14 | { |
| 14 | - public function socket($data){ | ||
| 15 | - // Socket 服务器的 IP 和端口 | ||
| 16 | - $socketServerIp = '127.0.0.1'; | ||
| 17 | - $socketServerPort = 9555; // 替换为实际端口 | ||
| 18 | - // 创建一个 TCP Socket 客户端 | ||
| 19 | - $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | ||
| 20 | - if ($socket === false) { | ||
| 21 | - return response()->json(['error' => 'Socket creation failed']); | ||
| 22 | - } | ||
| 23 | - // 连接到 Socket 服务器 | ||
| 24 | - $result = socket_connect($socket, $socketServerIp, $socketServerPort); | ||
| 25 | - if ($result === false) { | ||
| 26 | - return response()->json(['error' => 'Socket connection failed']); | ||
| 27 | - } | ||
| 28 | - $data = 'hello'; | ||
| 29 | - // 发送数据到 Socket 服务器 | ||
| 30 | - socket_write($socket, $data, strlen($data)); | ||
| 31 | - // 从服务器接收数据 | ||
| 32 | - $response = socket_read($socket, 1024); | ||
| 33 | - // 关闭 Socket 连接 | ||
| 34 | - socket_close($socket); | ||
| 35 | - return response()->json(['response' => $response]); | 15 | + private $client; |
| 16 | + | ||
| 17 | + public $serverIp = '127.0.0.1'; | ||
| 18 | + | ||
| 19 | + public $serverPort = '9555'; | ||
| 20 | + | ||
| 21 | + public function __construct() { | ||
| 22 | + $socketUrl = "ws://{$this->serverIp}:{$this->serverPort}"; | ||
| 23 | + $this->client = new Client($socketUrl); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * @remark :发送消息 | ||
| 28 | + * @name :send | ||
| 29 | + * @author :lyh | ||
| 30 | + * @method :post | ||
| 31 | + * @time :2023/8/31 10:18 | ||
| 32 | + */ | ||
| 33 | + public function send($data) { | ||
| 34 | + $this->client->send($data); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public function receive() { | ||
| 38 | + return $this->client->receive(); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + /** | ||
| 42 | + * @remark :关闭连接 | ||
| 43 | + * @name :close | ||
| 44 | + * @author :lyh | ||
| 45 | + * @method :post | ||
| 46 | + * @time :2023/8/31 10:21 | ||
| 47 | + */ | ||
| 48 | + public function close() { | ||
| 49 | + $this->client->close(); | ||
| 36 | } | 50 | } |
| 37 | } | 51 | } |
| @@ -35,12 +35,11 @@ class DomainInfoLogic extends BaseLogic | @@ -35,12 +35,11 @@ class DomainInfoLogic extends BaseLogic | ||
| 35 | if(isset($this->param['id']) && !empty($this->param['id'])){ | 35 | if(isset($this->param['id']) && !empty($this->param['id'])){ |
| 36 | $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); | 36 | $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); |
| 37 | }else{ | 37 | }else{ |
| 38 | - $data = $this->getDomainInfo($this->param['domain']); | ||
| 39 | - if(!empty($data['domain_start_time']) && !empty($data['domain_end_time'])){ | ||
| 40 | - $this->param['domain_start_time'] = $data['domain_start_time']; | ||
| 41 | - $this->param['domain_end_time'] = $data['domain_end_time']; | ||
| 42 | - } | ||
| 43 | - | 38 | +// $data = $this->getDomainInfo($this->param['domain']); |
| 39 | +// if(!empty($data['domain_start_time']) && !empty($data['domain_end_time'])){ | ||
| 40 | +// $this->param['domain_start_time'] = $data['domain_start_time']; | ||
| 41 | +// $this->param['domain_end_time'] = $data['domain_end_time']; | ||
| 42 | +// } | ||
| 44 | $rs = $this->model->add($this->param); | 43 | $rs = $this->model->add($this->param); |
| 45 | } | 44 | } |
| 46 | if($rs === false){ | 45 | if($rs === false){ |
| @@ -112,7 +112,6 @@ class MailLogic extends BaseLogic | @@ -112,7 +112,6 @@ class MailLogic extends BaseLogic | ||
| 112 | * @time :2023/7/8 9:27 | 112 | * @time :2023/7/8 9:27 |
| 113 | */ | 113 | */ |
| 114 | public function mail_del(){ | 114 | public function mail_del(){ |
| 115 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($this->param, true) . PHP_EOL, FILE_APPEND); | ||
| 116 | DB::beginTransaction(); | 115 | DB::beginTransaction(); |
| 117 | try { | 116 | try { |
| 118 | $this->model->del(['id'=>['in',$this->param['id']]]); | 117 | $this->model->del(['id'=>['in',$this->param['id']]]); |
| @@ -188,7 +188,6 @@ class InquiryInfoLogic extends BaseLogic | @@ -188,7 +188,6 @@ class InquiryInfoLogic extends BaseLogic | ||
| 188 | 'CLIENT-IP: '.$post_data['ip'], | 188 | 'CLIENT-IP: '.$post_data['ip'], |
| 189 | 'X-FORWARDED-FOR: '.$post_data['ip'] | 189 | 'X-FORWARDED-FOR: '.$post_data['ip'] |
| 190 | ); | 190 | ); |
| 191 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export(json_encode($post_data_new).'debug', true) . PHP_EOL, FILE_APPEND); | ||
| 192 | return http_post($url,$post_data_new,$header); | 191 | return http_post($url,$post_data_new,$header); |
| 193 | } | 192 | } |
| 194 | 193 |
| @@ -23,13 +23,11 @@ $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); | @@ -23,13 +23,11 @@ $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); | ||
| 23 | $server = new Server("0.0.0.0", 9555); | 23 | $server = new Server("0.0.0.0", 9555); |
| 24 | 24 | ||
| 25 | $server->on('open', function ($server, $request) { | 25 | $server->on('open', function ($server, $request) { |
| 26 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export('连接已打开', true) . PHP_EOL, FILE_APPEND); | ||
| 27 | // WebSocket 连接已打开 | 26 | // WebSocket 连接已打开 |
| 28 | echo "WebSocket 连接已打开\n"; | 27 | echo "WebSocket 连接已打开\n"; |
| 29 | }); | 28 | }); |
| 30 | 29 | ||
| 31 | $server->on('message', function ($server, $frame) { | 30 | $server->on('message', function ($server, $frame) { |
| 32 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export('收到消息', true) . PHP_EOL, FILE_APPEND); | ||
| 33 | $message = $frame->data; | 31 | $message = $frame->data; |
| 34 | echo "收到消息: $message\n"; | 32 | echo "收到消息: $message\n"; |
| 35 | // 获取客户端连接的文件描述符 | 33 | // 获取客户端连接的文件描述符 |
| @@ -49,7 +47,6 @@ $server->on('message', function ($server, $frame) { | @@ -49,7 +47,6 @@ $server->on('message', function ($server, $frame) { | ||
| 49 | }); | 47 | }); |
| 50 | 48 | ||
| 51 | $server->on('close', function ($server, $fd) { | 49 | $server->on('close', function ($server, $fd) { |
| 52 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export('关闭连接', true) . PHP_EOL, FILE_APPEND); | ||
| 53 | // WebSocket 连接已关闭 | 50 | // WebSocket 连接已关闭 |
| 54 | echo "WebSocket 连接已关闭\n"; | 51 | echo "WebSocket 连接已关闭\n"; |
| 55 | }); | 52 | }); |
-
请 注册 或 登录 后发表评论