46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
namespace Mince;
|
|
|
|
final class Remote {
|
|
private static string $url = '';
|
|
private static string $secret = '';
|
|
|
|
public static function setUrl(string $url): void {
|
|
self::$url = $url;
|
|
}
|
|
|
|
public static function setSecret(string $secret): void {
|
|
self::$secret = $secret;
|
|
}
|
|
|
|
public static function call(string $mode, string $name): string {
|
|
$time = (string)floor(time() / 120);
|
|
$sign = hash_hmac('sha256', "{$time}#{$mode}#{$name}", self::$secret, true);
|
|
|
|
$request = curl_init(self::$url);
|
|
curl_setopt_array($request, [
|
|
CURLOPT_AUTOREFERER => false,
|
|
CURLOPT_FAILONERROR => false,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HEADER => false,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_POSTFIELDS => [
|
|
'm' => $mode,
|
|
's' => $sign,
|
|
'n' => $name,
|
|
],
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_TCP_FASTOPEN => true,
|
|
CURLOPT_CONNECTTIMEOUT => 2,
|
|
CURLOPT_MAXREDIRS => 2,
|
|
CURLOPT_PROTOCOLS => CURLPROTO_HTTP | CURLPROTO_HTTPS,
|
|
CURLOPT_TIMEOUT => 5,
|
|
CURLOPT_USERAGENT => 'mc.flashii.net',
|
|
]);
|
|
$response = curl_exec($request);
|
|
curl_close($request);
|
|
|
|
return $response;
|
|
}
|
|
}
|