作者 李宇航

合并分支 'master-server' 到 'master'

gx数据



查看合并请求 !1383
@@ -62,13 +62,20 @@ class RequestUrlLog extends Command @@ -62,13 +62,20 @@ class RequestUrlLog extends Command
62 * @method :post 62 * @method :post
63 * @time :2025/3/10 11:36 63 * @time :2025/3/10 11:36
64 */ 64 */
65 - public function postRequest($url, $postData) { 65 + public function postRequest($url, $postData)
  66 + {
  67 + if (empty($header)) {
  68 + $header = array(
  69 + "Accept: application/json",
  70 + "Content-Type:application/json;charset=utf-8",
  71 + );
  72 + }
66 $ch = curl_init(); 73 $ch = curl_init();
67 curl_setopt($ch, CURLOPT_URL, $url); 74 curl_setopt($ch, CURLOPT_URL, $url);
68 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 75 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
69 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 76 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
70 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 77 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
71 - curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); 78 + curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
72 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 79 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
73 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 80 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
74 curl_setopt($ch, CURLOPT_AUTOREFERER, 1); 81 curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
@@ -76,13 +83,16 @@ class RequestUrlLog extends Command @@ -76,13 +83,16 @@ class RequestUrlLog extends Command
76 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 83 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
77 // 记录请求开始时间 84 // 记录请求开始时间
78 $startTime = microtime(true); 85 $startTime = microtime(true);
79 - $response = curl_exec($ch); 86 + $res = curl_exec($ch);
80 // 记录请求结束时间 87 // 记录请求结束时间
81 $endTime = microtime(true); 88 $endTime = microtime(true);
82 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 89 $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  90 + if (curl_errno($ch)) {
  91 + curl_error($ch);
  92 + }
83 $requestTime = round(($endTime - $startTime) * 1000, 2); // 转换为毫秒 93 $requestTime = round(($endTime - $startTime) * 1000, 2); // 转换为毫秒
84 curl_close($ch); 94 curl_close($ch);
85 - return ['response' => $response, 'http_code' => $httpCode, 'request_time_ms' => $requestTime]; 95 + return ['response' => $res, 'http_code' => $httpCode, 'request_time_ms' => $requestTime];
86 } 96 }
87 97
88 } 98 }