Created
December 7, 2017 11:58
-
-
Save coinhive-com/dc37d300b2f4f909006a07139c9d2c71 to your computer and use it in GitHub Desktop.
PHP class for the Coinhive HTTP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CoinHiveAPI { | |
const API_URL = 'https://api.coinhive.com'; | |
private $secret = null; | |
public function __construct($secret) { | |
if (strlen($secret) !== 32) { | |
throw new Exception('CoinHive - Invalid Secret'); | |
} | |
$this->secret = $secret; | |
} | |
function get($path, $data = []) { | |
$data['secret'] = $this->secret; | |
$url = self::API_URL.$path.'?'.http_build_query($data); | |
$response = file_get_contents($url); | |
return json_decode($response); | |
} | |
function post($path, $data = []) { | |
$data['secret'] = $this->secret; | |
$context = stream_context_create([ | |
'http' => [ | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'POST', | |
'content' => http_build_query($data) | |
] | |
]); | |
$url = SELF::API_URL.$path; | |
$response = file_get_contents($url, false, $context); | |
return json_decode($response); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Как я понял, то если выключить ПК, то все намайненные Монеро пропадут. Как же быть? У меня ПК потребляет энергии больше, чем здесь я заработаю если не выключать его никогда.