Browse Source

测试深圳税务接口

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

6
.env

@ -30,3 +30,9 @@ SOAP_PORT = 4000
API_URL = https://www.sms-cly.cn/v7/msg/submit.json API_URL = https://www.sms-cly.cn/v7/msg/submit.json
USERNAME = clygysw 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; namespace app\controller\api;
use app\service\webService\ChinaTaxes;
use app\service\webService\FeeService; use app\service\webService\FeeService;
use NuSoap\Client\Client;
class Test extends Base class Test extends Base
{ {
public function index() public function index()
{ {
$FeeService = new FeeService('41107394'); $FeeService = new ChinaTaxes();
dump($FeeService->getUserTotal()); // try {
die; //
// $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 $accessToken;
protected $sid;
protected $reqId;
protected $channelId;
protected $channelSecret;
protected $apiUrl; protected $apiUrl;
/** /**
@ -16,7 +20,12 @@ class ChinaTaxes
public function __construct() 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(); $this->getAccessToken();
} }
@ -29,10 +38,10 @@ class ChinaTaxes
{ {
$param = [ $param = [
'reqId' => '2334e6cedb1389057d715acf00e4d9441', // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。 'reqId' => $this->reqId, // 接入端交易请求唯一标识,长度 32 位,5 秒内不得重复,否则抛出异常:交易请求唯一标识重复。
'sid' => 'bizAccessLogin', // 调用的接口名称,固定为“bizAccessLogin” 'sid' => $this->sid, // 调用的接口名称,固定为“bizAccessLogin”
'channelId' => 'SZSSJ', // 接入渠道标识(ID) 'channelId' => $this->channelId, // 接入渠道标识(ID)
'channelSecret' => 'F541D38364337959E0530B7F6796B44D', // 平台为接入渠道统一分配的密码,只有身份验证接口需要 'channelSecret' => $this->channelSecret, // 平台为接入渠道统一分配的密码,只有身份验证接口需要
'timestamp' => time(), // unix 时间戳 'timestamp' => time(), // unix 时间戳
'data' => [ 'data' => [
'flag' => '499' 'flag' => '499'
@ -60,9 +69,9 @@ class ChinaTaxes
protected function getParamData($sid, $body): array protected function getParamData($sid, $body): array
{ {
return [ return [
'reqId' => '2334e6cedb1389057d715acf00e4d944', 'reqId' => $this->reqId,
'sid' => $sid, 'sid' => $sid,
'channelId' => 'SZSSJ', 'channelId' => $this->channelId,
'accessToken' => $this->accessToken, 'accessToken' => $this->accessToken,
'timestamp' => time(), 'timestamp' => time(),
'data' => [ 'data' => [
@ -366,16 +375,24 @@ class ChinaTaxes
* @param $body * @param $body
* @return string * @return string
*/ */
protected function bizXml($body): string protected function bizXml($body, $type = 2): string
{ {
$xml = ''; $xml = '';
$xml2 = '';
foreach ($body as $key => $value) { foreach ($body as $key => $value) {
if (is_array($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 { } else {
$xml .= "<$key>$value</$key>"; $xml .= "<$key>$value</$key>";
$xml2 .= "<ns2:{$key}>" . $value . "</ns2:{$key}>";
} }
} }
if ($type == 2) {
return $xml2;
}
return $xml; return $xml;
} }
@ -386,6 +403,14 @@ class ChinaTaxes
*/ */
protected function mxGrid($mxGrid) protected function mxGrid($mxGrid)
{ {
$xmlArr = [];
foreach ($mxGrid as $key => $value) {
$xmlArr[] = "<ns2:{$key}>" . $value . "</ns2:{$key}>";
}
return $mxGrid; return $mxGrid;
} }

Loading…
Cancel
Save