6 changed files with 1460 additions and 214 deletions
@ -0,0 +1,55 @@ |
|||
<?php |
|||
|
|||
namespace app\model; |
|||
|
|||
use think\Model; |
|||
|
|||
class InvoiceIssuanceData extends Model |
|||
{ |
|||
|
|||
/** |
|||
* 保存 税务接口 |
|||
* @param $invoice_issuance_id |
|||
* @param $bdznsrsbh |
|||
* @param $jsyj |
|||
* @param $assetID |
|||
* @param $pdf_filepath |
|||
* @throws \think\db\exception\DataNotFoundException |
|||
* @throws \think\db\exception\DbException |
|||
* @throws \think\db\exception\ModelNotFoundException |
|||
*/ |
|||
public function saveData($invoice_issuance_id, $bdznsrsbh, $jsyj, $assetID, $pdf_filepath) |
|||
{ |
|||
$query = $this->where('invoice_issuance_id', $invoice_issuance_id)->find(); |
|||
$save = [ |
|||
'bdznsrsbh' => $bdznsrsbh, |
|||
'jsyj' => $jsyj, |
|||
'assetID' => $assetID, |
|||
'pdf_filepath' => $pdf_filepath, |
|||
]; |
|||
if ($query) { |
|||
$save['update_time'] = time(); |
|||
$query->save($save); |
|||
} else { |
|||
$save['create_time'] = time(); |
|||
$this->save($save); |
|||
} |
|||
} |
|||
|
|||
public function saveField($invoice_issuance_id, $field, $value, $type = 1) |
|||
{ |
|||
$where = ['invoice_issuance_id' => $invoice_issuance_id]; |
|||
if ($type == 1) $where['status'] = 1; |
|||
$query = $this->where($where)->find(); |
|||
$save = [$field => $value]; |
|||
if ($query) { |
|||
$save['update_time'] = time(); |
|||
$query->save($save); |
|||
} else { |
|||
$save['create_time'] = time(); |
|||
$save['invoice_issuance_id'] = $invoice_issuance_id; |
|||
$this->save($save); |
|||
} |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,733 @@ |
|||
<?php |
|||
|
|||
namespace app\service\webService; |
|||
|
|||
use fast\FuncException; |
|||
use think\facade\Cache; |
|||
|
|||
class ChinaTaxes |
|||
{ |
|||
|
|||
protected $puCodeUser; |
|||
protected $accessToken; |
|||
protected $sid; |
|||
protected $reqId; |
|||
protected $channelId; |
|||
protected $channelSecret; |
|||
protected $apiUrl; |
|||
protected $my = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuc3JzYmgiOiI2MjAxMDQ3NzQ0MTk4NVgiLCJpc3MiOiJTU1NIR1oiLCJkanhoIjoiMTAxMTQ0MDMwMDAwMjY0NzE2NzQiLCJzdGFydFRpbWUiOiIiLCJ1bmRUaW11IjoiMjAyMi0wNi0zMCAxODowNDo0MSIsImV4cCI6MTY1NjU4MzQ4MSwic3BqZyI6IjEifQ.Ho0H43DxSGDmydHamMABRampNaNTu3K5vJwTJzoLAMA'; |
|||
protected $xmlType = 2; |
|||
protected $paramType = 1; |
|||
/** |
|||
* @throws FuncException |
|||
*/ |
|||
public function __construct($data) |
|||
{ |
|||
|
|||
$this->puCodeUser = $data; |
|||
$this->apiUrl = env('taxes.api_url'); |
|||
$this->reqId = $this->getReqId();//env('taxes.req_id'); // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。 |
|||
$this->channelId = env('taxes.channel_id'); // 接入渠道标识(ID) |
|||
$this->channelSecret = env('taxes.channel_secret'); // 平台为接入渠道统一分配的密码,只有身份验证接口需要 |
|||
|
|||
$this->sid = 'bizAccessLogin'; // 调用的接口名称,固定为“bizAccessLogin” |
|||
|
|||
$this->getAccessToken(); |
|||
} |
|||
|
|||
/** |
|||
* 2.1身份验证 |
|||
* @throws FuncException |
|||
*/ |
|||
protected function getAccessToken() |
|||
{ |
|||
$tax_key = 'tax_access_token'; |
|||
$tax_access_token = Cache::get($tax_key); |
|||
if ($tax_access_token) { |
|||
$this->accessToken = $tax_access_token; |
|||
} else { |
|||
$param = [ |
|||
'reqId' => $this->reqId, // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。 |
|||
'sid' => $this->sid, // 调用的接口名称,固定为“bizAccessLogin” |
|||
'channelId' => $this->channelId, // 接入渠道标识(ID) |
|||
'channelSecret' => $this->channelSecret, // 平台为接入渠道统一分配的密码,只有身份验证接口需要 |
|||
'timestamp' => time(), // unix 时间戳 |
|||
'data' => [ |
|||
'flag' => '大工业区生活垃圾处理费征收及开票需要' |
|||
] // 身份验证数据,默认为空 |
|||
]; |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
if (isset($result['error'])) { |
|||
throw new FuncException($result['error']['message']); |
|||
} |
|||
|
|||
if (!isset($result['result']['accessToken'])) { |
|||
throw new FuncException('返回参数有误'); |
|||
} |
|||
|
|||
$this->accessToken = $result['result']['accessToken']; |
|||
Cache::set($tax_key, $this->accessToken, 28680); |
|||
} |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @return string |
|||
*/ |
|||
protected function getReqId(): string |
|||
{ |
|||
return md5(time() . rand(0,9)); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 3.1保存委托代征明细数据接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function savingDetailedData() |
|||
{ |
|||
$mxGrid = [ |
|||
'bdznsrsbh' => '91440300MA5D40268',// 被代征纳税人识别号 * |
|||
'bdznsrmc' => '花若兰',// 被代征纳税人名称 * |
|||
'gjhdqszDm' => '156',// 国家或地区数字代码 |
|||
'sfzjlxDm' => '201',// 身份证件类型代码 |
|||
'zjhm' => '540127195512135368',// 证件号码 * |
|||
'hyDm' => '6490',// 行业代码 |
|||
'zsxmDm' => '30433',// 征收项目代码 |
|||
'zspmDm' => '304331300',// 征收品目代码 |
|||
'zszmDm' => '',// 征收子目代码 |
|||
'jsyj' => '11.11',// 计税依据,保留两位小数 |
|||
'sl1' => '',// |
|||
'ynse' => '',// |
|||
'ydzse' => '',// |
|||
'yjse' => '',// 1 |
|||
'ydzse1' => '',// 1 |
|||
'jmse' => '',// 1 |
|||
'phjmse' => '',// 1 |
|||
'phjzbl' => '',// 1 |
|||
'phjmxzDm' => '',// 1 |
|||
'ssjmxzDm' => '',// 1 |
|||
'wszmkjbz' => 'Y',// 完税证明开具标志为 Y 开具,N不开具 |
|||
'xmmc' => '测试',// 项目名称 |
|||
'xmbm' => 'T435',// 项目编码 |
|||
'username' => '测试',// 用户名称(同一个批次,同一个用户编号下,值相同) |
|||
'nbyhbm' => 'EF4353',// 用户编号 |
|||
'jldwmc' => '立方米',// 单位 |
|||
'sl' => '100',// 数量 |
|||
'zxbz1' => '10',// 标准 |
|||
'skyhmc' => '招商银行',// 托收银行(同一个批次,同一个用户编号下,值相同) |
|||
'yhzh' => '454878548',// 银行账号(同一个批次,同一个用户编号下,值相同) |
|||
'zsfsmc' => '手工转账',// 缴费方式(同一个批次,同一个用户编号下,值相同) |
|||
'tjsd' => '2022-11-01至2022-11-30',// 收费时段(同一个批次,同一个用户编号下,值相同) |
|||
'jfyj1' => '测试',// 计费依据(同一个批次,同一个用户编号下,值相同) |
|||
'yhje' => '10.00',// 优惠金额 |
|||
'hjje' => '990.00',// 合计金额 |
|||
'jfrq' => '2022-11-30',// 缴费时间(同一个批次,同一个用户编号下,值相同) |
|||
'lxfs' => '测试',// 联系方式(同一个批次,同一个用户编号下,值相同) |
|||
'lxdz' => '测试',// 送票地址(同一个批次,同一个用户编号下,值相同) |
|||
'remark' => '测试',// 备注(同一个批次,同一个用户编号下,值相同) |
|||
'bz' => '测试',// 备注信息(同一个批次,同一个用户编号下,值相同) |
|||
]; |
|||
dump($this->puCodeUser); |
|||
dump($mxGrid); |
|||
$body = [ |
|||
'sbczlxDm' => 'insert', //申报操作类型代码,为”delete”,” insert” 或”update” |
|||
'sflsb' => 'N', //是否零申报 ,为非零申报”N” |
|||
'sbpch' => '', //批次号,详见备注 |
|||
'nsqxDm' => '06', //纳税期限代码,“06”按月 |
|||
'skssqq' => '2024-06-01', //税款所属期起,格式,年-月-日 * |
|||
'skssqz' => '2024-06-30', //税款所属期止,格式,年-月-日 * |
|||
'zsxmdm' => '30433', //征收项目代码:30433 |
|||
'my' => $this->my, //密钥,数字签名校验和资格校验 |
|||
'mxGrid' => $this->mxGrid($mxGrid) |
|||
]; |
|||
dump($body); |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_WTDZDRJK', $body); |
|||
dump(json_encode($param)); |
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
$this->resultXml($result); |
|||
} |
|||
|
|||
protected function resultXml($result, $key = 'SZQKLDZSPSB0001ZipBase64ResponsBw'): array |
|||
{ |
|||
dump($result); |
|||
if (!isset($result['result'])) { |
|||
throw new \Exception('请求失败'); |
|||
} |
|||
$data = $this->xmlDom($result['result']); |
|||
dump($data); |
|||
dump(json_encode($data)); |
|||
if (isset($data['code']) && $data['code'] != 200) { |
|||
throw new \Exception($data['message']); |
|||
} |
|||
$deData = $this->deCompressXml($data[$key]); |
|||
dump($deData); |
|||
$returnData = $this->xmlDom($deData); |
|||
dump($returnData); |
|||
if ($returnData['ns2:code'] !== 200) { |
|||
throw new \Exception($returnData['ns2:message']); |
|||
} |
|||
dump($returnData);die; |
|||
return $returnData; |
|||
} |
|||
|
|||
/** |
|||
* 3.6实时加工委托代征明细数据接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function realTimeProcessing() |
|||
{ |
|||
|
|||
$body = [ |
|||
'sbpch' => '101144030000264716742412W0000004', // 批次号,详见备注 |
|||
'my' => $this->my, // 密钥,数字签名校验和资格校验 |
|||
'czlx' => 'JG', // 操作类型(CX:查询;JG:加工) |
|||
]; |
|||
|
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_JGWTDZ', $body); |
|||
dump($param); |
|||
dump(json_encode($param)); |
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result, 'SZQKLDZSPSB0006ZipBase64ResponsBw'); |
|||
} |
|||
|
|||
/** |
|||
* 3.8开具电子缴款凭证接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function issueElectronic() |
|||
{ |
|||
|
|||
$body = [ |
|||
'sbpch' => '101144030000264716742412W0000003', // 批次号,详见备注 |
|||
'bdzmxGrid' => [ |
|||
'bdzmxlb' => [ |
|||
'bdznsrsbh' => '91440300772709730N', // 被代征人纳税人识别号 |
|||
'yhbm' => 'EF4353', // 用户编码 |
|||
] |
|||
], |
|||
'skssqq' => '2024-06-01', // 税款所属期起,格式,年-月-日 |
|||
'skssqz' => '2024-06-30', // 税款所属期止,格式,年-月-日 |
|||
'my' => $this->my // 密钥,数字签名校验和资格校验 |
|||
]; |
|||
|
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_PZ_SQKJDZJKPZ', $body); |
|||
dump(json_encode($param)); |
|||
$result = $this->json_curl(json_encode($param)); |
|||
return $this->resultXml($result); |
|||
} |
|||
|
|||
/** |
|||
* 3.9查询电子缴款凭证上链信息 |
|||
* @throws FuncException |
|||
*/ |
|||
public function queryPaymentVoucher() |
|||
{ |
|||
|
|||
$body = [ |
|||
'assetID' => '6D1F1BBA19DA247BF75C04B6705A2969' |
|||
]; |
|||
|
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDZJKPZSLXX', $body); |
|||
|
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
return $this->resultXml($result); |
|||
} |
|||
|
|||
/** |
|||
* 3.3 查询上传异常数据接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function queryUploadErrorData() |
|||
{ |
|||
$body = [ |
|||
'sbpch' => '101144030000264716742412W0000004', // 批次号,详见备注 |
|||
'my' => $this->my // 密钥,数字签名校验和资格校验 |
|||
]; |
|||
|
|||
$this->xmlType = 4; |
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_DW_DZSCMXYC_QUERY', $body); |
|||
dump($param); |
|||
// dump(json_encode($param));exit; |
|||
|
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
return $this->resultXml($result, 'SZQKLDZSPSB0003ZipBase64ResponsBw'); |
|||
dump($result);die; |
|||
} |
|||
|
|||
/** |
|||
* 3.7 查询待开具电子缴款凭证数据接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function queryIssuedPaymentVoucher() |
|||
{ |
|||
$body = [ |
|||
'bdzmxList' => [ |
|||
'bdzmxVO' => [ |
|||
'bdznsrsbh' => '91440300MA5D40268' // 被代征人纳税人识别号 |
|||
] |
|||
], |
|||
'skssqq' => '2024-06-01', // 税款所属期起,格式,年-月-日 |
|||
'skssqz' => '2024-06-30', // 税款所属期止,格式,年-月-日 |
|||
'my' => $this->my // 密钥,数字签名校验和资格校验 |
|||
]; |
|||
|
|||
$this->xmlType = 4; |
|||
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDKDZJKPZ', $body); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
return $this->resultXml($result, 'SZQKLDZSPSB0003ZipBase64ResponsBw'); |
|||
} |
|||
|
|||
/** |
|||
* 3.10身份校验接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function identityCheck() |
|||
{ |
|||
$body = [ |
|||
'sfxxList' => [ |
|||
'nsrlx' => '1' // 2 非自然人、1 自然人 |
|||
], |
|||
'yhbh' => 'EF4353', // 水司的用户编号 |
|||
'nsrsbh' => '91440300MA5D40268', // 传输类型为非自然人不可以为空 |
|||
'nsrmc' => '深圳市华珞纸制品有限公司', // 不可为空 |
|||
'zjhm' => '540127195512135368', // 传输类型为自然人,不可以为空 |
|||
'zjlx' => '201', // 传输类型为自然人,不可以为空,添加证件类型代码 999 |
|||
'gj' => '156', // 国籍 |
|||
]; |
|||
|
|||
$this->xmlType = 5; |
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SFJYJK', $body); |
|||
|
|||
dump($param); |
|||
|
|||
$param['data']['bizXml'] = '<SZQKLDZSPSB0007ZipBase64RequestBw>H4sIAAAAAAAAAO2Uy27TQBSG10XiHYxXsLBnxpe0jhxXRKgs6n BLQSibyJmY2FV8IWNih10rCipU{r}{n}bKgKqkCsuKyqRkiAAo/TqfsYjMclCpBFxQ6J1fz/zDnH3z+Sx1zOgr4wdAfEj8KaiGQoCm6Io |
|||
64f{r}{n}9mri7bUVaUlcts6fMy9IUr778W7DbsYjYahApAokRkeTD/nu23z/kcBOjveeHH37fNFLkrgKQJqm{r}{n}stNPoqEj4yi4JEn |
|||
FlMTJGraQEb+ajGK3JjZbN1ftK63mjWYdQrjY8uO6Q9yKdsu9/8AlST0VhU7H{r}{n}Y3XJgAGJAoP9zQZ4xrK5BHtu4NgRdhKeaIY |
|||
Ge37oMAK5Fw1lHIIuMyR2MRDWCqx62p7itAua9p84{r}{n}cka6/LMhOdvo0+IqQ/ulIVXlaNADCoQIFJfKqSU/JIkTYldkd7Vgknt |
|||
ZZvskKUzp7lznesEMyaCf{r}{n}WYoJSlFujryOZyHVBFxMCwkzhqJpUIWwcVlfuWroUL3GW8lsXYCt4y9j+voT/bpJD97Qg226M8m |
|||
/{r}{n}v8qfb9OtMT3cpzt79P1j+mKDTl7ydtZRdj9c9wJL1yBSFpGh60hBqq5WlkzAD37WFMQQFZtT5N66{r}{n}hfSKCdjKQ4KZlP |
|||
8TF0HRvMTavMRz8508HZ88e0e3Dv8aX/mX8Q3DOCt+qU//NxPwl4qpHyKnwUoh{r}{n}BQAA</SZQKLDZSPSB0007 |
|||
ZipBase64RequestBw>'; |
|||
|
|||
dump(json_encode($param)); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result, ''); |
|||
} |
|||
|
|||
/** |
|||
* 3.14代征明细数据虚拟户更正接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function collectionDetails() |
|||
{ |
|||
$body = [ |
|||
'gzxxList' => [ |
|||
'gzxxVO' => [ |
|||
'my' => $this->my // 密钥,数字签名校验和资格校验 |
|||
], |
|||
'nsrlx' => '1', // 2 非自然人、1 自然人 |
|||
'yhbh' => '41108008', // 水司的用户编号 |
|||
'nsrsbh' => '91440300772709730N', // 传输类型为单位不可以为空 |
|||
'nsrmc' => '深圳市大工业区水务有限公司', // 不可为空 |
|||
'zjhm' => '412826198307167158', // 传输类型为自然人,不可以为空 |
|||
'zjlx' => '201', // 传输类型为自然人,不可以为空,添加证件类型代码 999 |
|||
'gj' => '156', // 国籍 |
|||
'username' => '李冲', // 用户名称 |
|||
'skyhmc' => '农业银行', // 托收银行 |
|||
'yhzh' => '6228480120759512318', // 银行账号 |
|||
'lxdz' => '龙田街道竹坑社区聚龙二期4栋2904', // 用户地址 |
|||
'lxfs' => '13528899213', // 联系方式 |
|||
'sbpch' => '101144030000264716742412W0000003', // 申报批次号 |
|||
], |
|||
]; |
|||
|
|||
//$this->xmlType = 5; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SB_XNHGZ', $body); |
|||
dump($param);dump(json_encode($param)); |
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result, ''); |
|||
} |
|||
|
|||
/** |
|||
* 3.2作废委托代征明细数据接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function invalidEntrustCollection() |
|||
{ |
|||
$body = [ |
|||
'sbpch' => '101144030000264716742412W0000002', // 批次号,详见备注 |
|||
'my' => $this->my // 密钥,数字签名校验和资格校验 |
|||
]; |
|||
|
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_DELETEWTDZ', $body); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result, ''); |
|||
} |
|||
|
|||
/** |
|||
* 3.12代征明细数据汇总确认查询接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function daiZhengSummaryQuery() |
|||
{ |
|||
|
|||
$body = [ |
|||
'my' => $this->my, // 密钥,数字签名校验和资格校验 |
|||
'bdznsrsbh' => '91440300MA5FG5AF75', // 被代征人纳税人识别号 |
|||
'skssqq' => '2024-06-01', // 税款所属期起,格式,年-月-日 |
|||
'skssqz' => '2024-06-30', // 税款所属期止,格式,年-月-日 |
|||
]; |
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SB_CXDZMXSJHZ', $body); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
return $this->resultXml($result, 'SZQKLDZSPSB0003ZipBase64ResponsBw'); |
|||
} |
|||
|
|||
/** |
|||
* 3.13代征明细数据汇总确认结报接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function daiZhengSummaryReport() |
|||
{ |
|||
$body = [ |
|||
'my' => $this->my, // 密钥,数字签名校验和资格校验 |
|||
'zje' => '990.00', // 总金额 |
|||
'skssqq' => '2024-06-01', // 税款所属期起,格式,年-月-日 |
|||
'skssqz' => '2024-06-30', // 税款所属期止,格式,年-月-日 |
|||
]; |
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SB_BCWTDZHZJK', $body); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
return $this->resultXml($result, 'SZQKLDZSPSB0003ZipBase64ResponsBw'); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* 3.11税收完税证明换开申请接口 |
|||
* @return array |
|||
* @throws FuncException |
|||
*/ |
|||
public function taxationReplaceApply() |
|||
{ |
|||
$body = [ |
|||
'my' => $this->my, // 密钥,数字签名校验和资格校验 |
|||
'bdznsrsbh' => '91440300MA5FG5AF75', // 被代征人纳税人识别号 |
|||
'skssqq' => '2024-06-01', // 税款所属期起,格式,年-月-日 |
|||
'skssqz' => '2024-06-30', // 税款所属期止,格式,年-月-日 |
|||
]; |
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_ZM_SAVEPLSQKJSSWSZMJK', $body); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result, 'SZQKLDZSPSB00011ZipBase64ResponsBw'); |
|||
} |
|||
|
|||
/** |
|||
* 3.15查询作废的电子缴款凭证接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function queryInvalidPaymentVoucher() |
|||
{ |
|||
$body = [ |
|||
'my' => $this->my, // 密钥,数字签名校验和资格校验 |
|||
'zfqq' => '2024-06-01', // 作废期起,格式,年-月-日,查询作废时间内作废的票证,返回相应的 assetid |
|||
'zfqz' => '2024-06-30', // 作废期止,格式,年-月-日,查询作废时间内作废的票证,返回相应的 assetid |
|||
'assetid' => '73B1B59DE346D3EFCCEB1868E0D5B727', // 电子缴款凭证开具返回的 assetid,填写这个参数只查验单个票证是否作废 |
|||
]; |
|||
$this->xmlType = 4; |
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_PZ_QUERYDZJKPZZFQK', $body); |
|||
|
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result); |
|||
} |
|||
|
|||
|
|||
/** |
|||
* @param $sid |
|||
* @param $body |
|||
* @return array |
|||
*/ |
|||
protected function getParamData($sid, $body): array |
|||
{ |
|||
$data = [ |
|||
'reqId' => $this->getReqId(), // 接入端交易请求唯一标识 |
|||
'sid' => $sid,// 调 用 的 接 口 名 称 |
|||
'channelId' => $this->channelId,// 接入渠道标识 |
|||
'accessToken' => $this->accessToken,// 访问令牌,由调用身份验证接口获取 |
|||
'timestamp' => time(),// unix 时间戳 |
|||
'data' => [], |
|||
]; |
|||
if ($this->paramType == 3) { |
|||
$data['token'] = $this->accessToken; |
|||
} |
|||
$data['data'] = [ |
|||
'bizXml' => $this->bizXml($body) |
|||
]; |
|||
|
|||
return $data; |
|||
} |
|||
|
|||
/** |
|||
* 3.4申请开具接口 |
|||
* @throws FuncException |
|||
*/ |
|||
public function applyIssued() |
|||
{ |
|||
$body = [ |
|||
'bhzrnsrsbhs' => [ |
|||
'nsrsbh' => '91440300MA5FG5AF75' // 纳税人识别号 |
|||
], |
|||
'skssqq' => '2024-06-01', // 税款所属期起,格式,年-月-日 |
|||
'skssqz' => '2024-06-30', // 税款所属期止,格式,年-月-日 |
|||
'mm' => $this->my, // 密钥,数字签名校验和资格校验 |
|||
'pch' => '101144030000264716742411W0000030', // 文件名,英文或数字,长度在 20 位,且唯一 |
|||
]; |
|||
$this->xmlType = 4; |
|||
|
|||
$param = $this->getParamData('SSGZ_GZPT_SZQKL_ZM_SAVEPLSQKJSSWSZMFORWXT', $body); |
|||
dump($param); |
|||
$result = $this->json_curl(json_encode($param)); |
|||
|
|||
return $this->resultXml($result); |
|||
} |
|||
|
|||
/** |
|||
* 3.5下载完税证明 |
|||
*/ |
|||
public function downTaxPaymentProve(): string |
|||
{ |
|||
|
|||
$param = [ |
|||
'ctrl=PlkjwszmCtrl_jkxzWszmxx', // 必填,功能模块名称,固定值为“PlkjwszmCtrl_jkxzWszmxx“ |
|||
'token=' . $this->accessToken, // 必填,令牌,即通过前台资格校验模块生成的密钥 |
|||
'djxh=', // 必填,代征单位登记序号 |
|||
'bq=' // 必填,标签,即申请开具接口的的 pch 字段,是唯一的一个文件名称 |
|||
]; |
|||
|
|||
$paramStr = implode('&', $param); |
|||
|
|||
return 'https://szxz.shenzhen.chinatax.gov.cn/qkldzsp/sword?' . $paramStr; // 必填,请求路径 |
|||
} |
|||
|
|||
/** |
|||
* 处理 body 报文 |
|||
* @param $body |
|||
* @param $type |
|||
* @return string |
|||
*/ |
|||
protected function bizXml($body, $type = 0): string |
|||
{ |
|||
$start = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?> |
|||
<SZQKLDZSPSB0001ZipBase64RequestBw |
|||
xmlns:ns2="http://www.chinatax.gov.cn/dataspec/">'; |
|||
$start1 = '<SZQKLDZSPSB0001ZipBase64RequestBw>'; |
|||
$end = '</SZQKLDZSPSB0001ZipBase64RequestBw>'; |
|||
$xml = ''; |
|||
$xml2 = ''; |
|||
foreach ($body as $key => $value) { |
|||
if (is_array($value)) { |
|||
$xml .= "<$key>" . $this->bizXml($value, 1) . "</$key>"; |
|||
$xml2 .= "<ns2:{$key}>" . $this->bizXml($value, 1) . "</ns2:{$key}>"; |
|||
} else { |
|||
$xml .= "<$key>$value</$key>"; |
|||
$xml2 .= "<ns2:{$key}>" . $value . "</ns2:{$key}>"; |
|||
} |
|||
} |
|||
|
|||
if ($type) { |
|||
return $xml; |
|||
} |
|||
|
|||
if ($this->xmlType == 2) { |
|||
dump($xml2); |
|||
return $start1 . $this->enCompressXml($start . $xml2 . $end) . $end; |
|||
} |
|||
|
|||
if ($this->xmlType == 3) { |
|||
dump($xml); |
|||
return $start1 . $this->enCompressXml($xml) . $end; |
|||
} |
|||
|
|||
|
|||
if ($this->xmlType == 5) { |
|||
dump($xml); |
|||
dump($start1 . $this->enCompressXml( $xml ) . $end); |
|||
return $start1 . $this->enCompressXml( $xml ) . $end; |
|||
} |
|||
|
|||
|
|||
if ($this->xmlType == 4) { |
|||
dump($xml); |
|||
return $xml; |
|||
} |
|||
|
|||
return $this->enCompressXml($xml); |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param $mxGrid |
|||
* @return mixed |
|||
*/ |
|||
protected function mxGrid($mxGrid) |
|||
{ |
|||
$xmlStr = '<ns2:sbMxsjVOList>'; |
|||
|
|||
foreach ($mxGrid as $key => $value) { |
|||
$xmlStr .= "<ns2:{$key}>" . $value . "</ns2:{$key}>"; |
|||
} |
|||
|
|||
return $xmlStr . '</ns2:sbMxsjVOList>'; |
|||
} |
|||
|
|||
/** |
|||
* 发送请求JSON |
|||
* @param $json |
|||
* @return bool|string |
|||
* @throws FuncException |
|||
*/ |
|||
protected function json_curl($json) |
|||
{ |
|||
// 初始化cURL会话 |
|||
$ch = curl_init(); |
|||
|
|||
// 设置cURL选项 |
|||
curl_setopt($ch, CURLOPT_URL, $this->apiUrl); // 目标URL |
|||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 返回结果而不是输出 |
|||
curl_setopt($ch, CURLOPT_POST, true); // 发送POST请求 |
|||
|
|||
// 设置POST字段 |
|||
curl_setopt($ch, CURLOPT_POSTFIELDS, $json); |
|||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); // 设置HTTP头 |
|||
|
|||
// 跳过证书验证(不推荐在生产环境使用) |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
|||
|
|||
// 跳过主机名验证 |
|||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
|||
|
|||
// 执行cURL会话 |
|||
$response = curl_exec($ch); |
|||
|
|||
// 检查是否有错误发生 |
|||
if (curl_errno($ch)) { |
|||
\think\facade\Log::write(json_encode([ |
|||
'code' => curl_errno($ch), |
|||
'message' => 'error', |
|||
'url' => $this->apiUrl, |
|||
'data' => json_decode($json, true) |
|||
])); |
|||
throw new FuncException('请求失败'); |
|||
} |
|||
|
|||
// 关闭cURL会话 |
|||
curl_close($ch); |
|||
|
|||
return json_decode($response, true); |
|||
} |
|||
|
|||
protected function demo() |
|||
{ |
|||
$json_str = '{ "reqId": "'.md5(time() . rand(000,999)) |
|||
.'", "sid": "'.'SSGZ_GZPT_SZQKL_WTDZDRJK' |
|||
.'", "channelId":"'.$this->channelId |
|||
.'", "accessToken":"'.$this->accessToken |
|||
.'", "timestamp":"'.time() |
|||
.'", "data": { "bizXml": "<SZQKLDZSPSB0001ZipBase64RequestBw>H4sIAAAAAAAAAO1Xy27bRhT9FUN7SzMcipIMm4FkyS4VU6pEyQ9tComkRVJ8yaNE5KyyCdoUQR5o{r}{n}UMBIujAKNEEfyCJp6yZA+jOWXP1Fhw+JDIKmboGu6gXFc88992pmeDgkN294lrl2Wz3BumNvZWAW{r}{n}ZNZUW3YU3R5uZbqdnfViZg1P+rbSNx1b3cr4Ks7c4DelXuvmXrUnfSpVAACwp7uVPlY5tq2Ob6l4{r}{n}Upmu0b423rAxs5XRJhN3I5ebTqdZWdPt/qTvZYfO7axs5xQaYFeVcxl+k2o38EAmple1eN3G6slk{r}{n}M/ceGUmOTTzgj+JUGMSlrqzxy4oQh3CE8XjMM4CB6wCtAxgrIjqRkJUEpSUkklg+r/p1bbAr6029{r}{n}LnSJABu6gAW7nZe3BU4YuYf72/VSlopuyahOjqwhFQp5sdMCYlWcijVYaXR7n4ijnUqz1tL3tuuu{r}{n}jMSgWacLG0IbOgE36tuaIxiOLnbK/qq2Wo4OMgINMgx0RNnd8ZWdtjs46Ab/E3DmwGp3+wfQDOsN{r}{n}Wq+DaVMCRNwuew3i0FpnKkp00NY+Gwxa7BwxjWqXiB3BF6WpLqPKuOfTyRg1/biVNcd95RhJ5Qrb{r}{n}2uv3JK97oBNr0FVvjvWjeq+GnHz+sMl8JhFHiNaLrlG0Vt7uia4sL4roYWO/uafjScQMFGLjEzzQ{r}{n}+BJkWYAAEMv5apU9rLEo6pMoUgWWzF/89s3i3enswe/zs8cX51/NXr28fPLz7KdHF2+//+PsBf2d{r}{n}nb6YP7u3OH00u/vj7OF5uhstD5sRQ7N4yDIsQrBUKAKWgYVCnomkYTL2GDFCxzErvyyZMD80NGWM{r}{n}CQ1hnosECRUqNJ8iVIJxeRhGI8CeFdQBuGwdM3HWXWU5lCjclIKEOJcOAmxg36DDKRVZlEXxUoZc{r}{n}NCMTLu+NAAXAp7dYzEUwRApJ2AiH0EhY4z0tTIvjzoa1UkcwQK6WopdBOCBsWB5ZzSkJl8JUMgnj{r}{n}iAzMJJUEH/ruyk5ErQaofNyJizffXT5/Obv/ZvbtD4u7Ty7OXy/unM9f3buS+1CBgUwJlqg3GFAs{r}{n}ccvt5tp91+6j+2CthjpXdd+7X+enDy/fnl0+fzz/8s6V3McxAFFb0esE6IkpFvPX7vtfu+/jXpt/{r}{n}8Xr+9efzX57+9cMUAQ4xoaGonVgW/lfbGVdcPqf/jaEK1Pf/3FAck4fXbkp5J3rRi1/wcn/7FcD/{r}{n}CZ2KPLlgDAAA</SZQKLDZSPSB0001ZipBase64RequestBw>"}}'; |
|||
dump($json_str); |
|||
|
|||
$xmlData = $this->json_curl($json_str); |
|||
$dom = new \DOMDocument(); |
|||
$dom->loadXML($xmlData['result']); |
|||
$output = $this->xmlToArray($dom->documentElement); |
|||
|
|||
$data = $output['SZQKLDZSPSB0001ZipBase64ResponsBw']; |
|||
|
|||
dump($data); |
|||
$gzdecode = $this->deCompressXml($data); |
|||
dump($gzdecode); |
|||
exit(); |
|||
} |
|||
|
|||
protected function xmlDom($xmlData) |
|||
{ |
|||
$dom = new \DOMDocument(); |
|||
$dom->loadXML($xmlData); |
|||
return $this->xmlToArray($dom->documentElement); |
|||
} |
|||
|
|||
/** |
|||
* 加密 |
|||
* @param $str |
|||
* @return array|string|string[] |
|||
*/ |
|||
protected function enCompressXml($str) |
|||
{ |
|||
$gzencode = gzencode($str); |
|||
$baseStr = base64_encode($gzencode); |
|||
return str_replace(array("\n", "\r"), array('{n}', '{r}'), $baseStr); |
|||
} |
|||
|
|||
/** |
|||
* 解密 |
|||
* @param $str |
|||
* @return false|string |
|||
*/ |
|||
protected function deCompressXml($str) |
|||
{ |
|||
$repStr = str_replace(array('{n}', '{r}'), array("\n", "\r"), $str); |
|||
$baseStr = base64_decode($repStr); |
|||
return gzdecode($baseStr); |
|||
} |
|||
|
|||
/** |
|||
* |
|||
* @param $node |
|||
* @return array|mixed |
|||
*/ |
|||
protected function xmlToArray($node) |
|||
{ |
|||
$output = []; |
|||
|
|||
if ($node->hasChildNodes()) { |
|||
foreach ($node->childNodes as $child) { |
|||
if ($child->nodeType === XML_ELEMENT_NODE) { |
|||
$output[$child->nodeName] = $this->xmlToArray($child); |
|||
} elseif ($child->nodeType === XML_TEXT_NODE) { |
|||
$output = $child->nodeValue; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return $output; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue