diff --git a/app/controller/api/Test.php b/app/controller/api/Test.php index 6ca4698..5960eb9 100644 --- a/app/controller/api/Test.php +++ b/app/controller/api/Test.php @@ -13,7 +13,6 @@ class Test extends Base public function index() { try { - $InvoiceIssuanceService = new InvoiceIssuanceService(); $data = [ 'pucode' => '', @@ -21,6 +20,8 @@ class Test extends Base 'id' => '' ]; + $InvoiceIssuanceService = new InvoiceIssuanceService(); + $result = $InvoiceIssuanceService->IssueAnInvoice($data); if ($result !== true) { @@ -38,4 +39,21 @@ class Test extends Base $FeeService = new FeeService($pucode); return $FeeService->getUsers(); } + + /* + * + * ^ array:3 [▼ + "code" => "200" + "message" => "申请成功" + "pzsqkjYcxxList" => array:1 [▼ + "pzsqkjYcxxVO" => array:4 [▼ + "bdznsrsbh" => "91440300772709730N" + "yhbm" => "41107394" + "assetID" => "BC664422394E9D115C730C58AEB7BD7B" + "typeID" => "A0A35204362E8C26B40E8609C66090C2" + ] + ] +] + * + */ } diff --git a/app/service/invoice/InvoiceIssuanceService.php b/app/service/invoice/InvoiceIssuanceService.php index 1bd3c9b..b77e127 100644 --- a/app/service/invoice/InvoiceIssuanceService.php +++ b/app/service/invoice/InvoiceIssuanceService.php @@ -188,6 +188,8 @@ class InvoiceIssuanceService $bdznsrsbh = '91440300772709730N'; // 被代征纳税人识别号 + $feeUsers['bdznsrsbh'] = $bdznsrsbh; + // 保存 $ChinaTaxes = new ChinaTaxes($feeUsers, $invoiceDate); $savingDetailedData = $ChinaTaxes->savingDetailedData(); @@ -207,14 +209,19 @@ class InvoiceIssuanceService $mxGrid = $realTimeProcessing['data']['mxGrid']; $jsyj = 0; // 总金额 - foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) { - if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj']; + if (isset($mxGrid['sbMxsjVOList'])) { + foreach ($mxGrid['sbMxsjVOList'] as $sbMxsjVOValue) { + if (isset($sbMxsjVOValue['jsyj'])) $jsyj += $sbMxsjVOValue['jsyj']; + } } // 加工成功 电子缴款申请 - $issueElectronic = $ChinaTaxes->issueElectronic($sbpch); + $issueElectronic = $ChinaTaxes->issueElectronic($sbpch, $bdznsrsbh); - $assetID = $issueElectronic['pzsqkjYcxxList']['assetID']; // 文件唯一标识 + if (!isset($issueElectronic['pzsqkjYcxxList']['pzsqkjYcxxVO']['assetID'])) { + throw new FuncException('文件唯一标识不存在'); + } + $assetID = $issueElectronic['pzsqkjYcxxList']['pzsqkjYcxxVO']['assetID']; // 文件唯一标识 // 查询电子缴款凭证上链信息 $queryPaymentVoucher = $ChinaTaxes->queryPaymentVoucher($assetID); @@ -227,7 +234,7 @@ class InvoiceIssuanceService // 盖章 $requestData = ['data' => $data, 'meta' => $meta]; $deCompress = $this->deCompress($requestData); - if ($deCompress['status'] !== 200) { + if ($deCompress['status'] != 200) { throw new FuncException('pdf数据解密失败'); } if (!isset($deCompress['data']['pdfdata'])) { @@ -236,7 +243,7 @@ class InvoiceIssuanceService $pdfFilepath = $this->savePdfFile($deCompress['data']['pdfdata']); (new InvoiceIssuanceData())->saveData($invoiceIssuance['id'], $bdznsrsbh, $jsyj, $assetID, $pdfFilepath); - } else if ($realTimeProcessing['code'] === 302) { + } else if ($realTimeProcessing['code'] == 302) { // 加工失败 // 查询上传异常数据接口 diff --git a/app/service/webService/ChinaTaxes.php b/app/service/webService/ChinaTaxes.php index dd46468..d36b09e 100644 --- a/app/service/webService/ChinaTaxes.php +++ b/app/service/webService/ChinaTaxes.php @@ -110,9 +110,10 @@ class ChinaTaxes */ public function savingDetailedData(): array { + $userName = !empty($this->puCodeUser['ContactName']) ? $this->puCodeUser['ContactName'] : $this->puCodeUser['UserName']; $mxGrid = [ - 'bdznsrsbh' => $this->puCodeUser['tax_number'],// 被代征纳税人识别号 * - 'bdznsrmc' => $this->puCodeUser['UserName'],// 被代征纳税人名称 * + 'bdznsrsbh' => $this->puCodeUser['bdznsrsbh'],// 被代征纳税人识别号 * + 'bdznsrmc' => $userName,// 被代征纳税人名称 * 'gjhdqszDm' => '156',// 国家或地区数字代码 'sfzjlxDm' => '201',// 身份证件类型代码 'zjhm' => $this->puCodeUser['CertificateCode'],// 证件号码 * @@ -120,7 +121,7 @@ class ChinaTaxes 'zsxmDm' => '30433',// 征收项目代码 'zspmDm' => '804331300',// 征收品目代码 'zszmDm' => '',// 征收子目代码 - 'jsyj' => '-1000',// 计税依据,保留两位小数 + 'jsyj' => '11.11',// 计税依据,保留两位小数 'sl1' => '',// 税率,可手工填写,不填则默认系统自动计算,保留两位小数 'ynse' => '',// 应纳税额,可手工填写,不填则默认系统自动计算,保留两位小数 'ydzse' => '',// 应代征税额,可手工填写,不填则默认系统自动计算,保留两位小数 @@ -134,7 +135,7 @@ class ChinaTaxes 'wszmkjbz' => 'Y',// 完税证明开具标志为 Y 开具,N不开具 'xmmc' => '测试',// 项目名称 'xmbm' => 'T435',// 项目编码 - 'username' => $this->puCodeUser['UserName'],// 用户名称(同一个批次,同一个用户编号下,值相同) + 'username' => $userName,// 用户名称(同一个批次,同一个用户编号下,值相同) 'nbyhbm' => $this->puCodeUser['UserCode'],// 用户编号 'jldwmc' => '立方米',// 单位 'sl' => '100',// 数量 @@ -191,7 +192,6 @@ class ChinaTaxes 'czlx' => 'CX', // 操作类型(CX:查询;JG:加工) ]; - $param = $this->getParamData('SSGZ_GZPT_SZQKL_JGWTDZ', $body); return $this->resultXml($param, '6', 3); @@ -200,17 +200,18 @@ class ChinaTaxes /** * 3.8开具电子缴款凭证接口 * @param $sbpch + * @param $bdznsrsbh * @return array * @throws FuncException */ - public function issueElectronic($sbpch): array + public function issueElectronic($sbpch, $bdznsrsbh): array { $body = [ 'sbpch' => $sbpch, // 批次号,详见备注 'bdzmxGrid' => [ 'bdzmxlb' => [ - 'bdznsrsbh' => $this->puCodeUser['CertificateCode'], // 被代征人纳税人识别号 + 'bdznsrsbh' => $bdznsrsbh, // 被代征人纳税人识别号 'yhbm' => $this->puCodeUser['UserCode'], // 用户编码 ] ], @@ -242,8 +243,8 @@ class ChinaTaxes $result = $this->resultXml($param, '', 1); return [ - 'meta' => $this->deCompressXml($result['pzkjxxVO']['meta']), - 'data' => $this->deCompressXml($result['pzkjxxVO']['data']) + 'meta' => $result['pzkjxxVO']['meta'], + 'data' => $result['pzkjxxVO']['data'] ]; } @@ -514,9 +515,11 @@ class ChinaTaxes */ protected function bizXml($body, int $type = 0): string { - $start = ''; + $start = ' +'; $start1 = ''; - $end = ''; + $end = ''; $xml = ''; $xml2 = ''; foreach ($body as $key => $value) { @@ -535,13 +538,13 @@ class ChinaTaxes // 需要ns2 前后组合 加密返回 if ($this->xmlType == 2) { - + $this->xmlType = 1; return $start1 . $this->enCompressXml($start . $xml2 . $end) . $end; } // 需要ns2 前后组合 加密返回 if ($this->xmlType == 3) { - + $this->xmlType = 1; return $start1 . $this->enCompressXml($start . $xml . $end) . $end; } @@ -691,13 +694,18 @@ class ChinaTaxes $result = $this->json_curl(json_encode($param)); if (!isset($result['result'])) { + if (isset($result['error']['message'])) { + throw new FuncException($result['error']['message']); + } throw new FuncException('请求失败'); } $data = $this->xmlDom($result['result']); if (isset($data['code']) && $data['code'] != 200) { - if ($type == 1) return $data; + if ($type == 1 && $data['code'] == 302) return $data; throw new FuncException($data['message']); + } else if ($type == 1) { + return $data; } $deData = $this->deCompressXml($data[$key]);