-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.php
58 lines (54 loc) · 1.46 KB
/
common.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
<?php
function backtrace()
{
$backtrace = debug_backtrace();
$backtrace = array_shift($backtrace);
return json_encode($backtrace);
}
function curl_get($uri, $req = NULL)
{
$str = '';
foreach ($req as $key => $value) {
$str .= $key . '=' . $value . '&';
}
$req = trim($str, '&');
$url = $uri . '?' . $req;
$cuh = curl_init();
curl_setopt($cuh, CURLOPT_URL, $url);
curl_setopt($cuh, CURLOPT_HEADER, 0);
curl_setopt($cuh, CURLOPT_TIMEOUT, 90);
curl_setopt($cuh, CURLOPT_RETURNTRANSFER, 1);
$rsp = curl_exec($cuh);
if ($rsp === false) {
$error = curl_error($cuh);
$errno = curl_errno($cuh);
curl_close($cuh);
RedisLog::info($errno . $error);
} else {
curl_close($cuh);
}
$rsp = json_decode($rsp, true);
return $rsp;
}
function curl_post($uri, $req)
{
$url = $uri;
$cuh = curl_init();
curl_setopt($cuh, CURLOPT_URL, $url);
curl_setopt($cuh, CURLOPT_HEADER, 0);
curl_setopt($cuh, CURLOPT_TIMEOUT, 90);
curl_setopt($cuh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cuh, CURLOPT_POST, 1);
curl_setopt($cuh, CURLOPT_POSTFIELDS, $req);
$rsp = curl_exec($cuh);
if ($rsp === false) {
$error = curl_error($cuh);
$errno = curl_errno($cuh);
curl_close($cuh);
\think\custom\common\RedisLog::info($errno . $error);
} else {
curl_close($cuh);
}
$rsp = json_decode($rsp, true);
return $rsp;
}