TaxInvoice.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. <?php
  2. use think\facade\Cache;
  3. class Rmethod{
  4. public $header;
  5. public $method;
  6. public $body;
  7. public $url;
  8. public $timeout=5;
  9. public function __construct(){
  10. $this->header=["Content-Type"=>"application/json"];
  11. }
  12. /**
  13. * @return mixed
  14. */
  15. public function getBody(){
  16. return $this->body;
  17. }
  18. /**
  19. * @param mixed $body
  20. */
  21. public function setBody($body){
  22. $this->body = $body;
  23. }
  24. /**
  25. * @param mixed $method
  26. */
  27. public function setMethod($method){
  28. $this->method = $method;
  29. }
  30. /**
  31. * @param mixed $url
  32. */
  33. public function setUrl($url){
  34. $this->url = $url;
  35. }
  36. /**
  37. * @param mixed $header
  38. */
  39. public function setHeader($header){
  40. $this->header = $header;
  41. }
  42. /**
  43. * @param string $url
  44. * @param array $body
  45. * @param string $method
  46. * @return bool|string
  47. */
  48. public function request($url='',$body=[],$method=""){
  49. !empty($body)?$this->body=$body:"";
  50. $url!=""?$this->url=$url:"";
  51. $this->method= $method!=""?$method:"post";
  52. $data=$this->curlmothod();
  53. return json_decode($data,true);
  54. }
  55. protected function curlmothod() {
  56. //⽀持json数据数据提交
  57. $post_string =$this->checkBody();
  58. $header=$this->checkHeader();
  59. $URL = strtolower($this->method)=="get" && !empty($post_data) ? $this->url."?".$post_string :$this->url;
  60. $ch = curl_init(); // 启动⼀个CURL会话
  61. curl_setopt($ch, CURLOPT_URL, $URL); // 要访问的地址
  62. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查 // https请求不验证证书和hosts
  63. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在 // 模拟⽤户使⽤的浏览器
  64. if(strtolower($this->method)=="post"){
  65. curl_setopt($ch, CURLOPT_POST, true); // 发送⼀个常规的Post请求
  66. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string); // Post提交的数据包
  67. }
  68. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout); // 设置超时限制防⽌死循环
  69. curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
  70. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取的信息以⽂件流的形式返回
  71. curl_setopt($ch, CURLOPT_HTTPHEADER, $header); //模拟的header头
  72. $result = curl_exec($ch);
  73. curl_close($ch);
  74. return $result;
  75. }
  76. public function checkHeader(){
  77. if (!empty($this->header)){
  78. $temp=[];
  79. foreach ($this->header as $key=>$value){
  80. $temp[]=$key.":".$value;
  81. }
  82. return $temp;
  83. }
  84. return[];
  85. }
  86. public function checkBody(){
  87. if (!empty($this->body)){
  88. $body = http_build_query($this->body);
  89. if(key_exists("Content-Type",$this->header) && $this->header['Content-Type']=="application/json"){
  90. $body =json_encode($this->body);
  91. }
  92. return $body;
  93. }
  94. return'';
  95. }
  96. }
  97. class TaxInvoice {
  98. protected $appKey;
  99. protected $appSecret;
  100. protected $request;
  101. protected $entCode;//企业税号
  102. protected $zipCode;//压缩标识
  103. protected $encryptCode;//加密标识 0 base64 1 3DES
  104. protected $domain='https://sandbox.ele-cloud.com';//测试域名
  105. // protected $domain='https://sandbox.ele-cloud.com';
  106. public function __construct(string $appKey,string $appSecret,string $entCode='',$zipCode=0,$encryptCode=0){
  107. $this->appKey=$appKey;
  108. $this->appSecret=$appSecret;
  109. $this->entCode=$entCode;
  110. $this->zipCode=$zipCode;
  111. $this->encryptCode=$encryptCode;
  112. $this->request=new Rmethod();
  113. }
  114. /** * 年月日、时分秒 + 3位毫秒数
  115. * @param string $format
  116. * @param null $utimestamp
  117. * @return false|string */
  118. public function ts_time($format = 'u', $utimestamp = null)
  119. { if (is_null($utimestamp)){ $utimestamp = microtime(true); }
  120. $timestamp = floor($utimestamp);
  121. $milliseconds = round(($utimestamp - $timestamp) * 1000);
  122. return str_pad(date("YmdHis").$milliseconds,17,"0",STR_PAD_RIGHT);
  123. }
  124. /**
  125. * @param string $buyer_id
  126. * @param string $batchNum
  127. * @param string $start
  128. * @param string $end
  129. * @param string $status
  130. * @return array|bool|float|int|mixed|stdClass|string|null
  131. */
  132. public function getMainInvoice(string $buyer_id='',string $batchNum='',string $start='',string
  133. $end='',string $status=''){
  134. $url=$this->domain."/api/dxhy-open-income/v1/getMainInvoice?access_token=".$this->GetToken();
  135. $param = [
  136. "GMFSBH"=>$buyer_id,
  137. "PCH"=>$batchNum,
  138. "CJKSRQ"=>$start,
  139. "CJJSRQ"=>$end,
  140. "ZTBZ"=>$status,
  141. ];
  142. $data=$this->request->request($url,$this->GetParam($param));
  143. return $this->ReturnData($data);
  144. }
  145. /**
  146. * @param int $refresh
  147. * @return mixed|string
  148. */public function GetToken($refresh=0){
  149. $token = Cache::get("TAXToken");
  150. if($token==false || $refresh==1){
  151. $result=$this->auth();
  152. if(key_exists("access_token",$result)){
  153. Cache::set("TAXToken",$result['access_token'],$result['expires_in']);
  154. $token=$result['access_token'];
  155. }
  156. }
  157. return $token;
  158. }
  159. /**
  160. * @return bool|string
  161. */public function auth(){
  162. $uri=$this->domain."/api/authen/token";
  163. $param=["appKey"=>$this->appKey,"appSecret"=>$this->appSecret];
  164. $result=$this->request->request($url=$uri,$body=$param,$method="post");
  165. return $result;
  166. }
  167. /**
  168. * @param $data
  169. * @return array
  170. */public function GetParam($data){
  171. $param=[
  172. "zipCode"=>$this->zipCode,
  173. "entCode"=>$this->entCode,
  174. "encryptCode"=>$this->encryptCode,
  175. "dataExchangeId"=>$this->ts_time().rand(pow(10,14),pow(10,15)-1),
  176. "content"=>base64_encode(json_encode($data,JSON_UNESCAPED_UNICODE))
  177. ];
  178. return $param;
  179. }
  180. /**
  181. * @param $data
  182. * @return array|bool|float|int|mixed|stdClass|string|null
  183. */public function ReturnData($data){
  184. if(key_exists("returnCode",$data['returnStateInfo'])){
  185. if ($data['returnStateInfo']['returnCode']=='0000'){
  186. $result= base64_decode($data['content']);
  187. return json_decode($result,true);
  188. }else{
  189. $returnMessage= base64_decode($data['returnStateInfo']['returnMessage']);
  190. return ["code"=>$data['returnStateInfo']['returnCode'],"message"=>$returnMessage];
  191. }
  192. }
  193. return ["code"=>0,"message"=>"fail"];
  194. }
  195. /**
  196. * @param string $buyer_id
  197. * @param string $batchNum
  198. * @param string $start
  199. * @param string $end
  200. * @param string $status
  201. * @param int $num
  202. * @return array|bool|float|int|mixed|stdClass|string|null
  203. */
  204. public function getInvoiceState(string $buyer_id='',string $batchNum='',string $start='',string
  205. $end='',string $status='',int $num=1){
  206. $url=$this->domain."/api/dxhy-open-income/v1/getInvoiceState?access_token=".$this->GetToken();
  207. $param = [
  208. "GMFSBH"=>$buyer_id,
  209. "PCH"=>$batchNum,
  210. "ZTBGKSRQ"=>$start,
  211. "ZTBGJSRQ"=>$end,
  212. "ZTBZ"=>$status,
  213. "KSHS"=>$num,
  214. ];
  215. $data=$this->request->request($url,$this->GetParam($param));
  216. return $this->ReturnData($data);
  217. }
  218. /**
  219. * @param string $buyer_id
  220. * @param int $total
  221. * @param string $batchNum
  222. * @param array $invArr [{invoiceCode:'',invoiceNumber:'',invoiceType:'',inv_subtotal_amount:'',opentime:'',
  223. * buyer_id:'',reason:''}]
  224. * @return array|bool|float|int|mixed|stdClass|string|null
  225. */
  226. public function applyLegalize(string $buyer_id='',int $total=0,string $batchNum='',array $invArr=[]){
  227. $url=$this->domain."/api/dxhy-open-income/v1/applyLegalize?access_token=".$this->GetToken();
  228. $temp=[];
  229. if(!empty($invArr)){
  230. foreach ($invArr as $value){
  231. $data=[];
  232. $data['FPDM']=$value['invoiceCode'];
  233. $data['FPHM']=$value['invoiceNumber'];
  234. $data['YXSE']=$value['inv_subtotal_amount'];
  235. $data['SQSKSSQ']=$value['opentime'];
  236. $data['GMFSBH']=$value['buyer_id'];
  237. $data['FPLXDM']=$value['invoiceType'];
  238. $data['BDKYY']=$value['reason']??'';
  239. $temp[]=$data;
  240. }
  241. }
  242. $param = [
  243. "GMFSBH"=>$buyer_id,
  244. "PCH"=>$batchNum,
  245. "FHHS"=>$total,
  246. "FPZHXX"=>$temp,
  247. ];
  248. // "FPDM":"3100174130", "FPHM":"08975555", "GMFSBH":"91110104444324CP321", "SQRZLX":"1", "FPLXDM":"01",
  249. // "SQSKSSQ":"202005", "YXSE":"200", "BDKYY":
  250. $data=$this->request->request($url,$this->GetParam($param));
  251. return $this->ReturnData($data);
  252. }
  253. /**
  254. * @param string $batchNum
  255. * @return array|bool|float|int|mixed|stdClass|string|null
  256. */
  257. public function applyLegalizeResult(string $batchNum=''){
  258. $url=$this->domain."/api/dxhy-open-income/v1/applyLegalizeResult?access_token=".$this->GetToken();
  259. $param = ["PCH"=>$batchNum];
  260. $data=$this->request->request($url,$this->GetParam($param));
  261. return $this->ReturnData($data);
  262. }
  263. /**
  264. * @param string $buyer_id
  265. * @param string $period
  266. * @return array|bool|float|int|mixed|stdClass|string|null
  267. */public function getCountInfo(string $buyer_id='',string $period=''){
  268. $url=$this->domain."/api/dxhy-open-income/v1/getCountInfo?access_token=".$this->GetToken();
  269. $param = [
  270. "GMFSBH"=>$buyer_id,
  271. "RZSKSSQ"=>$period,
  272. ];
  273. $data=$this->request->request($url,$this->GetParam($param));
  274. return $this->ReturnData($data);
  275. }
  276. /**
  277. * @param string $buyer_id
  278. * @param string $period
  279. * @param string $batchNum
  280. * @param string $statisFlag
  281. * @return array|bool|float|int|mixed|stdClass|string|null
  282. */public function applyCount(string $buyer_id='',string $period='',string $batchNum='',string $statisFlag=''){
  283. $url=$this->domain."/api/dxhy-open-income/v1/applyCount?access_token=".$this->GetToken();
  284. $param = [
  285. "GMFSBH"=>$buyer_id,
  286. "RZSKSSQ"=>$period,
  287. "TJBZ"=>$statisFlag,
  288. "PCH"=>$batchNum
  289. ];
  290. $data=$this->request->request($url,$this->GetParam($param));
  291. return $this->ReturnData($data);
  292. }
  293. /**
  294. * @param string $buyer_id
  295. * @param string $batchNum
  296. * @return array|bool|float|int|mixed|stdClass|string|null
  297. */
  298. public function applyCountResult(string $buyer_id='',string $batchNum=''){
  299. $url=$this->domain."/api/dxhy-open-income/v1/applyCountResult?access_token=".$this->GetToken();
  300. $param = [
  301. "GMFSBH"=>$buyer_id,
  302. "PCH"=>$batchNum
  303. ];
  304. $data=$this->request->request($url,$this->GetParam($param));
  305. return $this->ReturnData($data);
  306. }
  307. /**
  308. * @param string $buyer_id
  309. * @param string $batchNum
  310. * @param string $ack
  311. * @param string $statisTime
  312. * @param string $period
  313. * @param string $confirm_passwd
  314. * @return array|bool|float|int|mixed|stdClass|string|null
  315. */
  316. public function applyConfirm(string $buyer_id='',string $batchNum='',string $ack='',string $statisTime='',string
  317. $period='',string $confirm_passwd=''){
  318. $url=$this->domain."/api/dxhy-open-income/v1/applyConfirm?access_token=".$this->GetToken();
  319. $param = [
  320. "GMFSBH"=>$buyer_id,
  321. "PCH"=>$batchNum,
  322. "QRBZ"=>$ack,
  323. "TJSJ"=>$statisTime,
  324. "RZSKSSQ"=>$period,
  325. "QRMM"=>$confirm_passwd,
  326. ];
  327. $data=$this->request->request($url,$this->GetParam($param));
  328. return $this->ReturnData($data);
  329. }
  330. /**
  331. * @param string $buyer_id
  332. * @param string $batchNum
  333. * @param string $ack
  334. * @param string $statisTime
  335. * @return array|bool|float|int|mixed|stdClass|string|null
  336. */
  337. public function applyConfirmResult(string $buyer_id='',string $batchNum='',string $ack='',string $statisTime=''){
  338. $url=$this->domain."/api/dxhy-open-income/v1/applyConfirmResult?access_token=".$this->GetToken();
  339. $param = [
  340. "GMFSBH"=>$buyer_id,
  341. "PCH"=>$batchNum,
  342. "QRBZ"=>$ack,
  343. "TJSJ"=>$statisTime,
  344. ];
  345. $data=$this->request->request($url,$this->GetParam($param));
  346. return $this->ReturnData($data);
  347. }
  348. /**
  349. * @param string $idCard
  350. * @return array|bool|float|int|mixed|stdClass|string|null
  351. */
  352. public function getCompanyInfo(string $idCard=''){
  353. $url=$this->domain."/api/dxhy-open-income/v1/getCompanyInfo?access_token=".$this->GetToken();
  354. $param = [
  355. "SBH"=>$idCard,
  356. ];
  357. $data=$this->request->request($url,$this->GetParam($param));
  358. return $this->ReturnData($data);
  359. }
  360. /**
  361. * @param string $idCard
  362. * @param string $confirm_passwd
  363. * @param string $new_passwd
  364. * @return array|bool|float|int|mixed|stdClass|string|null
  365. */
  366. public function setPassword(string $idCard='',string $confirm_passwd='',string $new_passwd=''){
  367. $url=$this->domain."/api/dxhy-open-income/v1/setPassword?access_token=".$this->GetToken();
  368. $param = [
  369. "SBH"=>$idCard,
  370. "YWMM"=>$confirm_passwd,
  371. "NEWYWMM"=>$new_passwd,
  372. ];
  373. $data=$this->request->request($url,$this->GetParam($param));
  374. return $this->ReturnData($data);
  375. }
  376. /**
  377. * @param string $idCard
  378. * @return array|bool|float|int|mixed|stdClass|string|null
  379. */
  380. public function resetPassword(string $idCard=''){
  381. $url=$this->domain."/api/dxhy-open-income/v1/resetPassword?access_token=".$this->GetToken();
  382. $param = [
  383. "SBH"=>$idCard
  384. ];
  385. $data=$this->request->request($url,$this->GetParam($param));
  386. return $this->ReturnData($data);
  387. }
  388. /**
  389. * @param array $OrderBatchArr
  390. * @param array $OrderInvList
  391. * @return array|bool|float|int|mixed|\stdClass|string|null
  392. */public function GenerateInvoice(array $OrderBatchArr=[], array $OrderInvList=[]){
  393. $url=$this->domain."/api/order-api/order-api/v5/GenerateInvoice?access_token=".$this->GetToken();
  394. $param = [
  395. "DDPCXX"=>$OrderBatchArr,
  396. "DDZXX"=>$OrderInvList
  397. ];
  398. $data=$this->request->request($url,$this->GetParam($param));
  399. // var_dump($data);
  400. return $this->ReturnData($data);
  401. }
  402. //{"HZSQDSCPC":{"SQBSCQQPCH":"申请表上传请求批次号","NSRSBH":"申请方纳税人识别号","KPZD":"开票终端","FPLXDM":"发票类型代码","KZZD":"扩展字段"},
  403. //"HZSQDSCZXX":[
  404. //{"HZSQDTXX":{"SQBSCQQLSH":"申请表上传请求流水号","YYSBZ":"营业税标志","XXBLX":"信息表类型","YFPDM":"原蓝字发票代码","YFPHM":"原蓝字发票号码","YFPKPRQ":"原蓝字发票开票日期","TKSJ":"填开时间",
  405. //"XHFSBH":"销货方纳税人识别","XHFMC":"销货方纳税人名称","GMFSBH":"购买方纳税人识别号","GMFMC":"购买方纳税人名称","HJJE":"合计金额(带负号,不含税) ","HJSE":"合计税额(带负号)","SQSM":"申请说明",
  406. //"XXBTSBS":"信息表特殊标识","KZZD1":"扩展字段 1","KZZD2":"扩展字段 2"},"DDMXXX":[{"XH":"项目序号","FPHXZ":"发票行性质","SPBM":"商品编码","ZXBM":"自行编码","YHZCBS":"优惠政策标识",
  407. //"LSLBS":"零税率标识","ZZSTSGL":"增值税特殊管理","XMMC":"项目名称","GGXH":"规格型号","DW":"单位","SPSL":"商品数量","DJ":"单价","JE":"金额","HSBZ":"含税标志,固定不含税","SL":"税率","SE":"税额",
  408. //"KCE":"扣除额"}]}]}
  409. /**
  410. * @param string $idCard 纳税人识别号
  411. * @param string $OrderBatchNum 开票申请批次号
  412. * @return array|bool|float|int|mixed|\stdClass|string|null
  413. */
  414. public function GetAllocatedInvoices(string $idCard='',string $OrderBatchNum=''){
  415. $url=$this->domain."/api/order-api/order-api/v5/GetAllocatedInvoices?access_token=".$this->GetToken();
  416. $param = [
  417. "NSRSBH"=>$idCard,
  418. "DDQQPCH"=>$OrderBatchNum
  419. ];
  420. $data=$this->request->request($url,$this->GetParam($param));
  421. return $this->ReturnData($data);
  422. }
  423. /**
  424. * @param string $idCard 纳税人识别号
  425. * @param string $OrderSerialNum 流水号
  426. * @param string $extraCode 提取码
  427. * @param string $orderCode 订单号
  428. * @param string $isFile 是否版式文件 0需要1 不需要
  429. * @param string $orderStart 订单日期起始
  430. * @param string $orderEnd 订单日期终止
  431. * @return array|bool|float|int|mixed|\stdClass|string|null
  432. */public function GetOrderInfoAndInvoiceInfo(string $idCard='',string $OrderSerialNum='',string $extraCode='',string
  433. $orderCode='',string $isFile="",string $orderStart='',string $orderEnd=''){
  434. $url=$this->domain."/api/order-api/order-api/v5/GetOrderInfoAndInvoiceInfo?access_token=".$this->GetToken();
  435. $param = [
  436. "NSRSBH"=>$idCard,
  437. "DDQQLSH"=>$OrderSerialNum,
  438. "TQM"=>$extraCode,
  439. "DDH"=>$orderCode,
  440. "BSWJ"=>$isFile,
  441. "DDRQQ"=>$orderStart,
  442. "DDRQZ"=>$orderEnd,
  443. ];
  444. $data=$this->request->request($url,$this->GetParam($param));
  445. return $this->ReturnData($data);
  446. }
  447. //同步商品信息接口
  448. /**
  449. * @param string $seller_id
  450. * @param string $invoiceType
  451. * @param string $invoiceCode
  452. * @param string $invoiceNumber
  453. * @param string $cancelType
  454. * @param string $cancelText
  455. * @return array|bool|float|int|mixed|\stdClass|string|null
  456. */public function DeprecateInvoices(string $seller_id='',string $invoiceType='',string $invoiceCode='',string
  457. $invoiceNumber='',string $cancelType='',string $cancelText=''){
  458. $url=$this->domain."/api/order-api/order-api/v5/DeprecateInvoices?access_token=".$this->GetToken();
  459. $param=[
  460. "XHFSBH"=>$seller_id,
  461. "FPLXDM"=>$invoiceType,
  462. "FPDM"=>$invoiceCode,
  463. "FPHM"=>$invoiceNumber,
  464. "ZFLX"=>$cancelType,
  465. "ZFYY"=>$cancelText,
  466. ];
  467. $data=$this->request->request($url,$this->GetParam($param));
  468. return $this->ReturnData($data);
  469. }
  470. //查询企业购买方信息接口
  471. /**
  472. * @param string $seller_id
  473. * @param string $invoiceNumber
  474. * @param string $invoiceCode
  475. * @return array|bool|float|int|mixed|\stdClass|string|null
  476. */public function QueryInvalidInvoice(string $seller_id='',string $invoiceNumber='',string $invoiceCode=''){
  477. $url=$this->domain."/api/order-api/order-api/v5/DeprecateInvoices?access_token=".$this->GetToken();
  478. $param=[
  479. "XHFSBH"=>$seller_id,
  480. "FPDM"=>$invoiceCode,
  481. "FPHM"=>$invoiceNumber,
  482. ];
  483. $data=$this->request->request($url,$this->GetParam($param));
  484. return $this->ReturnData($data);
  485. }
  486. //企业购买方信息接口
  487. /**
  488. * @param array $redTicketArr
  489. * @param array $redTicketList
  490. * @return array|bool|float|int|mixed|\stdClass|string|null
  491. */public function AllocateRedInvoiceApplication(array $redTicketArr=[],array $redTicketList=[]){
  492. $url=$this->domain."/api/order-api/order-api/v5/AllocateRedInvoiceApplication?access_token=".$this->GetToken();
  493. $param=[
  494. "HZSQDSCPC"=>$redTicketArr,
  495. "HZSQDSCZXX"=>$redTicketList,
  496. ];
  497. $data=$this->request->request($url,$this->GetParam($param));
  498. return $this->ReturnData($data);
  499. }
  500. //红字发票申请表审核结果下载(增专专用)
  501. /**
  502. * @param string $goodId
  503. * @param string $seller_id
  504. * @param string $seller_name
  505. * @param string $projectName
  506. * @param string $page
  507. * @param string $size
  508. * @return array|bool|float|int|mixed|\stdClass|string|null
  509. */public function QueryCommodityInfo(string $goodId='',string $seller_id='',string $seller_name='',string
  510. $projectName='',string $page="1",string $size=''){
  511. $url=$this->domain."/api/order-api/order-api/v5/QueryCommodityInfo?access_token=".$this->GetToken();
  512. $param=[
  513. "SPID"=>$goodId,
  514. "XHFSBH"=>$seller_id,
  515. "XHFMC"=>$seller_name,
  516. "XMMC"=>$projectName,
  517. "YS"=>$page,
  518. "GS"=>$size
  519. ];
  520. $data=$this->request->request($url,$this->GetParam($param));
  521. return $this->ReturnData($data);
  522. }
  523. //为生成动态二维码接口,用于扫码开票二维码生成,暂时只支持蓝字发 票,暂时只支持电子普通发票,普通发票
  524. /**
  525. * @param string $goodId
  526. * @param string $seller_id
  527. * @param string $seller_name
  528. * @param string $catCode
  529. * @param string $goodCode
  530. * @param string $discountFlag
  531. * @param string $zeroRateFlag
  532. * @param string $addTaxM
  533. * @param string $projectName
  534. * @param string $spec
  535. * @param string $unit
  536. * @param string $price
  537. * @return array|bool|float|int|mixed|\stdClass|string|null
  538. */public function SyncCommodityInfo(string $goodId='',string $seller_id='',string $seller_name='',string
  539. $catCode='',string $goodCode="",string $discountFlag='', string $zeroRateFlag='',string $addTaxM='',string
  540. $projectName='',string $spec='',string $unit='',string $price=''){
  541. $url=$this->domain."/api/order-api/order-api/v5/SyncCommodityInfo?access_token=".$this->GetToken();
  542. $param=[
  543. "SPID"=>$goodId,
  544. "XHFSBH"=>$seller_id,
  545. "XHFMC"=>$seller_name,
  546. "XMMC"=>$projectName,
  547. "SPBM"=>$catCode,
  548. "ZXBM"=>$goodCode,
  549. "YHZCBS"=>$discountFlag,
  550. "LSLBS"=>$zeroRateFlag,
  551. "ZZSTSGL"=>$addTaxM,
  552. "GGXH"=>$spec,
  553. "DW"=>$unit,
  554. "DJ"=>$price,
  555. ];
  556. $data=$this->request->request($url,$this->GetParam($param));
  557. return $this->ReturnData($data);
  558. }
  559. //f发票信息查验
  560. /**
  561. * @param string $buyerCode
  562. * @param string $buyer_id
  563. * @param string $seller_id
  564. * @param string $buyer_name
  565. * @param string $seller_name
  566. * @param string $page
  567. * @param string $size
  568. * @return array|bool|float|int|mixed|\stdClass|string|null
  569. */public function queryBuyerInfo(string $buyerCode='',string $buyer_id='',string $seller_id='',string $buyer_name='',
  570. string $seller_name='',string $page='',string $size=''){
  571. $url=$this->domain."/api/order-api/order-api/v5/queryBuyerInfo?access_token=".$this->GetToken();
  572. $param=[
  573. "XHFSBH"=>$seller_id,
  574. "XHFMC"=>$seller_name,
  575. "GMFBM"=>$buyerCode,
  576. "GMFSBH"=>$buyer_id,
  577. "GMFMC"=>$buyer_name,
  578. "YS"=>$page,
  579. "GS"=>$size,
  580. ];
  581. $data=$this->request->request($url,$this->GetParam($param));
  582. return $this->ReturnData($data);
  583. }
  584. //异步批量发票查验
  585. /**
  586. * @param string $buyerCode
  587. * @param string $buyer_id
  588. * @param string $seller_id
  589. * @param string $buyer_name
  590. * @param string $seller_name
  591. * @param string $buyer_type
  592. * @param string $buyer_addr
  593. * @param string $buyer_tel
  594. * @param string $buyer_bank
  595. * @param string $buyer_bankNo
  596. * @param string $buyer_email
  597. * @param string $buyer_mobile
  598. * @param string $actionType
  599. * @param string $remark
  600. * @return array|bool|float|int|mixed|\stdClass|string|null
  601. */public function SyncBuyerInfo(string $buyerCode='',string $buyer_id='',string $seller_id='',string $buyer_name='',
  602. string $seller_name='',string $buyer_type='',string $buyer_addr='',string $buyer_tel='',string $buyer_bank='',
  603. string $buyer_bankNo='',string $buyer_email='',string $buyer_mobile='',string $actionType='',string $remark=''){
  604. $url=$this->domain."/api/order-api/order-api/v5/SyncBuyerInfo?access_token=".$this->GetToken();
  605. $param=[
  606. "XHFSBH"=>$seller_id,
  607. "XHFMC"=>$seller_name,
  608. "GMFBM"=>$buyerCode,
  609. "GMFSBH"=>$buyer_id,
  610. "GMFMC"=>$buyer_name,
  611. "GMFLX"=>$buyer_type,
  612. "GMFDZ"=>$buyer_addr,
  613. "GMFDH"=>$buyer_tel,
  614. "GMFYH"=>$buyer_bank,
  615. "GMFZH"=>$buyer_bankNo,
  616. "GMFYX"=>$buyer_email,
  617. "GMFSJH"=>$buyer_mobile,
  618. "CZLX"=>$actionType,
  619. "BZ"=>$remark,
  620. ];
  621. $data=$this->request->request($url,$this->GetParam($param));
  622. return $this->ReturnData($data);
  623. }
  624. //批量发票查验结果
  625. /**
  626. * @param string $resultBatchNum
  627. * @param string $idCard
  628. * @param string $invoiceType
  629. * @param string $start
  630. * @param string $end
  631. * @param string $buyer_id
  632. * @param string $seller_id
  633. * @param string $infoCode
  634. * @param string $downScope
  635. * @param string $page
  636. * @param string $size
  637. * @return array|bool|float|int|mixed|\stdClass|string|null
  638. */public function DownloadRedInvoiceApplicationResult(string $resultBatchNum='',string $idCard='',string
  639. $invoiceType='',string $start='',string $end='',string $buyer_id='',string $seller_id='',string $infoCode='',
  640. string $downScope='',string $page='',string $size=''){
  641. $url=$this->domain."/api/order-api/order-api/v5/DownloadRedInvoiceApplicationResult?access_token=".$this->GetToken();
  642. $param=[
  643. "SQBXZQQPCH"=>$resultBatchNum,
  644. "NSRSBH"=>$idCard,
  645. "FPLXDM"=>$invoiceType,
  646. "TKRQQ"=>$start,
  647. "TKRQZ"=>$end,
  648. "GMFSBH"=>$buyer_id,
  649. "XHFSBH"=>$seller_id,
  650. "XXBBH"=>$infoCode,
  651. "XXBFW"=>$downScope,
  652. "YS"=>$page,
  653. "GS"=>$size
  654. ];
  655. $data=$this->request->request($url,$this->GetParam($param));
  656. return $this->ReturnData($data);
  657. }
  658. /**
  659. * @param array $invInfo
  660. * @param array $invGoodList
  661. * @return array|bool|float|int|mixed|\stdClass|string|null
  662. */public function GenerateDynamicCode(array $invInfo=[],array $invGoodList=[]){
  663. $url=$this->domain."/api/order-api/order-api/v5/GenerateDynamicCode?access_token=".$this->GetToken();
  664. $param=[
  665. "DDTXX"=>$invInfo,
  666. "DDMXXX"=>$invGoodList
  667. ];
  668. $data=$this->request->request($url,$this->GetParam($param));
  669. return $this->ReturnData($data);
  670. }
  671. /**
  672. * @param string $checkCode
  673. * @param string $invSubtotal
  674. * @param string $invoiceCode
  675. * @param string $invoiceNumber
  676. * @param string $issueDate
  677. * @param string $invType
  678. * @return array|bool|float|int|mixed|\stdClass|string|null
  679. */public function CheckInvoiceSingle(string $checkCode='',string $invSubtotal='',string $invoiceCode='',string
  680. $invoiceNumber='',string $issueDate='',string $invType=''){
  681. $url=$this->domain."/api/open-recipt/V1/CheckInvoiceSingle?access_token=".$this->GetToken();
  682. $param=[
  683. "jym"=>$checkCode,
  684. "fpje"=>$invSubtotal,
  685. "fpdm"=>$invoiceCode,
  686. "kprq"=>$issueDate,
  687. "fphm"=>$invoiceNumber,
  688. "fpzl"=>$invType,
  689. ];
  690. $data=$this->request->request($url,$this->GetParam($param));
  691. return $this->ReturnData($data);
  692. }
  693. /**
  694. * @param string $batchNum
  695. * @param array $invoiceList
  696. * @return array|bool|float|int|mixed|\stdClass|string|null
  697. */public function MultilCheckInvoice(string $batchNum='',array $invoiceList=[]){
  698. $url=$this->domain."/api/open-recipt/V1/MultilCheckInvoice?access_token=".$this->GetToken();
  699. $param=[
  700. "pch"=>$batchNum,
  701. "invoiceList"=>$invoiceList
  702. ];
  703. $data=$this->request->request($url,$this->GetParam($param));
  704. return $this->ReturnData($data);
  705. }
  706. /**
  707. * @param string $batchNum
  708. * @return array|bool|float|int|mixed|\stdClass|string|null
  709. */public function BatchGetInvoice(string $batchNum=''){
  710. $url=$this->domain."/api/open-recipt/V1/BatchGetInvoice?access_token=".$this->GetToken();
  711. $param=[
  712. "pch"=>$batchNum
  713. ];
  714. $data=$this->request->request($url,$this->GetParam($param));
  715. return $this->ReturnData($data);
  716. }
  717. //全票面采集
  718. /**
  719. * @param string $entCode
  720. */public function setentCode($entCode=''){
  721. $this->entCode=$entCode;
  722. }
  723. /**
  724. * @param string $buyer_id 购方税号
  725. * @param string $invtype 发票类型 增值税专用发票:01 机动车销售统一发票:03 增值税电子专用发票:08 通行费电子发票:14 电子发票(增值税专用发票): 31
  726. * @param string $batchNum 批次号 32 位.代表一次请求,每次请 求批次号不重复。如果数据一 次性获取完成,批次号需要更 换。如果一次性数据获取不完, 批次号需保持一致。
  727. * @param string $start 发票采集开始时间 20170101140245
  728. * @param string $end 发票采集结束时间 20170101140245
  729. * @param int $page 开始行数
  730. * @param string $status 状态 1继续请求 0结束请求
  731. * @param string $size 每次请求数量
  732. */
  733. public function getInvoice(string $buyer_id='',string $invtype="",string $batchNum='',string $start='',string
  734. $end='',int $page=1,string $status='',string $size=''){
  735. $url=$this->domain."/api/dxhy-open-income/v1/getInvoice?access_token=".$this->GetToken();
  736. $param = [
  737. "GMFSBH"=>$buyer_id,
  738. "FPLXDM"=>$invtype,
  739. "PCH"=>$batchNum,
  740. "CJKSRQ"=>$start,
  741. "CJJSRQ"=>$end,
  742. "KSHS"=>$page,
  743. "ZTBZ"=>$status,
  744. "FHHS"=>$size
  745. ];
  746. $data=$this->request->request($url,$this->GetParam($param));
  747. return $this->ReturnData($data);
  748. }}