-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.txt
131 lines (107 loc) · 2.8 KB
/
example.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
class Api {
// API URL
public $api_url = 'http://yourwebsite.com/api/v1';
// Your API key
public $api_key = '';
/**
*
* Add Order
*
*/
public function add_order($data) {
$post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
$result = $this->connect($post);
return json_decode($result);
}
/**
*
* Order status
*
*/
public function status($order_id) {
$result = $this->connect(array(
'key' => $this->api_key,
'action' => 'status',
'order' => $order_id
));
return json_decode($result);
}
/**
*
* Order multi status
*
*/
public function multi_status($order_ids) {
$result = $this->connect(array(
'key' => $this->api_key,
'action' => 'status',
'orders' => json_encode($order_ids)
));
return json_decode($result);
}
/**
*
* All services
*
*/
public function services() {
$result = $this->connect(array(
'key' => $this->api_key,
'action' => 'services',
));
return json_decode($result);
}
/**
*
* Balance
*
*/
public function balance() {
$result = $this->connect(array(
'key' => $this->api_key,
'action' => 'balance',
));
return json_decode($result);
}
/**
*
* Connect to panel
*
*/
private function connect($post) {
$_post = Array();
if (is_array($post)) {
foreach ($post as $name => $value) {
$_post[] = $name.'='.urlencode($value);
}
}
if (is_array($post)) {
$url_complete = join('&', $_post);
}
$url = $this->api_url."?".$url_complete;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'API (compatible; MSIE 5.01; Windows NT 5.0)');
$result = curl_exec($ch);
if (curl_errno($ch) != 0 && empty($result)) {
$result = false;
}
curl_close($ch);
return $result;
}
}
// Examples
$api = new Api();
# return all services
$services = $api->services();
# return user balance
$balance = $api->balance();
// add order
$order = $api->add_order(array('service' => 2, 'link' => 'http://example.com/test', 'quantity' => 100));
# return status, charge, remains, start count, order_id
$status = $api->status(23);
# return orders status, charge, remains, start count, order_id
$statuses = $api->multi_status([12, 2, 13]);