|
@@ -56,6 +56,26 @@ function json_error($code,$msg='')
|
|
|
json_return($error['code'],[],$error['msg']);
|
|
|
}
|
|
|
|
|
|
+function http_get($url,$data)
|
|
|
+{
|
|
|
+ return json_decode(http_request('GET',$url,$data),true);
|
|
|
+}
|
|
|
+
|
|
|
+function http_post($url,$data)
|
|
|
+{
|
|
|
+ return json_decode(http_request('POST',$url,$data),true);
|
|
|
+}
|
|
|
+
|
|
|
+function http_request($method,$url,$data)
|
|
|
+{
|
|
|
+ $method = strtolower($method);
|
|
|
+ $params['method'] = $method;
|
|
|
+ $params['url'] = $url;
|
|
|
+ $params['data'] = $data;
|
|
|
+
|
|
|
+ return _curl($params);
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* php发送http请求
|
|
|
* @param array $params 相关请求参数
|
|
@@ -75,6 +95,8 @@ function _curl(array $params,$is_json=false )
|
|
|
CURLOPT_TIMEOUT => 60,
|
|
|
CURLOPT_SSL_VERIFYHOST=>2,
|
|
|
CURLOPT_SSL_VERIFYPEER=>0,
|
|
|
+
|
|
|
+
|
|
|
];
|
|
|
switch ($params['method'])
|
|
|
{
|
|
@@ -126,6 +148,33 @@ function _curl(array $params,$is_json=false )
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
+
|
|
|
+function request_post($url = '', $postData = []) {
|
|
|
+ if (empty($url)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ $postUrl = $url;
|
|
|
+ //初始化curl //转义
|
|
|
+ $ch = curl_init();
|
|
|
+ if ($postData != []) {
|
|
|
+ $vars = http_build_query($postData, '', '&');
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
|
|
|
+ }
|
|
|
+ //抓取指定网页
|
|
|
+ curl_setopt($ch, CURLOPT_URL,$postUrl);
|
|
|
+ //设置header
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
+ //要求结果为字符串且输出到屏幕上
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ //规避SSL验证
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
|
+ //跳过HOST验证
|
|
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
+ //运行curl
|
|
|
+ $data = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ return $data;
|
|
|
+}
|
|
|
/**
|
|
|
* 统一返回信息
|
|
|
* @param $code
|