Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1.     function sendBTC(string $address, string $amount, string $pin = 'пинкод', string $apiKey = 'api ключ')
  2.     {
  3.         $ch = curl_init();
  4.         curl_setopt_array($ch, [
  5.             CURLOPT_URL => 'https://block.io/api/v2/withdraw/?api_key='.$apiKey.'&amounts='.$amount.'&to_addresses='.$address.'&pin=' . $pin,
  6.             CURLOPT_SSL_VERIFYHOST => false,
  7.             CURLOPT_SSL_VERIFYPEER => false,
  8.             //CURLOPT_NOBODY => true,
  9.             //CURLOPT_NOBODY => true,
  10.             CURLOPT_RETURNTRANSFER => true,
  11.         ]);
  12.  
  13.         $result = curl_exec($ch);
  14.         curl_close($ch);
  15.  
  16.         $result = json_decode($result, true);
  17.         if (json_last_error() !== \JSON_ERROR_NONE) {
  18.             throw new \Exception('Error json parsing.');
  19.         }
  20.         if (!is_array($result)) {
  21.             throw new \Exception('Response is not array.');
  22.         }
  23.         if ($result['status'] === 'fail') {
  24.             throw new \Exception('Failed: ' . $result['data']['error_message'] ?? '');
  25.         }
  26.         if (!isset($result['data']['txid'])) {
  27.             throw new \Exception('Txid have not');
  28.         }
  29.  
  30.         return $result['data']['txid'];
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement