fixed
This commit is contained in:
1
front/application/.htaccess
Normal file
1
front/application/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
deny from all
|
||||
72
front/application/api/controller/BaseCommonController.php
Normal file
72
front/application/api/controller/BaseCommonController.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* 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
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
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'=>'服务运行中'];
|
||||
}
|
||||
}
|
||||
34
front/application/api/controller/BaseHttpApi.php
Normal file
34
front/application/api/controller/BaseHttpApi.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* 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不合法');
|
||||
//}
|
||||
}
|
||||
}
|
||||
34
front/application/api/controller/BaseWssApi.php
Normal file
34
front/application/api/controller/BaseWssApi.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/4/5} {19:55}
|
||||
*/
|
||||
|
||||
namespace app\api\controller;
|
||||
|
||||
|
||||
class BaseWssApi extends BaseCommonController
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:socket专用json格式
|
||||
*
|
||||
* author:wh
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
49
front/application/api/controller/Common.php
Normal file
49
front/application/api/controller/Common.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* 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
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function getUniqueId(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$uniqueid = md5(Tools::getMillisecond());
|
||||
return Tools::set_ok('ok',['uniqueid'=>$uniqueid]);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* desc:获取对话token,在听译对话开始之前调用,用于隔离聊天记录
|
||||
* 参数:无
|
||||
*
|
||||
* api/Common/getSayToken
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
function getSayToken(){
|
||||
return Mmodel::catchJson(function (){
|
||||
$uniqueid = md5(Tools::getMillisecond());
|
||||
return Tools::set_ok('ok',['uniqueid'=>$uniqueid]);
|
||||
});
|
||||
}
|
||||
}
|
||||
80
front/application/api/controller/Sms.php
Normal file
80
front/application/api/controller/Sms.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* 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
|
||||
* author:wh
|
||||
*/
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
98
front/application/api/controller/Wsspush.php
Normal file
98
front/application/api/controller/Wsspush.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* 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
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
||||
$socketTaskId = input('socketTaskId');
|
||||
Gateway::sendToClient($socketTaskId,json_encode(Tools::set_ok('向指定客户端发送信息。',$socketTaskId),JSON_UNESCAPED_UNICODE));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:向所有客户端发消息
|
||||
* api/wsspush/pushToAll
|
||||
* author:wh
|
||||
* @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
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
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('向指定客户端发送信息成功。'));
|
||||
}
|
||||
}
|
||||
103
front/application/api/logic/BaseLogic.php
Normal file
103
front/application/api/logic/BaseLogic.php
Normal file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/23} {18:01}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\api\controller\BaseWssApi;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use think\Db;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class BaseLogic
|
||||
{
|
||||
function domsg($client_id, $data){
|
||||
try {
|
||||
$res = @json_decode($data, true);
|
||||
Tools::log_to_write_txt(['json_decode:', $res]);
|
||||
if (!$res) {
|
||||
$json = BaseWssApi::json_wss('error', '消息格式错误');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
if (empty($res['action'])) {
|
||||
$json = BaseWssApi::json_wss('error', '消息格式错误,action必须');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
$act_arr = explode('/', $res['action']);
|
||||
if (empty($act_arr[0])) {
|
||||
$json = BaseWssApi::json_wss('error', '错误的action格式');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
if (empty($act_arr[1])) {
|
||||
$json = BaseWssApi::json_wss('error', '错误的action格式!');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
return;
|
||||
}
|
||||
//根据action执行业务逻辑
|
||||
$controller = ucfirst($act_arr[0]);
|
||||
$function = $act_arr[1];
|
||||
$object = '\\app\\api\\logic\\' . $controller . 'Logic';
|
||||
$obj = $this->getinstance($object);
|
||||
$obj->$function($client_id, $res);
|
||||
} catch (\Exception $e) {
|
||||
Tools::error_txt_log($e);
|
||||
$json = BaseWssApi::json_wss('error', '服务繁忙');
|
||||
Gateway::sendToClient($client_id, json_encode($json, JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
}
|
||||
|
||||
function getinstance($className)
|
||||
{
|
||||
// 类名字符串
|
||||
// 参数数组
|
||||
|
||||
// 确保类存在
|
||||
if (!class_exists($className)) {
|
||||
throw new \InvalidArgumentException("Class {$className} does not exist.");
|
||||
}
|
||||
// 创建反射类实例
|
||||
$reflection = new \ReflectionClass($className);
|
||||
|
||||
// 检查构造函数是否存在
|
||||
//if (!$reflection->hasMethod('__construct')) {
|
||||
// throw new \LogicException("Class {$className} has no constructor.");
|
||||
//}
|
||||
//$constructor = $reflection->getConstructor();
|
||||
|
||||
// 如果构造函数有参数,我们需要匹配参数
|
||||
//if ($constructor !== null) {
|
||||
// $constructorParams = $constructor->getParameters();
|
||||
//
|
||||
// // 确保参数数量匹配
|
||||
// if (count($constructorParams) !== count($params)) {
|
||||
// throw new \InvalidArgumentException("Number of constructor parameters does not match provided arguments.");
|
||||
//
|
||||
// }
|
||||
// // 创建参数数组,将参数类型与值匹配
|
||||
// $matchedParams = [];
|
||||
// foreach ($constructorParams as $index => $param) {
|
||||
// // 如果参数允许null,或者参数类型与传递的值兼容,添加到匹配参数数组
|
||||
// if ($param->allowsNull() || $param->getClass() === null || $param->getClass()->isInstance($params[$index])) {
|
||||
// $matchedParams[] = $params[$index];
|
||||
// } else {
|
||||
// throw new \InvalidArgumentException("Provided argument does not match constructor parameter type at position {$index}.");
|
||||
// }
|
||||
// }
|
||||
// // 使用反射类创建并初始化类实例
|
||||
// $instance = $reflection->newInstanceArgs($matchedParams);
|
||||
//} else {
|
||||
//
|
||||
//}
|
||||
// 构造函数无参数,直接创建实例
|
||||
$instance = $reflection->newInstanceWithoutConstructor();
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
19
front/application/api/logic/WssMessageLogic.php
Normal file
19
front/application/api/logic/WssMessageLogic.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2024/5/23} {17:34}
|
||||
*/
|
||||
|
||||
namespace app\api\logic;
|
||||
|
||||
|
||||
use app\api\controller\BaseWssApi;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class WssMessageLogic extends BaseLogic
|
||||
{
|
||||
|
||||
}
|
||||
12
front/application/command.php
Normal file
12
front/application/command.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: yunwuxin <448901948@qq.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [];
|
||||
1381
front/application/common.php
Normal file
1381
front/application/common.php
Normal file
File diff suppressed because it is too large
Load Diff
63
front/application/common/behavior/LoginBehavior.php
Normal file
63
front/application/common/behavior/LoginBehavior.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2023/12/5} {15:45}
|
||||
*/
|
||||
|
||||
namespace app\common\behavior;
|
||||
|
||||
|
||||
use app\api\logic\LoginLogic;
|
||||
use wanghua\general_utility_tools_php\api\BaseUserLogic;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class LoginBehavior
|
||||
{
|
||||
//public function run(&$params)
|
||||
//{
|
||||
// // 行为逻辑
|
||||
//}
|
||||
|
||||
public function actionBegin(){
|
||||
return true;
|
||||
//白名单
|
||||
$white_arr = [
|
||||
//【全小写】
|
||||
'api/login/login',
|
||||
'api/reg/reg',
|
||||
'api/email/sendemail',
|
||||
'api/email/check',
|
||||
'api/users/forgot',
|
||||
|
||||
//public
|
||||
'api/twitter/search',
|
||||
|
||||
];
|
||||
$module = request()->module();
|
||||
$controller = request()->controller();
|
||||
$action = request()->action();
|
||||
|
||||
if($module != 'api'){
|
||||
return false;
|
||||
}
|
||||
$url = strtolower($module.'/'.$controller.'/'.$action);
|
||||
//dump($url);
|
||||
if(in_array($url, $white_arr)){
|
||||
//dump('不校验');
|
||||
return true;//不校验
|
||||
}
|
||||
|
||||
Tools::log_to_write_txt(['action log'=>input()]);
|
||||
$r = session('api_user_info');
|
||||
//dump($r);die;
|
||||
if(empty($r)){
|
||||
Tools::log_to_write_txt(['api_user_info'=>$r]);
|
||||
echo json_encode(Tools::set_fail('登录失效'),JSON_UNESCAPED_UNICODE);die;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
front/application/common/exception/SystemException.php
Normal file
42
front/application/common/exception/SystemException.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2022/03/08} {14:17}
|
||||
*/
|
||||
|
||||
namespace app\common\exception;
|
||||
|
||||
|
||||
use think\exception\Handle;
|
||||
use think\Request;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class SystemException extends Handle
|
||||
{
|
||||
public function render(\Exception $e)
|
||||
{
|
||||
// 参数验证错误
|
||||
//if ($e instanceof ValidateException) {
|
||||
// return json($e->getError(), 422);
|
||||
//}
|
||||
|
||||
// 请求异常
|
||||
//if ($e instanceof HttpException && request()->isAjax()) {
|
||||
// return response($e->getMessage(), $e->getStatusCode());
|
||||
//}
|
||||
|
||||
Tools::log_to_write_txt([
|
||||
'error'=>'系统错误.'.$e->getMessage(),
|
||||
'input'=>input(),
|
||||
'error_info'=>$e->getTraceAsString()
|
||||
]);
|
||||
|
||||
|
||||
//request()->LogObj->flush();
|
||||
|
||||
//可以在此交由系统处理
|
||||
return parent::render($e);
|
||||
}
|
||||
}
|
||||
31
front/application/common/model/BaseModel.php
Normal file
31
front/application/common/model/BaseModel.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2021/6/21} {15:02}
|
||||
*/
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
use think\Model;
|
||||
|
||||
class BaseModel extends Model
|
||||
{
|
||||
|
||||
protected static $log_file = '';//日志文件名
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
* @param $self_table
|
||||
* @return \think\db\Query
|
||||
*/
|
||||
protected static function tab($self_table){
|
||||
return Db::table($self_table);
|
||||
}
|
||||
}
|
||||
421
front/application/common/model/TabConf.php
Normal file
421
front/application/common/model/TabConf.php
Normal file
@@ -0,0 +1,421 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
class TabConf
|
||||
{
|
||||
|
||||
/**
|
||||
* ai分析药品、影像、病历结果
|
||||
*/
|
||||
static $___fa_drugs_images_medical_task = '___fa_drugs_images_medical_task';
|
||||
|
||||
|
||||
/**
|
||||
* AI药品、影像、病历上传任务记录
|
||||
*/
|
||||
static $__fa_drugs_images_medical_result = '__fa_drugs_images_medical_result';
|
||||
|
||||
|
||||
/**
|
||||
* 基本信息图片上传并AI分析结果
|
||||
*/
|
||||
static $__fa_hbruser_drugs_images_medical_report = '__fa_hbruser_drugs_images_medical_report';
|
||||
|
||||
|
||||
/**
|
||||
* 管理员表
|
||||
*/
|
||||
static $fa_admin = 'fa_admin';
|
||||
|
||||
|
||||
/**
|
||||
* 管理员日志表
|
||||
*/
|
||||
static $fa_admin_log = 'fa_admin_log';
|
||||
|
||||
|
||||
/**
|
||||
* 地区表
|
||||
*/
|
||||
static $fa_area = 'fa_area';
|
||||
|
||||
|
||||
/**
|
||||
* 附件表
|
||||
*/
|
||||
static $fa_attachment = 'fa_attachment';
|
||||
|
||||
|
||||
/**
|
||||
* 分组表
|
||||
*/
|
||||
static $fa_auth_group = 'fa_auth_group';
|
||||
|
||||
|
||||
/**
|
||||
* 权限分组表
|
||||
*/
|
||||
static $fa_auth_group_access = 'fa_auth_group_access';
|
||||
|
||||
|
||||
/**
|
||||
* 节点表
|
||||
*/
|
||||
static $fa_auth_rule = 'fa_auth_rule';
|
||||
|
||||
|
||||
/**
|
||||
* 分类表
|
||||
*/
|
||||
static $fa_category = 'fa_category';
|
||||
|
||||
|
||||
/**
|
||||
* 在线命令表
|
||||
*/
|
||||
static $fa_command = 'fa_command';
|
||||
|
||||
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
static $fa_config = 'fa_config';
|
||||
|
||||
|
||||
/**
|
||||
* 登录设备(一个医生有多个病历,一个医生同时只有一个客户端)
|
||||
*/
|
||||
static $fa_device = 'fa_device';
|
||||
|
||||
|
||||
/**
|
||||
* 基本信息图片上传和AI分析结果
|
||||
*/
|
||||
static $fa_drugs_images_medical_result = 'fa_drugs_images_medical_result';
|
||||
|
||||
|
||||
/**
|
||||
* 任务处理进度记录
|
||||
*/
|
||||
static $fa_drugs_images_medical_task = 'fa_drugs_images_medical_task';
|
||||
|
||||
|
||||
/**
|
||||
* 邮箱验证码表
|
||||
*/
|
||||
static $fa_ems = 'fa_ems';
|
||||
|
||||
|
||||
/**
|
||||
* 估量-ai处理结果
|
||||
*/
|
||||
static $fa_guliang_ai_deal_result = 'fa_guliang_ai_deal_result';
|
||||
|
||||
|
||||
/**
|
||||
* 估量-问答记录
|
||||
*/
|
||||
static $fa_guliangqarecord = 'fa_guliangqarecord';
|
||||
|
||||
|
||||
/**
|
||||
* 估量-问答配置
|
||||
*/
|
||||
static $fa_guliangquestion = 'fa_guliangquestion';
|
||||
|
||||
|
||||
/**
|
||||
* 估量-用户
|
||||
*/
|
||||
static $fa_gulianguser = 'fa_gulianguser';
|
||||
|
||||
|
||||
/**
|
||||
* 基本信息图片上传和AI分析结果
|
||||
*/
|
||||
static $fa_hbruser_drugs_images_medical = 'fa_hbruser_drugs_images_medical';
|
||||
|
||||
|
||||
/**
|
||||
* 基本信息图片上传并AI分析结果
|
||||
*/
|
||||
static $fa_hbruser_drugs_images_medical_report = 'fa_hbruser_drugs_images_medical_report';
|
||||
|
||||
|
||||
/**
|
||||
* 任务处理进度记录
|
||||
*/
|
||||
static $fa_hbruser_drugs_images_medical_task = 'fa_hbruser_drugs_images_medical_task';
|
||||
|
||||
|
||||
/**
|
||||
* 短信发送记录
|
||||
*/
|
||||
static $fa_hdr_sms_record = 'fa_hdr_sms_record';
|
||||
|
||||
|
||||
/**
|
||||
* 管理员
|
||||
*/
|
||||
static $fa_hdradmin = 'fa_hdradmin';
|
||||
|
||||
|
||||
/**
|
||||
* 科室
|
||||
*/
|
||||
static $fa_hdrdepartment = 'fa_hdrdepartment';
|
||||
|
||||
|
||||
/**
|
||||
* 医生账户信息
|
||||
*/
|
||||
static $fa_hdrdoctorusers = 'fa_hdrdoctorusers';
|
||||
|
||||
|
||||
/**
|
||||
* 统一随访记录
|
||||
*/
|
||||
static $fa_hdrfollowup = 'fa_hdrfollowup';
|
||||
|
||||
|
||||
/**
|
||||
* 随访模板
|
||||
*/
|
||||
static $fa_hdrfollowuptemplate = 'fa_hdrfollowuptemplate';
|
||||
|
||||
|
||||
/**
|
||||
* 患者健康洞察
|
||||
*/
|
||||
static $fa_hdrhealth_insight = 'fa_hdrhealth_insight';
|
||||
|
||||
|
||||
/**
|
||||
* 问诊报告存档(疼痛科、听译、h5问诊统一存放)(一个基本信息对应一个报告)
|
||||
*/
|
||||
static $fa_hdrmedical_report = 'fa_hdrmedical_report';
|
||||
|
||||
|
||||
/**
|
||||
* 打开对话窗口记录(同时向患者端发送当前对话患者信息)
|
||||
*/
|
||||
static $fa_hdropen_chat_room_record = 'fa_hdropen_chat_room_record';
|
||||
|
||||
|
||||
/**
|
||||
* 人格测试结果
|
||||
*/
|
||||
static $fa_hdrpersonalitytest = 'fa_hdrpersonalitytest';
|
||||
|
||||
|
||||
/**
|
||||
* 科室问卷答案
|
||||
*/
|
||||
static $fa_hdrquestionnaireanswer = 'fa_hdrquestionnaireanswer';
|
||||
|
||||
|
||||
/**
|
||||
* 科室问卷问题(一个问题对应多个答案)
|
||||
*/
|
||||
static $fa_hdrquestionnairequestion = 'fa_hdrquestionnairequestion';
|
||||
|
||||
|
||||
/**
|
||||
* 患者挂号列表(可重复挂号)
|
||||
*/
|
||||
static $fa_hdrregister = 'fa_hdrregister';
|
||||
|
||||
|
||||
/**
|
||||
* 用户答题记录
|
||||
*/
|
||||
static $fa_hdruseranswerrecord = 'fa_hdruseranswerrecord';
|
||||
|
||||
|
||||
/**
|
||||
* 统一问诊用户基本信息
|
||||
*/
|
||||
static $fa_hdruserbaseinfo = 'fa_hdruserbaseinfo';
|
||||
|
||||
|
||||
/**
|
||||
* 基本信息图片上传并AI分析结果
|
||||
*/
|
||||
static $fa_hdruserbaseinfo_upload = 'fa_hdruserbaseinfo_upload';
|
||||
|
||||
|
||||
/**
|
||||
* H5用户
|
||||
*/
|
||||
static $fa_hdrusersh5 = 'fa_hdrusersh5';
|
||||
|
||||
|
||||
/**
|
||||
* 智语医助-设备关联表
|
||||
*/
|
||||
static $fa_healdevicerelation = 'fa_healdevicerelation';
|
||||
|
||||
|
||||
/**
|
||||
* 医生新消息
|
||||
*/
|
||||
static $fa_message = 'fa_message';
|
||||
|
||||
|
||||
/**
|
||||
* 短信验证码表
|
||||
*/
|
||||
static $fa_sms = 'fa_sms';
|
||||
|
||||
|
||||
/**
|
||||
* 系统维护配置,支持模块、控制器、方法。全等匹配。
|
||||
*/
|
||||
static $fa_sys_maintain_config = 'fa_sys_maintain_config';
|
||||
|
||||
|
||||
/**
|
||||
* 测试表
|
||||
*/
|
||||
static $fa_test = 'fa_test';
|
||||
|
||||
|
||||
/**
|
||||
* 听译优医助手对话记录
|
||||
*/
|
||||
static $fa_tingyiueassistantchathis = 'fa_tingyiueassistantchathis';
|
||||
|
||||
|
||||
/**
|
||||
* 疼痛科聊天历史
|
||||
*/
|
||||
static $fa_tt_chathistory = 'fa_tt_chathistory';
|
||||
|
||||
|
||||
/**
|
||||
* 随访记录(数智人医生)
|
||||
*/
|
||||
static $fa_tt_followup = 'fa_tt_followup';
|
||||
|
||||
|
||||
/**
|
||||
* 疼痛科自由对话聊天历史
|
||||
*/
|
||||
static $fa_tt_free_chathistory = 'fa_tt_free_chathistory';
|
||||
|
||||
|
||||
/**
|
||||
* 疼痛科病历报告(听译问诊)(一个基本信息对应一个报告)
|
||||
*/
|
||||
static $fa_tt_medical_report = 'fa_tt_medical_report';
|
||||
|
||||
|
||||
/**
|
||||
* 疼痛科用户基本信息
|
||||
*/
|
||||
static $fa_tt_userbaseinfo = 'fa_tt_userbaseinfo';
|
||||
|
||||
|
||||
/**
|
||||
* 疼痛科用户
|
||||
*/
|
||||
static $fa_tt_users = 'fa_tt_users';
|
||||
|
||||
|
||||
/**
|
||||
* 听译-聊天历史
|
||||
*/
|
||||
static $fa_ty_chathistory = 'fa_ty_chathistory';
|
||||
|
||||
|
||||
/**
|
||||
* 随访记录(听译助手)
|
||||
*/
|
||||
static $fa_ty_followup = 'fa_ty_followup';
|
||||
|
||||
|
||||
/**
|
||||
* 听译-病历报告(听译问诊)(一个基本信息对应一个报告)
|
||||
*/
|
||||
static $fa_ty_medical_report = 'fa_ty_medical_report';
|
||||
|
||||
|
||||
/**
|
||||
* 听译问诊-患者病历信息
|
||||
*/
|
||||
static $fa_ty_userbaseinfo = 'fa_ty_userbaseinfo';
|
||||
|
||||
|
||||
/**
|
||||
* 听译问诊-患者病历信息
|
||||
*/
|
||||
static $fa_ty_usermedicalrecord = 'fa_ty_usermedicalrecord';
|
||||
|
||||
|
||||
/**
|
||||
* 听译-医生账号
|
||||
*/
|
||||
static $fa_ty_users = 'fa_ty_users';
|
||||
|
||||
|
||||
/**
|
||||
* 会员表
|
||||
*/
|
||||
static $fa_user = 'fa_user';
|
||||
|
||||
|
||||
/**
|
||||
* 会员组表
|
||||
*/
|
||||
static $fa_user_group = 'fa_user_group';
|
||||
|
||||
|
||||
/**
|
||||
* 会员余额变动表
|
||||
*/
|
||||
static $fa_user_money_log = 'fa_user_money_log';
|
||||
|
||||
|
||||
/**
|
||||
* 会员规则表
|
||||
*/
|
||||
static $fa_user_rule = 'fa_user_rule';
|
||||
|
||||
|
||||
/**
|
||||
* 会员积分变动表
|
||||
*/
|
||||
static $fa_user_score_log = 'fa_user_score_log';
|
||||
|
||||
|
||||
/**
|
||||
* 会员Token表
|
||||
*/
|
||||
static $fa_user_token = 'fa_user_token';
|
||||
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
static $fa_users = 'fa_users';
|
||||
|
||||
|
||||
/**
|
||||
* 用户操作日志
|
||||
*/
|
||||
static $fa_users_operate_log = 'fa_users_operate_log';
|
||||
|
||||
|
||||
/**
|
||||
* 版本表
|
||||
*/
|
||||
static $fa_version = 'fa_version';
|
||||
|
||||
|
||||
/**
|
||||
* 系统杂项配置
|
||||
*/
|
||||
static $fa_zc_sundry_config = 'fa_zc_sundry_config';
|
||||
|
||||
}
|
||||
2872
front/application/data/sql/digital_doctor-数智人医生1.0封版.sql
Normal file
2872
front/application/data/sql/digital_doctor-数智人医生1.0封版.sql
Normal file
File diff suppressed because one or more lines are too long
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
|
||||
}
|
||||
}
|
||||
173
front/application/index/logic/events/Events.php
Normal file
173
front/application/index/logic/events/Events.php
Normal file
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\logic\events;
|
||||
|
||||
use app\api\controller\BaseWssApi;
|
||||
use app\api\logic\AudioRevertLogic;
|
||||
use app\api\logic\BaseLogic;
|
||||
use app\api\logic\TyuserLogic;
|
||||
use app\api\logic\WssMessageLogic;
|
||||
use GatewayWorker\Lib\Gateway;
|
||||
use IFlytek\Xfyun\Speech\LfasrClient;
|
||||
use think\Db;
|
||||
use think\worker\Application;
|
||||
use wanghua\general_utility_tools_php\http\Curl;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
use wanghua\general_utility_tools_php\websocket\BaseEvents;
|
||||
use Workerman\Worker;
|
||||
|
||||
|
||||
/**
|
||||
* 本事件监控逻辑
|
||||
*
|
||||
* 1、安装长连接框架:composer require workerman/gateway-worker
|
||||
|
||||
* 2、配置基本参数
|
||||
* 配置为文件为 config/gateway_worker.php(必须使用对应命令才能启动)
|
||||
* 配置端口startPort,pingData,eventHandler,其它默认就好
|
||||
* eventHandler配置为app\index\logic\events\Events.php类,用于处理监听后的业务逻辑
|
||||
* 3、启动服务
|
||||
* 启动命令为:php think worker:gateway
|
||||
* 4、 nginx服务配置以支持/wss方式访问
|
||||
* 参考配置:
|
||||
* location /wss
|
||||
{
|
||||
proxy_pass http://127.0.0.1:2000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
}
|
||||
* 5、JavaScript客户端建立连接并访问
|
||||
* ws = new WebSocket("wss://boomim.playone.cn/wss");//这种访问方式需要nginx配置
|
||||
ws.onopen = function() {
|
||||
alert("连接成功");
|
||||
ws.send('hello,thinkphp');
|
||||
alert("给服务端发送一个字符串:hello,thinkphp");
|
||||
};
|
||||
*/
|
||||
class Events extends BaseEvents
|
||||
{
|
||||
|
||||
// /**
|
||||
// * onWorkerStart 事件回调
|
||||
// * 当businessWorker进程启动时触发。每个进程生命周期内都只会触发一次
|
||||
// *
|
||||
// * @access public
|
||||
// * @param \Workerman\Worker $businessWorker
|
||||
// * @return void
|
||||
// */
|
||||
// public static function onWorkerStart(Worker $businessWorker)
|
||||
// {
|
||||
// $app = new Application;
|
||||
//
|
||||
// $app->initialize();
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * onConnect 事件回调
|
||||
// * 当客户端连接上gateway进程时(TCP三次握手完毕时)触发
|
||||
// *
|
||||
// * @access public
|
||||
// * @param int $client_id
|
||||
// * @return void
|
||||
// */
|
||||
// public static function onConnect($client_id)
|
||||
// {
|
||||
// //一个连接只触发一次
|
||||
// Tools::log_to_write_txt(['客户端完成TCP握手:'=>"[{$client_id}]"]);
|
||||
//
|
||||
// $json = BaseWssApi::json_wss('onConnect','连接成功',['client_id'=>$client_id]);
|
||||
// Gateway::sendToCurrentClient($json);
|
||||
// }
|
||||
//
|
||||
// public static function onWebSocketConnect($client_id, $data)
|
||||
// {
|
||||
//
|
||||
//// var_export($data);
|
||||
// //对应客户端打开连接, 一个连接只触发一次
|
||||
// Tools::log_to_write_txt(['客户端打开了websocket连接',$client_id,$data]);
|
||||
// //$res = Tools::set_ok('ok',['client_id'=>$client_id,'msg'=>'客户端打开连接时,发送到服务端的消息:','data'=>$data]);
|
||||
// //
|
||||
// //Gateway::sendToCurrentClient(json_encode($res,JSON_UNESCAPED_UNICODE));
|
||||
// //$json = BaseWssApi::json_wss('openConnect','打开连接成功',['client_id'=>$client_id,'data'=>$data]);
|
||||
// //Gateway::sendToCurrentClient($json);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * onMessage 事件回调
|
||||
// * 当客户端发来数据(Gateway进程收到数据)后触发
|
||||
// *
|
||||
// * 解析消息,根据action处理业务逻辑
|
||||
// *
|
||||
// * @access public
|
||||
// * @param int $client_id
|
||||
// * @param mixed $data
|
||||
// * @return void
|
||||
// */
|
||||
// public static function onMessage($client_id, $data)
|
||||
// {
|
||||
// Tools::log_to_write_txt(['客户端发来数据(Gateway进程收到数据).client_id:'.$client_id,$data]);
|
||||
// //$res = Tools::set_ok('ok',['client_id'=>$client_id,'msg'=>'你发来的消息我接收到了:',$client_id=>$data]);
|
||||
// //Gateway::sendToClient($client_id,json_encode($res,JSON_UNESCAPED_UNICODE));
|
||||
//
|
||||
// //if(empty($data)){
|
||||
// // $json = BaseWssApi::json_wss('error','消息为空');
|
||||
// //
|
||||
// // Gateway::sendToClient($client_id, $json);
|
||||
// // return ;
|
||||
// //}
|
||||
// ////解析消息
|
||||
// //$xunfei_record_config = config('xunfei_record_config');
|
||||
// //$appId = $xunfei_record_config['appid'];
|
||||
// //$secretKey = $xunfei_record_config['secretKey'];
|
||||
// //
|
||||
// ////解析action
|
||||
// //// 处理接收到的语音数据
|
||||
// //// 这里需要将二进制数据转换为讯飞API所需的格式
|
||||
// //// 以下代码仅为示例,具体实现需要根据讯飞API文档进行调整
|
||||
// //$lfasrClient = new LfasrClient($appId, $secretKey);
|
||||
// //$lfasrClient->sendBinaryData($data, function ($result) use ($client_id) {
|
||||
// // // 处理讯飞API返回的实时转写结果
|
||||
// // // 将结果发送回客户端
|
||||
// // Gateway::sendToClient($client_id, json_encode(['type' => 'transcription', 'data' => $result]));
|
||||
// //});
|
||||
// $obj = new BaseLogic();
|
||||
// $obj->domsg($client_id,$data);
|
||||
//
|
||||
// }
|
||||
|
||||
/**
|
||||
* onClose 事件回调 当用户断开连接时触发的方法
|
||||
*
|
||||
* @param integer $client_id 断开连接的客户端client_id
|
||||
* @return void
|
||||
*/
|
||||
public static function onClose($client_id)
|
||||
{
|
||||
//GateWay::sendToAll("client[$client_id] logout\n");
|
||||
Tools::log_to_write_txt(['断开连接.client_id:'.$client_id]);
|
||||
|
||||
//$url = 'https://boomim.playone.cn/api/Partnermerchants/offline';
|
||||
//Curl::curl_post($url,['clientid'=>$client_id]);
|
||||
|
||||
(new TyuserLogic())->offline($client_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* onWorkerStop 事件回调
|
||||
* 当businessWorker进程退出时触发。每个进程生命周期内都只会触发一次。
|
||||
*
|
||||
* @param \Workerman\Worker $businessWorker
|
||||
* @return void
|
||||
*/
|
||||
//public static function onWorkerStop(Worker $businessWorker)
|
||||
//{
|
||||
// //echo "WorkerStop\n";
|
||||
// Tools::log_to_write_txt(['businessWorker进程退出时触发。每个进程生命周期内都只会触发一次.',$businessWorker]);
|
||||
// //所有人离线,不需要修改所有用户离线状态,
|
||||
// //因为离线后再上线clint_id会重新生成
|
||||
//}
|
||||
}
|
||||
18
front/application/index/model/BaseModel.php
Normal file
18
front/application/index/model/BaseModel.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2021/1/14} {14:37}
|
||||
*/
|
||||
|
||||
namespace app\index\model;
|
||||
|
||||
|
||||
use think\Db;
|
||||
|
||||
class BaseModel extends \app\common\model\BaseModel
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
320
front/application/index/model/WechatUserModel.php
Normal file
320
front/application/index/model/WechatUserModel.php
Normal file
@@ -0,0 +1,320 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2022/01/18} {16:24}
|
||||
*/
|
||||
|
||||
|
||||
namespace app\index\model;
|
||||
|
||||
use app\apidata\Config;
|
||||
use app\common\model\TabConf;
|
||||
use think\Db;
|
||||
|
||||
class WechatUserModel extends \app\index\model\BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
* @param $wx_user_info \app\index\model\微信用户
|
||||
*
|
||||
* {
|
||||
* "openid":"or9D2vs863Ky5Py2ovkAiu9XFLO4",
|
||||
* "nickname":"起源果蔬副食大华",
|
||||
* "sex":0,
|
||||
* "language":"",
|
||||
* "city":"",
|
||||
* "province":"",
|
||||
* "country":"",
|
||||
* "headimgurl":"https://thirdwx.qlogo.cn/mmopen/vi_32/joiaA475nx3fJiaqx0ibdnWo4A7Q3uCgu2hsribI0ATLItORjuUgCSP8mCaBkqL61ibGojib4pQYX1djUhZpF5zoqpSg/132",
|
||||
* "privilege":[]
|
||||
* }
|
||||
*/
|
||||
static function insertInfo(array $wx_user_info)
|
||||
{
|
||||
|
||||
if (isset($wx_user_info['privilege'])) {
|
||||
$wx_user_info['privilege'] = json_encode($wx_user_info['privilege']);
|
||||
}
|
||||
$data = [
|
||||
'nickname' => $wx_user_info['nickname'],
|
||||
'country' => $wx_user_info['country'],
|
||||
'province' => $wx_user_info['province'],
|
||||
'city' => $wx_user_info['city'],
|
||||
'headimage' => $wx_user_info['headimgurl'],
|
||||
'language' => $wx_user_info['language'],
|
||||
'openid' => $wx_user_info['openid'],
|
||||
'unionid' => isset($wx_user_info['unionid']) ? $wx_user_info['unionid'] : '',
|
||||
'privilege' => $wx_user_info['privilege'],
|
||||
'sex' => $wx_user_info['sex'],
|
||||
'arm_group' => '',
|
||||
'score' => 0,//积分
|
||||
'group_buy_earnings' => 0,//拼团收益
|
||||
'water_drop_balance' => 0,//水滴
|
||||
];
|
||||
self::tab(TabConf::$fa_wechatuser)
|
||||
->data($data)
|
||||
->insert();
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:更新用户信息
|
||||
*
|
||||
* author:wh
|
||||
* @throws \think\Exception
|
||||
* @throws \think\exception\PDOException
|
||||
*/
|
||||
static function updateUser($wx_user_info)
|
||||
{
|
||||
$data = [
|
||||
'nickname' => $wx_user_info['nickname'],
|
||||
'headimage' => $wx_user_info['headimgurl'],
|
||||
'unionid' => isset($wx_user_info['unionid']) ? $wx_user_info['unionid'] : '',
|
||||
];
|
||||
self::tab(TabConf::$fa_wechatuser)
|
||||
->data($data)
|
||||
->where('openid', index_user_openid())
|
||||
->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
* @param string $unionid
|
||||
* @return array|bool|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
static function getWxUserByUnionid(string $unionid)
|
||||
{
|
||||
return Db::table(TabConf::$fa_wechatuser)
|
||||
->field('id')
|
||||
->where('unionid', $unionid)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
* @param string $openid
|
||||
* @return array|bool|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
static function getWxUserByOpenid(string $openid)
|
||||
{
|
||||
return Db::table(TabConf::$fa_wechatuser)
|
||||
//->field('id')
|
||||
->where('openid', $openid)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:
|
||||
* author:wh
|
||||
* @param string $openid
|
||||
* @return array|bool|\PDOStatement|string|\think\Model|null
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
static function getNicknameByOpenid(string $openid)
|
||||
{
|
||||
return Db::table(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->value('nickname');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* desc:增加店铺会员积分
|
||||
*
|
||||
* author:wh
|
||||
*/
|
||||
static function addShopMemberScore(string $openid, $shop_member_score)
|
||||
{
|
||||
Db::table(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->setInc('shop_member_score', $shop_member_score);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* desc:增加积分、积分变动记录
|
||||
* author:wh
|
||||
*/
|
||||
static function addScore(string $openid, $order_real_amount)
|
||||
{
|
||||
$score = $order_real_amount * 100;
|
||||
//用户
|
||||
$user = Db::table(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->find();
|
||||
//增加积分变动记录
|
||||
Db::table(TabConf::$fa_score_change_record)
|
||||
->data([
|
||||
'nickname' => $user['nickname'],
|
||||
'openid' => $user['openid'],
|
||||
'score' => $score,
|
||||
'score_before' => $user['score'],
|
||||
'score_after' => $user['score'] + $score,
|
||||
'from' => 'main_store_goods_buy_order',
|
||||
])
|
||||
->insert();
|
||||
//增加积分
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->setInc('score', $score);//分为单位
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:减去积分 扣除积分、积分变动记录
|
||||
* author:wh
|
||||
*/
|
||||
static function deductScore(string $openid, $order_real_amount, $remark = '')
|
||||
{
|
||||
$score = $order_real_amount * 100;
|
||||
//用户
|
||||
$user = Db::table(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->find();
|
||||
//增加积分变动记录
|
||||
Db::table(TabConf::$fa_score_change_record)
|
||||
->data([
|
||||
'nickname' => $user['nickname'],
|
||||
'openid' => $user['openid'],
|
||||
'score' => -$score,
|
||||
'score_before' => $user['score'],
|
||||
'score_after' => $user['score'] - $score,
|
||||
'from' => 'system_deduct_score',//系统冲扣积分
|
||||
'remark' => $remark,
|
||||
])
|
||||
->insert();
|
||||
//增加积分
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->setDec('score', $score);//分为单位
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:积分冲补
|
||||
*
|
||||
* author:wh
|
||||
* @param string $openid
|
||||
* @param $order_real_amount
|
||||
* @param string $remark
|
||||
* @return bool|int|string|true
|
||||
* @throws \think\Exception
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
*/
|
||||
static function repairScore(string $openid, $order_real_amount, $remark = '')
|
||||
{
|
||||
$score = $order_real_amount * 100;
|
||||
//用户
|
||||
$user = Db::table(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->find();
|
||||
//增加积分变动记录
|
||||
Db::table(TabConf::$fa_score_change_record)
|
||||
->data([
|
||||
'nickname' => $user['nickname'],
|
||||
'openid' => $user['openid'],
|
||||
'score' => $score,
|
||||
'score_before' => $user['score'],
|
||||
'score_after' => $user['score'] + $score,
|
||||
'from' => 'system_repair_score',//系统冲补积分
|
||||
'remark' => $remark,
|
||||
])
|
||||
->insert();
|
||||
//增加积分
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->setInc('score', $score);//分为单位
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:每笔订单成功之后增加水滴
|
||||
*
|
||||
* author:wh
|
||||
* @param string $openid
|
||||
* @param $order_real_amount
|
||||
* @return bool|int|string|true
|
||||
* @throws \think\Exception
|
||||
*/
|
||||
static function addWaterDropBalance(string $openid, $order_real_amount)
|
||||
{
|
||||
$water_drop_basic_num = (int)Config::sundryConfigVal('water_drop_basic_num');
|
||||
|
||||
$water = 0;
|
||||
if ($order_real_amount < 1) {
|
||||
$water = 1;//小于1积累1滴水滴
|
||||
} else if ($order_real_amount >= 1 && $order_real_amount < 10) {
|
||||
$water = 2;
|
||||
} else if ($order_real_amount >= 10 && $order_real_amount < 50) {
|
||||
$water = 3;
|
||||
} else if ($order_real_amount >= 50 && $order_real_amount < 100) {
|
||||
$water = 4;
|
||||
} else if ($order_real_amount >= 100 && $order_real_amount < 500) {
|
||||
$water = 5;
|
||||
} else if ($order_real_amount >= 500 && $order_real_amount < 2000) {
|
||||
$water = 6;
|
||||
} else if ($order_real_amount >= 2000) {
|
||||
$water = 7;
|
||||
}
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->setInc('water_drop_balance', $water * $water_drop_basic_num);
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:实时获取用户身上的微信拼团收益
|
||||
* author:wh
|
||||
*/
|
||||
static function getUserEarnings()
|
||||
{
|
||||
$val = self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', index_user_openid())
|
||||
->value('group_buy_earnings');
|
||||
|
||||
return 1 * $val;
|
||||
}
|
||||
|
||||
static function getUserTypeByOpenid(string $openid)
|
||||
{
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', $openid)
|
||||
->value('user_type');
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:实时获取用户身上的积分
|
||||
* author:wh
|
||||
*/
|
||||
static function getUserScore()
|
||||
{
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', index_user_openid())
|
||||
->value('score');
|
||||
}
|
||||
|
||||
/**
|
||||
* desc:实时获取用户身上的水滴
|
||||
* author:wh
|
||||
*/
|
||||
static function getUserWater()
|
||||
{
|
||||
return self::tab(TabConf::$fa_wechatuser)
|
||||
->where('openid', index_user_openid())
|
||||
->value('water_drop_balance');
|
||||
}
|
||||
}
|
||||
42
front/application/index/view/test/testwss.html
Normal file
42
front/application/index/view/test/testwss.html
Normal file
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<textarea type="text" id="msg">{"action":"user/offline","method":"response","msg":"22222","items":[]}</textarea> <button onclick="sendmsg()">发送消息</button>
|
||||
</body>
|
||||
<script>
|
||||
let ws = new WebSocket("wss://ybx_prediagnosis.excn.top/wss");//这种访问方式需要nginx配置
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log("连接成功");
|
||||
// ws.send('hello,thinkphp');
|
||||
// let str = '{"action":"Tychat/saveChatHistory","items":{"chat_msg":"你好","type":"doc"}';
|
||||
// console.log(str);
|
||||
};
|
||||
ws.onmessage = function(e){
|
||||
// console.log(e);
|
||||
//e.data 的数据格式也是字符串,手动解析这些数据才能得到其他格式的数据。
|
||||
const _data = JSON.parse(e.data);
|
||||
console.log(e.data,_data);
|
||||
}
|
||||
|
||||
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
||||
ws.onclose = function(e){
|
||||
console.log("close");
|
||||
}
|
||||
|
||||
//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
||||
ws.onerror = function(error){
|
||||
console.log(error);
|
||||
}
|
||||
function sendmsg(){
|
||||
let msg = document.getElementById("msg").value;
|
||||
console.log('发送:'+msg);
|
||||
ws.send(msg);
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
41
front/application/index/view/test/testwss2.html
Normal file
41
front/application/index/view/test/testwss2.html
Normal file
@@ -0,0 +1,41 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<input type="text" id="msg" value='{"action":"user/offline","method":"response","msg":"22222","items":[]}'> <button onclick="sendmsg()">发送消息</button>
|
||||
</body>
|
||||
<script>
|
||||
let ws = new WebSocket("wss://rtasr.xfyun.cn/v1/ws?appid=d482af59&ts=1721021537&signa=WuLBMEvYlr7T1NKZLeQOiCU%2FJIo%3D&lang=zh-cn");//这种访问方式需要nginx配置
|
||||
|
||||
ws.onopen = function() {
|
||||
console.log("连接成功");
|
||||
ws.send('hello,thinkphp');
|
||||
console.log("给服务端发送一个字符串:hello,thinkphp");
|
||||
};
|
||||
ws.onmessage = function(e){
|
||||
// console.log(e);
|
||||
//e.data 的数据格式也是字符串,手动解析这些数据才能得到其他格式的数据。
|
||||
const _data = JSON.parse(e.data);
|
||||
console.log(e.data,_data);
|
||||
}
|
||||
|
||||
//当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
||||
ws.onclose = function(e){
|
||||
console.log("close");
|
||||
}
|
||||
|
||||
//如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
||||
ws.onerror = function(error){
|
||||
console.log(error);
|
||||
}
|
||||
function sendmsg(){
|
||||
let msg = document.getElementById("msg").value;
|
||||
console.log('发送:'+msg);
|
||||
ws.send(msg);
|
||||
}
|
||||
</script>
|
||||
</html>
|
||||
14
front/application/provider.php
Normal file
14
front/application/provider.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 应用容器绑定定义
|
||||
return [
|
||||
];
|
||||
45
front/application/tags.php
Normal file
45
front/application/tags.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: liu21st <liu21st@gmail.com>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
// 动态绑定属性
|
||||
//框架生命周期日志(只支持tp5.0)
|
||||
//\think\facade\Request::instance()->bind('LogObj',new \wanghua\general_utility_tools_php\log\Driver('mysql'));
|
||||
//业务日志对象
|
||||
//\think\Request::instance()->bind('ServeLogObj',new \wanghua\general_utility_tools_php\log\Driver('file'));
|
||||
|
||||
|
||||
|
||||
// 注册 app\index\behavior\CheckLang行为类到app_init标签位
|
||||
//\think\Hook::add('app_init', '\\wanghua\\general_utility_tools_php\\log\\example\\LoggerBehavior');
|
||||
//注册 app\admin\behavior\CronRun行为类到app_init标签位
|
||||
//\think\Hook::add('app_end', '\\wanghua\\general_utility_tools_php\\log\\example\\LoggerBehavior');
|
||||
|
||||
|
||||
|
||||
// 应用行为扩展定义文件
|
||||
return [
|
||||
// 应用初始化
|
||||
'app_init' => [],
|
||||
// 应用开始
|
||||
'app_begin' => [],
|
||||
// 模块初始化
|
||||
'module_init' => [],
|
||||
// 操作开始执行
|
||||
'action_begin' => [
|
||||
'app\\common\\behavior\\LoginBehavior',
|
||||
],
|
||||
// 视图内容过滤
|
||||
'view_filter' => [],
|
||||
// 日志写入
|
||||
'log_write' => [],
|
||||
// 应用结束
|
||||
'app_end' => [],
|
||||
];
|
||||
Reference in New Issue
Block a user