TaxInvoice.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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://openapi.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. \think\facade\Log::info("参数:".json_encode($data,JSON_UNESCAPED_UNICODE));
  179. return $param;
  180. }
  181. /**
  182. * @param $data
  183. * @return array|bool|float|int|mixed|stdClass|string|null
  184. */public function ReturnData($data){
  185. \think\facade\Log::info("返回值:".json_encode($data,JSON_UNESCAPED_UNICODE));
  186. if(key_exists("returnCode",$data['returnStateInfo'])){
  187. if ($data['returnStateInfo']['returnCode']=='0000'){
  188. $result= base64_decode($data['content']);
  189. return json_decode($result,true);
  190. }else{
  191. $returnMessage= base64_decode($data['returnStateInfo']['returnMessage']);
  192. return ["code"=>$data['returnStateInfo']['returnCode'],"message"=>$returnMessage];
  193. }
  194. }
  195. return ["code"=>0,"message"=>"fail"];
  196. }
  197. /**
  198. * @param string $buyer_id
  199. * @param string $batchNum
  200. * @param string $start
  201. * @param string $end
  202. * @param string $status
  203. * @param int $num
  204. * @return array|bool|float|int|mixed|stdClass|string|null
  205. */
  206. public function getInvoiceState(string $buyer_id='',string $batchNum='',string $start='',string
  207. $end='',string $status='',int $num=1){
  208. $url=$this->domain."/api/dxhy-open-income/v1/getInvoiceState?access_token=".$this->GetToken();
  209. $param = [
  210. "GMFSBH"=>$buyer_id,
  211. "PCH"=>$batchNum,
  212. "ZTBGKSRQ"=>$start,
  213. "ZTBGJSRQ"=>$end,
  214. "ZTBZ"=>$status,
  215. "KSHS"=>$num,
  216. ];
  217. $data=$this->request->request($url,$this->GetParam($param));
  218. return $this->ReturnData($data);
  219. }
  220. /**
  221. * @param string $buyer_id
  222. * @param int $total
  223. * @param string $batchNum
  224. * @param array $invArr [{invoiceCode:'',invoiceNumber:'',invoiceType:'',inv_subtotal_amount:'',opentime:'',
  225. * buyer_id:'',reason:''}]
  226. * @return array|bool|float|int|mixed|stdClass|string|null
  227. */
  228. public function applyLegalize(string $buyer_id='',int $total=0,string $batchNum='',array $invArr=[]){
  229. $url=$this->domain."/api/dxhy-open-income/v1/applyLegalize?access_token=".$this->GetToken();
  230. $temp=[];
  231. if(!empty($invArr)){
  232. foreach ($invArr as $value){
  233. $data=[];
  234. $data['FPDM']=$value['invoiceCode'];
  235. $data['FPHM']=$value['invoiceNumber'];
  236. $data['YXSE']=$value['inv_subtotal_amount'];
  237. $data['SQSKSSQ']=$value['opentime'];
  238. $data['GMFSBH']=$value['buyer_id'];
  239. $data['FPLXDM']=$value['invoiceType'];
  240. $data['BDKYY']=$value['reason']??'';
  241. $temp[]=$data;
  242. }
  243. }
  244. $param = [
  245. "GMFSBH"=>$buyer_id,
  246. "PCH"=>$batchNum,
  247. "FHHS"=>$total,
  248. "FPZHXX"=>$temp,
  249. ];
  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. return $this->ReturnData($data);
  400. }
  401. //{"HZSQDSCPC":{"SQBSCQQPCH":"申请表上传请求批次号","NSRSBH":"申请方纳税人识别号","KPZD":"开票终端","FPLXDM":"发票类型代码","KZZD":"扩展字段"},
  402. //"HZSQDSCZXX":[
  403. //{"HZSQDTXX":{"SQBSCQQLSH":"申请表上传请求流水号","YYSBZ":"营业税标志","XXBLX":"信息表类型","YFPDM":"原蓝字发票代码","YFPHM":"原蓝字发票号码","YFPKPRQ":"原蓝字发票开票日期","TKSJ":"填开时间",
  404. //"XHFSBH":"销货方纳税人识别","XHFMC":"销货方纳税人名称","GMFSBH":"购买方纳税人识别号","GMFMC":"购买方纳税人名称","HJJE":"合计金额(带负号,不含税) ","HJSE":"合计税额(带负号)","SQSM":"申请说明",
  405. //"XXBTSBS":"信息表特殊标识","KZZD1":"扩展字段 1","KZZD2":"扩展字段 2"},"DDMXXX":[{"XH":"项目序号","FPHXZ":"发票行性质","SPBM":"商品编码","ZXBM":"自行编码","YHZCBS":"优惠政策标识",
  406. //"LSLBS":"零税率标识","ZZSTSGL":"增值税特殊管理","XMMC":"项目名称","GGXH":"规格型号","DW":"单位","SPSL":"商品数量","DJ":"单价","JE":"金额","HSBZ":"含税标志,固定不含税","SL":"税率","SE":"税额",
  407. //"KCE":"扣除额"}]}]}
  408. /**
  409. * @param string $idCard 纳税人识别号
  410. * @param string $OrderBatchNum 开票申请批次号
  411. * @return array|bool|float|int|mixed|\stdClass|string|null
  412. */
  413. public function GetAllocatedInvoices(string $idCard='',string $OrderBatchNum=''){
  414. $url=$this->domain."/api/order-api/order-api/v5/GetAllocatedInvoices?access_token=".$this->GetToken();
  415. $param = [
  416. "NSRSBH"=>$idCard,
  417. "DDQQPCH"=>$OrderBatchNum
  418. ];
  419. $data=$this->request->request($url,$this->GetParam($param));
  420. return $this->ReturnData($data);
  421. }
  422. /**
  423. * @param string $idCard 纳税人识别号
  424. * @param string $OrderSerialNum 流水号
  425. * @param string $extraCode 提取码
  426. * @param string $orderCode 订单号
  427. * @param string $isFile 是否版式文件 0需要1 不需要
  428. * @param string $orderStart 订单日期起始
  429. * @param string $orderEnd 订单日期终止
  430. * @return array|bool|float|int|mixed|\stdClass|string|null
  431. */public function GetOrderInfoAndInvoiceInfo(string $idCard='',string $OrderSerialNum='',string $extraCode='',string
  432. $orderCode='',string $isFile="",string $orderStart='',string $orderEnd=''){
  433. $url=$this->domain."/api/order-api/order-api/v5/GetOrderInfoAndInvoiceInfo?access_token=".$this->GetToken();
  434. $param = [
  435. "NSRSBH"=>$idCard,
  436. "DDQQLSH"=>$OrderSerialNum,
  437. "TQM"=>$extraCode,
  438. "DDH"=>$orderCode,
  439. "BSWJ"=>$isFile,
  440. "DDRQQ"=>$orderStart,
  441. "DDRQZ"=>$orderEnd,
  442. ];
  443. $data=$this->request->request($url,$this->GetParam($param));
  444. return $this->ReturnData($data);
  445. }
  446. //同步商品信息接口
  447. /**
  448. * @param string $seller_id
  449. * @param string $invoiceType
  450. * @param string $invoiceCode
  451. * @param string $invoiceNumber
  452. * @param string $cancelType
  453. * @param string $cancelText
  454. * @return array|bool|float|int|mixed|\stdClass|string|null
  455. */public function DeprecateInvoices(string $seller_id='',string $invoiceType='',string $invoiceCode='',string
  456. $invoiceNumber='',string $cancelType='',string $cancelText=''){
  457. $url=$this->domain."/api/order-api/order-api/v5/DeprecateInvoices?access_token=".$this->GetToken();
  458. $param=[
  459. "XHFSBH"=>$seller_id,
  460. "FPLXDM"=>$invoiceType,
  461. "FPDM"=>$invoiceCode,
  462. "FPHM"=>$invoiceNumber,
  463. "ZFLX"=>$cancelType,
  464. "ZFYY"=>$cancelText,
  465. ];
  466. $data=$this->request->request($url,$this->GetParam($param));
  467. return $this->ReturnData($data);
  468. }
  469. //查询企业购买方信息接口
  470. /**
  471. * @param string $seller_id
  472. * @param string $invoiceNumber
  473. * @param string $invoiceCode
  474. * @return array|bool|float|int|mixed|\stdClass|string|null
  475. */public function QueryInvalidInvoice(string $seller_id='',string $invoiceNumber='',string $invoiceCode=''){
  476. $url=$this->domain."/api/order-api/order-api/v5/DeprecateInvoices?access_token=".$this->GetToken();
  477. $param=[
  478. "XHFSBH"=>$seller_id,
  479. "FPDM"=>$invoiceCode,
  480. "FPHM"=>$invoiceNumber,
  481. ];
  482. $data=$this->request->request($url,$this->GetParam($param));
  483. return $this->ReturnData($data);
  484. }
  485. //企业购买方信息接口
  486. /**
  487. * @param array $redTicketArr
  488. * @param array $redTicketList
  489. * @return array|bool|float|int|mixed|\stdClass|string|null
  490. */public function AllocateRedInvoiceApplication(array $redTicketArr=[],array $redTicketList=[]){
  491. $url=$this->domain."/api/order-api/order-api/v5/AllocateRedInvoiceApplication?access_token=".$this->GetToken();
  492. $param=[
  493. "HZSQDSCPC"=>$redTicketArr,
  494. "HZSQDSCZXX"=>$redTicketList,
  495. ];
  496. $data=$this->request->request($url,$this->GetParam($param));
  497. return $this->ReturnData($data);
  498. }
  499. //红字发票申请表审核结果下载(增专专用)
  500. /**
  501. * @param string $goodId
  502. * @param string $seller_id
  503. * @param string $seller_name
  504. * @param string $projectName
  505. * @param string $page
  506. * @param string $size
  507. * @return array|bool|float|int|mixed|\stdClass|string|null
  508. */public function QueryCommodityInfo(string $goodId='',string $seller_id='',string $seller_name='',string
  509. $projectName='',string $page="1",string $size=''){
  510. $url=$this->domain."/api/order-api/order-api/v5/QueryCommodityInfo?access_token=".$this->GetToken();
  511. $param=[
  512. "SPID"=>$goodId,
  513. "XHFSBH"=>$seller_id,
  514. "XHFMC"=>$seller_name,
  515. "XMMC"=>$projectName,
  516. "YS"=>$page,
  517. "GS"=>$size
  518. ];
  519. $data=$this->request->request($url,$this->GetParam($param));
  520. return $this->ReturnData($data);
  521. }
  522. //为生成动态二维码接口,用于扫码开票二维码生成,暂时只支持蓝字发 票,暂时只支持电子普通发票,普通发票
  523. /**
  524. * @param string $goodId
  525. * @param string $seller_id
  526. * @param string $seller_name
  527. * @param string $catCode
  528. * @param string $goodCode
  529. * @param string $discountFlag
  530. * @param string $zeroRateFlag
  531. * @param string $addTaxM
  532. * @param string $projectName
  533. * @param string $spec
  534. * @param string $unit
  535. * @param string $price
  536. * @return array|bool|float|int|mixed|\stdClass|string|null
  537. */public function SyncCommodityInfo(string $goodId='',string $seller_id='',string $seller_name='',string
  538. $catCode='',string $goodCode="",string $discountFlag='', string $zeroRateFlag='',string $addTaxM='',string
  539. $projectName='',string $spec='',string $unit='',string $price=''){
  540. $url=$this->domain."/api/order-api/order-api/v5/SyncCommodityInfo?access_token=".$this->GetToken();
  541. $param=[
  542. "SPID"=>$goodId,
  543. "XHFSBH"=>$seller_id,
  544. "XHFMC"=>$seller_name,
  545. "XMMC"=>$projectName,
  546. "SPBM"=>$catCode,
  547. "ZXBM"=>$goodCode,
  548. "YHZCBS"=>$discountFlag,
  549. "LSLBS"=>$zeroRateFlag,
  550. "ZZSTSGL"=>$addTaxM,
  551. "GGXH"=>$spec,
  552. "DW"=>$unit,
  553. "DJ"=>$price,
  554. ];
  555. $data=$this->request->request($url,$this->GetParam($param));
  556. return $this->ReturnData($data);
  557. }
  558. //f发票信息查验
  559. /**
  560. * @param string $buyerCode
  561. * @param string $buyer_id
  562. * @param string $seller_id
  563. * @param string $buyer_name
  564. * @param string $seller_name
  565. * @param string $page
  566. * @param string $size
  567. * @return array|bool|float|int|mixed|\stdClass|string|null
  568. */public function queryBuyerInfo(string $buyerCode='',string $buyer_id='',string $seller_id='',string $buyer_name='',
  569. string $seller_name='',string $page='',string $size=''){
  570. $url=$this->domain."/api/order-api/order-api/v5/queryBuyerInfo?access_token=".$this->GetToken();
  571. $param=[
  572. "XHFSBH"=>$seller_id,
  573. "XHFMC"=>$seller_name,
  574. "GMFBM"=>$buyerCode,
  575. "GMFSBH"=>$buyer_id,
  576. "GMFMC"=>$buyer_name,
  577. "YS"=>$page,
  578. "GS"=>$size,
  579. ];
  580. $data=$this->request->request($url,$this->GetParam($param));
  581. return $this->ReturnData($data);
  582. }
  583. //异步批量发票查验
  584. /**
  585. * @param string $buyerCode
  586. * @param string $buyer_id
  587. * @param string $seller_id
  588. * @param string $buyer_name
  589. * @param string $seller_name
  590. * @param string $buyer_type
  591. * @param string $buyer_addr
  592. * @param string $buyer_tel
  593. * @param string $buyer_bank
  594. * @param string $buyer_bankNo
  595. * @param string $buyer_email
  596. * @param string $buyer_mobile
  597. * @param string $actionType
  598. * @param string $remark
  599. * @return array|bool|float|int|mixed|\stdClass|string|null
  600. */public function SyncBuyerInfo(string $buyerCode='',string $buyer_id='',string $seller_id='',string $buyer_name='',
  601. string $seller_name='',string $buyer_type='',string $buyer_addr='',string $buyer_tel='',string $buyer_bank='',
  602. string $buyer_bankNo='',string $buyer_email='',string $buyer_mobile='',string $actionType='',string $remark=''){
  603. $url=$this->domain."/api/order-api/order-api/v5/SyncBuyerInfo?access_token=".$this->GetToken();
  604. $param=[
  605. "XHFSBH"=>$seller_id,
  606. "XHFMC"=>$seller_name,
  607. "GMFBM"=>$buyerCode,
  608. "GMFSBH"=>$buyer_id,
  609. "GMFMC"=>$buyer_name,
  610. "GMFLX"=>$buyer_type,
  611. "GMFDZ"=>$buyer_addr,
  612. "GMFDH"=>$buyer_tel,
  613. "GMFYH"=>$buyer_bank,
  614. "GMFZH"=>$buyer_bankNo,
  615. "GMFYX"=>$buyer_email,
  616. "GMFSJH"=>$buyer_mobile,
  617. "CZLX"=>$actionType,
  618. "BZ"=>$remark,
  619. ];
  620. $data=$this->request->request($url,$this->GetParam($param));
  621. return $this->ReturnData($data);
  622. }
  623. //批量发票查验结果
  624. /**
  625. * @param string $resultBatchNum
  626. * @param string $idCard
  627. * @param string $invoiceType
  628. * @param string $start
  629. * @param string $end
  630. * @param string $buyer_id
  631. * @param string $seller_id
  632. * @param string $infoCode
  633. * @param string $downScope
  634. * @param string $page
  635. * @param string $size
  636. * @return array|bool|float|int|mixed|\stdClass|string|null
  637. */public function DownloadRedInvoiceApplicationResult(string $resultBatchNum='',string $idCard='',string
  638. $invoiceType='',string $start='',string $end='',string $buyer_id='',string $seller_id='',string $infoCode='',
  639. string $downScope='',string $page='',string $size=''){
  640. $url=$this->domain."/api/order-api/order-api/v5/DownloadRedInvoiceApplicationResult?access_token=".$this->GetToken();
  641. $param=[
  642. "SQBXZQQPCH"=>$resultBatchNum,
  643. "NSRSBH"=>$idCard,
  644. "FPLXDM"=>$invoiceType,
  645. "TKRQQ"=>$start,
  646. "TKRQZ"=>$end,
  647. "GMFSBH"=>$buyer_id,
  648. "XHFSBH"=>$seller_id,
  649. "XXBBH"=>$infoCode,
  650. "XXBFW"=>$downScope,
  651. "YS"=>$page,
  652. "GS"=>$size
  653. ];
  654. $data=$this->request->request($url,$this->GetParam($param));
  655. return $this->ReturnData($data);
  656. }
  657. /**
  658. * @param array $invInfo
  659. * @param array $invGoodList
  660. * @return array|bool|float|int|mixed|\stdClass|string|null
  661. */public function GenerateDynamicCode(array $invInfo=[],array $invGoodList=[]){
  662. $url=$this->domain."/api/order-api/order-api/v5/GenerateDynamicCode?access_token=".$this->GetToken();
  663. $param=[
  664. "DDTXX"=>$invInfo,
  665. "DDMXXX"=>$invGoodList
  666. ];
  667. $data=$this->request->request($url,$this->GetParam($param));
  668. return $this->ReturnData($data);
  669. }
  670. /**
  671. * @param string $checkCode
  672. * @param string $invSubtotal
  673. * @param string $invoiceCode
  674. * @param string $invoiceNumber
  675. * @param string $issueDate
  676. * @param string $invType
  677. * @return array|bool|float|int|mixed|\stdClass|string|null
  678. */public function CheckInvoiceSingle(string $checkCode='',string $invSubtotal='',string $invoiceCode='',string
  679. $invoiceNumber='',string $issueDate='',string $invType=''){
  680. $url=$this->domain."/api/open-recipt/V1/CheckInvoiceSingle?access_token=".$this->GetToken();
  681. $param=[
  682. "jym"=>$checkCode,
  683. "fpje"=>$invSubtotal,
  684. "fpdm"=>$invoiceCode,
  685. "kprq"=>$issueDate,
  686. "fphm"=>$invoiceNumber,
  687. "fpzl"=>$invType,
  688. ];
  689. $data=$this->request->request($url,$this->GetParam($param));
  690. return $this->ReturnData($data);
  691. }
  692. /**
  693. * @param string $batchNum
  694. * @param array $invoiceList
  695. * @return array|bool|float|int|mixed|\stdClass|string|null
  696. */public function MultilCheckInvoice(string $batchNum='',array $invoiceList=[]){
  697. $url=$this->domain."/api/open-recipt/V1/MultilCheckInvoice?access_token=".$this->GetToken();
  698. $param=[
  699. "pch"=>$batchNum,
  700. "invoiceList"=>$invoiceList
  701. ];
  702. $data=$this->request->request($url,$this->GetParam($param));
  703. return $this->ReturnData($data);
  704. }
  705. /**
  706. * @param string $batchNum
  707. * @return array|bool|float|int|mixed|\stdClass|string|null
  708. */public function BatchGetInvoice(string $batchNum=''){
  709. $url=$this->domain."/api/open-recipt/V1/BatchGetInvoice?access_token=".$this->GetToken();
  710. $param=[
  711. "pch"=>$batchNum
  712. ];
  713. $data=$this->request->request($url,$this->GetParam($param));
  714. return $this->ReturnData($data);
  715. }
  716. //全票面采集
  717. /**
  718. * @param string $entCode
  719. */public function setentCode($entCode=''){
  720. $this->entCode=$entCode;
  721. }
  722. /**
  723. * @param string $buyer_id 购方税号
  724. * @param string $invtype 发票类型 增值税专用发票:01 机动车销售统一发票:03 增值税电子专用发票:08 通行费电子发票:14 电子发票(增值税专用发票): 31
  725. * @param string $batchNum 批次号 32 位.代表一次请求,每次请 求批次号不重复。如果数据一 次性获取完成,批次号需要更 换。如果一次性数据获取不完, 批次号需保持一致。
  726. * @param string $start 发票采集开始时间 20170101140245
  727. * @param string $end 发票采集结束时间 20170101140245
  728. * @param int $page 开始行数
  729. * @param string $status 状态 1继续请求 0结束请求
  730. * @param string $size 每次请求数量
  731. */
  732. public function getInvoice(string $buyer_id='',string $invtype="",string $batchNum='',string $start='',string
  733. $end='',int $page=1,string $status='',string $size=''){
  734. $url=$this->domain."/api/dxhy-open-income/v1/getInvoice?access_token=".$this->GetToken();
  735. $param = [
  736. "GMFSBH"=>$buyer_id,
  737. "FPLXDM"=>$invtype,
  738. "PCH"=>$batchNum,
  739. "CJKSRQ"=>$start,
  740. "CJJSRQ"=>$end,
  741. "KSHS"=>$page,
  742. "ZTBZ"=>$status,
  743. "FHHS"=>$size
  744. ];
  745. $data=$this->request->request($url,$this->GetParam($param));
  746. return $this->ReturnData($data);
  747. }}