fixed
This commit is contained in:
94
front/application/index/controller/BaseAuthController.php
Normal file
94
front/application/index/controller/BaseAuthController.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2022/5/4} {9:12}
|
||||
*/
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
|
||||
|
||||
use app\index\model\WechatUserModel;
|
||||
use think\Request;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class BaseAuthController extends BaseCommonController
|
||||
{
|
||||
|
||||
public function __construct(Request $request = null)
|
||||
{
|
||||
parent::__construct($request);
|
||||
|
||||
|
||||
//首页提示语
|
||||
$this->assign('index_msg',cache('index_msg_alert_cache_time'));
|
||||
|
||||
//线上环境加载微信授权
|
||||
if(config('sys_env') == 'PROD'){
|
||||
$wx_user_info = session('wx_user_info');
|
||||
if(empty($wx_user_info['openid'])) {
|
||||
//重定向之前,保存当前url, 在获取授权信息之后,回跳到授权之前的网页地址
|
||||
session('redirect_before_url_session',request()->url(true));
|
||||
//没有则重定向去授权
|
||||
return $this->redirect(url('Wexinauth/usrAuth','',301,true));
|
||||
}
|
||||
|
||||
$this->saveWechatUser($wx_user_info);
|
||||
}
|
||||
|
||||
|
||||
//校验系统维护状态 start
|
||||
$chm = $this->checkMaintain();
|
||||
if($chm['is_maintain']){
|
||||
if($chm['openid']){
|
||||
//解析openid
|
||||
if(!in_array(index_user_openid(), explode(',',$chm['openid']))){
|
||||
//白名单之外维护中
|
||||
//Tools::log_to_write_txt([
|
||||
// '维护测试'=>$chm['openid'],
|
||||
// 'my'=>index_user_openid()
|
||||
//]);
|
||||
return $this->error($chm['msg']);
|
||||
}
|
||||
}else{
|
||||
//不存在,直接维护中
|
||||
return $this->error($chm['msg'].'!');
|
||||
}
|
||||
}
|
||||
//校验系统维护状态 end
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
* @param $wx_user_info
|
||||
*/
|
||||
private function saveWechatUser($wx_user_info){
|
||||
try {
|
||||
$wechat_user = WechatUserModel::getWxUserByOpenid($wx_user_info['openid']);
|
||||
if(empty($wechat_user)){
|
||||
return WechatUserModel::insertInfo($wx_user_info);
|
||||
}
|
||||
//扩展,按周期更新,而不是不更新
|
||||
if(empty($wechat_user['update_time']) || time()-strtotime($wechat_user['update_time'])>5*3600){
|
||||
|
||||
return WechatUserModel::updateUser($wx_user_info);
|
||||
}
|
||||
|
||||
|
||||
}catch (\Exception $e){
|
||||
Tools::log_to_write_txt([
|
||||
'error'=>'存储异常.'.$e->getMessage(),
|
||||
'wx_user_info'=>$wx_user_info,
|
||||
'error_info'=>$e->getTraceAsString()
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
29
front/application/index/controller/BaseCommonController.php
Normal file
29
front/application/index/controller/BaseCommonController.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2023/1/21} {16:22}
|
||||
*/
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
|
||||
use app\apidata\Config;
|
||||
use app\common\model\TabConf;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use think\Request;
|
||||
use wanghua\general_utility_tools_php\framework\BaseController;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class BaseCommonController extends BaseController
|
||||
{
|
||||
function __construct(Request $request = null)
|
||||
{
|
||||
parent::__construct($request);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
47
front/application/index/controller/BasePublicController.php
Normal file
47
front/application/index/controller/BasePublicController.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2022/5/4} {9:39}
|
||||
*/
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
|
||||
use think\Request;
|
||||
use wanghua\general_utility_tools_php\framework\base\PublicController;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class BasePublicController extends BaseCommonController
|
||||
{
|
||||
|
||||
public function __construct(Request $request = null)
|
||||
{
|
||||
parent::__construct($request);
|
||||
|
||||
|
||||
|
||||
|
||||
//校验系统维护状态 start
|
||||
$chm = $this->checkMaintain();
|
||||
if($chm['is_maintain']){
|
||||
if($chm['openid']){
|
||||
//解析openid
|
||||
if(!in_array(index_user_openid(), explode(',',$chm['openid']))){
|
||||
//白名单之外维护中
|
||||
//Tools::log_to_write_txt([
|
||||
// '维护测试'=>$chm['openid'],
|
||||
// 'my'=>index_user_openid()
|
||||
//]);
|
||||
return $this->error($chm['msg']);
|
||||
}
|
||||
}else{
|
||||
//不存在,直接维护中
|
||||
return $this->error($chm['msg'].'!');
|
||||
}
|
||||
}
|
||||
//校验系统维护状态 end
|
||||
|
||||
}
|
||||
}
|
||||
17
front/application/index/controller/Index.php
Normal file
17
front/application/index/controller/Index.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace app\index\controller;
|
||||
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Controller;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
use Workerman\Worker;
|
||||
|
||||
class Index extends Controller
|
||||
{
|
||||
|
||||
function index()
|
||||
{
|
||||
return $this->redirect(request()->domain().'/ai');
|
||||
}
|
||||
}
|
||||
63
front/application/index/controller/Login.php
Normal file
63
front/application/index/controller/Login.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2023/11/19} {22:32}
|
||||
*/
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
|
||||
use think\Controller;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
use wanghua\general_utility_tools_php\wechat\TmpWexinauth;
|
||||
use wanghua\general_utility_tools_php\wechat\UserAuth;
|
||||
use wanghua\general_utility_tools_php\wechat\WechatLogic;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class Login extends Controller
|
||||
{
|
||||
|
||||
function login()
|
||||
{
|
||||
$username = input('username');
|
||||
$password = input('password');
|
||||
|
||||
|
||||
return json(Tools::set_res(200,'ok',['username'=>$username]));
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:微信授权
|
||||
* author:wh
|
||||
*/
|
||||
function wxauth()
|
||||
{
|
||||
try {
|
||||
$code = input('code');
|
||||
if(empty($code)){
|
||||
return Tools::set_fail('CODE参数错误');
|
||||
}
|
||||
$wxconfig = get_boom_union_wechat_config();
|
||||
|
||||
$res = (new UserAuth($wxconfig,$wxconfig['access_token_path']))->usrAccessTokenApplet($code);
|
||||
|
||||
//绑定客户端ID和用户openid
|
||||
|
||||
|
||||
return json(Tools::set_ok('ok',$res));
|
||||
}catch (\Exception $e){
|
||||
Tools::log_to_write_text([
|
||||
'error'=>'微信授权异常。'.$e->getMessage(),
|
||||
'input'=>input(),
|
||||
'error_info'=>$e->getTraceAsString()
|
||||
]);
|
||||
|
||||
return json(Tools::set_fail('请求异常'));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
137
front/application/index/controller/Test.php
Normal file
137
front/application/index/controller/Test.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user