TaxInvoice.php 29 KB

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