作者 刘锟

update

@@ -63,14 +63,14 @@ protected function error($message = 'error', $status = 400, $data = []) @@ -63,14 +63,14 @@ protected function error($message = 'error', $status = 400, $data = [])
63 63
64 /** 64 /**
65 * 响应 65 * 响应
66 - * @param null $msg 66 + * @param string $msg
67 * @param int $code 67 * @param int $code
68 * @param array $data 68 * @param array $data
69 * @param int $result_code 69 * @param int $result_code
70 * @param string $type 70 * @param string $type
71 * @return void 71 * @return void
72 */ 72 */
73 - public function response($msg = null, $code = self::SUCCESS, $data = [], $result_code = 200, $type = 'application/json') 73 + public function response($msg = 'success', $code = self::SUCCESS, $data = [], $result_code = 200, $type = 'application/json')
74 { 74 {
75 $result = [ 75 $result = [
76 'msg' => $msg, 76 'msg' => $msg,
@@ -256,7 +256,8 @@ public function websiteHtml(Request $request) @@ -256,7 +256,8 @@ public function websiteHtml(Request $request)
256 * 文案 256 * 文案
257 * @param Request $request 257 * @param Request $request
258 */ 258 */
259 - public function getRandInquiryText(Request $request){ 259 + public function getRandInquiryText(Request $request)
  260 + {
260 //IP限流+验证参数 261 //IP限流+验证参数
261 $this->limitIp($request); 262 $this->limitIp($request);
262 263
@@ -266,7 +267,7 @@ public function getRandInquiryText(Request $request){ @@ -266,7 +267,7 @@ public function getRandInquiryText(Request $request){
266 } catch (\Exception $e) { 267 } catch (\Exception $e) {
267 $resStr = $e->getMessage(); 268 $resStr = $e->getMessage();
268 } 269 }
269 - $this->response("ok",self::SUCCESS,$resStr); 270 + $this->response("ok", self::SUCCESS, $resStr);
270 return; 271 return;
271 } 272 }
272 273
@@ -275,7 +276,8 @@ public function getRandInquiryText(Request $request){ @@ -275,7 +276,8 @@ public function getRandInquiryText(Request $request){
275 * @param Request $request 276 * @param Request $request
276 * @return string 277 * @return string
277 */ 278 */
278 - public function pullCode(Request $request){ 279 + public function pullCode(Request $request)
  280 + {
279 $command = "cd /www/wwwroot/self_site && ./pull_custom_code.sh"; 281 $command = "cd /www/wwwroot/self_site && ./pull_custom_code.sh";
280 shell_exec($command); 282 shell_exec($command);
281 return $this->success(); 283 return $this->success();
@@ -285,8 +287,9 @@ public function pullCode(Request $request){ @@ -285,8 +287,9 @@ public function pullCode(Request $request){
285 * @param $url 287 * @param $url
286 * @return bool|string 288 * @return bool|string
287 */ 289 */
288 - public function httpGet($url){  
289 - $ch1 = curl_init(); 290 + public function httpGet($url)
  291 + {
  292 + $ch1 = curl_init();
290 $timeout = 0; 293 $timeout = 0;
291 curl_setopt($ch1, CURLOPT_URL, $url); 294 curl_setopt($ch1, CURLOPT_URL, $url);
292 curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true); 295 curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);
@@ -449,22 +452,22 @@ public function deleteDirectory($path) @@ -449,22 +452,22 @@ public function deleteDirectory($path)
449 * @param $request 452 * @param $request
450 * @param string $type 453 * @param string $type
451 * @param int $traffic 454 * @param int $traffic
452 - * @return string 455 + * @return string|void
453 */ 456 */
454 public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRAFFICZERO) 457 public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRAFFICZERO)
455 { 458 {
456 if ($request->getClientIp() == "127.0.0.1") { 459 if ($request->getClientIp() == "127.0.0.1") {
457 - return $this->success(); 460 + $this->response();
458 } 461 }
459 //判断是否是爬虫 462 //判断是否是爬虫
460 $isReptile = $this->isReptile($request); 463 $isReptile = $this->isReptile($request);
461 if ($isReptile) { 464 if ($isReptile) {
462 - return $this->success(); 465 + $this->response();
463 } 466 }
464 467
465 $data = $request->all(); 468 $data = $request->all();
466 if (empty($data)) { 469 if (empty($data)) {
467 - return $this->success(); 470 + $this->response();
468 } 471 }
469 $data["device_port"] = $this->userAgentHandle($request->userAgent(), $data["device_port"] ?? self::DEVICE_PORT_ONE); 472 $data["device_port"] = $this->userAgentHandle($request->userAgent(), $data["device_port"] ?? self::DEVICE_PORT_ONE);
470 $req["data"] = $data; 473 $req["data"] = $data;
@@ -484,14 +487,14 @@ public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRA @@ -484,14 +487,14 @@ public function transmit($request, $type = self::TYPEVISIT, $traffic = self::TRA
484 //转发接口 487 //转发接口
485 $transmitUrl = env("TRANSMIT_URL"); 488 $transmitUrl = env("TRANSMIT_URL");
486 $resp = $this->httpPost($transmitUrl . "api/selfSiteApi/", json_encode($req)); 489 $resp = $this->httpPost($transmitUrl . "api/selfSiteApi/", json_encode($req));
487 - if (($resp["status"]??0) != self::SUCCESS) { 490 + if (($resp["status"] ?? 0) != self::SUCCESS) {
488 $dataJson = json_encode($req); 491 $dataJson = json_encode($req);
489 if (!file_exists(storage_path('logs/fail_req'))) { 492 if (!file_exists(storage_path('logs/fail_req'))) {
490 mkdir(storage_path('logs/fail_req', 0777, true)); 493 mkdir(storage_path('logs/fail_req', 0777, true));
491 } 494 }
492 @file_put_contents(storage_path('logs/fail_req/' . date('Y-m-d') . '.log'), var_export($dataJson, true) . PHP_EOL, FILE_APPEND); 495 @file_put_contents(storage_path('logs/fail_req/' . date('Y-m-d') . '.log'), var_export($dataJson, true) . PHP_EOL, FILE_APPEND);
493 } 496 }
494 - return $this->success($resp['data']??[]); 497 + $this->response("success", self::SUCCESS, $resp["data"] ?? []);
495 } 498 }
496 499
497 /** 500 /**
@@ -28,6 +28,7 @@ function getProjectCode() @@ -28,6 +28,7 @@ function getProjectCode()
28 git checkout . 28 git checkout .
29 git pull 29 git pull
30 composer update --ignore-platform-reqs 30 composer update --ignore-platform-reqs
  31 + chmod -R 777 pull_custom_code.sh
31 fi 32 fi
32 } 33 }
33 34