123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803 |
- <?php
- use think\facade\Cache;
- class Rmethod{
- public $header;
- public $method;
- public $body;
- public $url;
- public $timeout=5;
- public function __construct(){
- $this->header=["Content-Type"=>"application/json"];
- }
-
- public function getBody(){
- return $this->body;
- }
-
- public function setBody($body){
- $this->body = $body;
- }
-
- public function setMethod($method){
- $this->method = $method;
- }
-
- public function setUrl($url){
- $this->url = $url;
- }
-
- public function setHeader($header){
- $this->header = $header;
- }
-
- public function request($url='',$body=[],$method=""){
- !empty($body)?$this->body=$body:"";
- $url!=""?$this->url=$url:"";
- $this->method= $method!=""?$method:"post";
- $data=$this->curlmothod();
- return json_decode($data,true);
- }
- protected function curlmothod() {
-
- $post_string =$this->checkBody();
- $header=$this->checkHeader();
- $URL = strtolower($this->method)=="get" && !empty($post_data) ? $this->url."?".$post_string :$this->url;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $URL);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
- if(strtolower($this->method)=="post"){
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
- }
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
- curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
- $result = curl_exec($ch);
- curl_close($ch);
- return $result;
- }
- public function checkHeader(){
- if (!empty($this->header)){
- $temp=[];
- foreach ($this->header as $key=>$value){
- $temp[]=$key.":".$value;
- }
- return $temp;
- }
- return[];
- }
- public function checkBody(){
- if (!empty($this->body)){
- $body = http_build_query($this->body);
- if(key_exists("Content-Type",$this->header) && $this->header['Content-Type']=="application/json"){
- $body =json_encode($this->body);
- }
- return $body;
- }
- return'';
- }
- }
- class TaxInvoice {
- protected $appKey;
- protected $appSecret;
- protected $request;
- protected $entCode;
- protected $zipCode;
- protected $encryptCode;
- protected $domain='https://openapi.ele-cloud.com';
-
- public function __construct(string $appKey,string $appSecret,string $entCode='',$zipCode=0,$encryptCode=0){
- $this->appKey=$appKey;
- $this->appSecret=$appSecret;
- $this->entCode=$entCode;
- $this->zipCode=$zipCode;
- $this->encryptCode=$encryptCode;
- \think\facade\Log::info("appkey:{$appKey} appSecret:{$appSecret} entCode:{$entCode} ");
- $this->request=new Rmethod();
- }
- public function ts_time($format = 'u', $utimestamp = null)
- { if (is_null($utimestamp)){ $utimestamp = microtime(true); }
- $timestamp = floor($utimestamp);
- $milliseconds = round(($utimestamp - $timestamp) * 1000);
- return str_pad(date("YmdHis").$milliseconds,17,"0",STR_PAD_RIGHT);
- }
-
- public function getMainInvoice(string $buyer_id='',string $batchNum='',string $start='',string
- $end='',string $status=''){
- $url=$this->domain."/api/dxhy-open-income/v1/getMainInvoice?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "PCH"=>$batchNum,
- "CJKSRQ"=>$start,
- "CJJSRQ"=>$end,
- "ZTBZ"=>$status,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function GetToken($refresh=0){
- $token = Cache::store("redis2")->get("TAXToken".$this->entCode);
- if($token==false || $refresh==1){
- $result=$this->auth();
- \think\facade\Log::info("参数:".json_encode($result,JSON_UNESCAPED_UNICODE));
- if(key_exists("access_token",$result) && $result['access_token']!=''){
- Cache::store('redis2')->set("TAXToken".$this->entCode,$result['access_token'],$result['expires_in']);
- $token=$result['access_token'];
- }
- }
- return $token;
- }
-
- public function auth(){
- $uri=$this->domain."/api/authen/token";
- $param=["appKey"=>$this->appKey,"appSecret"=>$this->appSecret];
- $result=$this->request->request($url=$uri,$body=$param,$method="post");
- return $result;
- }
-
- public function GetParam($data){
- $func=debug_backtrace();
- $dataEXchangeId =str_pad($this->ts_time().rand(pow(10,14),pow(10,15)-1),32,'0');
- while(strlen($dataEXchangeId)!=32){
- $dataEXchangeId =str_pad($this->ts_time().rand(pow(10,14),pow(10,15)-1),32,'0');
- }
- $param=[
- "zipCode"=>$this->zipCode,
- "entCode"=>$this->entCode,
- "encryptCode"=>$this->encryptCode,
- "dataExchangeId"=>$dataEXchangeId,
- "content"=>base64_encode(json_encode($data,JSON_UNESCAPED_UNICODE))
- ];
- \think\facade\Log::info("接口:".$func[1]['function']);
- \think\facade\Log::info("参数:".json_encode($data,JSON_UNESCAPED_UNICODE));
- \think\facade\Log::info("dataExchangeId:".$param['dataExchangeId']);
- return $param;
- }
- public function ReturnData($data){
- $return =["code"=>0,"message"=>"fail"];
- if(key_exists("returnCode",$data['returnStateInfo'])){
- if ($data['returnStateInfo']['returnCode']=='0000'){
- $result= base64_decode($data['content']);
- $return = json_decode($result,true);
- }else{
- if($data['returnStateInfo']['returnCode']=='9110'){
- $this->GetToken(1);
- }
- $returnMessage= base64_decode($data['returnStateInfo']['returnMessage']);
- $return =["code"=>$data['returnStateInfo']['returnCode'],"message"=>$returnMessage];
- }
- }
- \think\facade\Log::info("返回值:".json_encode($return,JSON_UNESCAPED_UNICODE));
- return $return;
- }
-
- public function getInvoiceState(string $buyer_id='',string $batchNum='',string $start='',string
- $end='',string $status='',int $num=1){
- $url=$this->domain."/api/dxhy-open-income/v1/getInvoiceState?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "PCH"=>$batchNum,
- "ZTBGKSRQ"=>$start,
- "ZTBGJSRQ"=>$end,
- "ZTBZ"=>$status,
- "KSHS"=>$num,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function applyLegalize(string $buyer_id='',int $total=0,string $batchNum='',array $invArr=[]){
- $url=$this->domain."/api/dxhy-open-income/v1/applyLegalize?access_token=".$this->GetToken();
- $temp=[];
- if(!empty($invArr)){
- foreach ($invArr as $value){
- $data=[];
- $data['FPDM']=$value['invoiceCode'];
- $data['FPHM']=$value['invoiceNumber'];
- $data['YXSE']=$value['inv_subtotal_amount'];
- $data['SQSKSSQ']=$value['opentime'];
- $data['GMFSBH']=$value['buyer_id'];
- $data['FPLXDM']=$value['invoiceType'];
- $data['BDKYY']=$value['reason']??'';
- $temp[]=$data;
- }
- }
- $param = [
- "GMFSBH"=>$buyer_id,
- "PCH"=>$batchNum,
- "FHHS"=>$total,
- "FPZHXX"=>$temp,
- ];
-
-
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function applyLegalizeResult(string $batchNum=''){
- $url=$this->domain."/api/dxhy-open-income/v1/applyLegalizeResult?access_token=".$this->GetToken();
- $param = ["PCH"=>$batchNum];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function getCountInfo(string $buyer_id='',string $period=''){
- $url=$this->domain."/api/dxhy-open-income/v1/getCountInfo?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "RZSKSSQ"=>$period,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function applyCount(string $buyer_id='',string $period='',string $batchNum='',string $statisFlag=''){
- $url=$this->domain."/api/dxhy-open-income/v1/applyCount?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "RZSKSSQ"=>$period,
- "TJBZ"=>$statisFlag,
- "PCH"=>$batchNum
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function applyCountResult(string $buyer_id='',string $batchNum=''){
- $url=$this->domain."/api/dxhy-open-income/v1/applyCountResult?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "PCH"=>$batchNum
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function applyConfirm(string $buyer_id='',string $batchNum='',string $ack='',string $statisTime='',string
- $period='',string $confirm_passwd=''){
- $url=$this->domain."/api/dxhy-open-income/v1/applyConfirm?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "PCH"=>$batchNum,
- "QRBZ"=>$ack,
- "TJSJ"=>$statisTime,
- "RZSKSSQ"=>$period,
- "QRMM"=>$confirm_passwd,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function applyConfirmResult(string $buyer_id='',string $batchNum='',string $ack='',string $statisTime=''){
- $url=$this->domain."/api/dxhy-open-income/v1/applyConfirmResult?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "PCH"=>$batchNum,
- "QRBZ"=>$ack,
- "TJSJ"=>$statisTime,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function getCompanyInfo(string $idCard=''){
- $url=$this->domain."/api/dxhy-open-income/v1/getCompanyInfo?access_token=".$this->GetToken();
- $param = [
- "SBH"=>$idCard,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function setPassword(string $idCard='',string $confirm_passwd='',string $new_passwd=''){
- $url=$this->domain."/api/dxhy-open-income/v1/setPassword?access_token=".$this->GetToken();
- $param = [
- "SBH"=>$idCard,
- "YWMM"=>$confirm_passwd,
- "NEWYWMM"=>$new_passwd,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function resetPassword(string $idCard=''){
- $url=$this->domain."/api/dxhy-open-income/v1/resetPassword?access_token=".$this->GetToken();
- $param = [
- "SBH"=>$idCard
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function GenerateInvoice(array $OrderBatchArr=[], array $OrderInvList=[]){
- $url=$this->domain."/api/order-api/order-api/v5/GenerateInvoice?access_token=".$this->GetToken();
- $param = [
- "DDPCXX"=>$OrderBatchArr,
- "DDZXX"=>$OrderInvList
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
-
-
-
-
-
-
- public function GetAllocatedInvoices(string $idCard='',string $OrderBatchNum=''){
- $url=$this->domain."/api/order-api/order-api/v5/GetAllocatedInvoices?access_token=".$this->GetToken();
- $param = [
- "NSRSBH"=>$idCard,
- "DDQQPCH"=>$OrderBatchNum
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function GetOrderInfoAndInvoiceInfo(string $idCard='',string $OrderSerialNum='',string $extraCode='',string
- $orderCode='',string $isFile="",string $orderStart='',string $orderEnd=''){
- $url=$this->domain."/api/order-api/order-api/v5/GetOrderInfoAndInvoiceInfo?access_token=".$this->GetToken();
- $param = [
- "NSRSBH"=>$idCard,
- "DDQQLSH"=>$OrderSerialNum,
- "TQM"=>$extraCode,
- "DDH"=>$orderCode,
- "BSWJ"=>$isFile,
- "DDRQQ"=>$orderStart,
- "DDRQZ"=>$orderEnd,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function DeprecateInvoices(string $seller_id='',string $invoiceType='',string $invoiceCode='',string
- $invoiceNumber='',string $cancelType='',string $cancelText=''){
- $url=$this->domain."/api/order-api/order-api/v5/DeprecateInvoices?access_token=".$this->GetToken();
- $param=[
- "XHFSBH"=>$seller_id,
- "FPLXDM"=>$invoiceType,
- "FPDM"=>$invoiceCode,
- "FPHM"=>$invoiceNumber,
- "ZFLX"=>$cancelType,
- "ZFYY"=>$cancelText,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function QueryInvalidInvoice(string $seller_id='',string $invoiceNumber='',string $invoiceCode=''){
- $url=$this->domain."/api/order-api/order-api/v5/QueryInvalidInvoice?access_token=".$this->GetToken();
- $param=[
- "XHFSBH"=>$seller_id,
- "FPDM"=>$invoiceCode,
- "FPHM"=>$invoiceNumber,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function AllocateRedInvoiceApplication(array $redTicketArr=[],array $redTicketList=[]){
- $url=$this->domain."/api/order-api/order-api/v5/AllocateRedInvoiceApplication?access_token=".$this->GetToken();
- $param=[
- "HZSQDSCPC"=>$redTicketArr,
- "HZSQDSCZXX"=>$redTicketList,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function QueryCommodityInfo(string $goodId='',string $seller_id='',string $seller_name='',string
- $projectName='',string $page="1",string $size=''){
- $url=$this->domain."/api/order-api/order-api/v5/QueryCommodityInfo?access_token=".$this->GetToken();
- $param=[
- "SPID"=>$goodId,
- "XHFSBH"=>$seller_id,
- "XHFMC"=>$seller_name,
- "XMMC"=>$projectName,
- "YS"=>$page,
- "GS"=>$size
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function SyncCommodityInfo(string $goodId='',string $seller_id='',string $seller_name='',string
- $catCode='',string $goodCode="",string $discountFlag='', string $zeroRateFlag='',string $addTaxM='',string
- $projectName='',string $spec='',string $unit='',string $price=''){
- $url=$this->domain."/api/order-api/order-api/v5/SyncCommodityInfo?access_token=".$this->GetToken();
- $param=[
- "SPID"=>$goodId,
- "XHFSBH"=>$seller_id,
- "XHFMC"=>$seller_name,
- "XMMC"=>$projectName,
- "SPBM"=>$catCode,
- "ZXBM"=>$goodCode,
- "YHZCBS"=>$discountFlag,
- "LSLBS"=>$zeroRateFlag,
- "ZZSTSGL"=>$addTaxM,
- "GGXH"=>$spec,
- "DW"=>$unit,
- "DJ"=>$price,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function queryBuyerInfo(string $buyerCode='',string $buyer_id='',string $seller_id='',string $buyer_name='',
- string $seller_name='',string $page='',string $size=''){
- $url=$this->domain."/api/order-api/order-api/v5/queryBuyerInfo?access_token=".$this->GetToken();
- $param=[
- "XHFSBH"=>$seller_id,
- "XHFMC"=>$seller_name,
- "GMFBM"=>$buyerCode,
- "GMFSBH"=>$buyer_id,
- "GMFMC"=>$buyer_name,
- "YS"=>$page,
- "GS"=>$size,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function SyncBuyerInfo(string $buyerCode='',string $buyer_id='',string $seller_id='',string $buyer_name='',
- string $seller_name='',string $buyer_type='',string $buyer_addr='',string $buyer_tel='',string $buyer_bank='',
- string $buyer_bankNo='',string $buyer_email='',string $buyer_mobile='',string $actionType='',string $remark=''){
- $url=$this->domain."/api/order-api/order-api/v5/SyncBuyerInfo?access_token=".$this->GetToken();
- $param=[
- "XHFSBH"=>$seller_id,
- "XHFMC"=>$seller_name,
- "GMFBM"=>$buyerCode,
- "GMFSBH"=>$buyer_id,
- "GMFMC"=>$buyer_name,
- "GMFLX"=>$buyer_type,
- "GMFDZ"=>$buyer_addr,
- "GMFDH"=>$buyer_tel,
- "GMFYH"=>$buyer_bank,
- "GMFZH"=>$buyer_bankNo,
- "GMFYX"=>$buyer_email,
- "GMFSJH"=>$buyer_mobile,
- "CZLX"=>$actionType,
- "BZ"=>$remark,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function DownloadRedInvoiceApplicationResult(string $resultBatchNum='',string $idCard='',string
- $invoiceType='',string $start='',string $end='',string $buyer_id='',string $seller_id='',string $infoCode='',
- string $downScope='0',string $page='1',int $size=10){
- $url=$this->domain."/api/order-api/order-api/v5/DownloadRedInvoiceApplicationResult?access_token=".$this->GetToken();
- $param=[
- "SQBXZQQPCH"=>$resultBatchNum,
- "NSRSBH"=>$idCard,
- "FPLXDM"=>$invoiceType,
- "TKRQQ"=>$start,
- "TKRQZ"=>$end,
- "GMFSBH"=>$buyer_id,
- "XHFSBH"=>$seller_id,
- "XXBBH"=>$infoCode,
- "XXBFW"=>$downScope,
- "YS"=>$page,
- "GS"=>$size
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function GenerateDynamicCode(array $invInfo=[],array $invGoodList=[]){
- $url=$this->domain."/api/order-api/order-api/v5/GenerateDynamicCode?access_token=".$this->GetToken();
- $param=[
- "DDTXX"=>$invInfo,
- "DDMXXX"=>$invGoodList
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function CheckInvoiceSingle(string $checkCode='',string $invSubtotal='',string $invoiceCode='',string
- $invoiceNumber='',string $issueDate='',string $invType=''){
- $url=$this->domain."/api/open-recipt/V1/CheckInvoiceSingle?access_token=".$this->GetToken();
- $param=[
- "jym"=>$checkCode,
- "fpje"=>$invSubtotal,
- "fpdm"=>$invoiceCode,
- "kprq"=>$issueDate,
- "fphm"=>$invoiceNumber,
- "fpzl"=>$invType,
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function MultilCheckInvoice(string $batchNum='',array $invoiceList=[]){
- $url=$this->domain."/api/open-recipt/V1/MultilCheckInvoice?access_token=".$this->GetToken();
- $param=[
- "pch"=>$batchNum,
- "invoiceList"=>$invoiceList
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
- public function BatchGetInvoice(string $batchNum=''){
- $url=$this->domain."/api/open-recipt/V1/BatchGetInvoice?access_token=".$this->GetToken();
- $param=[
- "pch"=>$batchNum
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }
-
-
- public function setentCode($entCode=''){
- $this->entCode=$entCode;
- }
-
-
- public function getInvoice(string $buyer_id='',string $invtype="",string $batchNum='',string $start='',string
- $end='',int $page=1,string $status='',string $size=''){
- $url=$this->domain."/api/dxhy-open-income/v1/getInvoice?access_token=".$this->GetToken();
- $param = [
- "GMFSBH"=>$buyer_id,
- "FPLXDM"=>$invtype,
- "PCH"=>$batchNum,
- "CJKSRQ"=>$start,
- "CJJSRQ"=>$end,
- "KSHS"=>$page,
- "ZTBZ"=>$status,
- "FHHS"=>$size
- ];
- $data=$this->request->request($url,$this->GetParam($param));
- return $this->ReturnData($data);
- }}
|