刘桂岩 3 سال پیش
والد
کامیت
391d222249
1فایلهای تغییر یافته به همراه67 افزوده شده و 18 حذف شده
  1. 67 18
      app/controller/Index.php

+ 67 - 18
app/controller/Index.php

@@ -49,37 +49,86 @@ class Index extends BaseController
             }
             $report = json_encode($obj);
             DB::table('dianapiinfo')->where('Barcode',$code)->update(['result_xml'=>$report]);
+            $this->getPdf($code);
             return 'success';
         }catch(\SoapFault $e){
             return $e->getMessage();
         }
     }
 
-
-    public function aa()
+    public function getPdf($code)
     {
-        $a = new \SimpleXMLElement();
-
-
-
-
-        ;die;
+        $type = 1;
         libxml_disable_entity_loader(false);
-        $client = new \SoapClient("http://112.103.134.89:10020/server.php?wsdl");
+        $client = new \SoapClient("https://r.dalabs.cn/ReportService.asmx?wsdl");
         $data = [
-            'Barcode'=>'12203310010001'
+            'ClientID'=>Config::get('app')['dian']['ClientID'],
+            'ClientGUID'=>Config::get('app')['dian']['ClientGUID'],
+            'BarCode'=>$code,
+            'model'=>$type
         ];   //请求参数
-        $a2x = new array2xml();
-        $data = $a2x->toXml($data);     //参数转xml
         try{
-            $result = $client->getDiAnData($data);   //请求获取接口
+            $result = $client->GetReportInfo($data);   //请求获取接口
+            $data = ((array)$result)['GetReportInfoResult'];
+            $obj = simplexml_load_string("<data>".$data."</data>","SimpleXMLElement", LIBXML_NOCDATA);
+            if($obj)
+            {
+                $info = json_decode(json_encode($obj),true);
+                $returnCode = $info['Msg']['Code'];
+                if($returnCode !== '1')
+                {
+                    return '报告PDF获取失败!迪安回传信息:'.$info['Msg']['Descript'];
+                }
+                if(isset($info['NewDataSet']['Table1']['BARCODE']))
+                {
+                    $pdf = $info['NewDataSet']['Table1']['PDFREPORTURL'];
+                    $name = $info['NewDataSet']['Table1']['BARCODE'];
+                    $this->downImgRar($pdf,$name,'pdf',$info['NewDataSet']['Table1']['BARCODE']);
+                }else{
+                    foreach ($info['NewDataSet']['Table1'] as $k=>$v)
+                    {
+                        $pdf = $v['PDFREPORTURL'];
+                        $name = $v['BARCODE'].'_'.($k+1);
+                        $this->downImgRar($pdf,$name,'pdf',$v['BARCODE']);
+                    }
+                }
+
+            }
+            return 'success';
         }catch(\SoapFault $e){
             return $e->getMessage();
         }
-        var_dump(htmlspecialchars($result));die;
-        $obj = simplexml_load_string($result,"SimpleXMLElement", LIBXML_NOCDATA);
-        $ins = json_encode($obj);
-        $obj = json_decode($ins,true);
-        var_dump($obj);die;
+    }
+
+    function downImgRar($url,$rename,$ext,$barCode){
+        switch ($ext) {
+            case 'png':
+            case 'jpg':    //下载图片
+                $file_path = '/images/';
+                break;
+            case 'pdf':    //下载PDF
+                $file_path = '/pdf/';
+                break;
+            case 'zip':
+            case 'rar':    //下载压缩包
+                $file_path = '/rar/';
+                break;
+            default:
+                $file_path = '/files/';
+                break;
+        }
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_HEADER, 0);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
+        curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
+        $rawdata=curl_exec ($ch);
+        curl_close ($ch);
+        // 使用中文文件名需要转码
+        file_put_contents($_SERVER['DOCUMENT_ROOT'].$file_path.$rename.'.'.$ext,$rawdata);
+        // 返回路径
+        $path = $_SERVER['DOCUMENT_ROOT'].$file_path.$rename.".".$ext;
+        $ins = ['type'=>$ext,'url'=>$path,'barcode'=>$barCode];
+        Db::table('annex')->insert($ins);
+        return 'success';
     }
 }