代码拉取完成,页面将自动刷新
同步操作将从 Hamm/Tester 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<?php
header("Content-Type: application/json;chartset=uft-8");
if (isset($_GET['key'])) {
$key = htmlspecialchars($_GET['key']);
$path = "./data/" . $key . ".php";
$result = '';
if (file_exists($path)) {
$result = file_get_contents($path);
}
jok('', $result);
die;
}
$post = file_get_contents('php://input');
$post = json_decode($post, true);
if (!$post) {
jerr('参数错误');
}
$url = $post['url'];
if (!$url) {
jerr('请填写API请求地址');
}
$method = $post['method'] ?? 'GET';
$body = $post['body'] ?? "";
$header = $post['header'] ?? "";
$cookie = $post['cookie'] ?? "";
if (substr($header, 0 - strlen(PHP_EOL)) == PHP_EOL) {
$header = substr($header, 0, strlen($header) - strlen(PHP_EOL));
}
$header = explode(PHP_EOL, $header);
$key = sha1(time() . rand(10000000, 99999999));
$dir = "./data/" . date('Ymd');
if (!is_dir($dir)) {
mkdir($dir);
}
file_put_contents($dir . "/" . $key . ".php", json_encode([
"url" => $url,
"body" => $body,
"header" => $header,
"cookie" => $cookie,
"method" => $method
]));
if (isset($_GET['local'])) {
return jok('', date('Ymd') . "/" . $key);
}
$result = curlHelper($url, $body, $header, $cookie, $method);
$result['key'] = date('Ymd') . "/" . $key;
jok('', $result);
function jok($msg, $data)
{
echo json_encode([
'code' => 200,
'msg' => $msg,
'data' => $data,
]);
die;
}
function jerr($msg)
{
echo json_encode([
'code' => 500,
'msg' => $msg,
]);
die;
}
function curlHelper($url, $data = null, $header = [], $cookies = "", $method = 'GET')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
switch ($method) {
case "GET":
curl_setopt($ch, CURLOPT_HTTPGET, true);
break;
case "POST":
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "PUT":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "DELETE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "PATCH":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "TRACE":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "TRACE");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "OPTIONS":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "OPTIONS");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
case "HEAD":
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "HEAD");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
break;
default:
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
$output = [];
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
// 根据头大小去获取头信息内容
$output['header'] = substr($response, 0, $headerSize);
$output['body'] = substr($response, $headerSize, strlen($response) - $headerSize);
$output['detail'] = curl_getinfo($ch);
curl_close($ch);
return $output;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。