· 4 years ago · Jun 06, 2021, 01:54 AM
1<?php
2class Api
3{
4 public $api_url = ''; // API URL / Endpoint
5
6 public $api_id = ''; // Your API ID
7
8 public $api_key = ''; // Your API key
9
10 public function order($data) { // add order
11 return json_decode($this->connect($this->api_url . '/order', array_merge(array(
12 'api_id' => $this->api_id,
13 'api_key' => $this->api_key,
14 ), $data
15 )));
16 }
17
18 public function status($order_id) { // get order status
19 return json_decode($this->connect($this->api_url . '/status', array(
20 'api_id' => $this->api_id,
21 'api_key' => $this->api_key,
22 'id' => $order_id
23 )));
24 }
25
26 public function services() { // get services
27 return json_decode($this->connect($this->api_url . '/services', array(
28 'api_id' => $this->api_id,
29 'api_key' => $this->api_key,
30 )));
31 }
32
33 public function profile() { // get profile
34 return json_decode($this->connect($this->api_url . '/profile', array(
35 'api_id' => $this->api_id,
36 'api_key' => $this->api_key,
37 )));
38 }
39
40
41 private function connect($url, $post) {
42 $_post = Array();
43 if (is_array($post)) {
44 foreach ($post as $name => $value) {
45 $_post[] = $name.'='.urlencode($value);
46 }
47 }
48
49 $ch = curl_init($url);
50 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
51 curl_setopt($ch, CURLOPT_POST, 1);
52 curl_setopt($ch, CURLOPT_HEADER, 0);
53 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
54 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
55 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
56 if (is_array($post)) {
57 curl_setopt($ch, CURLOPT_POSTFIELDS, join('&', $_post));
58 }
59 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
60 $result = curl_exec($ch);
61 if (curl_errno($ch) != 0 && empty($result)) {
62 $result = false;
63 }
64 curl_close($ch);
65 return $result;
66 }
67}