@@ -17,18 +17,23 @@ class HttpClient
17
17
protected static $ client ;
18
18
19
19
protected static $ defaults = [
20
- 'debug ' => false ,
21
- 'verify ' => true ,
20
+ 'debug ' => false ,
21
+ 'verify ' => true ,
22
22
// You can set any number of default request options.
23
23
'timeout ' => 30 ,
24
24
];
25
25
26
+ /**
27
+ * 配置
28
+ * @param array $config
29
+ */
26
30
public static function setConfig (array $ config )
27
31
{
28
32
self ::$ defaults = $ config + self ::$ defaults ;
29
33
}
30
34
31
35
/**
36
+ * 客户端
32
37
* @return Client
33
38
*/
34
39
public static function getClient ()
@@ -41,9 +46,10 @@ public static function getClient()
41
46
}
42
47
43
48
/**
44
- * @param $method
49
+ * 请求
50
+ * @param $method
45
51
* @param string $uri
46
- * @param array $options
52
+ * @param array $options
47
53
* @return bool|\Psr\Http\Message\StreamInterface
48
54
* @throws \GuzzleHttp\Exception\GuzzleException
49
55
*/
@@ -58,7 +64,8 @@ public static function request($method, $uri = '', array $options = [])
58
64
}
59
65
60
66
/**
61
- * @param $uri
67
+ * get请求
68
+ * @param $uri
62
69
* @param array $options
63
70
* @return bool|\Psr\Http\Message\StreamInterface
64
71
* @throws \GuzzleHttp\Exception\GuzzleException
@@ -69,7 +76,8 @@ public static function get($uri, array $options = [])
69
76
}
70
77
71
78
/**
72
- * @param $url
79
+ * post请求
80
+ * @param $url
73
81
* @param array $options
74
82
* @return bool|\Psr\Http\Message\StreamInterface
75
83
* @throws \GuzzleHttp\Exception\GuzzleException
@@ -82,28 +90,30 @@ public static function post($url, $options = [])
82
90
}
83
91
84
92
/**
85
- * @param $url
93
+ * post json 数据
94
+ * @param $url
86
95
* @param string $options
87
- * @param array $queries
88
- * @param int $encodeOption
96
+ * @param array $queries
97
+ * @param int $encodeOption
89
98
* @return bool|\Psr\Http\Message\StreamInterface
90
99
* @throws \GuzzleHttp\Exception\GuzzleException
91
100
*/
92
- public function json ($ url , $ options = '{} ' , array $ queries = [], $ encodeOption = JSON_UNESCAPED_UNICODE )
101
+ public static function json ($ url , $ options = '{} ' , array $ queries = [], $ encodeOption = JSON_UNESCAPED_UNICODE )
93
102
{
94
103
is_array ($ options ) && $ options = json_encode ($ options , $ encodeOption );
95
104
96
105
return self ::request ('POST ' , $ url , [
97
- 'query ' => $ queries ,
98
- 'body ' => $ options ,
106
+ 'query ' => $ queries ,
107
+ 'body ' => $ options ,
99
108
'headers ' => [
100
- 'content-type ' => 'application/json '
109
+ 'content-type ' => 'application/json ' ,
101
110
],
102
111
]);
103
112
}
104
113
105
114
/**
106
- * @param $url
115
+ * 文件上传
116
+ * @param $url
107
117
* @param array $files
108
118
* @param array $form
109
119
* @param array $queries
@@ -116,7 +126,7 @@ public static function upload($url, array $files = [], array $form = [], array $
116
126
117
127
foreach ($ files as $ name => $ path ) {
118
128
$ multipart [] = [
119
- 'name ' => $ name ,
129
+ 'name ' => $ name ,
120
130
'contents ' => fopen ($ path , 'r ' ),
121
131
];
122
132
}
@@ -130,7 +140,8 @@ public static function upload($url, array $files = [], array $form = [], array $
130
140
131
141
132
142
/**
133
- * @param $method
143
+ * 解析json字符串
144
+ * @param $method
134
145
* @param array $args
135
146
* @return bool|mixed
136
147
*/
0 commit comments