Browse Source

测试深圳税务接口

master
wanghongjun 1 year ago
parent
commit
904867c698
  1. 8
      .env
  2. 14
      app/controller/api/Test.php
  3. 47
      app/service/webService/ChinaTaxes.php

8
.env

@ -29,4 +29,10 @@ SOAP_PORT = 4000
[SMS]
API_URL = https://www.sms-cly.cn/v7/msg/submit.json
USERNAME = clygysw
PASSWORD = r9jndi
PASSWORD = r9jndi
[TAXES]
API_URL = https://szxz.shenzhen.chinatax.gov.cn:6443/access/api
REQ_ID = 2334e6cedb1389057d715acf00e4d9441
CHANNEL_ID = szqkldzspss
CHANNEL_SECRET = F541D38364337959E0530B7F6796B44D

14
app/controller/api/Test.php

@ -3,17 +3,23 @@ declare (strict_types=1);
namespace app\controller\api;
use app\service\webService\ChinaTaxes;
use app\service\webService\FeeService;
use NuSoap\Client\Client;
class Test extends Base
{
public function index()
{
$FeeService = new FeeService('41107394');
dump($FeeService->getUserTotal());
die;
$FeeService = new ChinaTaxes();
// try {
//
// $ChinaTaxes = new ChinaTaxes();
//
// die;
// } catch (\Exception $e) {
// dump($e);die;
// }
}
}

47
app/service/webService/ChinaTaxes.php

@ -8,6 +8,10 @@ class ChinaTaxes
{
protected $accessToken;
protected $sid;
protected $reqId;
protected $channelId;
protected $channelSecret;
protected $apiUrl;
/**
@ -16,7 +20,12 @@ class ChinaTaxes
public function __construct()
{
$this->apiUrl = env('taxes.api_url');
$this->apiUrl = env('taxes.api_url');
$this->reqId = 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();
}
@ -29,10 +38,10 @@ class ChinaTaxes
{
$param = [
'reqId' => '2334e6cedb1389057d715acf00e4d9441', // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。
'sid' => 'bizAccessLogin', // 调用的接口名称,固定为“bizAccessLogin”
'channelId' => 'SZSSJ', // 接入渠道标识(ID)
'channelSecret' => 'F541D38364337959E0530B7F6796B44D', // 平台为接入渠道统一分配的密码,只有身份验证接口需要
'reqId' => $this->reqId, // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。
'sid' => $this->sid, // 调用的接口名称,固定为“bizAccessLogin”
'channelId' => $this->channelId, // 接入渠道标识(ID)
'channelSecret' => $this->channelSecret, // 平台为接入渠道统一分配的密码,只有身份验证接口需要
'timestamp' => time(), // unix 时间戳
'data' => [
'flag' => '499'
@ -60,9 +69,9 @@ class ChinaTaxes
protected function getParamData($sid, $body): array
{
return [
'reqId' => '2334e6cedb1389057d715acf00e4d944',
'reqId' => $this->reqId,
'sid' => $sid,
'channelId' => 'SZSSJ',
'channelId' => $this->channelId,
'accessToken' => $this->accessToken,
'timestamp' => time(),
'data' => [
@ -366,16 +375,24 @@ class ChinaTaxes
* @param $body
* @return string
*/
protected function bizXml($body): string
protected function bizXml($body, $type = 2): string
{
$xml = '';
$xml = '';
$xml2 = '';
foreach ($body as $key => $value) {
if (is_array($value)) {
$xml .= "<$key>" . $this->bizXml($value) . "</$key>";
$xml .= "<$key>" . $this->bizXml($value) . "</$key>";
$xml2 .= "<ns2:{$key}>" . $this->bizXml($value, $type) . "</ns2:{$key}>";
} else {
$xml .= "<$key>$value</$key>";
$xml .= "<$key>$value</$key>";
$xml2 .= "<ns2:{$key}>" . $value . "</ns2:{$key}>";
}
}
if ($type == 2) {
return $xml2;
}
return $xml;
}
@ -386,6 +403,14 @@ class ChinaTaxes
*/
protected function mxGrid($mxGrid)
{
$xmlArr = [];
foreach ($mxGrid as $key => $value) {
$xmlArr[] = "<ns2:{$key}>" . $value . "</ns2:{$key}>";
}
return $mxGrid;
}

Loading…
Cancel
Save