view->fetch(); } /** * 调用第三方矢量转换接口 */ public function uploadVector() { if (!$this->request->isPost()) { return json(['code' => 0, 'msg' => '请求方式错误']); } $file = $this->request->file('file'); if (!$file) { return json(['code' => 0, 'msg' => '请上传文件']); } $vectorFormat = trim((string)$this->request->post('vectorFormat', '.pdf')); $maxlong = trim((string)$this->request->post('maxlong', '')); $fileName = trim((string)$this->request->post('fileName', '')); $realPath = $file->getRealPath(); if ($realPath === false || !is_file($realPath)) { return json(['code' => 0, 'msg' => '上传文件读取失败']); } $mimeType = (string)$file->getInfo('type'); if ($mimeType === '') { $mimeType = 'application/octet-stream'; } $postData = [ 'file' => new \CURLFile($realPath, $mimeType, $file->getInfo('name')), 'apiKey' => self::VECTOR_API_KEY, 'vectorFormat' => $vectorFormat, ]; if ($maxlong !== '') { $postData['maxlong'] = $maxlong; } if ($fileName !== '') { $postData['fileName'] = $fileName; } $ch = curl_init('http://mm.kknc.site/webapi/webapi.php'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 120); $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); curl_close($ch); return json(['code' => 0, 'msg' => '接口调用失败: ' . $error]); } $httpCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode >= 400) { return json([ 'code' => 0, 'msg' => '接口返回异常状态码: ' . $httpCode, 'data' => $response, ]); } $jsonData = json_decode($response, true); if (json_last_error() === JSON_ERROR_NONE) { return json(['code' => 1, 'msg' => '请求成功', 'data' => $jsonData]); } return json(['code' => 1, 'msg' => '请求成功', 'data' => $response]); } /** * 查询任务状态并返回下载地址 */ public function queryVector() { $bianhao = trim((string)$this->request->request('bianhao', '')); if ($bianhao === '') { return json(['code' => 0, 'msg' => 'bianhao 不能为空']); } $queryUrl = 'http://mm.kknc.site/webapi/webapi.php?' . http_build_query(['bianhao' => $bianhao]); $ch = curl_init($queryUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 60); $response = curl_exec($ch); if ($response === false) { $error = curl_error($ch); curl_close($ch); return json(['code' => 0, 'msg' => '查询失败: ' . $error]); } $httpCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode >= 400) { return json([ 'code' => 0, 'msg' => '查询接口异常状态码: ' . $httpCode, 'data' => $response, ]); } $jsonData = json_decode($response, true); if (json_last_error() === JSON_ERROR_NONE) { return json(['code' => 1, 'msg' => '查询成功', 'data' => $jsonData]); } return json(['code' => 1, 'msg' => '查询成功', 'data' => $response]); } }