Files
car_info/app/process/Proxy.php
T
2025-06-25 10:10:27 +08:00

35 lines
1.0 KiB
PHP

<?php
namespace app\process;
use support\Log;
use Workerman\Connection\AsyncTcpConnection;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
class Proxy
{
public function onMessage(TcpConnection $connection, Request $request)
{
$replace = [
// 'api.example.com' => 'api.openai.com',
'ntrans.xample.cn' => 'ntrans.xfyun.cn',
];
$host = $request->host(true);
log::info('$host:'.$host);
if (!isset($replace[$host])) {
return $connection->send(response('404 not found', 404));
}
$host = $replace[$host];
$buffer = (string)$request;
$con = new AsyncTcpConnection("tcp://$host:443", ['ssl' =>[
'verify_peer' => false
]]);
$buffer = preg_replace("/Host: ?(.*?)\r\n/", "Host: $host\r\n", $buffer);
$con->transport = 'ssl';
$connection->protocol = null;
$con->send($buffer);
$con->pipe($connection);
$connection->pipe($con);
$con->connect();
}
}