This commit is contained in:
2025-03-17 11:27:07 +08:00
parent 7a7f432006
commit 5febeca83f
6805 changed files with 6 additions and 6 deletions

View File

@@ -0,0 +1,72 @@
<?php
/*
* description
* authorwh
* email
* createTime{2023/1/21} {16:22}
*/
namespace app\api\controller;
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()
{
parent::__construct();
}
/**
* desc检查路径维护状态
*
* “===”完全匹配不能使用like
*
* authorwh
*/
protected function checkMaintain(){
$configs = Db::table(TabConf::$fa_sys_maintain_config)
->where('status','1')
->cache()
->select();
//模块
$strmodule = request()->module();
foreach ($configs as $config){
if($strmodule == $config['url']){
//模块维护中
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
}
}
//模块/控制器
$strcontroller = strtolower(request()->module().'/'.request()->controller());
foreach ($configs as $config){
if($strcontroller == $config['url']){
//模块维护中
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
}
}
//模块/控制器/方法
$straction = strtolower(request()->module().'/'.request()->controller().'/'.request()->action());
foreach ($configs as $config){
if($straction == $config['url']){
//模块维护中
return ['is_maintain'=>true,'msg'=>$config['msg'],'openid'=>$config['openid']];
}
}
//未维护
return ['is_maintain'=>false,'msg'=>'服务运行中'];
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/4/22} {11:52}
*/
namespace app\api\controller;
use app\index\controller\BaseCommonController;
use think\App;
use think\Controller;
use think\Exception;
use wanghua\general_utility_tools_php\tool\Ip;
class BaseHttpApi extends BaseCommonController
{
/**
http请求专用
*/
public function __construct()
{
parent::__construct();
//ip校验
//$ip = request()->ip();
//$res = Ip::ip_is_china($ip,false);
//if(!$res){
// throw new Exception('ip不合法');
//}
}
}

View File

@@ -0,0 +1,34 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/4/5} {19:55}
*/
namespace app\api\controller;
class BaseWssApi extends BaseCommonController
{
/**
* descsocket专用json格式
*
* authorwh
* @param $action
* @param string $msg
* @param array $items
* @param string $method
* @return false|string
*/
static function json_wss($action,$msg='', $items=[], $method='response'){
$json = [
'action'=>$action,
'method'=>$method,
'msg'=>$msg,
'items'=>$items
];
return json_encode($json, JSON_UNESCAPED_UNICODE);
}
}

View File

@@ -0,0 +1,49 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/8/13} {17:27}
*/
namespace app\api\controller;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\tool\Tools;
class Common extends BaseHttpApi
{
/**
* desc唯一id
* 参数:无
*
* api/Common/getUniqueId
*
* authorwh
*/
function getUniqueId(){
return Mmodel::catchJson(function (){
$uniqueid = md5(Tools::getMillisecond());
return Tools::set_ok('ok',['uniqueid'=>$uniqueid]);
});
}
/**
* desc获取对话token在听译对话开始之前调用用于隔离聊天记录
* 参数:无
*
* api/Common/getSayToken
*
* authorwh
*/
function getSayToken(){
return Mmodel::catchJson(function (){
$uniqueid = md5(Tools::getMillisecond());
return Tools::set_ok('ok',['uniqueid'=>$uniqueid]);
});
}
}

View File

@@ -0,0 +1,80 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/8/13} {11:22}
*/
namespace app\api\controller;
use app\common\model\TabConf;
use think\Db;
use wanghua\general_utility_tools_php\Mmodel;
use wanghua\general_utility_tools_php\sms\AliSms;
use wanghua\general_utility_tools_php\tool\Tools;
use wanghua\general_utility_tools_php\Validate;
class Sms extends BaseHttpApi
{
/**
* desc发送短信验证码
* 参数:
* mobile 手机号
* event 发送场景
*
* api/sms/send
* authorwh
*/
function send(){
return Mmodel::catchJson(function (){
$mobile = input('mobile');
if(empty($mobile)){
return Tools::set_fail('手机号错误');
}
if(!Validate::is_mobile($mobile)){
return Tools::set_fail('手机号错误');
}
//发送间隔不能低于60秒
$sms_record = Db::table(TabConf::$fa_sms)
->where('create_time','>',date('Y-m-d H:i:s',time()-60))
->where('mobile',$mobile)
->order('id desc')
->find();
if($sms_record){
return Tools::set_fail('发送太频繁,请稍后再试');
}
//查询记录10分钟内超过10次禁止发送
$count = Db::table(TabConf::$fa_sms)
->where('create_time','>',date('Y-m-d H:i:s',time()-600))
->where('mobile',$mobile)
->count();
if($count>=10){
return Tools::set_fail('发送次数过多,请稍后再试');
}
$config = config('sms_config');
$code = Tools::rand_str(6,3);
Tools::log_to_write_txt(['发送短信,开始','mobile'=>$mobile,'code'=>$code,'$config'=>$config]);
$res = (new AliSms($config,$config['sms_sign_name'],$config['sms_template_code']))
->send($mobile,json_encode(['code'=>$code]));
Tools::log_to_write_txt(['发送短信,结束',$res]);
//写入发送记录
$sms_data = [
'event'=>input('event'),
'mobile'=>$mobile,
'code'=>$code,
'times'=>0,
'ip'=>request()->ip(),
];
Db::table(TabConf::$fa_sms)->insert($sms_data);
return Tools::set_ok('操作成功',$res);
});
}
}

View File

@@ -0,0 +1,98 @@
<?php
/*
* description
* authorwh
* email
* createTime{2024/4/5} {19:51}
*/
namespace app\api\controller;
use app\api\logic\StatisticsLogic;
use app\common\model\TabConf;
use GatewayWorker\Lib\Gateway;
use think\Db;
use wanghua\general_utility_tools_php\Date;
use wanghua\general_utility_tools_php\tool\Tools;
/**
* socket 主动推送
*
* Class Wsspush
* @package app\api\controller
*/
class Wsspush extends BaseWssApi
{
/**
* desc向指定客户端发送信息
*
* api/wsspush/index/socketTaskId/xxxx
*
* authorwh
*/
public function index()
{
$socketTaskId = input('socketTaskId');
Gateway::sendToClient($socketTaskId,json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE));
}
/**
* desc向所有客户端发消息
* api/wsspush/pushToAll
* authorwh
* @throws \Exception
*/
function pushToAll(){
//$json = Tools::wss_json_ok('Reportty/createReport','ok',['flow_code'=>'create_report_end']);
//Gateway::sendToAll($json);
}
public function hello($name = 'ThinkPHP5')
{
return 'hello,' . $name;
}
/**
* desc向客户端推送消息
*
* 接收一维数组表单
*
* /api/wsspush/pushMessageToClient
*
* authorwh
*/
function pushMessageToClient(){
$socketTaskId = input('clientid');
if(empty($socketTaskId)){
return json(Tools::set_fail('客户端id必须'));
}
$action = input('action');
if(empty($action)){
return json(Tools::set_fail('ACTION MUST'));
}
$msg = input('msg');
if(empty($msg)){
return json(Tools::set_fail('MSG MUST'));
}
$all_params = [];
foreach (input() as $key=>$item){
if(in_array($key, ['clientid','action','msg'])){
continue;
}
$all_params[$key] = $item;
}
//json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE);
$json = self::json_wss($action,$msg,$all_params);
Gateway::sendToClient($socketTaskId, $json);
return json(Tools::set_ok('向指定客户端发送信息成功。'));
}
}