翻译域名代理
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
namespace app\process;
|
||||
|
||||
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.example.cn' => 'ntrans.xfyun.cn',
|
||||
];
|
||||
$host = $request->host(true);
|
||||
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();
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -53,7 +53,8 @@ class Xunfei
|
||||
//在控制台-我的应用-机器翻译获取
|
||||
$api_key = "b6d805f240176ecaea85130cb5f2bca1";
|
||||
// 机器翻译接口地址
|
||||
$url = "https://ntrans.xfyun.cn/v2/ots";
|
||||
// $url = "https://ntrans.xfyun.cn/v2/ots";
|
||||
$url = "https://ntrans.example.cn";
|
||||
//body组装
|
||||
// $text = "中华人民共和国于1949年成立";//待翻译文本
|
||||
$body = json_encode($this->getBody($app_id, $from, $to, $text));
|
||||
|
||||
+11
-4
@@ -60,9 +60,16 @@ return [
|
||||
]
|
||||
],
|
||||
// 船舶信息更新定时任务
|
||||
'ship-update-scheduler' => [
|
||||
'handler' => app\process\ShipUpdateScheduler::class,
|
||||
// 'ship-update-scheduler' => [
|
||||
// 'handler' => app\process\ShipUpdateScheduler::class,
|
||||
// 'reloadable' => false,
|
||||
// 'constructor' => []
|
||||
// ],
|
||||
// http代理配置
|
||||
'proxy' => [
|
||||
'handler' => app\process\Proxy::class,
|
||||
'listen' => 'http://0.0.0.0:25519',
|
||||
'count' => 1,
|
||||
'reloadable' => false,
|
||||
'constructor' => []
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user