@@ -17,18 +17,23 @@ class HttpClient
1717 protected static $ client ;
1818
1919 protected static $ defaults = [
20- 'debug ' => false ,
21- 'verify ' => true ,
20+ 'debug ' => false ,
21+ 'verify ' => true ,
2222 // You can set any number of default request options.
2323 'timeout ' => 30 ,
2424 ];
2525
26+ /**
27+ * 配置
28+ * @param array $config
29+ */
2630 public static function setConfig (array $ config )
2731 {
2832 self ::$ defaults = $ config + self ::$ defaults ;
2933 }
3034
3135 /**
36+ * 客户端
3237 * @return Client
3338 */
3439 public static function getClient ()
@@ -41,9 +46,10 @@ public static function getClient()
4146 }
4247
4348 /**
44- * @param $method
49+ * 请求
50+ * @param $method
4551 * @param string $uri
46- * @param array $options
52+ * @param array $options
4753 * @return bool|\Psr\Http\Message\StreamInterface
4854 * @throws \GuzzleHttp\Exception\GuzzleException
4955 */
@@ -58,7 +64,8 @@ public static function request($method, $uri = '', array $options = [])
5864 }
5965
6066 /**
61- * @param $uri
67+ * get请求
68+ * @param $uri
6269 * @param array $options
6370 * @return bool|\Psr\Http\Message\StreamInterface
6471 * @throws \GuzzleHttp\Exception\GuzzleException
@@ -69,7 +76,8 @@ public static function get($uri, array $options = [])
6976 }
7077
7178 /**
72- * @param $url
79+ * post请求
80+ * @param $url
7381 * @param array $options
7482 * @return bool|\Psr\Http\Message\StreamInterface
7583 * @throws \GuzzleHttp\Exception\GuzzleException
@@ -82,28 +90,30 @@ public static function post($url, $options = [])
8290 }
8391
8492 /**
85- * @param $url
93+ * post json 数据
94+ * @param $url
8695 * @param string $options
87- * @param array $queries
88- * @param int $encodeOption
96+ * @param array $queries
97+ * @param int $encodeOption
8998 * @return bool|\Psr\Http\Message\StreamInterface
9099 * @throws \GuzzleHttp\Exception\GuzzleException
91100 */
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 )
93102 {
94103 is_array ($ options ) && $ options = json_encode ($ options , $ encodeOption );
95104
96105 return self ::request ('POST ' , $ url , [
97- 'query ' => $ queries ,
98- 'body ' => $ options ,
106+ 'query ' => $ queries ,
107+ 'body ' => $ options ,
99108 'headers ' => [
100- 'content-type ' => 'application/json '
109+ 'content-type ' => 'application/json ' ,
101110 ],
102111 ]);
103112 }
104113
105114 /**
106- * @param $url
115+ * 文件上传
116+ * @param $url
107117 * @param array $files
108118 * @param array $form
109119 * @param array $queries
@@ -116,7 +126,7 @@ public static function upload($url, array $files = [], array $form = [], array $
116126
117127 foreach ($ files as $ name => $ path ) {
118128 $ multipart [] = [
119- 'name ' => $ name ,
129+ 'name ' => $ name ,
120130 'contents ' => fopen ($ path , 'r ' ),
121131 ];
122132 }
@@ -130,7 +140,8 @@ public static function upload($url, array $files = [], array $form = [], array $
130140
131141
132142 /**
133- * @param $method
143+ * 解析json字符串
144+ * @param $method
134145 * @param array $args
135146 * @return bool|mixed
136147 */
0 commit comments