ftp_server = Env::get('cebapi.ceb_ftp_host'); $key_env = Env::get('cebapi.KEY_ENV'); if ( $key_env == "TEST") { $this->cebhost = Env::get('cebapi.ceb_test_host'); $this->ftp_port = Env::get('cebapi.ceb_test_ftp_port'); } else { // PROD $this->cebhost = Env::get('cebapi.ceb_prop_host'); $this->ftp_port = Env::get('cebapi.ceb_prod_ftp_port'); } $this->ftp_user_name = Env::get('cebapi.ftp_user_name'); $this->ftp_user_pass = Env::get('cebapi.ftp_user_pass'); } public function getFileFromFtp($remotefile) { $ret['code'] = 1; $ret['data'] = ""; try { $sftp = new SFTPConnection($this->ftp_server, $this->ftp_port); $sftp->login($this->ftp_user_name, $this->ftp_user_pass); $fileData = $sftp->getFile( $remotefile); $ret['data'] = $fileData; return $ret; } catch (Exception $e) { $ret['code'] = -1; $ret['data'] = $e->getMessage() ; return $ret; } } public function sendFileToFtp($localfile, $path, $remotefile) { try { $sftp = new SFTPConnection($this->ftp_server, $this->ftp_port); $sftp->login($this->ftp_user_name, $this->ftp_user_pass); $sftp->uploadFile($localfile, $path, $remotefile); Log::debug('upload to ftp:' . $remotefile); } catch (Exception $e) { echo $e->getMessage() . "\n"; return false; } return true; } // 2.2.2 评估报告结果返回申请 public function getURLESZ006(){ return $this->cebhost . self::ESZ006_API; } public function getURLESZ004() { return $this->cebhost . self::ESZ004_API; } public function getURLESZ011() { return $this->cebhost . self::ESZ011_API; } public function getURLESZ009() { return $this->cebhost . self::ESZ009_API; } public function sendInquiryResult($data) { $url = $this->getURLESZ004(); $cebData['businessNo'] = $data['business_no'] ; $cebData['companyCode'] = $data['company_code'] ; $cebData['businessType'] = $data['business_type'] ; if($data['business_type'] == "01") { //贷前询价 $cebData['unitPriceDetail'] = "0"; $cebData['guidedUnitPriceDetail'] = "0"; }else if ($data['business_type'] == "02"){ //贷中询价 $cebData['unitPriceDetail'] = $data['unitPriceDetail']; $cebData['guidedUnitPriceDetail'] = $data['guidedUnitPriceDetail']; } $cebData['certificateNo'] = $data['certificate_no'] ; $cebData['estimateDealNo'] = $data['estimate_deal_no']; $cebData['totalPrice'] = $data['eva_total_value'] ; $cebData['chargeAmt'] = $data['charge_amt'] ; $cebData['guidedPrice'] = $data['guide_price'] ; $cebData['netWorth'] = $data['eva_net_value'] ; $cebData['evaluatorName'] = $data['evaluator_name'] ; $cebData['telephoneNumber'] = $data['telephone_number'] ; $cebData['estimateTime'] = $data['estimate_time'] ; $cebData['status'] = $data['status'] ; $cebData['field1'] = '' ; $cebData['field2'] = '' ; if(isset($data['reason'])) { $cebData['field3'] = $data['reason']; }else { $cebData['field3'] = ''; } return $this->sendToCEB($url,$cebData,"ESZ004"); } public function sendReevaluateResult($data) { $url = $this->getURLESZ011(); $cebData['businessNo'] = $data['businessNo'] ; $cebData['companyCode'] = $data['companyCode'] ; $cebData['estimateDealNo'] = $data['estimateDealNo'] ; $cebData['reevaluatedFileName'] = $data['reevaluatedFileName'] ; $cebData['reevaluatedFileEnd'] = $data['reevaluatedFileEnd'] ; $cebData['reevaluatedFilePath'] = $data['reevaluatedFilePath'] ; $cebData['status'] = $data['status'] ; $cebData['estimateTime'] = $data['estimateTime'] ; $cebData['field1'] = '' ; $cebData['field2'] = '' ; if(isset($data['reason'])) { $cebData['field3'] = $data['reason']; }else { $cebData['field3'] = ''; } return $this->sendToCEB($url,$cebData,"ESZ011"); } /** * ESZ006 预评估和正式报告回复 function * * @param [type] $data * @return void */ public function sendReportResult($data) { $url = $this->getURLESZ006(); $cebData['businessNo'] = $data['business_no'] ; $cebData['companyCode'] = $data['company_code'] ; $cebData['businessType'] = $data['business_type'] ; $cebData['returnReportType'] = $data['return_report_type'] ; $cebData['unitPrice'] = $data['eva_unit_price'] ; $cebData['estimateDealNo'] = $data['estimate_deal_no']; //已有预估编号,不需要再加公司编码做前缀 $cebData['totalPrice'] = $data['eva_total_value'] ; $cebData['totalTax'] = $data['total_tax'] ; $cebData['detailTax'] = $data['detail_tax']; $cebData['chargeAmt'] = $data['charge_amt'] ; $cebData['guidedPrice'] = $data['guide_price'] ; $cebData['netWorth'] = $data['eva_net_value'] ; $cebData['estimateReportName'] = $data['estimate_report_name'] ; $cebData['estimateReportEnd'] = $data['estimate_report_end'] ; $cebData['estimateReportPath'] = $data['estimate_report_path'] ; if( $data['business_type'] == CebReportResult::BUSINESS_TYPE_REPORT ) { $cebData['mortgagor1'] = $data['mortgagor1'] ; $cebData['mortgagor2'] = $data['mortgagor2'] ; $cebData['mortgagor3'] = $data['mortgagor3'] ; $cebData['mortgagor4'] = $data['mortgagor4'] ; $cebData['mortgagor5'] = $data['mortgagor5'] ; $cebData['mortgagor6'] = $data['mortgagor6'] ; $cebData['field1'] = $data['field1'] ; } else { $cebData['mortgagor1'] = "" ; $cebData['mortgagor2'] = "" ; $cebData['mortgagor3'] = "" ; $cebData['mortgagor4'] = "" ; $cebData['mortgagor5'] = "" ; $cebData['mortgagor6'] = "" ; $cebData['field1'] = ''; } $cebData['resultStatus'] = $data['result_status'] ; $cebData['reason'] = $data['reason'] ; $cebData['field2'] = '' ; $cebData['field3'] = '' ; $cebData['estimateTime'] = $data['estimate_time'] ; return $this->sendToCEB($url,$cebData,"ESZ006"); } public function sendCheckResult($data) { $url = $this->getURLESZ009(); $cebData['businessNo'] = $data['business_no'] ; $cebData['companyCode'] = $data['company_code'] ; $cebData['estimateDealNo'] = $data['estimate_deal_no']; $cebData['checkTotalPrice'] = $data['check_total_price'] ; $cebData['checkNetWorth'] = $data['check_net_worth'] ; $cebData['checkChargeAmt'] = $data['check_charge_amt'] ; $cebData['checkTime'] = $data['check_time'] ; $cebData['checkStatus'] = $data['check_status'] ; $cebData['field1'] = '' ; $cebData['field2'] = '' ; if(isset($data['reason'])){ $cebData['field3'] = $data['reason'] ; }else{ $cebData['field3'] = '' ; } return $this->sendToCEB($url,$cebData,"ESZ009"); } /** *发送给银行 */ public function sendToCEB($url,$data,$tranCode) { Log::debug("--------------------发送给光大银行-------------------"); Log::debug($url); Log::debug($data); //$arr_header['Content-Type'] = "application/json; charset=utf-8"; //$arr_header['Cebsz'] ="oemp"; //$arr_header['tranCode'] =$tranCode; $arr_header = array( "Content-Type: application/json; charset=utf-8", "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36", "Cebsz:oemp", "tranCode:" . $tranCode . "" ); $httpreturn = $this->http_post($url,$data,false,60,$arr_header); Log::debug("------------------Http post 返回-------------"); try{ Log::debug($httpreturn); }catch(Exception $e){ Log::warning($e->getMessage()); } return $httpreturn; } public function responseToCEB($code,$msg,$data) { $res['code'] = $code; $res['message'] = $msg; $res['data'] = $data; $response = Response::create($res, 'json'); return $response; } /** * GET 请求 * @param string $url */ public function http_get($url,$param,$arr_header=array()){ $oCurl = curl_init(); if (is_string($param)) { $strPOST = $param; } else { $aPOST = array(); foreach ($param as $key => $val) { $aPOST[] = $key . "=" . $val; } $strPOST = join("&", $aPOST); } $url = $url."?".$strPOST; if (stripos($url, "https://") !== false) { curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1 } curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); if(!empty($arr_header)){ $arr_header[] = "Content-Type: application/json; charset=utf-8"; } curl_setopt($oCurl, CURLOPT_HTTPHEADER, $arr_header); $sContent = curl_exec($oCurl); if (curl_errno($oCurl)){ throw new Exception(curl_error($oCurl),0); }else{ $httpStatusCode = curl_getinfo($oCurl, CURLINFO_HTTP_CODE); if (200 !== $httpStatusCode){ throw new Exception($arr_header[1],$httpStatusCode); } } curl_close($oCurl); return $sContent; } /** * POST 请求 * @param string $url * @param array $param * @param boolean $post_file 是否文件上传 * @param boolean $timeout 超时时间,单位秒 * @param boolean $arr_header http请求头 * @return string content */ public function http_post($url, $param, $post_file = false, $timeout = 30,$arr_header=array()){ $ch = curl_init(); curl_setopt_array($ch, array( // 不直接输出,返回到变量 CURLOPT_RETURNTRANSFER => true, // 设置超时为60s,防止机器被大量超时请求卡死 CURLOPT_TIMEOUT => $timeout )); // 支持POST请求 if (!empty($param)) { curl_setopt_array($ch, array( CURLOPT_POST => true, // 设置POST参数 CURLOPT_POSTFIELDS => json_encode($param) )); } /* if (is_string($param) || $post_file) { $strPOST = $param; } else { $aPOST = array(); foreach ($param as $key => $val) { $aPOST[] = $key . "=" . $val; } $strPOST = join("&", $aPOST); } */ curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $arr_header); $sContent = curl_exec($ch); $aStatus = curl_getinfo($ch); curl_close($ch); if (intval($aStatus["http_code"]) == 200) { return $sContent; } else { return $aStatus; } } /** * DELETE 请求 * @param string $url * @param array $param * @param boolean $user_name AUTH账号 * @param boolean $password AUTH密码 * @return string content */ function http_delete($url,$param,$user_name,$password) { $oCurl = curl_init(); if (is_string($param)) { $strPOST = $param; } else { $aPOST = array(); foreach ($param as $key => $val) { $aPOST[] = $key . "=" . $val; } $strPOST = join("&", $aPOST); } $url = $url."?".$strPOST; curl_setopt($oCurl, CURLOPT_URL, $url); curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($oCurl, CURLOPT_CUSTOMREQUEST, 'DELETE'); //设置头 curl_setopt($oCurl, CURLOPT_USERPWD, "{$user_name}:{$password}"); curl_setopt($oCurl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Safari/537.36'); curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, false);//SSL认证。 $sContent = curl_exec($oCurl); $aStatus = curl_getinfo($oCurl); curl_close($oCurl); if (intval($aStatus["http_code"]) == 200) { return $sContent; } else { return false; } } }