-
Notifications
You must be signed in to change notification settings - Fork 0
/
Request.php
140 lines (97 loc) · 2.83 KB
/
Request.php
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
131
132
133
134
135
136
137
138
139
140
<?php
class Request {
public $service;
public $url;
public $number;
public $cc = "+91";
public $payload = "";
public $data_type = "";
public $timeout = 100;
public function __construct($service,$number) {
$this->service = $service;
$this->number = $number;
}
public function _parse() {
if ($this->service->method == "POST") {
$this->payload = $this->service->data;
}
else {
$this->payload = $this->service->params;
}
foreach ($this->payload as $key => $value) {
if ($value == "{target}") {
$this->payload->$key = $this->number;
}
if ($value == "{cc}") {
$this->payload->$key = $this->cc;
}
}
// print_r($this->payload);
return $this->payload;
}
public function _headers()
{
$temp = [];
if (property_exists($this->service, "headers")) {
$temp = (array) $this->service->headers;
}
$temp = [ "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) \ AppleWebKit/537.36 (KHTML, like Gecko) \ Chrome/91.0.4472.124 Safari/537.36"];
// print_r($this->data_type);
if ($this->data_type == "json") {
array_push($temp, 'Content-Type: application/json');
}
return $temp;
}
public function _get($mh) {
$queryString = http_build_query($this->payload);
$this->url =$this->service->url;
$this->url = $this->url . '?' . $queryString;
$ch = curl_init($this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_headers());
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
// $response = curl_exec($ch);
// if ($response === false) {
// echo curl_error($ch);
// } else {
// echo $response;
// }
// curl_close($ch);
curl_multi_add_handle($mh,$ch);
}
public function _post($mh) {
$jsonData = "";
if (property_exists($this->service, "data_type") && $this->service->data_type == "json") {
$this->data_type = "json";
$jsonData = json_encode($this->payload);
}
else {
$jsonData = http_build_query( (array) $this->payload);
}
$this->url =$this->service->url;
$ch = curl_init($this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
// print_r($this->_headers());
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->_headers());
// $response = curl_exec($ch);
// if ($response === false) {
// echo curl_error($ch);
// } else {
// echo $response;
// }
// curl_close($ch);
curl_multi_add_handle($mh,$ch);
}
public function _run($mh) {
$this->_parse();
if ($this->service->method == "POST") {
$this->_post($mh);
}
else {
$this->_get($mh);
}
}
}