fixed
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
namespace app\index\controller;
|
namespace app\index\controller;
|
||||||
|
|
||||||
|
|
||||||
|
use app\api\logic\AudioRevertLogic;
|
||||||
use React\EventLoop\Factory;
|
use React\EventLoop\Factory;
|
||||||
use React\Socket\TcpConnector;
|
use React\Socket\TcpConnector;
|
||||||
use React\Socket\SecureConnector;
|
use React\Socket\SecureConnector;
|
||||||
@@ -19,6 +20,11 @@ use Evenement\EventEmitter;
|
|||||||
*/
|
*/
|
||||||
class Test extends BasePublicController
|
class Test extends BasePublicController
|
||||||
{
|
{
|
||||||
|
function test2(){
|
||||||
|
$obj = new AudioRevertLogic();
|
||||||
|
$obj->revert(1,2);
|
||||||
|
|
||||||
|
}
|
||||||
function test()
|
function test()
|
||||||
{
|
{
|
||||||
// 配置您的讯飞应用信息
|
// 配置您的讯飞应用信息
|
||||||
@@ -35,6 +41,8 @@ class Test extends BasePublicController
|
|||||||
$secureConnector = new SecureConnector($tcpConnector, $loop);
|
$secureConnector = new SecureConnector($tcpConnector, $loop);
|
||||||
|
|
||||||
// 实时语音转写API地址
|
// 实时语音转写API地址
|
||||||
|
//ws://8.130.29.83:2700
|
||||||
|
//$url = 'ws://8.130.29.83:2700';
|
||||||
$url = 'wss://rtasr.xfyun.cn/v1/ws';
|
$url = 'wss://rtasr.xfyun.cn/v1/ws';
|
||||||
|
|
||||||
// 计算签名
|
// 计算签名
|
||||||
|
|||||||
@@ -27,7 +27,10 @@
|
|||||||
"iflytekop/xfyun-sdk": "^2.0",
|
"iflytekop/xfyun-sdk": "^2.0",
|
||||||
"react/socket": "^1.15",
|
"react/socket": "^1.15",
|
||||||
"evenement/evenement": "^3.0",
|
"evenement/evenement": "^3.0",
|
||||||
"cboden/ratchet": "^0.4.4"
|
"cboden/ratchet": "^0.4.4",
|
||||||
|
"react/event-loop": "^1.5",
|
||||||
|
"react/http": "^1.10",
|
||||||
|
"react/promise": "^3.2"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require __DIR__ . '/vendor/autoload.php';
|
||||||
|
|
||||||
|
use React\EventLoop\Factory;
|
||||||
|
use React\Socket\Connector;
|
||||||
|
use React\Socket\ConnectionInterface;
|
||||||
|
use React\Promise\PromiseInterface;
|
||||||
|
use React\Stream\DuplexResourceStream;
|
||||||
|
use React\Stream\ThroughStream;
|
||||||
|
|
||||||
|
$loop = Factory::create(); // 创建事件循环
|
||||||
|
|
||||||
|
$socketConnector = new Connector($loop);
|
||||||
|
|
||||||
|
// 定义一个函数来处理WebSocket连接
|
||||||
|
function connectToWebSocket($url, LoopInterface $loop): PromiseInterface {
|
||||||
|
$parts = parse_url($url);
|
||||||
|
$host = $parts['host'];
|
||||||
|
$port = isset($parts['port']) ? $parts['port'] : ($parts['scheme'] === 'wss' ? 443 : 80);
|
||||||
|
$resource = $parts['path'] . (isset($parts['query']) ? '?' . $parts['query'] : '');
|
||||||
|
|
||||||
|
$headers = [
|
||||||
|
'Host' => $host,
|
||||||
|
'Upgrade' => 'websocket',
|
||||||
|
'Connection' => 'Upgrade',
|
||||||
|
'Sec-WebSocket-Key' => base64_encode(random_bytes(16)),
|
||||||
|
'Sec-WebSocket-Version' => 13,
|
||||||
|
];
|
||||||
|
|
||||||
|
$handshake = "GET $resource HTTP/1.1\r\n";
|
||||||
|
foreach ($headers as $name => $value) {
|
||||||
|
$handshake .= "$name: $value\r\n";
|
||||||
|
}
|
||||||
|
$handshake .= "\r\n";
|
||||||
|
|
||||||
|
return $socketConnector->connect("$host:$port", $loop)
|
||||||
|
->then(function (ConnectionInterface $conn) use ($handshake, $loop) {
|
||||||
|
$conn->write($handshake);
|
||||||
|
|
||||||
|
$response = new ThroughStream();
|
||||||
|
$response->on('data', function ($chunk) use (&$response, $conn) {
|
||||||
|
if (strpos($chunk, "\r\n\r\n") !== false) {
|
||||||
|
$response->emit('end');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$conn->pipe($response);
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
})
|
||||||
|
->then(function (ThroughStream $response) use ($loop) {
|
||||||
|
$response->on('end', function () use ($loop) {
|
||||||
|
$loop->nextTick(function () use ($conn) {
|
||||||
|
$conn->resume();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return $conn;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 连接到WebSocket服务器
|
||||||
|
connectToWebSocket('ws://8.130.29.83:2700', $loop)
|
||||||
|
->then(function ($conn) {
|
||||||
|
$conn->on('data', function ($data) {
|
||||||
|
echo "Received: $data\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
$conn->write("Hello Server!\n"); // 发送一条消息
|
||||||
|
})
|
||||||
|
->otherwise(function ($error) {
|
||||||
|
echo "Error: " . $error->getMessage() . "\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
$loop->run(); // 开始事件循环
|
||||||
|
|||||||
Reference in New Issue
Block a user