|
@@ -11,11 +11,11 @@ class Http
|
|
|
/**
|
|
|
* 发送一个POST请求
|
|
|
* @param string $url 请求URL
|
|
|
- * @param array $params 请求参数
|
|
|
- * @param array $options 扩展参数
|
|
|
+ * @param array $params 请求参数
|
|
|
+ * @param array $options 扩展参数
|
|
|
* @return mixed|string
|
|
|
*/
|
|
|
- public static function post($url, $params = [], $options = [])
|
|
|
+ public static function post(string $url, array $params = [], array $options = [])
|
|
|
{
|
|
|
$req = self::sendRequest($url, $params, 'POST', $options);
|
|
|
return $req['ret'] ? $req['msg'] : '';
|
|
@@ -24,11 +24,11 @@ class Http
|
|
|
/**
|
|
|
* 发送一个GET请求
|
|
|
* @param string $url 请求URL
|
|
|
- * @param array $params 请求参数
|
|
|
- * @param array $options 扩展参数
|
|
|
+ * @param array $params 请求参数
|
|
|
+ * @param array $options 扩展参数
|
|
|
* @return mixed|string
|
|
|
*/
|
|
|
- public static function get($url, $params = [], $options = [])
|
|
|
+ public static function get(string $url, array $params = [], array $options = [])
|
|
|
{
|
|
|
$req = self::sendRequest($url, $params, 'GET', $options);
|
|
|
return $req['ret'] ? $req['msg'] : '';
|
|
@@ -42,7 +42,7 @@ class Http
|
|
|
* @param mixed $options CURL的参数
|
|
|
* @return array
|
|
|
*/
|
|
|
- public static function sendRequest($url, $params = [], $method = 'POST', $options = [])
|
|
|
+ public static function sendRequest(string $url, $params = [], string $method = 'POST', $options = []): array
|
|
|
{
|
|
|
$method = strtoupper($method);
|
|
|
$protocol = substr($url, 0, 5);
|
|
@@ -108,7 +108,7 @@ class Http
|
|
|
* @param string $method 请求的方法
|
|
|
* @return boolean TRUE
|
|
|
*/
|
|
|
- public static function sendAsyncRequest($url, $params = [], $method = 'POST')
|
|
|
+ public static function sendAsyncRequest(string $url, $params = [], string $method = 'POST'): bool
|
|
|
{
|
|
|
$method = strtoupper($method);
|
|
|
$method = $method == 'POST' ? 'POST' : 'GET';
|
|
@@ -157,10 +157,10 @@ class Http
|
|
|
/**
|
|
|
* 发送文件到客户端
|
|
|
* @param string $file
|
|
|
- * @param bool $delaftersend
|
|
|
- * @param bool $exitaftersend
|
|
|
+ * @param bool $deleteAfterSend
|
|
|
+ * @param bool $exitAfterSend
|
|
|
*/
|
|
|
- public static function sendToBrowser($file, $delaftersend = true, $exitaftersend = true)
|
|
|
+ public static function sendToBrowser(string $file, bool $deleteAfterSend = true, bool $exitAfterSend = true)
|
|
|
{
|
|
|
if (file_exists($file) && is_readable($file)) {
|
|
|
header('Content-Description: File Transfer');
|
|
@@ -174,10 +174,10 @@ class Http
|
|
|
ob_clean();
|
|
|
flush();
|
|
|
readfile($file);
|
|
|
- if ($delaftersend) {
|
|
|
+ if ($deleteAfterSend) {
|
|
|
unlink($file);
|
|
|
}
|
|
|
- if ($exitaftersend) {
|
|
|
+ if ($exitAfterSend) {
|
|
|
exit;
|
|
|
}
|
|
|
}
|