LoliPHP/helper/curl.php

38 行
908 B
PHP
Raw パーマリンク 通常表示 履歴

2022-03-27 02:41:32 +09:00
<?php
2022-10-25 18:09:58 +09:00
require_once("../config.php");
2022-03-27 02:57:46 +09:00
2022-10-25 18:09:58 +09:00
function lolicurl ($url, $param="", $method="get", $contenttype="json") {
2022-03-27 02:57:46 +09:00
set_time_limit(0);
2022-10-25 18:09:58 +09:00
$header = ["Content-Type: application/".$contenttype, "Host: ".str_replace("https://", "", API_URI)];
2022-03-27 02:57:46 +09:00
if (!is_null(API_AUTH)) {
2022-10-25 18:09:58 +09:00
$header[] = "Authorization: Bearer ".API_AUTH;
2022-03-27 02:57:46 +09:00
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, API_URI.$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
2022-10-25 18:09:58 +09:00
if ($method == "post") {
2022-03-27 02:57:46 +09:00
curl_setopt($ch, CURLOPT_POST, 1);
2022-10-25 18:09:58 +09:00
if ($param != "") curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
2022-03-27 02:57:46 +09:00
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$get = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if (!$get) {
return $err;
}
$get = json_decode($get);
if (isset($get->status) && $get->status == 404) {
return [];
}
return $get;
}
2022-03-27 02:41:32 +09:00
?>