|
@@ -362,32 +362,27 @@ function pdfCurl($file_name)
|
|
|
return json_decode($result,true);
|
|
|
}
|
|
|
|
|
|
-function curlPost($url, $post_data = array(), $timeout = 5, $header = "", $data_type = "") {
|
|
|
- $header = empty($header) ? '' : $header;
|
|
|
- //支持json数据数据提交
|
|
|
- if($data_type == 'json'){
|
|
|
- $post_string = json_encode($post_data);
|
|
|
- }
|
|
|
- else if(is_array($post_data)){
|
|
|
- $post_string = http_build_query($post_data, '', '&');
|
|
|
- }else {
|
|
|
- $post_string = $post_data;
|
|
|
- }
|
|
|
+function curl_post($url,$post_data)
|
|
|
+{
|
|
|
+ // 1. 初始化一个cURL会话
|
|
|
+ //根据API的要求,定义相对应的Content-Type
|
|
|
+ $headers = [];
|
|
|
+ array_push($headers, "Content-Type".":"."application/json");
|
|
|
$ch = curl_init();
|
|
|
- curl_setopt($ch, CURLOPT_POST, true);
|
|
|
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
|
|
|
+ // 2. 设置请求选项, 包括具体的url
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // https请求 不验证证书和hosts
|
|
|
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
|
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
|
|
|
- curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
|
- curl_setopt($ch, CURLOPT_HTTPHEADER, array($header)); //模拟的header头
|
|
|
- $info = curl_getinfo($ch);
|
|
|
- $result = curl_exec($ch);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ // 设置请求为post类型
|
|
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
+ // 添加post数据到请求中
|
|
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
|
|
+ curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
|
+ // 3. 执行一个cURL会话并且获取相关回复
|
|
|
+ $response = curl_exec($ch);
|
|
|
+ // 4. 释放cURL句柄,关闭一个cURL会话
|
|
|
curl_close($ch);
|
|
|
-
|
|
|
- return $result;
|
|
|
+ return json_decode($response,true);
|
|
|
}
|
|
|
|
|
|
function getVideoTime($ali_id)
|