Browse Source

获取申请数据优化为键值对

master
wanghongjun 1 year ago
parent
commit
7882d07f55
  1. 425
      app/service/webService/ChinaTaxes.php

425
app/service/webService/ChinaTaxes.php

@ -0,0 +1,425 @@
<?php
namespace app\service\webService;
use fast\FuncException;
class ChinaTaxes
{
protected $accessToken;
protected $apiUrl;
/**
* @throws FuncException
*/
public function __construct()
{
$this->apiUrl = env('taxes.api_url');
$this->getAccessToken();
}
/**
* 2.1身份验证
* @throws FuncException
*/
protected function getAccessToken()
{
$param = [
'reqId' => '2334e6cedb1389057d715acf00e4d9441', // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。
'sid' => 'bizAccessLogin', // 调用的接口名称,固定为“bizAccessLogin”
'channelId' => 'SZSSJ', // 接入渠道标识(ID)
'channelSecret' => 'F541D38364337959E0530B7F6796B44D', // 平台为接入渠道统一分配的密码,只有身份验证接口需要
'timestamp' => time(), // unix 时间戳
'data' => [
'flag' => '499'
] // 身份验证数据,默认为空
];
$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'];
}
/**
* 获取请求参数
* @param $sid
* @param $body
* @return array
*/
protected function getParamData($sid, $body): array
{
return [
'reqId' => '2334e6cedb1389057d715acf00e4d944',
'sid' => $sid,
'channelId' => 'SZSSJ',
'accessToken' => $this->accessToken,
'timestamp' => time(),
'data' => [
'bizXml' => $this->bizXml($body)
]
];
}
/**
* 3.1保存委托代征明细数据接口
* @throws FuncException
*/
public function savingDetailedData()
{
$mxGrid = [
'ycms' => ''
];
$body = [
'sbczlxDm' => 'insert', //申报操作类型代码,为”delete”,” insert” 或”update”
'sflsb' => 'N', //是否零申报 ,为非零申报”N”
'sbpch' => '0', //批次号,详见备注
'nsqxDm' => '06', //纳税期限代码,“06”按月
'skssqq' => '2023-06-01', //税款所属期起,格式,年-月-日
'skssqz' => '2023-06-30', //税款所属期止,格式,年-月-日
'zsxmdm' => '30433', //征收项目代码:30433
'my' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuc3JzYmgiOiI2MjAxMDQ3NzQ0MTk4NVgiLCJpc3MiOiJTU1NIR1oiLCJkanhoIjoiMTAxMTQ0MDMwMDAwMjY0NzE2NzQiLCJzdGFydFRpbWUiOiIiLCJ1bmRUaW11IjoiMjAyMi0wNi0zMCAxODowNDo0MSIsImV4cCI6MTY1NjU4MzQ4MSwic3BqZyI6IjEifQ.Ho0H43DxSGDmydHamMABRampNaNTu3K5vJwTJzoLAMA', //密钥,数字签名校验和资格校验
'mxGrid' => $this->mxGrid($mxGrid)
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_WTDZDRJK', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.6实时加工委托代征明细数据接口
* @throws FuncException
*/
public function realTimeProcessing()
{
$body = [
'sbpch' => '', // 批次号,详见备注
'my' => '', // 密钥,数字签名校验和资格校验
'czlx' => '', // 操作类型(CX:查询;JG:加工)
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_JGWTDZ', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.8开具电子缴款凭证接口
* @throws FuncException
*/
public function issueElectronic()
{
$body = [
'sbpch' => '', // 批次号,详见备注
'bdzmxGrid' => [
'bdznsrsbh' => '', // 被代征人纳税人识别号
'yhbm' => '', // 用户编码
],
'skssqq' => '', // 税款所属期起,格式,年-月-日
'skssqz' => '', // 税款所属期止,格式,年-月-日
'my' => '' // 密钥,数字签名校验和资格校验
];
$param = $this->getParamData('SSGZ_GZPT_PZ_SQKJDZJKPZ', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.9查询电子缴款凭证上链信息
* @throws FuncException
*/
public function queryPaymentVoucher()
{
$body = [
'assetID' => ''
];
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDZJKPZSLXX', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.3 查询上传异常数据接口
* @throws FuncException
*/
public function queryUploadErrorData()
{
$body = [
'sbpch' => '', // 批次号,详见备注
'my' => '' // 密钥,数字签名校验和资格校验
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_DW_DZSCMXYC_QUERY', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.7 查询待开具电子缴款凭证数据接口
* @throws FuncException
*/
public function queryIssuedPaymentVoucher()
{
$body = [
'bdzmxList' => [
'bdznsrsbh' => '' // 被代征人纳税人识别号
],
'skssqq' => '', // 税款所属期起,格式,年-月-日
'skssqz' => '', // 税款所属期止,格式,年-月-日
'my' => '' // 密钥,数字签名校验和资格校验
];
$param = $this->getParamData('SSGZ_GZPT_PZ_QUERYDKDZJKP', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.10身份校验接口
* @throws FuncException
*/
public function identityCheck()
{
$body = [
'sfxxList' => [
'nsrlx' => '' // 2 非自然人、1 自然人
],
'yhbh' => '', // 水司的用户编号
'nsrsbh' => '', // 传输类型为非自然人不可以为空
'nsrmc' => '', // 不可为空
'zjhm' => '', // 传输类型为自然人,不可以为空
'zjlx' => '', // 传输类型为自然人,不可以为空,添加证件类型代码 999
'gj' => '', // 国籍
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SFJYJK', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.14代征明细数据虚拟户更正接口
* @throws FuncException
*/
public function collectionDetails()
{
$body = [
'gzxxList' => [
'gzxxVO' => [
'my' => '' // 密钥,数字签名校验和资格校验
],
'nsrlx' => 1, // 2 非自然人、1 自然人
'yhbh' => '', // 水司的用户编号
'nsrsbh' => '', // 传输类型为单位不可以为空
'nsrmc' => '', // 不可为空
'zjhm' => '', // 传输类型为自然人,不可以为空
'zjlx' => '', // 传输类型为自然人,不可以为空,添加证件类型代码 999
'gj' => '', // 国籍
'username' => '', // 用户名称
'skyhmc' => '', // 托收银行
'yhzh' => '', // 银行账号
'lxdz' => '', // 用户地址
'lxfs' => '', // 联系方式
'sbpch' => '', // 申报批次号
],
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SB_XNHGZ', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.2作废委托代征明细数据接口
* @throws FuncException
*/
public function invalidEntrustCollection()
{
$body = [
'sbpch' => '', // 批次号,详见备注
'my' => '' // 密钥,数字签名校验和资格校验
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_DELETEWTDZ', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.12代征明细数据汇总确认查询接口
* @throws FuncException
*/
public function daiZhengSummaryQuery()
{
$body = [
'my' => '', // 密钥,数字签名校验和资格校验
'bdznsrsbh' => '', // 被代征人纳税人识别号
'skssqq' => '', // 税款所属期起,格式,年-月-日
'skssqz' => '', // 税款所属期止,格式,年-月-日
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SB_CXDZMXSJHZ', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.13代征明细数据汇总确认结报接口
* @throws FuncException
*/
public function daiZhengSummaryReport()
{
$body = [
'my' => '', // 密钥,数字签名校验和资格校验
'zje' => '', // 总金额
'skssqq' => '', // 税款所属期起,格式,年-月-日
'skssqz' => '', // 税款所属期止,格式,年-月-日
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_SB_BCWTDZHZJK', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.15查询作废的电子缴款凭证接口
* @throws FuncException
*/
public function queryInvalidPaymentVoucher()
{
$body = [
'my' => '', // 密钥,数字签名校验和资格校验
'zfqq' => '', // 作废期起,格式,年-月-日,查询作废时间内作废的票证,返回相应的 assetid
'zfqz' => '', // 作废期止,格式,年-月-日,查询作废时间内作废的票证,返回相应的 assetid
'assetid' => '', // 电子缴款凭证开具返回的 assetid,填写这个参数只查验单个票证是否作废
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_PZ_QUERYDZJKPZZFQK', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 3.4申请开具接口
* @throws FuncException
*/
public function applyIssued()
{
$body = [
'bhzrnsrsbhs' => [
'nsrsbh' => '' // 纳税人识别号
],
'skssqq' => '', // 税款所属期起,格式,年-月-日
'skssqz' => '', // 税款所属期止,格式,年-月-日
'mm' => '', // 密钥,数字签名校验和资格校验
'pch' => '', // 文件名,英文或数字,长度在 20 位,且唯一
];
$param = $this->getParamData('SSGZ_GZPT_SZQKL_ZM_SAVEPLSQKJSSWSZMFORWXT', $body);
$result = $this->json_curl(json_encode($param));
}
/**
* 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
* @return string
*/
protected function bizXml($body): string
{
$xml = '';
foreach ($body as $key => $value) {
if (is_array($value)) {
$xml .= "<$key>" . $this->bizXml($value) . "</$key>";
} else {
$xml .= "<$key>$value</$key>";
}
}
return $xml;
}
/**
*
* @param $mxGrid
* @return mixed
*/
protected function mxGrid($mxGrid)
{
return $mxGrid;
}
/**
* 发送请求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会话
$response = curl_exec($ch);
// 检查是否有错误发生
if (curl_errno($ch)) {
throw new FuncException('请求失败');
}
// 关闭cURL会话
curl_close($ch);
return json_decode($response, true);
}
}
Loading…
Cancel
Save