· 4 years ago · Aug 16, 2021, 10:14 AM
1<?php
2class Api
3{
4 public $api_url = '██████████████████████████'; // API URL
5
6 public $api_key = ''; // Your API key
7
8 public function order($data) { // add order
9 $post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
10 return json_decode($this->connect($post));
11 }
12
13 public function status($order_id) { // get order status
14 return json_decode($this->connect(array(
15 'key' => $this->api_key,
16 'action' => 'status',
17 'order' => $order_id
18 )));
19 }
20
21 public function multiStatus($order_ids) { // get order status
22 return json_decode($this->connect(array(
23 'key' => $this->api_key,
24 'action' => 'status',
25 'orders' => implode(",", (array)$order_ids)
26 )));
27 }
28
29 public function services() { // get services
30 return json_decode($this->connect(array(
31 'key' => $this->api_key,
32 'action' => 'services',
33 )));
34 }
35
36 public function balance() { // get balance
37 return json_decode($this->connect(array(
38 'key' => $this->api_key,
39 'action' => 'balance',
40 )));
41 }
42
43
44 private function connect($post) {
45 $_post = Array();
46 if (is_array($post)) {
47 foreach ($post as $name => $value) {
48 $_post[] = $name.'='.urlencode($value);
49 }
50 }
51
52 $ch = curl_init($this->api_url);
53 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
54 curl_setopt($ch, CURLOPT_POST, 1);
55 curl_setopt($ch, CURLOPT_HEADER, 0);
56 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
57 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
58 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
59 if (is_array($post)) {
60 curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
61 }
62 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
63 $result = curl_exec($ch);
64 if (curl_errno($ch) != 0 && empty($result)) {
65 $result = false;
66 }
67 curl_close($ch);
68 return $result;
69 }
70}
71
72// Examples
73
74$api = new Api();
75
76$services = $api->services(); # return all services
77
78$balance = $api->balance(); # return user balance
79
80// add order
81
82$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100)); # Default
83
84$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'comments' => "good pic\ngreat photo\n:)\n;)")); # Custom Comments
85
86$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test')); # Package
87
88$order = $api->order(array('service' => 1, 'username' => 'username', 'min' => 100, 'max' => 110, 'posts' => 0,'delay' => 30, 'expiry' => '11/11/2019')); # Subscriptions
89
90$status = $api->status($order->order); # return status, charge, remains, start count, currency
91
92$statuses = $api->multiStatus([1, 2, 3]); # return orders status, charge, remains, start count, currency