apiUrl = $apiUrl; $this->model = new $model(); if (!$isUpdate) { $this->model->truncate(); } $this->selectedKeys = $selectedKeys; } public function get() { $jsonData = json_encode([ 'pageIndex' => (string)$this->pageIndex, 'pageUnit' => (string)$this->pageUnit ]); // 初始化 cURL $ch = curl_init(); // 设置 cURL 请求的选项 curl_setopt($ch, CURLOPT_URL, $this->host . $this->apiUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json;charset=utf-8' )); // 忽略 SSL 主机验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 忽略 SSL 证书验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 发送请求并获取响应 $response = curl_exec($ch); // 检查是否有错误发生 if (curl_errno($ch)) { $error = curl_error($ch); //dump($error); // 处理错误信息 } // 关闭 cURL 资源 curl_close($ch); $resArr = json_decode($response, true); if($this->model instanceof Contract){ $fetch_name="拉取合同"; }else{ $fetch_name="拉取合同明细"; } # 记录定时任务日志 (new FetchdataLog())->insert([ 'fetch_name' => $fetch_name, 'data_num' => $this->pageUnit, 'pull_time' => date('Y-m-d H:i:s'), 'return_code' => json_encode($resArr)['code']??200, // 'content' => json_encode($resArr), 'notes' => $this->host . $this->apiUrl ]); unset($response); if (empty($resArr['data']['rows'])) { return false; } if (!empty($resArr['data']['rows'])) { if (!empty($this->selectedKeys)) { $extractedData = []; foreach ($resArr['data']['rows'] as $item) { $extractedItem = []; foreach ($this->selectedKeys as $key => $value) { $extractedItem[$key] = $item[$value]; } $extractedData[] = $extractedItem; } $this->model->insertOrIgnore($extractedData); unset($extractedData); } else { $this->model->insertOrIgnore($resArr['data']['rows']); unset($resArr); } unset($jsonData); unset($ch); $this->pageIndex = (string)($this->pageIndex + $this->pageUnit); $this->get(); } return true; } public function get1() { $jsonData = json_encode([ 'pageIndex' => (string)$this->pageIndex, 'pageUnit' => (string)$this->taskpageUnit ]); // 初始化 cURL $ch = curl_init(); // 设置 cURL 请求的选项 curl_setopt($ch, CURLOPT_URL, $this->host . $this->apiUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json;charset=utf-8' )); // 忽略 SSL 主机验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 忽略 SSL 证书验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 发送请求并获取响应 $response = curl_exec($ch); // 检查是否有错误发生 if (curl_errno($ch)) { $error = curl_error($ch); // 处理错误信息 } // 关闭 cURL 资源 curl_close($ch); $resArr = json_decode($response, true); unset($response); if (empty($resArr['data']['rows'])) { return false; } if (!empty($resArr['data']['rows'])) { if (!empty($this->selectedKeys)) { $extractedData = []; foreach ($resArr['data']['rows'] as $item) { $extractedItem = []; foreach ($this->selectedKeys as $key => $value) { $extractedItem[$key] = $item[$value]; } $extractedData[] = $extractedItem; } $res2 = Db::table("module_account_archive_contracts_copy")->insertOrIgnore($extractedData); unset($extractedData); } else { $res2 = Db::table("module_account_archive_contracts_copy")->insertOrIgnore($resArr['data']['rows']); unset($resArr); } unset($jsonData); unset($ch); $this->pageIndex = (string)($this->pageIndex + $this->taskpageUnit); $this->get1(); } return true; } public function getUpdate($updateCount) { $jsonData = json_encode([ 'pageIndex' => (string)$updateCount, 'pageUnit' => (string)$this->pageUnit ]); // 初始化 cURL $ch = curl_init(); // 设置 cURL 请求的选项 curl_setopt($ch, CURLOPT_URL, $this->host . $this->apiUrl); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json;charset=utf-8' )); // 忽略 SSL 主机验证 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 忽略 SSL 证书验证 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 发送请求并获取响应 $response = curl_exec($ch); // 检查是否有错误发生 if (curl_errno($ch)) { $error = curl_error($ch); //dump($error); // 处理错误信息 } // 关闭 cURL 资源 curl_close($ch); $resArr = json_decode($response, true); unset($response); if (empty($resArr['data']['rows'])) { return false; } if (!empty($resArr['data']['rows'])) { if (!empty($this->selectedKeys)) { $extractedData = []; foreach ($resArr['data']['rows'] as $item) { $extractedItem = []; foreach ($this->selectedKeys as $key => $value) { $extractedItem[$key] = $item[$value]; } $extractedData[] = $extractedItem; } $this->model->insertOrIgnore($extractedData); unset($extractedData); } else { $this->model->insertOrIgnore($resArr['data']['rows']); unset($resArr); } unset($jsonData); unset($ch); $this->getUpdate((string)($updateCount + $this->pageUnit)); } return true; } }