-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurl.php
37 lines (35 loc) · 1.08 KB
/
curl.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
<?php
function postJsonWithCurl($url, $data): bool|string
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept-Encoding: gzip'
));
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
$response = curl_exec($ch);
curl_close($ch);
if ($response === false) {
return false;
}
return $response;
}
function getParameters(): false|array
{
$requiredParams = ['uin', 'version'];
$result = [];
foreach ($requiredParams as $param) {
if (!empty($_GET[$param])) {
$result[$param] = $_GET[$param];
} else {
return false;
}
}
$result['appid'] = !empty($_GET['appid']) ? $_GET['appid'] : null;
$result['targetApp'] = !empty($_GET['targetApp']) ? $_GET['targetApp'] : 'QQ';
return $result;
}