mirror of
https://github.com/hotspotbilling/phpnuxbill.git
synced 2024-11-14 20:24:55 +08:00
65 lines
2.3 KiB
PHP
65 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
|
**/
|
|
|
|
class Http
|
|
{
|
|
public static function getData($url, $headers = [])
|
|
{
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, 0);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$server_output = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $server_output;
|
|
}
|
|
|
|
public static function postJsonData($url, $array_post, $headers = [], $basic = null)
|
|
{
|
|
$headers[] = 'Content-Type: application/json';
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
|
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($array_post));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
if (!empty($basic)) {
|
|
curl_setopt($ch, CURLOPT_USERPWD, $basic);
|
|
}
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$server_output = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $server_output;
|
|
}
|
|
|
|
|
|
public static function postData($url, $array_post, $headers = [], $basic = null)
|
|
{
|
|
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
|
|
curl_setopt($ch, CURLOPT_VERBOSE, false);
|
|
curl_setopt($ch, CURLINFO_HEADER_OUT, false);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_post));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
if (!empty($basic)) {
|
|
curl_setopt($ch, CURLOPT_USERPWD, $basic);
|
|
}
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
$server_output = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $server_output;
|
|
}
|
|
}
|