Index.php 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. <?php
  2. namespace app\index\controller;
  3. use think\Request;
  4. use think\Db;
  5. class Index extends \think\Controller
  6. {
  7. //主页
  8. public function index(){
  9. //判断用户设备是否是移动端
  10. $mobileType = 'unknow';
  11. //判断用户设备是否是移动端
  12. if(isMobile() == true){
  13. $device = 'phone';
  14. $mobileType = mobileType();
  15. }
  16. else{
  17. $device = 'pc';
  18. }
  19. //获取当前年份
  20. $year = date('Y',time());
  21. //获取公共路径
  22. $commonURL = commonURL();
  23. //构建微信分享参数
  24. $appId = commonAPPID();
  25. $timestamp = time();
  26. $nonceStr = nonceStr(16);
  27. $url = commonURL().'/';
  28. $jsapiTicket = getOfficialJsapiTicket();
  29. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  30. $signature = sha1($string);
  31. return view('index', [
  32. 'device' => $device,
  33. 'mobileType' => $mobileType,
  34. 'year' => $year,
  35. 'commonURL' => $commonURL,
  36. 'appId' => $appId,
  37. 'timestamp' => $timestamp,
  38. 'nonceStr' => $nonceStr,
  39. 'signature' => $signature,
  40. ]);
  41. }
  42. //主页
  43. public function upload(){
  44. return view('upload');
  45. }
  46. //404
  47. public function errorPage(){
  48. //判断用户设备是否是移动端
  49. if(isMobile() == true){
  50. $device = 'phone';
  51. }
  52. else{
  53. $device = 'pc';
  54. }
  55. //获取公共路径
  56. $commonURL = commonURL();
  57. //获取公共路径
  58. $commonOpenURL = commonOpenURL();
  59. return view('error', [
  60. 'device' => $device,
  61. 'commonURL' => $commonURL,
  62. 'commonOpenURL' => $commonOpenURL,
  63. ]);
  64. }
  65. //客户端
  66. public function chatBox(){
  67. $ragId = request() -> param('ragId');
  68. $mobileType = 'unknow';
  69. $data['publicKey'] = commonPublicKey();
  70. $url = commonOpenURLLocal()."/apis/searchRag";
  71. $ragList = curlPost($url,$data);
  72. $ragList = json_decode($ragList);
  73. $ragList = stdClassObjToArray($ragList);
  74. if($ragList["code"] != 0){
  75. $ragList = $ragList['rags'];
  76. }
  77. $ragList = json_encode($ragList);
  78. $urlagent = commonOpenURLLocal()."/Apis/searchagents";
  79. $agentList = curlPost($urlagent,$data);
  80. $agentList = json_decode($agentList);
  81. $agentList = stdClassObjToArray($agentList);
  82. if($agentList ["code"] != 0){
  83. $agentList = $agentList['agents'];
  84. }
  85. $agentList = json_encode($agentList);
  86. // dump($ragList);
  87. // exit;
  88. //判断用户设备是否是移动端
  89. if(isMobile() == true){
  90. $device = 'phone';
  91. $mobileType = mobileType();
  92. }
  93. else{
  94. $device = 'pc';
  95. }
  96. //获取公共路径
  97. $commonURL = commonURL();
  98. //获取当前时间
  99. $now = date('Y-m-d H:i:s',time());
  100. //获取提问示例
  101. $question = db('Question') -> order('id DESC') -> select();
  102. // dump($question);
  103. // exit;
  104. //获取一个标记当前用户的传参
  105. $user = request() -> param('user');
  106. if(!$user){
  107. $user = rand(10000,99999);
  108. }
  109. //构建微信分享参数
  110. $appId = commonAPPID();
  111. $timestamp = time();
  112. $nonceStr = nonceStr(16);
  113. $url = commonURL().'/index/chatBox?user='.$user;
  114. $jsapiTicket = getOfficialJsapiTicket();
  115. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  116. $signature = sha1($string);
  117. // dump($userData[0]["strate"]);
  118. // exit;
  119. return view('chatBox', [
  120. 'device' => $device,
  121. 'mobileType' => $mobileType,
  122. 'commonURL' => $commonURL,
  123. 'now' => $now,
  124. 'question' => $question,
  125. 'commonOpenURLSSE' => commonOpenURLSSE(),
  126. 'commonOpenURLLocalSSE' => commonOpenURLLocalSSE(),
  127. 'commonWebsocket' => commonWebsocket(),
  128. 'user' => $user,
  129. 'ragList' => $ragList,
  130. 'agentList' => $agentList,
  131. 'appId' => $appId,
  132. 'timestamp' => $timestamp,
  133. 'nonceStr' => $nonceStr,
  134. 'signature' => $signature,
  135. 'ragId' => $ragId,
  136. ]);
  137. // return $url;
  138. }
  139. //客户端
  140. public function chatBox1(){
  141. $ragId = request() -> param('ragId');
  142. $mobileType = 'unknow';
  143. $data['publicKey'] = commonPublicKey();
  144. $url = commonOpenURLLocal()."/apis/searchRag";
  145. $ragList = curlPost($url,$data);
  146. if($ragList != null){
  147. $ragList = json_decode($ragList);
  148. $ragList = $ragList->rags;
  149. $ragList = stdClassObjToArray($ragList);
  150. }
  151. $urlagent = commonOpenURLLocal()."/Apis/searchagents";
  152. $agentList = curlPost($urlagent,$data);
  153. if($agentList != null){
  154. $agentList = json_decode($agentList);
  155. $agentList = $agentList->agents;
  156. $agentList = stdClassObjToArray($agentList);
  157. }
  158. // dump($ragList);
  159. // exit;
  160. //判断用户设备是否是移动端
  161. if(isMobile() == true){
  162. $device = 'phone';
  163. $mobileType = mobileType();
  164. }
  165. else{
  166. $device = 'pc';
  167. }
  168. //获取公共路径
  169. $commonURL = commonURL();
  170. //获取当前时间
  171. $now = date('Y-m-d H:i:s',time());
  172. //获取提问示例
  173. $question = db('Question') -> order('id DESC') -> select();
  174. // dump($question);
  175. // exit;
  176. //获取一个标记当前用户的传参
  177. $user = request() -> param('user');
  178. if(!$user){
  179. $user = rand(10000,99999);
  180. }
  181. //构建微信分享参数
  182. $appId = commonAPPID();
  183. $timestamp = time();
  184. $nonceStr = nonceStr(16);
  185. $url = commonURL().'/index/chatBox1?user='.$user;
  186. $jsapiTicket = getOfficialJsapiTicket();
  187. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  188. $signature = sha1($string);
  189. return view('chatBox1', [
  190. 'device' => $device,
  191. 'mobileType' => $mobileType,
  192. 'commonURL' => $commonURL,
  193. 'now' => $now,
  194. 'question' => $question,
  195. 'commonOpenURLSSE' => commonOpenURLSSE(),
  196. 'commonOpenURLLocalSSE' => commonOpenURLLocalSSE(),
  197. 'commonWebsocket' => commonWebsocket(),
  198. 'user' => $user,
  199. 'ragList' => $ragList,
  200. 'agentList' => $agentList,
  201. 'appId' => $appId,
  202. 'timestamp' => $timestamp,
  203. 'nonceStr' => $nonceStr,
  204. 'signature' => $signature,
  205. 'ragId' => $ragId,
  206. ]);
  207. // return $url;
  208. }
  209. //GPUs
  210. public function gpu(){
  211. //判断用户设备是否是移动端
  212. $mobileType = 'unknow';
  213. //判断用户设备是否是移动端
  214. if(isMobile() == true){
  215. $device = 'phone';
  216. $mobileType = mobileType();
  217. }
  218. else{
  219. $device = 'pc';
  220. }
  221. //获取当前年份
  222. $year = date('Y',time());
  223. //获取公共路径
  224. $commonURL = commonURL();
  225. //构建微信分享参数
  226. $appId = commonAPPID();
  227. $timestamp = time();
  228. $nonceStr = nonceStr(16);
  229. $url = commonURL().'/index/gpu';
  230. $jsapiTicket = getOfficialJsapiTicket();
  231. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  232. $signature = sha1($string);
  233. return view('gpu', [
  234. 'device' => $device,
  235. 'mobileType' => $mobileType,
  236. 'year' => $year,
  237. 'commonURL' => $commonURL,
  238. 'appId' => $appId,
  239. 'timestamp' => $timestamp,
  240. 'nonceStr' => $nonceStr,
  241. 'signature' => $signature,
  242. ]);
  243. }
  244. //数据蒸馏中心页面
  245. public function distill(){
  246. //判断用户设备是否是移动端
  247. $mobileType = 'unknow';
  248. //判断用户设备是否是移动端
  249. if(isMobile() == true){
  250. $device = 'phone';
  251. $mobileType = mobileType();
  252. }
  253. else{
  254. $device = 'pc';
  255. }
  256. //获取当前年份
  257. $year = date('Y',time());
  258. //获取公共路径
  259. $commonURL = commonURL();
  260. //构建微信分享参数
  261. $appId = commonAPPID();
  262. $timestamp = time();
  263. $nonceStr = nonceStr(16);
  264. $url = commonURL().'/index/distill';
  265. $jsapiTicket = getOfficialJsapiTicket();
  266. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  267. $signature = sha1($string);
  268. return view('distill', [
  269. 'device' => $device,
  270. 'mobileType' => $mobileType,
  271. 'year' => $year,
  272. 'commonURL' => $commonURL,
  273. 'appId' => $appId,
  274. 'timestamp' => $timestamp,
  275. 'nonceStr' => $nonceStr,
  276. 'signature' => $signature,
  277. ]);
  278. }
  279. //模型训练中心页面
  280. public function modelTrain(){
  281. //判断用户设备是否是移动端
  282. $mobileType = 'unknow';
  283. //判断用户设备是否是移动端
  284. if(isMobile() == true){
  285. $device = 'phone';
  286. $mobileType = mobileType();
  287. }
  288. else{
  289. $device = 'pc';
  290. }
  291. //获取当前年份
  292. $year = date('Y',time());
  293. //获取公共路径
  294. $commonURL = commonURL();
  295. //构建微信分享参数
  296. $appId = commonAPPID();
  297. $timestamp = time();
  298. $nonceStr = nonceStr(16);
  299. $url = commonURL().'/index/modelTrain';
  300. $jsapiTicket = getOfficialJsapiTicket();
  301. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  302. $signature = sha1($string);
  303. return view('modelTrain', [
  304. 'device' => $device,
  305. 'mobileType' => $mobileType,
  306. 'year' => $year,
  307. 'commonURL' => $commonURL,
  308. 'appId' => $appId,
  309. 'timestamp' => $timestamp,
  310. 'nonceStr' => $nonceStr,
  311. 'signature' => $signature,
  312. ]);
  313. }
  314. //模型开放平台页面
  315. public function modelOpen(){
  316. //判断用户设备是否是移动端
  317. $mobileType = 'unknow';
  318. //判断用户设备是否是移动端
  319. if(isMobile() == true){
  320. $device = 'phone';
  321. $mobileType = mobileType();
  322. }
  323. else{
  324. $device = 'pc';
  325. }
  326. //获取当前年份
  327. $year = date('Y',time());
  328. //获取公共路径
  329. $commonURL = commonURL();
  330. //构建微信分享参数
  331. $appId = commonAPPID();
  332. $timestamp = time();
  333. $nonceStr = nonceStr(16);
  334. $url = commonURL().'/index/modelOpen';
  335. $jsapiTicket = getOfficialJsapiTicket();
  336. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  337. $signature = sha1($string);
  338. return view('modelOpen', [
  339. 'device' => $device,
  340. 'mobileType' => $mobileType,
  341. 'year' => $year,
  342. 'commonURL' => $commonURL,
  343. 'appId' => $appId,
  344. 'timestamp' => $timestamp,
  345. 'nonceStr' => $nonceStr,
  346. 'signature' => $signature,
  347. ]);
  348. }
  349. //智能体开放平台页面
  350. public function agentOpen(){
  351. //判断用户设备是否是移动端
  352. $mobileType = 'unknow';
  353. //判断用户设备是否是移动端
  354. if(isMobile() == true){
  355. $device = 'phone';
  356. $mobileType = mobileType();
  357. }
  358. else{
  359. $device = 'pc';
  360. }
  361. //获取当前年份
  362. $year = date('Y',time());
  363. //获取公共路径
  364. $commonURL = commonURL();
  365. //构建微信分享参数
  366. $appId = commonAPPID();
  367. $timestamp = time();
  368. $nonceStr = nonceStr(16);
  369. $url = commonURL().'/index/agentOpen';
  370. $jsapiTicket = getOfficialJsapiTicket();
  371. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  372. $signature = sha1($string);
  373. return view('agentOpen', [
  374. 'device' => $device,
  375. 'mobileType' => $mobileType,
  376. 'year' => $year,
  377. 'commonURL' => $commonURL,
  378. 'appId' => $appId,
  379. 'timestamp' => $timestamp,
  380. 'nonceStr' => $nonceStr,
  381. 'signature' => $signature,
  382. ]);
  383. }
  384. //关于我们
  385. public function about(){
  386. //判断用户设备是否是移动端
  387. $mobileType = 'unknow';
  388. //判断用户设备是否是移动端
  389. if(isMobile() == true){
  390. $device = 'phone';
  391. $mobileType = mobileType();
  392. }
  393. else{
  394. $device = 'pc';
  395. }
  396. //获取当前年份
  397. $year = date('Y',time());
  398. //获取公共路径
  399. $commonURL = commonURL();
  400. //构建微信分享参数
  401. $appId = commonAPPID();
  402. $timestamp = time();
  403. $nonceStr = nonceStr(16);
  404. $url = commonURL().'/index/about';
  405. $jsapiTicket = getOfficialJsapiTicket();
  406. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  407. $signature = sha1($string);
  408. return view('about', [
  409. 'device' => $device,
  410. 'mobileType' => $mobileType,
  411. 'year' => $year,
  412. 'commonURL' => $commonURL,
  413. 'appId' => $appId,
  414. 'timestamp' => $timestamp,
  415. 'nonceStr' => $nonceStr,
  416. 'signature' => $signature,
  417. ]);
  418. }
  419. //新闻列表
  420. public function news(){
  421. //判断用户设备是否是移动端
  422. $mobileType = 'unknow';
  423. //判断用户设备是否是移动端
  424. if(isMobile() == true){
  425. $device = 'phone';
  426. $mobileType = mobileType();
  427. }
  428. else{
  429. $device = 'pc';
  430. }
  431. //获取当前年份
  432. $year = date('Y',time());
  433. //获取公共路径
  434. $commonURL = commonURL();
  435. //构建微信分享参数
  436. $appId = commonAPPID();
  437. $timestamp = time();
  438. $nonceStr = nonceStr(16);
  439. $url = commonURL().'/index/news';
  440. $jsapiTicket = getOfficialJsapiTicket();
  441. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  442. $signature = sha1($string);
  443. //获取新闻列表
  444. $news = db('news') -> order('id DESC') -> select();
  445. for($i = 0; $i < count($news); $i++){
  446. $news[$i]['date'] = date('Y-m-d',$news[$i]['time']);
  447. }
  448. return view('news', [
  449. 'device' => $device,
  450. 'mobileType' => $mobileType,
  451. 'year' => $year,
  452. 'commonURL' => $commonURL,
  453. 'appId' => $appId,
  454. 'timestamp' => $timestamp,
  455. 'nonceStr' => $nonceStr,
  456. 'signature' => $signature,
  457. 'news' => $news,
  458. ]);
  459. }
  460. //新闻详情
  461. public function newsDetail(){
  462. $commonURL = commonURL();
  463. $this -> redirect($commonURL.'/index/errorPage');
  464. }
  465. //model列表页
  466. public function models(){
  467. $commonURL = commonURL();
  468. $this -> redirect($commonURL.'/index/errorPage');
  469. }
  470. //大语言模型页
  471. public function modelLLM(){
  472. //判断用户设备是否是移动端
  473. $mobileType = 'unknow';
  474. //判断用户设备是否是移动端
  475. if(isMobile() == true){
  476. $device = 'phone';
  477. $mobileType = mobileType();
  478. }
  479. else{
  480. $device = 'pc';
  481. }
  482. //获取当前年份
  483. $year = date('Y',time());
  484. //获取公共路径
  485. $commonURL = commonURL();
  486. //获取公共路径
  487. $commonOpenURL = commonOpenURL();
  488. //获取当前时间
  489. $now = date('Y-m-d H:i:s',time());
  490. //获取提问示例
  491. $question = db('Question') -> order('id DESC') -> select();
  492. //构建微信分享参数
  493. $appId = commonAPPID();
  494. $timestamp = time();
  495. $nonceStr = nonceStr(16);
  496. $url = commonURL().'/index/modelLLM';
  497. $jsapiTicket = getOfficialJsapiTicket();
  498. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  499. $signature = sha1($string);
  500. return view('modelLLM', [
  501. 'device' => $device,
  502. 'mobileType' => $mobileType,
  503. 'year' => $year,
  504. 'commonURL' => $commonURL,
  505. 'now' => $now,
  506. 'question' => $question,
  507. 'commonOpenURL' => $commonOpenURL,
  508. 'commonOpenURLSSE' => commonOpenURLSSE(),
  509. 'appId' => $appId,
  510. 'timestamp' => $timestamp,
  511. 'nonceStr' => $nonceStr,
  512. 'signature' => $signature,
  513. ]);
  514. }
  515. //医疗BI页面
  516. public function chatBI(){
  517. $commonURL = commonURL();
  518. $this -> redirect($commonURL.'/index/errorPage');
  519. }
  520. //数字医生页面
  521. public function aiDoctor(){
  522. $commonURL = commonURL();
  523. $this -> redirect($commonURL.'/index/errorPage');
  524. }
  525. //病历质控
  526. public function internalQuality(){
  527. //判断用户设备是否是移动端
  528. $mobileType = 'unknow';
  529. //判断用户设备是否是移动端
  530. if(isMobile() == true){
  531. $device = 'phone';
  532. $mobileType = mobileType();
  533. }
  534. else{
  535. $device = 'pc';
  536. }
  537. //获取当前年份
  538. $year = date('Y',time());
  539. //获取公共路径
  540. $commonURL = commonURL();
  541. //获取公共路径
  542. $commonOpenURL = commonOpenURL();
  543. //获取当前时间
  544. $now = date('Y-m-d H:i:s',time());
  545. //获取一个标记当前用户的传参
  546. $user = request() -> param('user');
  547. if(!$user){
  548. $user = rand(10000,99999);
  549. }
  550. //构建微信分享参数
  551. $appId = commonAPPID();
  552. $timestamp = time();
  553. $nonceStr = nonceStr(16);
  554. $url = commonURL().'/index/internalQuality?user='.$user;
  555. $jsapiTicket = getOfficialJsapiTicket();
  556. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  557. $signature = sha1($string);
  558. return view('internalQuality', [
  559. 'device' => $device,
  560. 'mobileType' => $mobileType,
  561. 'year' => $year,
  562. 'commonURL' => $commonURL,
  563. 'now' => $now,
  564. 'commonOpenURL' => $commonOpenURL,
  565. 'commonOpenURLSSE' => commonOpenURLSSE(),
  566. 'commonWebsocket' => commonWebsocket(),
  567. 'user' => $user,
  568. 'appId' => $appId,
  569. 'timestamp' => $timestamp,
  570. 'nonceStr' => $nonceStr,
  571. 'signature' => $signature,
  572. ]);
  573. }
  574. //邀请函
  575. public function invitation(){
  576. //判断用户设备是否是移动端
  577. $mobileType = 'unknow';
  578. //判断用户设备是否是移动端
  579. if(isMobile() == true){
  580. $device = 'phone';
  581. $mobileType = mobileType();
  582. }
  583. else{
  584. $device = 'pc';
  585. }
  586. //获取当前年份
  587. $year = date('Y',time());
  588. //获取公共路径
  589. $commonURL = commonURL();
  590. //获取公共路径
  591. $commonOpenURL = commonOpenURL();
  592. //获取当前时间
  593. $now = date('Y-m-d H:i:s',time());
  594. //获取一个标记当前用户的传参
  595. $user = request() -> param('user');
  596. if(!$user){
  597. $user = rand(10000,99999);
  598. }
  599. //构建微信分享参数
  600. $appId = commonAPPID();
  601. $timestamp = time();
  602. $nonceStr = nonceStr(16);
  603. $url = commonURL().'/index/invitation';
  604. $jsapiTicket = getOfficialJsapiTicket();
  605. $string = "jsapi_ticket=$jsapiTicket&noncestr=$nonceStr&timestamp=$timestamp&url=$url";
  606. $signature = sha1($string);
  607. return view('invitation', [
  608. 'device' => $device,
  609. 'mobileType' => $mobileType,
  610. 'year' => $year,
  611. 'commonURL' => $commonURL,
  612. 'now' => $now,
  613. 'commonOpenURL' => $commonOpenURL,
  614. 'commonOpenURLSSE' => commonOpenURLSSE(),
  615. 'commonWebsocket' => commonWebsocket(),
  616. 'user' => $user,
  617. 'appId' => $appId,
  618. 'timestamp' => $timestamp,
  619. 'nonceStr' => $nonceStr,
  620. 'signature' => $signature,
  621. ]);
  622. }
  623. //
  624. public function knowledgeMessage(){
  625. // $input = request() -> param('input');
  626. // $kid = request() -> param('kid');
  627. $json = file_get_contents('php://input');
  628. $json = json_decode($json);
  629. $json = stdClassObjToArray($json);
  630. if($json){
  631. $input = $json['input'];
  632. $kid = $json['kid'];
  633. }
  634. $count = request() -> param('count');
  635. // $input = $_POST['input'];
  636. // $kid = $_POST['kid'];
  637. $count = json_decode($count);
  638. $count = stdClassObjToArray($count);
  639. // echo($input);
  640. // exit;
  641. if($count){
  642. $input = $count['input'];
  643. $kid = $count['kid'];
  644. }
  645. if(!$input){
  646. echo '{"code":500,"msg":"cURL 请求失败: 请检查参数。","data":null}';
  647. exit;
  648. }
  649. if(!$kid){
  650. echo '{"code":500,"msg":"cURL 请求失败: 请检查参数。","data":null}';
  651. exit;
  652. }
  653. $RAGdata = [
  654. "username" => "test",
  655. "password" => "test123"
  656. ];
  657. // 调用时只需传递非 Content-Type/Accept 的 Header
  658. $headers = [
  659. 'Cache-Control: no-cache',
  660. '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'
  661. ];
  662. $urlRAG = "http://192.168.1.8:6039/auth/login"; // 替换为实际 URL
  663. $id = curlPostRAG($urlRAG, $RAGdata, $headers);
  664. $token = $id; // 默认启用 JSON 模式
  665. $token = json_decode($token);
  666. $token = stdClassObjToArray($token);
  667. $token = $token['data']['token'];
  668. $url = "http://192.168.1.8:6039/rag/schema"; // 替换成实际接口地址
  669. $data = [
  670. "messages" => $input, // 替换成实际用户输入
  671. "model" => "qwen3-32B", // 替换成实际模型名称
  672. "maxDistance" => 0.7, // 替换成实际分数(浮点数)
  673. "kid" => $kid // 替换成实际知识库 ID
  674. ];
  675. // 初始化 cURL
  676. $ch = curl_init();
  677. // 设置 cURL 选项
  678. curl_setopt($ch, CURLOPT_URL, $url);
  679. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回响应数据
  680. curl_setopt($ch, CURLOPT_POST, true); // 使用 POST 方法
  681. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // 发送 JSON 数据
  682. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  683. "Authorization: Bearer " . $token,
  684. "Content-Type: application/json" // 声明请求体是 JSON
  685. ]);
  686. // 执行请求并获取响应
  687. $response = curl_exec($ch);
  688. // 检查是否有错误
  689. if (strpos($response, "code") !== false) {
  690. $response = json_decode($response);
  691. echo '{"code":'.$response ->code.',"msg":"cURL 请求失败: 请检查参数。","data":null}';
  692. exit;
  693. } else {
  694. // 解析 JSON 响应
  695. $response = json_decode($response, true);
  696. $response["code"] = 200;
  697. $response = json_encode($response, JSON_UNESCAPED_UNICODE);
  698. return $response; // 输出返回数据(prompt, vector, nearest)
  699. }
  700. // 关闭 cURL 资源
  701. curl_close($ch);
  702. }
  703. //
  704. function handleChatTest() {
  705. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  706. http_response_code(405); // 405 Method Not Allowed
  707. echo json_encode(['error' => 'Only POST requests are allowed']);
  708. return;
  709. }
  710. $expectedToken = 'sk-c39f1b287ef64c39b88ad0ff9c7420b6';
  711. $targetUrl = 'http://60.164.133.40:9997/v1/chat/completions';
  712. // 获取请求体和头信息
  713. $requestBody = file_get_contents('php://input');
  714. $headers = getallheaders();
  715. $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
  716. // 校验 Authorization
  717. if ($authorizationHeader !== 'Bearer ' . $expectedToken) {
  718. http_response_code(403);
  719. echo json_encode(['error' => 'Authorization header']);
  720. return;
  721. }
  722. // 发起代理请求
  723. $ch = curl_init($targetUrl);
  724. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  725. curl_setopt($ch, CURLOPT_POST, true);
  726. curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
  727. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  728. 'Content-Type: application/json',
  729. 'Authorization: ' . $authorizationHeader
  730. ]);
  731. // 设置回调,边接收边输出
  732. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
  733. echo $data;
  734. // 立即刷新输出缓冲
  735. @ob_flush();
  736. @flush();
  737. return strlen($data);
  738. });
  739. // 返回响应
  740. header('Content-Type: application/json');
  741. $res = curl_exec($ch);
  742. if (curl_errno($ch)) {
  743. http_response_code(500);
  744. echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
  745. }
  746. curl_close($ch);
  747. }
  748. function handleChat() {
  749. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  750. http_response_code(405);
  751. echo json_encode(['error' => 'Only POST requests are allowed']);
  752. return;
  753. }
  754. // 关闭所有缓冲,强制流式输出
  755. @ini_set('output_buffering', 'off');
  756. @ini_set('zlib.output_compression', false);
  757. while (ob_get_level() > 0) {
  758. ob_end_flush();
  759. }
  760. ob_implicit_flush(true);
  761. // 设置流式响应头
  762. header('Content-Type: application/json; charset=utf-8');
  763. header('Cache-Control: no-cache');
  764. header('X-Accel-Buffering: no'); // 对 Nginx 有效,关闭缓冲
  765. $expectedToken = 'sk-7e5a2dcb93a84fd8a9f04b6a9c8f1e32';
  766. $targetUrl = 'http://60.164.133.40:19997/v1/chat/completions';
  767. $requestBody = file_get_contents('php://input');
  768. $headers = getallheaders();
  769. $authorizationHeader = isset($headers['Authorization']) ? $headers['Authorization'] : '';
  770. if ($authorizationHeader !== 'Bearer ' . $expectedToken) {
  771. http_response_code(403);
  772. echo json_encode(['error' => 'Invalid Authorization header']);
  773. return;
  774. }
  775. $ch = curl_init($targetUrl);
  776. curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
  777. curl_setopt($ch, CURLOPT_POST, true);
  778. curl_setopt($ch, CURLOPT_TIMEOUT, 0);
  779. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  780. curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
  781. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  782. 'Content-Type: application/json',
  783. 'Authorization: ' . $authorizationHeader
  784. ]);
  785. curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($curl, $data) {
  786. echo $data;
  787. @ob_flush();
  788. @flush();
  789. return strlen($data);
  790. });
  791. $logFile = __DIR__ . '/handleChat.log';
  792. $timestamp = date('[Y-m-d H:i:s]');
  793. file_put_contents($logFile, $timestamp . ' ' .$requestBody .PHP_EOL, FILE_APPEND);
  794. $res = curl_exec($ch);
  795. if (curl_errno($ch)) {
  796. http_response_code(500);
  797. echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
  798. }
  799. curl_close($ch);
  800. $timestamp = date('[Y-m-d H:i:s]');
  801. file_put_contents($logFile, $timestamp . ' ' .PHP_EOL, FILE_APPEND);
  802. }
  803. function handleEmbedding() {
  804. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  805. http_response_code(405);
  806. echo json_encode(['error' => 'Only POST requests are allowed']);
  807. return;
  808. }
  809. $expectedToken = 'sk-c39f1b287ef64c39b88ad0ff9c7420b6';
  810. $targetUrl = 'http://60.164.133.40:19997/v1/embeddings';
  811. $headers = array_change_key_case(getallheaders(), CASE_LOWER);
  812. if (!isset($headers['authorization'])) {
  813. http_response_code(401);
  814. echo json_encode(['error' => 'Missing Authorization header']);
  815. return;
  816. }
  817. $authHeader = $headers['authorization'];
  818. if ($authHeader !== 'Bearer ' . $expectedToken) {
  819. http_response_code(403);
  820. echo json_encode(['error' => 'Invalid API token']);
  821. return;
  822. }
  823. $requestBody = file_get_contents('php://input');
  824. $ch = curl_init($targetUrl);
  825. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  826. curl_setopt($ch, CURLOPT_POST, true);
  827. curl_setopt($ch, CURLOPT_TIMEOUT, 0);
  828. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
  829. curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
  830. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  831. 'Content-Type: application/json',
  832. 'accept: application/json',
  833. 'Authorization: ' . $authHeader,
  834. ]);
  835. curl_setopt($ch, CURLOPT_HEADER, true);
  836. curl_setopt($ch, CURLOPT_ENCODING, ''); // 支持所有编码,防止自动解压影响
  837. $response = curl_exec($ch);
  838. if (curl_errno($ch)) {
  839. http_response_code(500);
  840. echo json_encode(['error' => 'cURL Error: ' . curl_error($ch)]);
  841. curl_close($ch);
  842. return;
  843. }
  844. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  845. $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
  846. curl_close($ch);
  847. $responseHeaders = substr($response, 0, $headerSize);
  848. $responseBody = substr($response, $headerSize);
  849. // 关闭所有输出缓冲区,防止格式被修改
  850. while (ob_get_level()) {
  851. ob_end_clean();
  852. }
  853. // 只转发 Content-Type,避免冲突
  854. foreach (explode("\r\n", $responseHeaders) as $headerLine) {
  855. if (stripos($headerLine, 'Content-Type:') === 0) {
  856. header($headerLine);
  857. }
  858. }
  859. http_response_code($httpCode);
  860. // 直接原样输出响应体,不做任何json_encode或修改
  861. echo $responseBody;
  862. }
  863. public function roleindex(){
  864. $data['askInfoId'] = request() -> param('askInfoId');
  865. // $data['askInfoId'] = '53ef8235ca3e5d60708baae51be72db8';
  866. $maprulecontent['token'] = array('eq', $data['askInfoId']);
  867. $tokenrole = db('tokenrole')->where($maprulecontent)->select();
  868. $urlrole = commonOpenURLLocal().'/apis/role';
  869. $rulename = curlPost($urlrole,$data);
  870. $rulename = json_decode($rulename);
  871. $rulename = stdClassObjToArray($rulename);
  872. if(strstr($rulename['reply'], '病例校验通过')){
  873. $datarole['aireply'] = $rulename['reply'];
  874. $datarole['reply'] = "【质控结果】 病例校验通过。";
  875. db('tokenrole')->where($maprulecontent)->update($datarole);
  876. }
  877. else{
  878. $datarole['aireply'] = $rulename['reply'];
  879. $datarole['reply'] = $rulename['reply'];
  880. db('tokenrole')->where($maprulecontent)->update($datarole);
  881. }
  882. return "ss";
  883. }
  884. public function roleindex1(){
  885. $data['askInfoId'] = request() -> param('askInfoId');
  886. // $data['askInfoId'] = '53ef8235ca3e5d60708baae51be72db8';
  887. $maprulecontent['token'] = array('eq', $data['askInfoId']);
  888. $tokenrole = db('tokenrole2')->where($maprulecontent)->select();
  889. $urlrole = commonOpenURLLocal().'/apis/role';
  890. $rulename = curlPost($urlrole,$data);
  891. $rulename = json_decode($rulename);
  892. $rulename = stdClassObjToArray($rulename);
  893. if(strstr($rulename['reply'], '病例校验通过')){
  894. $datarole['aireply'] = $rulename['reply'];
  895. $datarole['reply'] = "【质控结果】 病例校验通过。";
  896. db('tokenrole2')->where($maprulecontent)->update($datarole);
  897. }
  898. else{
  899. $datarole['aireply'] = $rulename['reply'];
  900. $datarole['reply'] = $rulename['reply'];
  901. db('tokenrole2')->where($maprulecontent)->update($datarole);
  902. }
  903. return "ss";
  904. }
  905. }