Apis.php 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. <?php
  2. namespace app\index\controller;
  3. use think\Request;
  4. use think\Db;
  5. header("Access-Control-Allow-Origin: *"); // 允许所有来源
  6. header("Access-Control-Allow-Headers: Content-Type"); // 允许的请求头
  7. //sm4
  8. use Evit\PhpGmCrypto\Encryption\EvitSM4Encryption;
  9. class Apis extends \think\Controller
  10. {
  11. //对传入的信息进行存储并获取短令牌
  12. public function getToken(){
  13. //通过入参构建准备存入数据库的内容
  14. $information = request() -> param('information');
  15. // $information = 'eyJlbmNyeXB0ZWRCYXNlNjQiOiJibjk2UzZxQXBlanhVTHZLSExkdDJuWEtKSnUwZit1YlVYanl1a29HU2JYdEk5bGV4RVZZUDFHNkVJcnZld3ZtZTZDUDlKaGZZSjZyR1wvUyttdGd6cHlTQzVLM1JkUWZUYzdRNndsTG5XbGludEhqdFM0RTJqdHVSWlFPeXNZQmZQU0x4anE0SG13MEI2WkE4bTRLK2xVTHJIRXdlMVUyUkFuWkYzbDBqblZmZVZ0clwvaEloKzZ6VzRVeHBHRzllWll5ZGNIVVBGOCtldGRxdEJ5aHB1TWtEYXEwRmlXckRVXC9BVkJZYXdtTmt3aTZiRFdrdWtZS1JKRWhIa0Z3SDdYZVh1REdFdmFBNEs5VktiRENQQXY4cXJoT21abGFOMVNcLzhXZG5VczBaaEVKSXk4WEVmREcxZ0oxOVJuQTUzbENVTGgrZVFnbWVQXC9DYTd2MisxRmpjZUhlVERPaGRNamVWeXlhXC81VzJ1OVI0bnFcLzBxZ3R5WVkwMDBxeEZMaWVncHNReFlCMzh0bEh5M1hVeVdOMFBVbkNcL2FNV29ncGMrNTZleEtwU0liYkJGQXN4b2tsY2xZWkkwREVDaExFZzIiLCJzbUlWIjoiNXlVYjhGY0xGd1FFN0NpNyIsInB1YmxpY0tleSI6IlhsZTZMUjVvT1pKdU84Y3lYODFqbDNRdmZCeGg1ZmxzIn0';
  16. $askInfo['encryption'] = $information;
  17. $informationCut = substr($information, 0, 20);
  18. $time = time();
  19. $token = md5($informationCut.$time.rand(10000,99999));
  20. $askInfo['token'] = $token;
  21. $askInfo['time'] = $time;
  22. $information = base64UrlDecode($information);
  23. $information = json_decode($information);
  24. $information = stdClassObjToArray($information);
  25. if(!$information){
  26. $error['code'] = 6;
  27. $error['message'] = '非法请求,已拒绝。';
  28. return json_encode($error,JSON_UNESCAPED_UNICODE);
  29. }
  30. //通过sm4进行解密
  31. $smIV = $information['smIV'];
  32. $publicKey = $information['publicKey'];
  33. $encryptedBase64 = $information['encryptedBase64'];
  34. $mapProject['public_key'] = array('eq',$publicKey);
  35. $privateKey = db('Project') -> where($mapProject) -> value('private_key');
  36. $config = [
  37. 'mode' => 'cbc',
  38. 'key' => $privateKey, // 16 字节二进制密钥
  39. 'iv' => $smIV, // 16 字节二进制 IV
  40. 'hash' => false
  41. ];
  42. $sm4 = new EvitSM4Encryption($config);
  43. $pass = base64_decode($encryptedBase64);
  44. $decrypted = $sm4->decrypt($pass);
  45. $decrypted = base64_decode($decrypted);
  46. $information = json_decode($decrypted);
  47. $information = stdClassObjToArray($information);
  48. if(!$information){
  49. $error['code'] = 0;
  50. $error['message'] = '解密错误,请核对仔细核对参数!';
  51. return json_encode($error,JSON_UNESCAPED_UNICODE);
  52. }
  53. //请求信息整理
  54. $dataInsert['smIV'] = $smIV;
  55. $dataInsert['publicKey'] = $publicKey;
  56. $dataInsert['model'] = $information['model'];
  57. $dataInsert['network'] = $information['network'];
  58. $dataInsert['input'] = $information['input'];
  59. //构建数据库记录
  60. $askInfo['decrypt'] = json_encode($dataInsert,JSON_UNESCAPED_UNICODE);
  61. //将请求记录存储至数据库
  62. db('askinfo') -> insert($askInfo);
  63. //将token返回给请求端
  64. $success['code'] = 1;
  65. $success['token'] = $token;
  66. return json_encode($success,JSON_UNESCAPED_UNICODE);
  67. }
  68. //对传入的参数进行校验
  69. public function check(){
  70. $token = request() -> param('token');
  71. $ragId = request() -> param('ragId');
  72. //通过获取的token获取对应的encryption
  73. $mapAskInfo['token'] = array('eq',$token);
  74. $information = db('askinfo') -> where($mapAskInfo) -> value('encryption');
  75. $information = base64UrlDecode($information);
  76. $information = json_decode($information);
  77. $information = stdClassObjToArray($information);
  78. if(!$information){
  79. $error['code'] = 6;
  80. $error['message'] = '非法请求,已拒绝。';
  81. return json_encode($error,JSON_UNESCAPED_UNICODE);
  82. }
  83. //通过sm4进行解密
  84. $smIV = $information['smIV'];
  85. $publicKey = $information['publicKey'];
  86. $encryptedBase64 = $information['encryptedBase64'];
  87. $mapProject['public_key'] = array('eq',$publicKey);
  88. $privateKey = db('Project') -> where($mapProject) -> value('private_key');
  89. $config = [
  90. 'mode' => 'cbc',
  91. 'key' => $privateKey, // 16 字节二进制密钥
  92. 'iv' => $smIV, // 16 字节二进制 IV
  93. 'hash' => false
  94. ];
  95. $sm4 = new EvitSM4Encryption($config);
  96. $pass = base64_decode($encryptedBase64);
  97. $decrypted = $sm4->decrypt($pass);
  98. $decrypted = base64_decode($decrypted);
  99. $information = json_decode($decrypted);
  100. $information = stdClassObjToArray($information);
  101. if(!$information){
  102. $error['code'] = 0;
  103. $error['message'] = '解密错误,请核对仔细核对参数!';
  104. return json_encode($error,JSON_UNESCAPED_UNICODE);
  105. }
  106. //获取接口请求信息
  107. $model = $information['model'];
  108. $network = $information['network'];
  109. $input = $information['input'];
  110. if(!is_array($input)){
  111. $error['code'] = 7;
  112. $error['message'] = '输入内容必须为数组格式!';
  113. return json_encode($error,JSON_UNESCAPED_UNICODE);
  114. }
  115. //判断模型是否存在
  116. $mapModel['model'] = array('eq',$model);
  117. $modelId = db('Model') -> where($mapModel) -> value('id');
  118. if($modelId){
  119. $mapModel['network'] = array('eq',$network);
  120. $modelId = db('Model') -> where($mapModel) -> value('id');
  121. //判断network参数是否正确
  122. if($modelId){
  123. //判断publicKey参数是否正确
  124. $mapProject['public_key'] = array('eq',$publicKey);
  125. $modelList = db('Project') -> where($mapProject) -> value('models');
  126. if($modelList){
  127. //判断publicKey是否具备模型权限
  128. $modelList = json_decode($modelList);
  129. if(in_array($modelId,$modelList)){
  130. $success['code'] = 5;
  131. $success['input'] = $input;
  132. $success['modelId'] = $modelId;
  133. if($ragId == 'empty'){
  134. $success['ragId'] = '';
  135. }
  136. else{
  137. //判断ragId和public是否存在关联关系
  138. $ragList = db('Project') -> where($mapProject) -> value('rags');
  139. $ragList = json_decode($ragList);
  140. $mapRag['ragid'] = array('eq',$ragId);
  141. $ragIdIncrement = db('Rag') -> where($mapRag) -> value('id');
  142. if(in_array($ragIdIncrement,$ragList)){
  143. $success['ragId'] = $ragId;
  144. }
  145. else{
  146. $error['code'] = 8;
  147. $error['message'] = '该公钥不具备该知识库权限,请联系管理员添加!';
  148. return json_encode($error,JSON_UNESCAPED_UNICODE);
  149. }
  150. }
  151. return json_encode($success,JSON_UNESCAPED_UNICODE);
  152. }
  153. else{
  154. $error['code'] = 4;
  155. $error['message'] = '该公钥不具备该模型权限,请联系管理员添加!';
  156. return json_encode($error,JSON_UNESCAPED_UNICODE);
  157. }
  158. }
  159. else{
  160. $error['code'] = 3;
  161. $error['message'] = '该公钥不正确,请核对参数“publicKey”的值!';
  162. return json_encode($error,JSON_UNESCAPED_UNICODE);
  163. }
  164. }
  165. else{
  166. $error['code'] = 2;
  167. $error['message'] = '该模型不支持该网络状态,请核对参数“network”的值!';
  168. return json_encode($error,JSON_UNESCAPED_UNICODE);
  169. }
  170. }
  171. else{
  172. $error['code'] = 1;
  173. $error['message'] = '模型不存在,请核对参数“model”的值!';
  174. return json_encode($error,JSON_UNESCAPED_UNICODE);
  175. }
  176. }
  177. //存储对应的回复记录
  178. public function reply(){
  179. $token = request() -> param('token');
  180. $reply = request() -> param('reply');
  181. $mapAskInfo['token'] = array('eq',$token);
  182. $data['reply'] = $reply;
  183. db('askinfo') -> where($mapAskInfo) -> update($data);
  184. $url = "http://192.168.10.115:3335/index/roleindex";
  185. $data["token"]= $token;
  186. curlPost($url,$data);
  187. }
  188. //供三方系统所支持的模型信息
  189. public function search(){
  190. //根据公钥查询模型列表
  191. $publicKey = request() -> param('publicKey');
  192. $mapProject['public_key'] = array('eq',$publicKey);
  193. $models = db('Project') -> where($mapProject) -> find();
  194. if($models){
  195. $modelList = json_decode($models['models']);
  196. //根据模型列表查询模型信息
  197. $mapModel['id'] = array('in',$modelList);
  198. $modelList = db('Model') -> where($mapModel) -> order('sort') -> select();
  199. $data['code'] = 1;
  200. $data['models'] = $modelList;
  201. return json($data,JSON_UNESCAPED_UNICODE) -> code(200);
  202. }
  203. else{
  204. $data['code'] = 0;
  205. $data['models'] = '该公钥并未配置模型权限,请联系管理员添加!';
  206. return json($data,JSON_UNESCAPED_UNICODE);
  207. }
  208. }
  209. //
  210. function handleChatTest() {
  211. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  212. http_response_code(405); // 405 Method Not Allowed
  213. echo json_encode(['error' => 'Only POST requests are allowed']);
  214. return;
  215. }
  216. $expectedToken = 'sk-d5f7c8b1a37c4a9ba24f905927a7b3f9';
  217. $targetUrl = 'http://192.168.10.115:9997/v1/chat/completions';
  218. // 获取请求体和头信息
  219. $requestBody = file_get_contents('php://input');
  220. $headers = getallheaders();
  221. $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
  222. // 校验 Authorization
  223. if ($authorizationHeader !== 'Bearer ' . $expectedToken) {
  224. http_response_code(403);
  225. echo json_encode(['error' => 'Authorization header']);
  226. return;
  227. }
  228. // 发起代理请求
  229. $ch = curl_init($targetUrl);
  230. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  231. curl_setopt($ch, CURLOPT_POST, true);
  232. curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
  233. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  234. 'Content-Type: application/json',
  235. 'Authorization: ' . $authorizationHeader
  236. ]);
  237. // 设置回调,边接收边输出
  238. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
  239. echo $data;
  240. // 立即刷新输出缓冲
  241. @ob_flush();
  242. @flush();
  243. return strlen($data);
  244. });
  245. // 返回响应
  246. header('Content-Type: application/json');
  247. $res = curl_exec($ch);
  248. if (curl_errno($ch)) {
  249. http_response_code(500);
  250. echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
  251. }
  252. curl_close($ch);
  253. }
  254. function handleChatapi() {
  255. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  256. http_response_code(405);
  257. echo json_encode(['error' => 'Only POST requests are allowed']);
  258. return;
  259. }
  260. // 关闭所有缓冲,强制流式输出
  261. @ini_set('output_buffering', 'off');
  262. @ini_set('zlib.output_compression', false);
  263. while (ob_get_level() > 0) {
  264. ob_end_flush();
  265. }
  266. ob_implicit_flush(true);
  267. // 设置流式响应头
  268. header('Content-Type: application/json; charset=utf-8');
  269. header('Cache-Control: no-cache');
  270. header('X-Accel-Buffering: no'); // 对 Nginx 有效,关闭缓冲
  271. $expectedToken = 'sk-d5f7c8b1a37c4a9ba24f905927a7b3f9';
  272. $targetUrl = 'http://192.168.10.115:19997/v1/chat/completions';
  273. $requestBody = file_get_contents('php://input');
  274. $headers = getallheaders();
  275. $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
  276. if ($authorizationHeader !== 'Bearer ' . $expectedToken) {
  277. http_response_code(403);
  278. echo json_encode(['error' => 'Invalid Authorization header']);
  279. return;
  280. }
  281. $ch = curl_init($targetUrl);
  282. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  283. curl_setopt($ch, CURLOPT_POST, true);
  284. curl_setopt($ch, CURLOPT_TIMEOUT, 0);
  285. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  286. curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
  287. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  288. 'Content-Type: application/json',
  289. 'Authorization: ' . $authorizationHeader
  290. ]);
  291. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
  292. echo $data;
  293. @ob_flush();
  294. @flush();
  295. return strlen($data);
  296. });
  297. $logFile = __DIR__ . '/handleChat.log';
  298. $timestamp = date('[Y-m-d H:i:s]');
  299. file_put_contents($logFile, $timestamp . ' ' .$requestBody .PHP_EOL, FILE_APPEND);
  300. $res = curl_exec($ch);
  301. if (curl_errno($ch)) {
  302. http_response_code(500);
  303. echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
  304. }
  305. curl_close($ch);
  306. $timestamp = date('[Y-m-d H:i:s]');
  307. file_put_contents($logFile, $timestamp . ' ' .PHP_EOL, FILE_APPEND);
  308. }
  309. function handleEmbedding() {
  310. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  311. http_response_code(405);
  312. echo json_encode(['error' => 'Only POST requests are allowed']);
  313. return;
  314. }
  315. $expectedToken = 'sk-a9de61b8b354442a98e842d9ecf2a204';
  316. $targetUrl = 'http://192.168.10.115:19997/v1/embeddings';
  317. $headers = array_change_key_case(getallheaders(), CASE_LOWER);
  318. if (!isset($headers['authorization'])) {
  319. http_response_code(401);
  320. echo json_encode(['error' => 'Missing Authorization header']);
  321. return;
  322. }
  323. $authHeader = $headers['authorization'];
  324. if ($authHeader !== 'Bearer ' . $expectedToken) {
  325. http_response_code(403);
  326. echo json_encode(['error' => 'Invalid API token']);
  327. return;
  328. }
  329. $requestBody = file_get_contents('php://input');
  330. $ch = curl_init($targetUrl);
  331. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  332. curl_setopt($ch, CURLOPT_POST, true);
  333. curl_setopt($ch, CURLOPT_TIMEOUT, 0);
  334. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  335. curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
  336. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  337. 'Content-Type: application/json',
  338. 'accept: application/json',
  339. 'Authorization: ' . $authHeader,
  340. ]);
  341. curl_setopt($ch, CURLOPT_HEADER, true);
  342. curl_setopt($ch, CURLOPT_ENCODING, ''); // 支持所有编码,防止自动解压影响
  343. $response = curl_exec($ch);
  344. if (curl_errno($ch)) {
  345. http_response_code(500);
  346. echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
  347. curl_close($ch);
  348. return;
  349. }
  350. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  351. $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  352. curl_close($ch);
  353. $responseHeaders = substr($response, 0, $headerSize);
  354. $responseBody = substr($response, $headerSize);
  355. // 关闭所有输出缓冲区,防止格式被修改
  356. while (ob_get_level()) {
  357. ob_end_clean();
  358. }
  359. // 只转发 Content-Type,避免冲突
  360. foreach (explode("\r\n", $responseHeaders) as $headerLine) {
  361. if (stripos($headerLine, 'Content-Type:') === 0) {
  362. header($headerLine);
  363. }
  364. }
  365. http_response_code($httpCode);
  366. // 直接原样输出响应体,不做任何json_encode或修改
  367. echo $responseBody;
  368. }
  369. //查询RAG列表
  370. public function searchRag(){
  371. //根据公钥查询模型列表
  372. $publicKey = request() -> param('publicKey');
  373. $mapProject['public_key'] = array('eq',$publicKey);
  374. $rags = db('Project') -> where($mapProject) -> find();
  375. if($rags){
  376. $ragList = json_decode($rags['rags']);
  377. //根据模型列表查询模型信息
  378. $mapRag['id'] = array('in',$ragList);
  379. $ragList = db('Rag') -> where($mapRag) -> select();
  380. $data['code'] = 1;
  381. $data['rags'] = $ragList;
  382. return json($data, JSON_UNESCAPED_UNICODE) -> code(200);
  383. }
  384. else{
  385. $data['code'] = 0;
  386. $data['models'] = '该公钥并未配置知识库权限,请联系管理员添加!';
  387. return json($data,JSON_UNESCAPED_UNICODE);
  388. }
  389. }
  390. //查询RAG列表
  391. public function searchagents(){
  392. //根据公钥查询模型列表
  393. $publicKey = request() -> param('publicKey');
  394. $mapProject['public_key'] = array('eq',$publicKey);
  395. $agents = db('Project') -> where($mapProject) -> find();
  396. if($agents){
  397. $agentsList = json_decode($agents['agents']);
  398. //根据模型列表查询模型信息
  399. $mapRag['id'] = array('in',$agentsList);
  400. $agentsList = db('agent') -> where($mapRag) -> select();
  401. $data['code'] = 1;
  402. $data['agents'] = $agentsList;
  403. return json($data,JSON_UNESCAPED_UNICODE) -> code(200);
  404. }
  405. else{
  406. $data['code'] = 0;
  407. $data['models'] = '该公钥并未配置智能体权限,请联系管理员添加!';
  408. return json($data,JSON_UNESCAPED_UNICODE);
  409. }
  410. }
  411. //检索增强接口
  412. public function ragData(){
  413. $input = request() -> param('input');
  414. $kid = request() -> param('kid');
  415. $RAGdata = [
  416. "username" => "test",
  417. "password" => "test123"
  418. ];
  419. // 调用时只需传递非 Content-Type/Accept 的 Header
  420. $headers = [
  421. 'Cache-Control: no-cache',
  422. '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'
  423. ];
  424. $urlRAG = "http://192.168.10.115:6039/auth/login"; // 替换为实际 URL
  425. $id = curlPostRAG($urlRAG, $RAGdata, $headers);
  426. $token = $id; // 默认启用 JSON 模式
  427. $token = json_decode($token);
  428. $token = stdClassObjToArray($token);
  429. $token = $token['data']['token'];
  430. $url = "http://192.168.10.115:6039/rag/schemaNoReRetrieval"; // 替换成实际接口地址
  431. $data = [
  432. "messages" => $input, // 替换成实际用户输入
  433. "model" => "123", // 替换成实际模型名称
  434. "maxDistance" => 0.7, // 替换成实际分数(浮点数)
  435. "kid" => $kid // 替换成实际知识库 ID
  436. ];
  437. // 初始化 cURL
  438. $ch = curl_init();
  439. // 设置 cURL 选项
  440. curl_setopt($ch, CURLOPT_URL, $url);
  441. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
  442. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  443. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  444. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  445. "Authorization: Bearer " . $token,
  446. "Content-Type: application/json" // 声明请求体是 JSON
  447. ]);
  448. // 执行请求并获取响应
  449. $response = curl_exec($ch);
  450. // 检查是否有错误
  451. if (curl_errno($ch)) {
  452. echo "cURL 请求失败: " . curl_error($ch);
  453. } else {
  454. // 解析 JSON 响应
  455. //$result = json_decode($response, true);
  456. return $response; // 输出返回数据(prompt, vector, nearest)
  457. }
  458. // 关闭 cURL 资源
  459. curl_close($ch);
  460. }
  461. //查询生命体征数据
  462. public function vitalSignsData(){
  463. $number = request() -> param('number');
  464. $data["number"] = request() -> param('number');
  465. if(!isset($number) || $number == "" ){
  466. return ("未输入患者编号,请输入。");
  467. }
  468. $data["lowerBloodPressure"] = request() -> param('lowerBloodPressure');
  469. $data["upperBloodPressure"] = request() -> param('upperBloodPressure');
  470. $data["heartRate"] = request() -> param('heartRate');
  471. $data["temperature"] = request() -> param('temperature');
  472. $data["bloodOxygen"] = request() -> param('bloodOxygen');
  473. $data["breatheRate"] = request() -> param('breatheRate');
  474. $data["name"] = request() -> param('name');
  475. $data["sex"] = request() -> param('sex');
  476. $data["age"] = request() -> param('age');
  477. $data["deptName"] = request() -> param('deptName');
  478. $data["doctor"] = request() -> param('doctor');
  479. $alarmType = request() -> param('alarmType');
  480. $data["alarmType"] = request() -> param('alarmType');
  481. if(!isset($alarmType) || trim($alarmType) === "" || $alarmType == "" ){
  482. return ("未输入异常类型,请输入。");
  483. }
  484. $data = json_encode($data,JSON_UNESCAPED_UNICODE);
  485. $urlvitalsigns = "http://192.168.10.115:6039/patient/vitalSigns";
  486. $headers = [
  487. 'Content-Type: application/json'
  488. ];
  489. $response = curlPost($urlvitalsigns,$data,$headers);
  490. return $response;
  491. }
  492. public function test123(){
  493. $data["input"] = "?";
  494. $data["kid"] = '1947484295610253313';
  495. // $data = json_encode($data, JSON_UNESCAPED_UNICODE);
  496. // dump($data);
  497. // exit;
  498. $url = "http://192.168.10.115:3338/apis/knowledgeMessage";
  499. $a = curlPost($url,$data);
  500. return $a;
  501. }
  502. public function testhttp(){
  503. $data["token"] = "c9fce85232e25a803f3b0e17714a674b";
  504. $data["ragId"] = '1947484295610253313';
  505. // $data = json_encode($data, JSON_UNESCAPED_UNICODE);
  506. // dump($data);
  507. // exit;
  508. $url = "http://192.168.10.115:3340";
  509. $a = curlPost($url,$data);
  510. return $a;
  511. }
  512. //供三方系统的检索增强接口
  513. public function knowledgeMessage(){
  514. // $input = request() -> param('input');
  515. // $kid = request() -> param('kid');
  516. $json = file_get_contents('php://input');
  517. $json = json_decode($json);
  518. $json = stdClassObjToArray($json);
  519. if($json){
  520. $input = $json['input'];
  521. $kid = $json['kid'];
  522. }
  523. $count = request() -> param('count');
  524. // $input = $_POST['input'];
  525. // $kid = $_POST['kid'];
  526. $count = json_decode($count);
  527. $count = stdClassObjToArray($count);
  528. // echo($input);
  529. // exit;
  530. if($count){
  531. $input = $count['input'];
  532. $kid = $count['kid'];
  533. }
  534. if(!$input){
  535. echo '{"code":500,"msg":"cURL 请求失败: 请检查参数。","data":null}';
  536. exit;
  537. }
  538. if(!$kid){
  539. echo '{"code":500,"msg":"cURL 请求失败: 请检查参数。","data":null}';
  540. exit;
  541. }
  542. $RAGdata = [
  543. "username" => "test",
  544. "password" => "test123"
  545. ];
  546. // 调用时只需传递非 Content-Type/Accept 的 Header
  547. $headers = [
  548. 'Cache-Control: no-cache',
  549. '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'
  550. ];
  551. $urlRAG = "http://192.168.10.115:6039/auth/login"; // 替换为实际 URL
  552. $id = curlPostRAG($urlRAG, $RAGdata, $headers);
  553. $token = $id; // 默认启用 JSON 模式
  554. $token = json_decode($token);
  555. $token = stdClassObjToArray($token);
  556. $token = $token['data']['token'];
  557. $url = "http://192.168.10.115:6039/rag/schema"; // 替换成实际接口地址
  558. $data = [
  559. "messages" => $input, // 替换成实际用户输入
  560. "model" => "123", // 替换成实际模型名称
  561. "maxDistance" => 0.7, // 替换成实际分数(浮点数)
  562. "kid" => $kid // 替换成实际知识库 ID
  563. ];
  564. // 初始化 cURL
  565. $ch = curl_init();
  566. // 设置 cURL 选项
  567. curl_setopt($ch, CURLOPT_URL, $url);
  568. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
  569. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  570. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  571. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  572. "Authorization: Bearer " . $token,
  573. "Content-Type: application/json" // 声明请求体是 JSON
  574. ]);
  575. // 执行请求并获取响应
  576. $response = curl_exec($ch);
  577. // 检查是否有错误
  578. if (strpos($response, "code") !== false) {
  579. $response = json_decode($response);
  580. echo '{"code":'.$response ->code.',"msg":"cURL 请求失败: 请检查参数。","data":null}';
  581. exit;
  582. } else {
  583. // 解析 JSON 响应
  584. $response = json_decode($response, true);
  585. $response["code"] = 200;
  586. $response = json_encode($response, JSON_UNESCAPED_UNICODE);
  587. return $response; // 输出返回数据(prompt, vector, nearest)
  588. }
  589. // 关闭 cURL 资源
  590. curl_close($ch);
  591. }
  592. public function MCPData(){
  593. $input = [ [
  594. "content" => "你好",
  595. "role" => "user"
  596. ],
  597. [
  598. "content" => "你好!我是EMOON AI助手,有什么可以帮助你的吗?",
  599. "role" => "assistant"
  600. ],
  601. [
  602. "content" => "查询2025年6月1日到2025年6月2的医院数据 并计算这三天外科的平均住院人数是多少?",
  603. "role" => "user"
  604. ],
  605. ];
  606. $kid = "";
  607. $RAGdata = [
  608. "username" => "test",
  609. "password" => "test123"
  610. ];
  611. // 调用时只需传递非 Content-Type/Accept 的 Header
  612. $headers = [
  613. 'Cache-Control: no-cache',
  614. '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'
  615. ];
  616. $urlRAG = "http://192.168.10.115:6039/auth/login"; // 替换为实际 URL
  617. $id = curlPostRAG($urlRAG, $RAGdata, $headers);
  618. $token = $id; // 默认启用 JSON 模式
  619. $token = json_decode($token);
  620. $token = stdClassObjToArray($token);
  621. $token = $token['data']['token'];
  622. $url = "http://192.168.10.115:6039/chat/send"; // 替换成实际接口地址
  623. $data = [
  624. "messages" => $input,
  625. "model" => "qwen3-8B", //X
  626. "temperature" => 0.5,
  627. "top_p" => 1,
  628. "presence_penalty" => 0,
  629. "frequency_penalty" => 0,
  630. "kid" => $kid,
  631. "chat_type" => 0,
  632. "appId" => "",
  633. "stream" => true
  634. ];
  635. // 初始化 cURL
  636. $ch = curl_init();
  637. // 设置 cURL 选项
  638. curl_setopt($ch, CURLOPT_URL, $url);
  639. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
  640. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  641. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  642. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  643. "Authorization: Bearer " . $token,
  644. "Content-Type: application/json" // 声明请求体是 JSON
  645. ]);
  646. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  647. // 执行请求并获取响应
  648. $response = curl_exec($ch);
  649. $lines = explode("\n", $response);
  650. $output = '';
  651. foreach ($lines as $line) {
  652. if (strpos($line, 'event:chat_completion') !== false) {
  653. // 提取data部分
  654. $content = str_replace('event:chat_completion data:', '', $line);
  655. $output .= trim($content);
  656. } elseif (trim($line) === '[DONE]') {
  657. // 处理结束标志
  658. $output .= "\n[传输结束]";
  659. }
  660. }
  661. // 现在$output包含所有提取的内容
  662. echo $output;
  663. // 关闭 cURL 资源
  664. curl_close($ch);
  665. }
  666. public function handleChat() {
  667. // 关闭所有缓冲,强制流式输出
  668. @ini_set('output_buffering', 'off');
  669. @ini_set('zlib.output_compression', false);
  670. while (ob_get_level() > 0) {
  671. ob_end_flush();
  672. }
  673. ob_implicit_flush(true);
  674. // 设置流式响应头
  675. header('Content-Type: text/event-stream; charset=utf-8');
  676. header('Cache-Control: no-cache');
  677. header('X-Accel-Buffering: no'); // 对 Nginx 有效,关闭缓冲
  678. $requestBody = file_get_contents('php://input');
  679. $headers = getallheaders();
  680. $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
  681. $input = [ [
  682. "content" => "你好",
  683. "role" => "user"
  684. ],
  685. [
  686. "content" => "你好!我是EMOON AI助手,有什么可以帮助你的吗?",
  687. "role" => "assistant"
  688. ],
  689. [
  690. "content" => "查询2025年6月1日到2025年6月2的医院数据 并计算这三天外科的平均住院人数是多少?",
  691. "role" => "user"
  692. ],
  693. ];
  694. $kid = "";
  695. $RAGdata = [
  696. "username" => "test",
  697. "password" => "test123"
  698. ];
  699. // 调用时只需传递非 Content-Type/Accept 的 Header
  700. $headers = [
  701. 'Cache-Control: no-cache',
  702. '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'
  703. ];
  704. $urlRAG = "http://192.168.10.115:6039/auth/login"; // 替换为实际 URL
  705. $id = curlPostRAG($urlRAG, $RAGdata, $headers);
  706. $token = $id; // 默认启用 JSON 模式
  707. $token = json_decode($token);
  708. $token = stdClassObjToArray($token);
  709. $token = $token['data']['token'];
  710. $url = "http://192.168.10.115:6039/chat/send"; // 替换成实际接口地址
  711. $data = [
  712. "messages" => $input,
  713. "model" => "qwen3-32B", //X
  714. "temperature" => 0.5,
  715. "top_p" => 1,
  716. "presence_penalty" => 0,
  717. "frequency_penalty" => 0,
  718. "kid" => $kid,
  719. "chat_type" => 0,
  720. "appId" => "",
  721. "stream" => true
  722. ];
  723. // 初始化 cURL
  724. $ch = curl_init();
  725. // 设置 cURL 选项
  726. curl_setopt($ch, CURLOPT_URL, $url);
  727. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); // 返回响应数据
  728. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  729. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  730. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  731. "Authorization: Bearer " . $token,
  732. "Content-Type: application/json" // 声明请求体是 JSON
  733. ]);
  734. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($url, $data) {
  735. echo $data;
  736. @ob_flush();
  737. @flush();
  738. return strlen($data);
  739. });
  740. $res = curl_exec($ch);
  741. curl_close($ch);
  742. }
  743. // public function MCPData() {
  744. // // 1. 强制设置SSE头并关闭缓冲
  745. // header('Content-Type: text/event-stream');
  746. // header('Cache-Control: no-cache');
  747. // ob_end_flush();
  748. // // 2. 模拟流式输出
  749. // for ($i = 1; $i <= 5; $i++) {
  750. // echo "event: test\n";
  751. // echo "data: " . json_encode(['count' => $i, 'time' => date('H:i:s')]) . "\n\n";
  752. // ob_flush();
  753. // flush();
  754. // sleep(1); // 模拟延迟
  755. // }
  756. // // 3. 结束标记
  757. // echo "event: end\n";
  758. // echo "data: {\"status\": \"complete\"}\n\n";
  759. // ob_flush();
  760. // flush();
  761. // }
  762. //生成随机key
  763. public function getKey() {
  764. $count = request() -> param('count');
  765. $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  766. $randomString = '';
  767. for ($i = 0; $i < $count; $i++) {
  768. $index = rand(0, strlen($characters) - 1);
  769. $randomString .= $characters[$index];
  770. }
  771. return $randomString;
  772. }
  773. //创建一个测试用例
  774. public function demo(){
  775. dump('-----------------------------');
  776. dump('【参数处理对照DEMO】');
  777. $information['model'] = 'emoon-E1-13B';
  778. $information['network'] = '1';
  779. $messages = [
  780. [
  781. 'role' => 'user',
  782. 'content' => "What is the highest mountain in the world?"
  783. ],
  784. [
  785. 'role' => 'assistant',
  786. 'content' => 'The highest mountain in the world is Mount Everest.'
  787. ],
  788. [
  789. 'role' => 'user',
  790. 'content' => 'What is the second?'
  791. ]
  792. ];
  793. $information['input'] = $messages;
  794. dump('-----------------------------');
  795. dump('1.数组');
  796. dump($information);
  797. //从后端生成是这种格式
  798. $data = json_encode($information, JSON_UNESCAPED_UNICODE);
  799. //从前端直接取值是这种格式
  800. //$data = '{"model":"emoon-E1-13B","network":"1","input":"[{\"role\":\"assistant\",\"content\":\"你好,我是医疗大语言模型「EMOON E1」,请问有什么可以帮您?\"},{\"role\":\"user\",\"content\":\"请问你是什么模型?\"},{\"role\":\"assistant\",\"content\":\"您好!我是EMOON E1 13B模型,一个专注于医疗领域的大语言模型。我由回车网络(EnterLO)训练研发,专门设计来提供医疗专业知识的解读和分析。如果您有任何医疗相关的问题或需要专业建议,我会尽力提供准确和有用的信息。请问有什么具体的医疗问题我可以帮您解答吗?\"},{\"role\":\"user\",\"content\":\"常见的脑科疾病以及对应的预防办法有哪些?\"}]"}';
  801. dump('-----------------------------');
  802. dump('2.数组转 json');
  803. dump($data);
  804. $data = base64_encode($data);
  805. dump('-----------------------------');
  806. dump('3.将 json 转换为 base64');
  807. dump($data);
  808. $config = [
  809. 'mode' => 'cbc',
  810. 'key' => 'VKc17yt2QiNZO8Ci', // 16 字节二进制密钥
  811. 'iv' => '1234567891478523', // 16 字节二进制 IV
  812. 'hash' => false
  813. ];
  814. dump('-----------------------------');
  815. dump('4.构建 sm4 参数,参数为:');
  816. dump($config);
  817. $sm4 = new EvitSM4Encryption($config);
  818. $encryptedBinary = $sm4->encrypt($data);
  819. dump('-----------------------------');
  820. dump('5.将 base64 进行 sm4 加密,此时为二进制文件');
  821. dump($encryptedBinary);
  822. $encryptedBase64 = base64_encode($encryptedBinary);
  823. dump('-----------------------------');
  824. dump('6.将二进制 转换为 Base64');
  825. dump($encryptedBase64);
  826. $modifiedData['encryptedBase64'] = $encryptedBase64;
  827. $modifiedData['smIV'] = '1234567891478523';
  828. $modifiedData['publicKey'] = 'tHJZp9mJQPJ4CJAu19F6vhIVa1cyZhP8';
  829. dump('-----------------------------');
  830. dump('7.构造最终的请求体数组');
  831. dump($modifiedData);
  832. $modifiedData = json_encode($modifiedData,JSON_UNESCAPED_UNICODE);
  833. dump('-----------------------------');
  834. dump('8.将请求体数组转换为 json');
  835. dump($modifiedData);
  836. $modifiedData = base64_encode($modifiedData);
  837. dump('-----------------------------');
  838. dump('9.将请求体 json 转换为 Base64');
  839. dump($modifiedData);
  840. $modifiedData = strtr($modifiedData, '+/', '-_');
  841. dump('-----------------------------');
  842. dump('10.// 将 + 替换为 -,/ 替换为 _');
  843. dump($modifiedData);
  844. dump('-----------------------------');
  845. dump('END.完成构建,将该字符串请求 https://open.emoon.com/apiSSE.php?information=XXXX');
  846. dump('-----------------------------');
  847. exit;
  848. }
  849. //sm4加密
  850. public function password() {
  851. $config = [
  852. 'mode' => 'cbc',
  853. 'key' => 'jdujuujhjuiki987', // 16 字节二进制密钥
  854. 'iv' => 'jdujuujhjuiki988', // 16 字节二进制 IV
  855. 'hash' => false
  856. ];
  857. $sm4 = new EvitSM4Encryption($config);
  858. // 加密
  859. $plaintext = 'nihao';
  860. $encryptedBinary = $sm4->encrypt($plaintext);
  861. // 将二进制结果转换为 Base64
  862. $encryptedBase64 = base64_encode($encryptedBinary);
  863. var_dump("Cipher text (Base64): " . $encryptedBase64);
  864. }
  865. //sm4解密
  866. public function unpassword(){
  867. $config = [
  868. 'mode' => 'cbc',
  869. 'key' => 'jdujuujhjuiki987', // 16 字节二进制密钥
  870. 'iv' => 'jdujuujhjuiki988', // 16 字节二进制 IV
  871. 'hash' => false
  872. ];
  873. $sm4 = new EvitSM4Encryption($config);
  874. // Decrypt
  875. $pass = 'fI7Cs/lAmFzG7EIuMKAyPQ==';
  876. $pass = base64_decode($pass);
  877. $decrypted = $sm4->decrypt($pass);
  878. var_dump("Plain text(Base64): " . $decrypted);
  879. }
  880. //获取对应的回复记录
  881. public function getreply(){
  882. $token = request() -> param('token');
  883. $mapAskInfo['token'] = array('eq',$token);
  884. $reply = db('askinfo') -> where($mapAskInfo) -> value('reply');
  885. return $reply;
  886. }
  887. public function role(){
  888. $askInfoId = request() -> param('askInfoId');
  889. // $askInfoId = '613802ffbe0b9534fd58606e7f9d8b74';
  890. $map['token'] = array('eq', $askInfoId);
  891. $rulename = db('askinfo')->where($map)->value('decrypt');
  892. $rulename = json_decode($rulename);
  893. $rulename = stdClassObjToArray($rulename);
  894. $rulecontent = db('askinfo')->where($map)->value('reply');
  895. $rulename['reply'] = $rulecontent;
  896. $rulename = json_encode($rulename,JSON_UNESCAPED_UNICODE);
  897. return $rulename;
  898. }
  899. //检索增强接口
  900. public function ragDataTEST(){
  901. $ruleCode = request() -> param('ruleCode');
  902. $medicalContent = request() -> param('medicalContent');
  903. $kid = request() -> param('kid');
  904. $RAGdata = [
  905. "username" => "admin",
  906. "password" => "admin123"
  907. ];
  908. // 调用时只需传递非 Content-Type/Accept 的 Header
  909. $headers = [
  910. 'Cache-Control: no-cache',
  911. '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'
  912. ];
  913. $urlRAG = "http://192.168.10.115:6039/auth/login"; // 替换为实际 URL
  914. $id = curlPostRAG($urlRAG, $RAGdata, $headers);
  915. $token = $id; // 默认启用 JSON 模式
  916. $token = json_decode($token);
  917. $token = stdClassObjToArray($token);
  918. $token = $token['data']['token'];
  919. $url = "http://192.168.10.115:6039/system/ruleFinal/fetchMatchingRules"; // 替换成实际接口地址
  920. $data = [
  921. "medicalContent" => $medicalContent, // 替换成实际用户输入
  922. "ruleCode" => $ruleCode, // 替换成实际模型名称
  923. "kid" => $kid // 替换成实际知识库 ID
  924. ];
  925. // 初始化 cURL
  926. $ch = curl_init();
  927. // 设置 cURL 选项
  928. curl_setopt($ch, CURLOPT_URL, $url);
  929. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
  930. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  931. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  932. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  933. "Authorization: Bearer " . $token,
  934. "Content-Type: application/json" // 声明请求体是 JSON
  935. ]);
  936. // 执行请求并获取响应
  937. $response = curl_exec($ch);
  938. // 检查是否有错误
  939. if (curl_errno($ch)) {
  940. echo "cURL 请求失败: " . curl_error($ch);
  941. } else {
  942. // 解析 JSON 响应
  943. //$result = json_decode($response, true);
  944. return $response; // 输出返回数据(prompt, vector, nearest)
  945. }
  946. // 关闭 cURL 资源
  947. curl_close($ch);
  948. }
  949. //检索增强接口
  950. public function ragDataMCQC(){
  951. $ruleCode = request() -> param('ruleCode');
  952. $medicalContent = request() -> param('medicalContent');
  953. $kid = request() -> param('kid');
  954. // $ruleCode = 'RYJLZS0002';
  955. // $medicalContent = 'medicalContent';
  956. // $kid = 'Rule_Final';
  957. $url = "http://192.168.10.115:6039/system/ruleFinal/fetchMatchingRules"; // 替换成实际接口地址
  958. $data = [
  959. "medicalContent" => $medicalContent, // 替换成实际用户输入
  960. "ruleCode" => $ruleCode, // 替换成实际模型名称
  961. "kid" => $kid // 替换成实际知识库 ID
  962. ];
  963. // 初始化 cURL
  964. $ch = curl_init();
  965. // 设置 cURL 选项
  966. curl_setopt($ch, CURLOPT_URL, $url);
  967. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
  968. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  969. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  970. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  971. // "Authorization: Bearer " . $token,
  972. "Content-Type: application/json" // 声明请求体是 JSON
  973. ]);
  974. // 执行请求并获取响应
  975. $response = curl_exec($ch);
  976. // 检查是否有错误
  977. if (curl_errno($ch)) {
  978. echo "cURL 请求失败: " . curl_error($ch);
  979. } else {
  980. // 解析 JSON 响应
  981. //$result = json_decode($response, true);
  982. return $response; // 输出返回数据(prompt, vector, nearest)
  983. }
  984. // 关闭 cURL 资源
  985. curl_close($ch);
  986. }
  987. }