· 5 years ago · Jul 05, 2020, 03:00 PM
1<?php
2
3
4class Api
5{
6 public $api_url = 'http://upredes.com.br/api/v2/index.php'; // API URL
7
8 public $api_key = ''; // Your API key
9
10 public function order($data) { // add order
11 $post = array_merge(array('key' => $this->api_key, 'action' => 'add'), $data);
12 return json_decode($this->connect($post));
13 }
14
15 public function status($order_id) { // get order status
16 return json_decode($this->connect(array(
17 'key' => $this->api_key,
18 'action' => 'status',
19 'order' => $order_id
20 )));
21 }
22
23 public function multiStatus($order_ids) { // get order status
24 return json_decode($this->connect(array(
25 'key' => $this->api_key,
26 'action' => 'status',
27 'orders' => implode(",", (array)$order_ids)
28 )));
29 }
30
31 public function services() { // get services
32 return json_decode($this->connect(array(
33 'key' => $this->api_key,
34 'action' => 'services',
35 )));
36 }
37
38 public function balance() { // get balance
39 return json_decode($this->connect(array(
40 'key' => $this->api_key,
41 'action' => 'balance',
42 )));
43 }
44
45
46 private function connect($post) {
47 $_post = Array();
48 if (is_array($post)) {
49 foreach ($post as $name => $value) {
50 $_post[] = $name.'='.urlencode($value);
51 }
52 }
53
54 $ch = curl_init($this->api_url);
55 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
56 curl_setopt($ch, CURLOPT_POST, 1);
57 curl_setopt($ch, CURLOPT_HEADER, 0);
58 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
59 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
60 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
61 if (is_array($post)) {
62 curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
63 }
64 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
65 $result = curl_exec($ch);
66 if (curl_errno($ch) != 0 && empty($result)) {
67 $result = false;
68 }
69 curl_close($ch);
70 return $result;
71 }
72}
73
74// Examples
75
76$api = new Api();
77
78$services = $api->services(); # return all services
79
80$balance = $api->balance(); # return user balance
81
82
83
84// add order
85
86$order = $api->order(array('service' => 134, 'link' => 'http://example.com/test', 'quantity' => 500)); # Default
87
88
89$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'keywords'=>"test, testing")); # SEO
90
91$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'comments' => "good pic\ngreat photo\n:)\n;)")); # Custom Comments
92
93$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'usernames'=>"test, testing", 'hashtags'=>"#goodphoto")); # Mentions with Hashtags
94
95$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'usernames' => "test\nexample\nfb")); # Mentions Custom List
96
97$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 100, 'hashtag'=>"test")); # Mentions Hashtag
98
99$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 1000, 'username'=>"test")); # Mentions User Followers
100
101$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 1000, 'media'=>"http://example.com/p/Ds2kfEr24Dr")); # Mentions Media Likers
102
103$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test', 'quantity' => 1000, 'usernames'=>"test")); # Mentions
104
105$order = $api->order(array('service' => 1, 'link' => 'http://example.com/test')); # Package
106
107$status = $api->status($order->order); # return status, charge, remains, start count, currency
108
109$statuses = $api->multiStatus([1, 2, 3]); # return orders status, charge, remains, start count, currency