first commit
This commit is contained in:
94
pgserver/application/admin/service/Consultfiles.php
Normal file
94
pgserver/application/admin/service/Consultfiles.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
class Consultfiles {
|
||||
|
||||
/**
|
||||
* 查档
|
||||
*/
|
||||
public function Consultfiles($data) {
|
||||
$url = config('serviceConfig.API_CONSULT_PRO_URL');
|
||||
$result = json_decode($this->post($url, json_encode($data), 60, ['Content-type: application/json']), true);
|
||||
|
||||
if (!isset($result['code']) || !in_array($result['code'], array(-1, 1, 2)))
|
||||
return '查询结果返回有误';
|
||||
|
||||
$res = array();
|
||||
if ($result['code'] == -1) {
|
||||
$res = ['code' => -1, 'msg' => $result['msg'], 'estate_inquiry_text' => $result['msg'], 'result_code' => $result['code'], 'result' => $result];
|
||||
} else if ($result['code'] == 1) {
|
||||
$status_txt = array_column( $result['data'], 'status_txt');
|
||||
$res = ['code' => $result['code'], 'estatestatus' => !empty($status_txt) ? $status_txt[0] : '', 'result_code' => $result['code'], 'result' => $result];
|
||||
} else if ($result['code'] == 2) {
|
||||
$printResult = array_column($result['data'], 'printResult');
|
||||
$res = ['code' => -1, 'msg' => $printResult, 'estate_inquiry_text' => $printResult, 'result_code' => $result['code'], 'result' => $result];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* POST 请求(支持文件上传)
|
||||
* @param string $url HTTP请求URL地址
|
||||
* @param array|string $data POST提交的数据
|
||||
* @param int $second 请求超时时间
|
||||
* @param array $header 请求Header信息
|
||||
* @return bool|string
|
||||
*/
|
||||
static public function post($url, $data = [], $second = 30, $header = []) {
|
||||
$curl = curl_init();
|
||||
self::applyData($data);
|
||||
self::applyHttp($curl, $url);
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $second);
|
||||
curl_setopt($curl, CURLOPT_URL, $url);
|
||||
curl_setopt($curl, CURLOPT_HEADER, false);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_POST, true);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
|
||||
if (!empty($header)) {
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||||
}
|
||||
list($content, $status) = [curl_exec($curl), curl_getinfo($curl), curl_close($curl)];
|
||||
return (intval($status["http_code"]) === 200) ? $content : false;
|
||||
}
|
||||
/**
|
||||
* Post 数据过滤处理
|
||||
* @param array $data
|
||||
* @param bool $isBuild
|
||||
* @return string
|
||||
*/
|
||||
private static function applyData(&$data, $isBuild = true) {
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
foreach ($data as &$value) {
|
||||
is_array($value) && $isBuild = true;
|
||||
if (!(is_string($value) && strlen($value) > 0 && $value[0] === '@')) {
|
||||
continue;
|
||||
}
|
||||
if (!file_exists(($file = realpath(trim($value, '@'))))) {
|
||||
continue;
|
||||
}
|
||||
list($isBuild, $mime) = [false, FileService::getFileMine(pathinfo($file, 4))];
|
||||
if (class_exists('CURLFile', false)) {
|
||||
$value = new CURLFile($file, $mime);
|
||||
} else {
|
||||
$value = "{$value};type={$mime}";
|
||||
}
|
||||
}
|
||||
$isBuild && $data = http_build_query($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置SSL参数
|
||||
* @param $curl
|
||||
* @param string $url
|
||||
*/
|
||||
private static function applyHttp(&$curl, $url) {
|
||||
if (stripos($url, "https") === 0) {
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
curl_setopt($curl, CURLOPT_SSLVERSION, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user