Index.php 38 KB

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