wupengfei 2 年之前
父節點
當前提交
b9b4d02aac
共有 3 個文件被更改,包括 32 次插入1 次删除
  1. 2 0
      .idea/workspace.xml
  2. 1 0
      application/api/controller/Upload.php
  3. 29 1
      application/common.php

+ 2 - 0
.idea/workspace.xml

@@ -2,6 +2,8 @@
 <project version="4">
   <component name="ChangeListManager">
     <list default="true" id="1a36929e-c054-4875-a943-593a74e55fa4" name="Default Changelist" comment="">
+      <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
+      <change beforePath="$PROJECT_DIR$/application/api/controller/Upload.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/api/controller/Upload.php" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/application/common.php" beforeDir="false" afterPath="$PROJECT_DIR$/application/common.php" afterDir="false" />
     </list>
     <option name="SHOW_DIALOG" value="false" />

+ 1 - 0
application/api/controller/Upload.php

@@ -97,6 +97,7 @@ class Upload extends Base
         $headers = [];
         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
         $res = pdfCurl($file->getInfo()['name']);
+        var_dump(curlPost('http://101.132.128.55:9999/v1/pdf/upload'),$_FILES);
         var_dump($res);
 
 

+ 29 - 1
application/common.php

@@ -345,9 +345,11 @@ function pdfCurl($file_name)
     curl_setopt($ch, CURLOPT_URL, 'http://101.132.128.55:9999/v1/pdf/upload');
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_POST, 1);
-    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['file@'=>$file_name]));
+    curl_setopt($ch, CURLOPT_POSTFIELDS, ['file'=>$file_name]);
     $headers = array();
+
     $headers[] = 'Content-Type: application/x-www-form-urlencoded';
+    $headers[] = 'Content-Type: multipart/form-data';
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     $result = curl_exec($ch);
     if (curl_errno($ch)) {
@@ -357,7 +359,33 @@ function pdfCurl($file_name)
     return $result;
 }
 
+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;
+    }
+    $ch = curl_init();
+    curl_setopt($ch, CURLOPT_POST, true);
+    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
+    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_close($ch);
 
+    return $result;
+}
 
 function getVideoTime($ali_id)
 {