xunfei-wss/app/controller/IndexController.php

93 lines
3.4 KiB
PHP
Raw Normal View History

2023-09-12 20:37:00 +08:00
<?php
namespace app\controller;
2023-10-13 18:47:46 +08:00
use app\extend\IFlytek\Xfyun\Speech\TtsClient;
2023-09-12 20:37:00 +08:00
use support\Request;
2023-09-16 18:17:16 +08:00
use Webman\Container;
2023-10-11 16:17:37 +08:00
use Webman\Push\Api;
2023-09-12 20:37:00 +08:00
class IndexController
{
2023-10-13 18:47:46 +08:00
private $app_id = '2eda6c2e';
private $api_key = '12ec1f9d113932575fc4b114a2f60ffd';
private $api_secret = 'MDEyMzE5YTc5YmQ5NjMwOTU1MWY4N2Y2';
private $ttsConfig = [
'aue' => 'lame',
'sfl' => 1,
'vcn' => 'x4_lingxiaoyao_en'
];
2023-09-12 20:37:00 +08:00
public function index(Request $request)
{
2023-10-11 16:17:37 +08:00
return json(['code' => 0, 'msg' => 'ok']);
2023-09-12 20:37:00 +08:00
}
public function view(Request $request)
{
return view('index/view', ['name' => 'webman']);
}
2023-10-18 18:33:35 +08:00
public function demo1(Request $request)
2023-09-12 20:37:00 +08:00
{
2023-10-18 18:33:35 +08:00
$data=[
2023-10-18 18:40:14 +08:00
['type'=>1,'uri'=>'https://goview.lihaink.cn/#/chart/preview/118','image'=>'https://worker-task.lihaink.cn/uploads/images/20231017/20231017173032d02895995.jpg'],
['type'=>1,'uri'=>'https://goview.lihaink.cn/#/chart/preview/115','image'=>'https://worker-task.lihaink.cn/uploads/images/20231017/20231017173052de7b64557.jpg'],
['type'=>1,'uri'=>'https://www.baidu.com','image'=>'https://worker-task.lihaink.cn/uploads/images/20231017/20231017173108d32b37266.jpg'],
['type'=>2,'uri'=>'https://worker-task.lihaink.cn/uploads/video/20231018/202310181533500589b3255.mp4','image'=>'https://worker-task.lihaink.cn/uploads/images/20231017/20231017173128418571732.jpg'],
2023-10-18 18:33:35 +08:00
];
return json(['code' => 0, 'msg' => 'ok','data'=>$data]);
2023-09-12 20:37:00 +08:00
}
2023-10-11 16:17:37 +08:00
public function push(Request $request){
$parmas=$request->get('name');
$api = new Api(
// webman下可以直接使用config获取配置非webman环境需要手动写入相应配置
'http://127.0.0.1:3232',
config('plugin.webman.push.app.app_key'),
config('plugin.webman.push.app.app_secret')
);
// 给订阅 user-1 的所有客户端推送 message 事件的消息
$api->trigger('user-1', 'message', [
'from_uid' => 1,
'content' => $parmas
]);
return json(['code' => 0, 'msg' => 'ok']);
}
2023-10-13 18:47:46 +08:00
public function tts(Request $request){
$text = $request->post('data');
2023-10-14 12:00:46 +08:00
$pattern = "/[\x{4e00}-\x{9fa5}\d]+/u";
if( preg_match($pattern, $text)){
2023-10-13 18:47:46 +08:00
$name = time() . rand(1, 100000) . '.mp3';
$tts = new TtsClient($this->app_id, $this->api_key, $this->api_secret, $this->ttsConfig);
file_put_contents(public_path('tts') . '/' . $name, $tts->request($text)->getBody()->getContents());
return json(['code' => 0, 'msg' => 'ok','data'=>['mp3'=>'https://chat.lihaink.cn/tts/' . $name]]);
}
return json(['code' => 0, 'msg' => 'ok']);
}
2024-01-04 18:59:55 +08:00
public function dataviewTouchPush(Request $request){
$parmas=$request->get();
2024-01-16 09:58:10 +08:00
$channel = $parmas['channel'];
2024-01-04 18:59:55 +08:00
$api = new Api(
// webman下可以直接使用config获取配置非webman环境需要手动写入相应配置
'http://127.0.0.1:3232',
config('plugin.webman.push.app.app_key'),
config('plugin.webman.push.app.app_secret')
);
// 给订阅 user-2 的所有客户端推送 message 事件的消息
2024-01-16 09:58:10 +08:00
$api->trigger($channel, 'message', [
'from_uid' => $channel,
2024-01-04 18:59:55 +08:00
'content' => $parmas
]);
return json(['code' => 0, 'msg' => 'ok', 'data'=>$parmas]);
}
2023-09-12 20:37:00 +08:00
}