-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathExpressCrypto.php
More file actions
130 lines (107 loc) · 5.02 KB
/
ExpressCrypto.php
File metadata and controls
130 lines (107 loc) · 5.02 KB
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
129
130
<?php
$current_ver="2.0";
/*
The ExpressCryptoV2 class exploses public methods
This class based on FaucetInBox lib https://github.com/coinables/Bitcoin-Faucet-Dice-Faucet-Box/blob/master/faucetbox/faucetbox.php
*/
class ExpressCryptoV2{
//params
protected $api_key;
protected $user_token;
protected $ip_user; //please send to us the ip of user that will help us tracking fraud actions.
protected $timeout; //by default we use configuration from your php.ini | however, you could customize the timeout depend of your needs (max 90s).
protected $api_base = "https://expresscrypto.io/public-api/v2/";
public $last_status = null;
//methods
public function __construct($api_key, $user_token, $ip_user = "", $disable_curl = false, $verify_peer = true, $timeout = null) {
$this->api_key = $api_key;
$this->user_token = $user_token;
$this->ip_user = $ip_user;
$this->disable_curl = $disable_curl;
$this->verify_peer = $verify_peer;
$this->curl_warning = false;
$this->setTimeout($timeout);
}
public function __exec($method, $params = array()) {
$this->last_status = null;
if($this->disable_curl) {
$response = $this->__execPHP($method, $params);
} else {
$response = $this->__execCURL($method, $params);
}
$response = json_decode($response, true);
if($response) {
$this->last_status = $response['status'];
} else {
$this->last_status = null;
$response = array("status" => 520, "message" => "Invalid response");
}
return $response;
}
public function __execPHP($method, $params = array()) {
$params = array_merge($params, array("api_key" => $this->api_key, "user_token" => $this->user_token, "ip_user" => $this->ip_user));
$opts = array(
"http" => array(
"method" => "POST",
"header" => "Content-type: application/x-www-form-urlencoded\r\n",
"content" => http_build_query($params),
"timeout" => $this->timeout
),
"ssl" => array(
"verify_peer" => $this->verify_peer
)
);
$ctx = stream_context_create($opts);
$fp = fopen($this->api_base . $method, 'rb', null, $ctx);
if(!$fp){
return json_encode(array("status" => 521, "message" => "Connection refused, please try again later..."));
}else{
$response = stream_get_contents($fp);
if($response && !$this->disable_curl) {
$this->curl_warning = true;
}
fclose($fp);
return $response;
}
}
public function __execCURL($method, $params = array()) {
$params = array_merge($params, array("api_key" => $this->api_key, "user_token" => $this->user_token, "ip_user" => $this->ip_user));
$headers = array(
"Content-type: application/json;charset=\"utf-8\"",
"Accept: application/json"
);
$ch = curl_init($this->api_base . $method);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_peer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_TIMEOUT, (int)$this->timeout);
$response = curl_exec($ch);
if(!$response) {
return json_encode(array("status" => 524, "message" => "Connection error"));
}
curl_close($ch);
return $response;
}
public function setTimeout($timeout) {
if($timeout === null) {
$socket_timeout = ini_get('default_socket_timeout');
$script_timeout = ini_get('max_execution_time');
$timeout = min($script_timeout / 2, $socket_timeout);
}
$this->timeout = $timeout;
}
public function sendPayment($userId, $currency, $amount){
return $this->__exec("sendPayment", array("userId" => $userId, "currency" => $currency, "amount" => $amount, "payment_type" => "Normal"));
}
public function sendReferralCommission($userId, $currency, $amount){
return $this->__exec("sendReferralCommission", array("userId" => $userId, "currency" => $currency, "amount" => $amount, "payment_type" => "Referral"));
}
public function checkUserHash($userId){
return $this->__exec("checkUserHash", array("userId" => $userId));
}
public function getBalance($currency){
return $this->__exec("getBalance", array("currency" => $currency));
}
}