fork download
  1. <?php
  2. class Api
  3. {
  4. const API_URL = 'http://d...content-available-to-author-only...n.com/api/v2'; // API URL/Replace reseller domain
  5. const API_TOKEN = ''; // Your API token
  6.  
  7. public function order($data) { // add order
  8. $post = array_merge([
  9. 'api_token' => self::API_TOKEN,
  10. 'action' => 'add'
  11. ], $data);
  12.  
  13. return json_decode($this->connect($post));
  14. }
  15.  
  16. public function status($order_id) { // get order status
  17. return json_decode($this->connect([
  18. 'api_token' => self::API_TOKEN,
  19. 'action' => 'status',
  20. 'order' => $order_id
  21. ]));
  22. }
  23.  
  24. public function balance() { // get balance
  25. return json_decode($this->connect([
  26. 'api_token' => self::API_TOKEN,
  27. 'action' => 'balance',
  28. ]));
  29. }
  30.  
  31. public function packages() { // get packages list
  32. return json_decode($this->connect([
  33. 'api_token' => self::API_TOKEN,
  34. 'action' => 'packages',
  35. ]));
  36. }
  37.  
  38. private function connect($post) {
  39. $_post = Array();
  40. foreach ($post as $name => $value) {
  41. $_post[$name] = urlencode($value);
  42. }
  43.  
  44. $ch = curl_init(self::API_URL);
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  46. curl_setopt($ch, CURLOPT_POST, 1);
  47. curl_setopt($ch, CURLOPT_HEADER, 0);
  48. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  49. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  50. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
  51.  
  52. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
  53. $result = curl_exec($ch);
  54. if (curl_errno($ch) != 0 && empty($result)) {
  55. $result = false;
  56. }
  57. curl_close($ch);
  58. return $result;
  59. }
  60. }
  61.  
  62. // Examples
  63.  
  64. $api = new Api();
  65.  
  66. // Fetch Packages
  67. $packages = $api->packages();
  68.  
  69. // Check balance
  70. $balance = $api->balance();
  71.  
  72. // Add order
  73. $order = $api->order(array('package' => 1, 'link' => 'http://e...content-available-to-author-only...e.com/link', 'quantity' => 100));
  74.  
  75. // Add Custom comments order
  76. $order = $api->order(array('package' => 11, 'link' => 'http://e...content-available-to-author-only...e.com/link', 'quantity' => 4, 'comments' => "good pic\ngreat photo\n:)\n;)")); # Custom Comments
  77.  
  78. // Check Order status
  79. $status = $api->status($order->order);
Success #stdin #stdout #stderr 0.04s 26500KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Notice:  Trying to get property 'order' of non-object in /home/iAYW1D/prog.php on line 79