Browse Source

临时转发接口方法替换

master
wanghongjun 1 year ago
parent
commit
6659910ba9
  1. 2
      app/controller/task/InvoiceIssuanceTask.php
  2. 106
      app/service/invoice/InvoiceIssuanceService.php

2
app/controller/task/InvoiceIssuanceTask.php

@ -26,7 +26,7 @@ class InvoiceIssuanceTask extends Base
$where = ['status' => 0, 'delete_time' => 0];
$InvoiceIssuanceData = (new InvoiceIssuanceModel())->where($where)->page(1, $this->limit)->select();
foreach ($InvoiceIssuanceData as $InvoiceIssuanceValue) {
$result = (new InvoiceIssuanceService())->IssueAnInvoice($InvoiceIssuanceValue);
$result = (new InvoiceIssuanceService())->tempIssueAnInvoice($InvoiceIssuanceValue);
if ($result === true) {
$this->invoiceSuccess($InvoiceIssuanceValue);
}

106
app/service/invoice/InvoiceIssuanceService.php

@ -505,4 +505,110 @@ class InvoiceIssuanceService
return json_decode($response, true);
}
/**
* 转发获取接口发票
* @param $data
* @return bool
*/
public function tempIssueAnInvoice($data): bool
{
try {
$resultData = $this->curl($data);
if (isset($resultData['code']) && $resultData['code'] == 1) {
// 存在错误
if (!empty($resultData['ycms'])) {
(new InvoiceIssuanceData())->saveField($data['id'], 'ycms', $resultData['ycms']);
throw new \Exception($resultData['ycms']);
}
if (!empty($resultData['sbpch'])) {
(new InvoiceIssuanceData())->saveField($data['id'], 'sbpch', $resultData['sbpch']);
if (isset($resultData['i_i_d_data'])) {
$d_data = $resultData['i_i_d_data'];
// 拼接pdf 盖章
$requestData = ['data' => $d_data['pdf_data'], 'meta' => $d_data['pdf_meta']];
$deCompress = $this->deCompress($requestData);
if ($deCompress['status'] != 200) {
throw new FuncException('pdf数据解密失败');
}
if (!isset($deCompress['data']['pdfdata'])) {
throw new FuncException('pdf文件合并失败');
}
$pdfFilepath = $deCompress['data']['pdfdata'];//$this->savePdfFile($deCompress['data']['pdfdata']);
// 保存
(new InvoiceIssuanceData())->saveData($d_data['i_i_id'], $d_data['bdznsrsbh'], $d_data['jsyj'], $d_data['assetID'], $pdfFilepath);
}
if (isset($resultData['i_i_data'])) {
$i_i_data = $resultData['i_i_data'];
if ($i_i_data['status'] == 3) {
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 3, 'issuance_time' => $i_i_data['issuance_time']]);
} else {
(new InvoiceIssuance())->where('id', $data['id'])->save(['status' => 2]);
}
}
}
} else {
throw new \Exception('请求失败');
}
return true;
} catch (\Exception $e) {
echo $e->getMessage() . '<br>';
return false;
}
}
/**
*
* @param array $data
* @return mixed
* @throws \Exception
*/
private function curl(array $data)
{
$data_json = json_encode($data);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://intp.xingtongworld.com/api/test/apiInvoiceIssuance",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $data_json,
CURLOPT_HTTPHEADER => [
"Accept: */*",
"Accept-Encoding: gzip, deflate, br",
"Connection: keep-alive",
"Content-Type: application/json",
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
throw new \Exception("cURL Error #:" . $err);
} else {
return json_decode($response, true);
}
}
}

Loading…
Cancel
Save