| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- <?php
- namespace app\index\controller;
- use think\Request;
- use think\Db;
- class Index extends \think\Controller
- {
- //主页
- public function index(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('index', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
- //主页
- public function upload(){
- return view('upload');
- }
- //404
- public function errorPage(){
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- }
- else{
- $device = 'pc';
- }
- //获取公共路径
- $commonURL = commonURL();
- //获取公共路径
- $commonOpenURL = commonOpenURL();
- return view('error', [
- 'device' => $device,
- 'commonURL' => $commonURL,
- 'commonOpenURL' => $commonOpenURL,
- ]);
- }
-
-
- //客户端
- public function chatBox(){
- $ragId = request() -> param('ragId');
- $mobileType = 'unknow';
- $data['publicKey'] = commonPublicKey();
- $url = commonOpenURLLocal()."/apis/searchRag";
- $ragList = curlPost($url,$data);
- $ragList = json_decode($ragList);
- $ragList = stdClassObjToArray($ragList);
- if($ragList["code"] != 0){
- $ragList = $ragList['rags'];
- }
- $ragList = json_encode($ragList);
- $urlagent = commonOpenURLLocal()."/Apis/searchagents";
- $agentList = curlPost($urlagent,$data);
- $agentList = json_decode($agentList);
- $agentList = stdClassObjToArray($agentList);
- if($agentList ["code"] != 0){
- $agentList = $agentList['agents'];
- }
- $agentList = json_encode($agentList);
- // dump($ragList);
- // exit;
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取公共路径
- $commonURL = commonURL();
- //获取当前时间
- $now = date('Y-m-d H:i:s',time());
- //获取提问示例
- $question = db('Question') -> order('id DESC') -> select();
- // dump($question);
- // exit;
- //获取一个标记当前用户的传参
- $user = request() -> param('user');
- if(!$user){
- $user = rand(10000,99999);
- }
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/chatBox?user='.$user;
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- // dump($userData[0]["strate"]);
- // exit;
-
- return view('chatBox', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'commonURL' => $commonURL,
- 'now' => $now,
- 'question' => $question,
- 'commonOpenURLSSE' => commonOpenURLSSE(),
- 'commonOpenURLLocalSSE' => commonOpenURLLocalSSE(),
- 'commonWebsocket' => commonWebsocket(),
- 'user' => $user,
- 'ragList' => $ragList,
- 'agentList' => $agentList,
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- 'ragId' => $ragId,
- ]);
- // return $url;
-
- }
- //客户端
- public function chatBox1(){
- $ragId = request() -> param('ragId');
- $mobileType = 'unknow';
- $data['publicKey'] = commonPublicKey();
- $url = commonOpenURLLocal()."/apis/searchRag";
- $ragList = curlPost($url,$data);
-
- if($ragList != null){
- $ragList = json_decode($ragList);
- $ragList = $ragList->rags;
- $ragList = stdClassObjToArray($ragList);
- }
-
- $urlagent = commonOpenURLLocal()."/Apis/searchagents";
- $agentList = curlPost($urlagent,$data);
- if($agentList != null){
- $agentList = json_decode($agentList);
- $agentList = $agentList->agents;
- $agentList = stdClassObjToArray($agentList);
- }
-
-
- // dump($ragList);
- // exit;
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取公共路径
- $commonURL = commonURL();
- //获取当前时间
- $now = date('Y-m-d H:i:s',time());
- //获取提问示例
- $question = db('Question') -> order('id DESC') -> select();
- // dump($question);
- // exit;
- //获取一个标记当前用户的传参
- $user = request() -> param('user');
- if(!$user){
- $user = rand(10000,99999);
- }
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/chatBox1?user='.$user;
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
-
- return view('chatBox1', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'commonURL' => $commonURL,
- 'now' => $now,
- 'question' => $question,
- 'commonOpenURLSSE' => commonOpenURLSSE(),
- 'commonOpenURLLocalSSE' => commonOpenURLLocalSSE(),
- 'commonWebsocket' => commonWebsocket(),
- 'user' => $user,
- 'ragList' => $ragList,
- 'agentList' => $agentList,
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- 'ragId' => $ragId,
- ]);
- // return $url;
-
- }
-
- //GPUs
- public function gpu(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/gpu';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('gpu', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
-
- //数据蒸馏中心页面
- public function distill(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/distill';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('distill', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
-
- //模型训练中心页面
- public function modelTrain(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/modelTrain';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('modelTrain', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
-
- //模型开放平台页面
- public function modelOpen(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/modelOpen';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('modelOpen', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
-
- //智能体开放平台页面
- public function agentOpen(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/agentOpen';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('agentOpen', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
-
- //关于我们
- public function about(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/about';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('about', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
-
- }
-
- //新闻列表
- public function news(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/news';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
-
- //获取新闻列表
- $news = db('news') -> order('id DESC') -> select();
- for($i = 0; $i < count($news); $i++){
- $news[$i]['date'] = date('Y-m-d',$news[$i]['time']);
- }
-
- return view('news', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
-
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
-
- 'news' => $news,
- ]);
-
- }
-
- //新闻详情
- public function newsDetail(){
- $commonURL = commonURL();
- $this -> redirect($commonURL.'/index/errorPage');
- }
-
- //model列表页
- public function models(){
- $commonURL = commonURL();
- $this -> redirect($commonURL.'/index/errorPage');
- }
-
- //大语言模型页
- public function modelLLM(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //获取公共路径
- $commonOpenURL = commonOpenURL();
- //获取当前时间
- $now = date('Y-m-d H:i:s',time());
- //获取提问示例
- $question = db('Question') -> order('id DESC') -> select();
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/modelLLM';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('modelLLM', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
- 'now' => $now,
- 'question' => $question,
- 'commonOpenURL' => $commonOpenURL,
- 'commonOpenURLSSE' => commonOpenURLSSE(),
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
- }
-
- //医疗BI页面
- public function chatBI(){
- $commonURL = commonURL();
- $this -> redirect($commonURL.'/index/errorPage');
-
- }
-
- //数字医生页面
- public function aiDoctor(){
- $commonURL = commonURL();
- $this -> redirect($commonURL.'/index/errorPage');
-
- }
-
- //病历质控
- public function internalQuality(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //获取公共路径
- $commonOpenURL = commonOpenURL();
- //获取当前时间
- $now = date('Y-m-d H:i:s',time());
- //获取一个标记当前用户的传参
- $user = request() -> param('user');
- if(!$user){
- $user = rand(10000,99999);
- }
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/internalQuality?user='.$user;
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('internalQuality', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
- 'now' => $now,
- 'commonOpenURL' => $commonOpenURL,
- 'commonOpenURLSSE' => commonOpenURLSSE(),
- 'commonWebsocket' => commonWebsocket(),
- 'user' => $user,
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
-
- }
-
- //邀请函
- public function invitation(){
- //判断用户设备是否是移动端
- $mobileType = 'unknow';
- //判断用户设备是否是移动端
- if(isMobile() == true){
- $device = 'phone';
- $mobileType = mobileType();
- }
- else{
- $device = 'pc';
- }
- //获取当前年份
- $year = date('Y',time());
- //获取公共路径
- $commonURL = commonURL();
- //获取公共路径
- $commonOpenURL = commonOpenURL();
- //获取当前时间
- $now = date('Y-m-d H:i:s',time());
- //获取一个标记当前用户的传参
- $user = request() -> param('user');
- if(!$user){
- $user = rand(10000,99999);
- }
- //构建微信分享参数
- $appId = commonAPPID();
- $timestamp = time();
- $nonceStr = nonceStr(16);
- $url = commonURL().'/index/invitation';
- $jsapiTicket = getOfficialJsapiTicket();
- $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr×tamp=$timestamp&url=$url";
- $signature = sha1($string);
- return view('invitation', [
- 'device' => $device,
- 'mobileType' => $mobileType,
- 'year' => $year,
- 'commonURL' => $commonURL,
- 'now' => $now,
- 'commonOpenURL' => $commonOpenURL,
- 'commonOpenURLSSE' => commonOpenURLSSE(),
- 'commonWebsocket' => commonWebsocket(),
- 'user' => $user,
- 'appId' => $appId,
- 'timestamp' => $timestamp,
- 'nonceStr' => $nonceStr,
- 'signature' => $signature,
- ]);
-
- }
-
- //
- public function knowledgeMessage(){
- // $input = request() -> param('input');
- // $kid = request() -> param('kid');
- $json = file_get_contents('php://input');
- $json = json_decode($json);
- $json = stdClassObjToArray($json);
- if($json){
- $input = $json['input'];
- $kid = $json['kid'];
- }
-
- $count = request() -> param('count');
- // $input = $_POST['input'];
- // $kid = $_POST['kid'];
- $count = json_decode($count);
- $count = stdClassObjToArray($count);
- // echo($input);
- // exit;
- if($count){
- $input = $count['input'];
- $kid = $count['kid'];
- }
- if(!$input){
- echo '{"code":500,"msg":"cURL 请求失败: 请检查参数。","data":null}';
- exit;
- }
- if(!$kid){
- echo '{"code":500,"msg":"cURL 请求失败: 请检查参数。","data":null}';
- exit;
- }
- $RAGdata = [
- "username" => "test",
- "password" => "test123"
- ];
- // 调用时只需传递非 Content-Type/Accept 的 Header
- $headers = [
- 'Cache-Control: no-cache',
- 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
- ];
-
- $urlRAG = "http://192.168.1.8:6039/auth/login"; // 替换为实际 URL
- $id = curlPostRAG($urlRAG, $RAGdata, $headers);
-
- $token = $id; // 默认启用 JSON 模式
- $token = json_decode($token);
- $token = stdClassObjToArray($token);
- $token = $token['data']['token'];
- $url = "http://192.168.1.8:6039/rag/schema"; // 替换成实际接口地址
- $data = [
- "messages" => $input, // 替换成实际用户输入
- "model" => "qwen3-32B", // 替换成实际模型名称
- "maxDistance" => 0.7, // 替换成实际分数(浮点数)
- "kid" => $kid // 替换成实际知识库 ID
- ];
- // 初始化 cURL
- $ch = curl_init();
- // 设置 cURL 选项
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
- curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
- curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
- "Authorization: Bearer " . $token,
- "Content-Type: application/json" // 声明请求体是 JSON
- ]);
- // 执行请求并获取响应
- $response = curl_exec($ch);
- // 检查是否有错误
- if (strpos($response, "code") !== false) {
- $response = json_decode($response);
- echo '{"code":'.$response ->code.',"msg":"cURL 请求失败: 请检查参数。","data":null}';
- exit;
- } else {
- // 解析 JSON 响应
- $response = json_decode($response, true);
- $response["code"] = 200;
- $response = json_encode($response, JSON_UNESCAPED_UNICODE);
- return $response; // 输出返回数据(prompt, vector, nearest)
- }
- // 关闭 cURL 资源
- curl_close($ch);
- }
-
- //
- function handleChatTest() {
- if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
- http_response_code(405); // 405 Method Not Allowed
- echo json_encode(['error' => 'Only POST requests are allowed']);
- return;
- }
- $expectedToken = 'sk-c39f1b287ef64c39b88ad0ff9c7420b6';
- $targetUrl = 'http://60.164.133.40:9997/v1/chat/completions';
-
- // 获取请求体和头信息
- $requestBody = file_get_contents('php://input');
- $headers = getallheaders();
- $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
-
- // 校验 Authorization
- if ($authorizationHeader !== 'Bearer ' . $expectedToken) {
- http_response_code(403);
- echo json_encode(['error' => 'Authorization header']);
- return;
- }
-
- // 发起代理请求
- $ch = curl_init($targetUrl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
- 'Content-Type: application/json',
- 'Authorization: ' . $authorizationHeader
- ]);
-
- // 设置回调,边接收边输出
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
- echo $data;
- // 立即刷新输出缓冲
- @ob_flush();
- @flush();
- return strlen($data);
- });
-
- // 返回响应
- header('Content-Type: application/json');
- $res = curl_exec($ch);
- if (curl_errno($ch)) {
- http_response_code(500);
- echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
- }
- curl_close($ch);
- }
-
-
- function handleChat() {
- if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
- http_response_code(405);
- echo json_encode(['error' => 'Only POST requests are allowed']);
- return;
- }
-
- // 关闭所有缓冲,强制流式输出
- @ini_set('output_buffering', 'off');
- @ini_set('zlib.output_compression', false);
- while (ob_get_level() > 0) {
- ob_end_flush();
- }
- ob_implicit_flush(true);
-
- // 设置流式响应头
- header('Content-Type: application/json; charset=utf-8');
- header('Cache-Control: no-cache');
- header('X-Accel-Buffering: no'); // 对 Nginx 有效,关闭缓冲
-
- $expectedToken = 'sk-7e5a2dcb93a84fd8a9f04b6a9c8f1e32';
- $targetUrl = 'http://60.164.133.40:19997/v1/chat/completions';
-
- $requestBody = file_get_contents('php://input');
- $headers = getallheaders();
- $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
-
- if ($authorizationHeader !== 'Bearer ' . $expectedToken) {
- http_response_code(403);
- echo json_encode(['error' => 'Invalid Authorization header']);
- return;
- }
-
- $ch = curl_init($targetUrl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 0);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
- 'Content-Type: application/json',
- 'Authorization: ' . $authorizationHeader
- ]);
-
- curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
- echo $data;
- @ob_flush();
- @flush();
- return strlen($data);
- });
- $logFile = __DIR__ . '/handleChat.log';
- $timestamp = date('[Y-m-d H:i:s]');
- file_put_contents($logFile, $timestamp . ' ' .$requestBody .PHP_EOL, FILE_APPEND);
- $res = curl_exec($ch);
- if (curl_errno($ch)) {
- http_response_code(500);
- echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
- }
- curl_close($ch);
- $timestamp = date('[Y-m-d H:i:s]');
- file_put_contents($logFile, $timestamp . ' ' .PHP_EOL, FILE_APPEND);
- }
-
- function handleEmbedding() {
- if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
- http_response_code(405);
- echo json_encode(['error' => 'Only POST requests are allowed']);
- return;
- }
-
- $expectedToken = 'sk-c39f1b287ef64c39b88ad0ff9c7420b6';
- $targetUrl = 'http://60.164.133.40:19997/v1/embeddings';
-
- $headers = array_change_key_case(getallheaders(), CASE_LOWER);
- if (!isset($headers['authorization'])) {
- http_response_code(401);
- echo json_encode(['error' => 'Missing Authorization header']);
- return;
- }
- $authHeader = $headers['authorization'];
- if ($authHeader !== 'Bearer ' . $expectedToken) {
- http_response_code(403);
- echo json_encode(['error' => 'Invalid API token']);
- return;
- }
-
- $requestBody = file_get_contents('php://input');
-
- $ch = curl_init($targetUrl);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_TIMEOUT, 0);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
- curl_setopt($ch, CURLOPT_HTTPHEADER, [
- 'Content-Type: application/json',
- 'accept: application/json',
- 'Authorization: ' . $authHeader,
- ]);
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_ENCODING, ''); // 支持所有编码,防止自动解压影响
-
- $response = curl_exec($ch);
-
- if (curl_errno($ch)) {
- http_response_code(500);
- echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
- curl_close($ch);
- return;
- }
-
- $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- curl_close($ch);
-
- $responseHeaders = substr($response, 0, $headerSize);
- $responseBody = substr($response, $headerSize);
-
- // 关闭所有输出缓冲区,防止格式被修改
- while (ob_get_level()) {
- ob_end_clean();
- }
-
- // 只转发 Content-Type,避免冲突
- foreach (explode("\r\n", $responseHeaders) as $headerLine) {
- if (stripos($headerLine, 'Content-Type:') === 0) {
- header($headerLine);
- }
- }
-
- http_response_code($httpCode);
-
- // 直接原样输出响应体,不做任何json_encode或修改
- echo $responseBody;
- }
-
-
- public function roleindex(){
- $data['askInfoId'] = request() -> param('askInfoId');
-
- // $data['askInfoId'] = '53ef8235ca3e5d60708baae51be72db8';
- $maprulecontent['token'] = array('eq', $data['askInfoId']);
- $tokenrole = db('tokenrole')->where($maprulecontent)->select();
- $urlrole = commonOpenURLLocal().'/apis/role';
- $rulename = curlPost($urlrole,$data);
- $rulename = json_decode($rulename);
- $rulename = stdClassObjToArray($rulename);
-
-
- if(strstr($rulename['reply'], '病例校验通过')){
-
-
- $datarole['aireply'] = $rulename['reply'];
- $datarole['reply'] = "【质控结果】 病例校验通过。";
- db('tokenrole')->where($maprulecontent)->update($datarole);
- }
- else{
-
- $datarole['aireply'] = $rulename['reply'];
- $datarole['reply'] = $rulename['reply'];
- db('tokenrole')->where($maprulecontent)->update($datarole);
- }
-
- return "ss";
- }
- public function roleindex1(){
- $data['askInfoId'] = request() -> param('askInfoId');
-
- // $data['askInfoId'] = '53ef8235ca3e5d60708baae51be72db8';
- $maprulecontent['token'] = array('eq', $data['askInfoId']);
- $tokenrole = db('tokenrole2')->where($maprulecontent)->select();
- $urlrole = commonOpenURLLocal().'/apis/role';
- $rulename = curlPost($urlrole,$data);
- $rulename = json_decode($rulename);
- $rulename = stdClassObjToArray($rulename);
-
-
- if(strstr($rulename['reply'], '病例校验通过')){
-
-
- $datarole['aireply'] = $rulename['reply'];
- $datarole['reply'] = "【质控结果】 病例校验通过。";
- db('tokenrole2')->where($maprulecontent)->update($datarole);
- }
- else{
-
- $datarole['aireply'] = $rulename['reply'];
- $datarole['reply'] = $rulename['reply'];
- db('tokenrole2')->where($maprulecontent)->update($datarole);
- }
-
- return "ss";
- }
- }
|