$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"; } }