Files
fast_response/admin/application/index/controller/Test.php
2025-03-25 15:41:52 +08:00

137 lines
3.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{2023/11/20} {10:28}
*/
namespace app\index\controller;
use app\api\logic\AudioRevertLogic;
use React\EventLoop\Factory;
use React\Socket\TcpConnector;
use React\Socket\SecureConnector;
use React\Socket\ConnectionInterface;
use wanghua\general_utility_tools_php\sms\AliSms;
/**
* @deprecated
*/
class Test extends BasePublicController
{
function test()
{
$config = config('sms_config');
$obj = new AliSms($config,$config['sms_sign_name'],$config['sms_template_code']);
//$obj->addTemplate();
//die;
$res = $obj->send('18290416033',json_encode(['code'=>1223]));
dump($res);
die;
$api_cache_arr['aaa'][] = ['api_name'=>111,'doc_txt'=>222];
$api_cache_arr['bb'][] = ['api_name'=>777,'doc_txt'=>777];
$api_cache_arr['aaa'][] = ['api_name'=>666,'doc_txt'=>666];
$api_cache_arr['ccc'][] = ['api_name'=>111,'doc_txt'=>222];
$api_cache_arr['aaa'][] = ['api_name'=>555,'doc_txt'=>555];
$api_cache_arr['ccc'][] = ['api_name'=>333,'doc_txt'=>333];
dump($api_cache_arr);die;
// 使用示例
$color = $this->stringToColor("example string");
//echo $color; // 输出颜色码
die;
$color_code = substr(md5('asdfasdf'),0,6);
echo '<div style="background-color:'.$color_code.'">test</div>';die;
// 使用示例
$color = $this->stringToColor("example string");
echo $color; // 输出颜色码
die;
// 配置您的讯飞应用信息
$appId = 'd482af59';
$apiKey = '0d20dab630904ad8676d9075375a1914';
// 创建事件循环
$loop = Factory::create();
// 创建TcpConnector它实现了ConnectorInterface
$tcpConnector = new TcpConnector($loop);
// 使用TcpConnector创建SecureConnector
$secureConnector = new SecureConnector($tcpConnector, $loop);
// 实时语音转写API地址
//ws://8.130.29.83:2700
//$url = 'ws://8.130.29.83:2700';
$url = 'wss://rtasr.xfyun.cn/v1/ws';
// 计算签名
$ts = time();
$baseString = $appId . $ts;
$md5BaseString = md5($baseString);
$signa = base64_encode(hash_hmac('sha1', $md5BaseString, $apiKey, true));
dump($signa);
$params = [
'appid' => $appId,
'ts' => $ts,
'signa' => $signa,
'lang' => 'zh-cn', // 中文普通话
];
dump($params);
$str = '';
$i = 0;
foreach ($params as $key => $value){
if($i==count($params)-1){
$str .= $key . '=' . $value ;
}else{
$str .= $key . '=' . $value . '&';
}
$i++;
}
$encodedParams = urlencode($str); // 对查询参数进行URL编码
// 构建WebSocket请求URL
$requestUrl = $url . '?' . $encodedParams;
dump($requestUrl);
// 使用SecureConnector连接到WebSocket服务器
$secureConnector->connect($requestUrl)->then(function (ConnectionInterface $conn) {
echo "Connected to the WebSocket server\n";
// ... 其他逻辑 ...
}, function ($error) {
// 连接失败处理
echo "Connection error: " . $error->getMessage() . "\n";
});
// 运行事件循环
$loop->run();
}
function callback($resource, $buffer, $length) {
global $audioQueue;
array_push($audioQueue, $buffer);
}
function testwss(){
return view();
}
function testwss2(){
return view();
}
function buildApiDoc()
{
parent::buildApiDoc();
}
public function buildTablesConf()
{
parent::buildTablesConf(); // TODO: Change the autogenerated stub
}
public function clearCache()
{
parent::clearCache(); // TODO: Change the autogenerated stub
}
}