Skip to content

Instantly share code, notes, and snippets.

@fdcore
Last active February 12, 2018 14:22
Show Gist options
  • Save fdcore/fffd48e325a165313f9836c08f4797d7 to your computer and use it in GitHub Desktop.
Save fdcore/fffd48e325a165313f9836c08f4797d7 to your computer and use it in GitHub Desktop.
<?php
/*
$id (int) номер игры / ни на что не влияет
$min (int) минимальное значение рандома
$max (int) максимальное
$api (uuid) апи ключ
@return (array) массив данных ответа
*/
function get_random($id=1, $min=1, $max=100, $api=''){
$data = array(
"jsonrpc" => "2.0",
"id" => $id,
"method" => 'generateSignedIntegers',
"params" => array(
"apiKey" => $api,
"n" => 1,
"min" => $min,
"max" => $max,
"replacement" => true
)
);
$data_string = json_encode($data);
$ch = curl_init('https://api.random.org/json-rpc/1/invoke');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
return json_decode($result, true);
}
$result = get_random(2, 1, 100, 'апи ключ');
?>
<h1>WIN <?php echo end($result['result']['random']['data']); ?></h1>
<form action='https://api.random.org/verify' method='post'>
<input type='hidden' name='format' value='json' />
<input type='hidden' name='random' value='<?php echo json_encode($result['result']['random']) ?>' />
<input type='hidden' name='signature' value="<?php echo $result['result']['signature'] ?>" />
<input type='submit' value='Validate' />
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment