first commit

This commit is contained in:
annnj-company
2026-04-17 18:29:53 +08:00
parent e49fa5a215
commit 130c1026c4
5615 changed files with 1639145 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
<?php
namespace app\admin\service;
use think\facade\Log;
class SyncHttpService {
public static function post($url = "", $params = [], $header = []) {
empty($url) && apiErrMsg('地址不能为空');
$goUrl = strpos($url, 'http') !== false ? $url : config('domain') . "/index.php/" . $url;
Log::debug('SyncHttpService post url:'. $goUrl);
$info = parse_url($goUrl);
$host = $info['host'];
$port = $info['port'] ?? (strpos($goUrl, 'https') !== false ? 443 : 80);
$path = $info['path'];
$query = empty($params) ? '' : http_build_query($params);
$errno = 0;
$errstr = '';
$timeout = 300;
try {
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
$head = "POST $path HTTP/1.0\r\n";
$head .= "Host: $host\r\n";
$head .= "Content-type: application/x-www-form-urlencoded\r\n";
$head .= "Content-Length: " . strlen($query) . "\r\n";
$head .= "Connection:close\r\n";
if($header) {
foreach($header as $k => $v) {
$head .= "{$k}: {$v}\r\n";
}
}
$head .= "\r\n";
$head .= trim($query);
fwrite($fp, $head);
usleep(20000);
fclose($fp);
} catch (\Exception $exc) {
Log::debug('SyncHttpService error===');
Log::debug(compact('host', 'port', 'errno', 'errstr'));
Log::debug(compact('params', 'query'));
Log::debug('SyncHttpService error===');
writeLog($goUrl, 'SyncHttpServiceError');
writeLog(compact('host', 'port', 'errno', 'errstr'), 'SyncHttpServiceError');
writeLog(compact('params', 'query'), 'SyncHttpServiceError');
writeLog($exc, 'SyncHttpServiceError');
}
}
}