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