Skip to content

Instantly share code, notes, and snippets.

@coinhive-com
Created December 7, 2017 11:58
Show Gist options
  • Save coinhive-com/dc37d300b2f4f909006a07139c9d2c71 to your computer and use it in GitHub Desktop.
Save coinhive-com/dc37d300b2f4f909006a07139c9d2c71 to your computer and use it in GitHub Desktop.
PHP class for the Coinhive HTTP API
<?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);
}
}
@cryonix33
Copy link

Как я понял, то если выключить ПК, то все намайненные Монеро пропадут. Как же быть? У меня ПК потребляет энергии больше, чем здесь я заработаю если не выключать его никогда.

@taweesakteejantuk66
Copy link

good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment