作者 李宇航

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

gx数据



查看合并请求 !1379
... ... @@ -9,6 +9,8 @@
namespace App\Console\Commands\RequestUrlLog;
use App\Models\Com\RequestUrl;
use App\Models\Project\Project;
use Illuminate\Console\Command;
class RequestUrlLog extends Command
... ... @@ -25,5 +27,60 @@ class RequestUrlLog extends Command
*
* @var string
*/
protected $description = '统计昨日数据';
protected $description = '请求日志统计';
/**
* @remark :请求接口是否异常
* @name :handle
* @author :lyh
* @method :post
* @time :2025/3/10 10:51
*/
public function handle(){
//获取需要请求的接口
$requestUrlModel = new RequestUrl();
$urlList = $requestUrlModel->list(['status'=>0]);
foreach ($urlList as $v){
//循环请求设置
if($v['method'] == 'get'){
}else{
$url = $v['url'];
$param = json_decode($v['param'],true);
$result = $this->postRequest($url,$param);
echo '执行的url:' . $url . PHP_EOL . '返回的结果:'.json_encode($result,true) . date('Y-m-d H:i:s');
//更新请求结果
$requestUrlModel->edit(['text'=>json_encode($result,true)],['id'=>$v['id']]);
}
}
return true;
}
/**
* @remark :请求设置
* @name :postRequest
* @author :lyh
* @method :post
* @time :2025/3/10 11:36
*/
public function postRequest($url, $postData) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
// 记录请求开始时间
$startTime = microtime(true);
$response = curl_exec($ch);
// 记录请求结束时间
$endTime = microtime(true);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$requestTime = round(($endTime - $startTime) * 1000, 2); // 转换为毫秒
curl_close($ch);
return ['response' => $response, 'http_code' => $httpCode, 'request_time_ms' => $requestTime];
}
}
... ...
<?php
/**
* @remark :
* @name :RequestUrl.php
* @author :lyh
* @method :post
* @time :2025/3/10 10:57
*/
namespace App\Models\Com;
use App\Models\Base;
/**
* @remark :模拟请求的url
* @name :RequestUrl
* @author :lyh
* @method :post
* @time :2025/3/10 10:57
*/
class RequestUrl extends Base
{
protected $table = 'gl_request_url_log';
}
... ...