Fpay


SUBMITTED BY: XGrats

DATE: Sept. 30, 2023, 7:13 a.m.

FORMAT: Text only

SIZE: 2.3 kB

HITS: 276

  1. <?php
  2. class FaucetPay
  3. {
  4. public $BASE = "https://faucetpay.io/";
  5. public $use_curl = true;
  6. public $default_array = array(
  7. 'api_key' => ''
  8. );
  9. function __construct($api_key, $use_curl=true, $api_version='v1')
  10. {
  11. $this->BASE .= $api_version;
  12. $this->default_array['api_key'] = $api_key;
  13. $this->use_curl = $use_curl;
  14. }
  15. function post_curl($url, $params)
  16. {
  17. $ch = curl_init($url);
  18. curl_setopt_array($ch, array(
  19. CURLOPT_POST => 1,
  20. CURLOPT_POSTFIELDS => $params,
  21. CURLOPT_RETURNTRANSFER => true
  22. ));
  23. $data = curl_exec($ch);
  24. curl_close($ch);
  25. return json_decode($data, true);
  26. }
  27. function post_no_curl($url, $params)
  28. {
  29. $postdata = http_build_query(
  30. $params
  31. );
  32. $opts = array('http' =>
  33. array(
  34. 'method' => 'POST',
  35. 'header' => 'Content-type: application/x-www-form-urlencoded',
  36. 'content' => $postdata
  37. )
  38. );
  39. $context = stream_context_create($opts);
  40. $result = file_get_contents($url, false, $context);
  41. return json_decode($result, true);
  42. }
  43. function __call($method, $arguments)
  44. {
  45. // TODO: When named arguments widely used, i will implement here
  46. if (count($arguments) === 0)
  47. {
  48. $arguments[0] = [];
  49. $arguments[1] = false;
  50. }
  51. $response = array();
  52. $test = end($arguments) === TRUE;
  53. $arguments = array_merge($this->default_array, $arguments[0]);
  54. if ($this->use_curl)
  55. {
  56. $response = $this->post_curl("{$this->BASE}/$method", $arguments);
  57. }
  58. else
  59. {
  60. $response = $this->post_no_curl("{$this->BASE}/$method", $arguments);
  61. }
  62. if ($test)
  63. {
  64. echo "Calling: <b>{$this->BASE}/$method</b><br/>
  65. <h3>Arguments</h3>";
  66. echo "<pre>" . print_r($arguments, true) . "</pre>";
  67. echo "<br/><h3>Response</h3>";
  68. echo "<pre>" . print_r($response, true) . "</pre>";
  69. }
  70. return $response;
  71. }
  72. }
  73. ?>

comments powered by Disqus