作者 竞泽

add:all

###广州单一窗口
```
demo
```
... ...
<?php
return [
'base_uri' => 'https://open.singlewindow.gz.cn',
'record_sn' => '4423968643',
'secret_key' => '12345678',
'company_cert_sn' => '20200000000652',
'sender_sn' => 'GEYOUSUOAI',
'receiver_sn' => 'KJPUBLICPT'
];
... ...
<?php
namespace Lackoxygen\GzCbec;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\RequestOptions;
use Illuminate\Support\Arr;
use Lackoxygen\GzCbec\Contract\ClientInterface;
use Lackoxygen\GzCbec\Contract\RequestInterface;
use GuzzleHttp\Client as GuzzleHttp;
use Lackoxygen\GzCbec\Exception\Exception;
use Psr\Http\Message\ResponseInterface;
class Client implements ClientInterface
{
/**
* @var GuzzleHttp
*/
protected $guzzleHttp;
/**
* @var RequestInterface
*/
protected $request;
/**
* @var array
*/
protected $config = [
'base_uri' => 'https://open.singlewindow.gz.cn',
'record_sn' => 'C011111100414353',
'secret_key' => '12345678',
'company_cert_sn' => '20200000000652',
'sender_sn' => 'GEYOUSUOAI',
'receiver_sn' => 'KJPUBLICPT'
];
protected function __construct(RequestInterface $request)
{
$this->guzzleHttp = new GuzzleHttp([
'base_uri' => Arr::get($this->config, 'base_uri'),
'verify' => false
]);
$this->request = $request;
}
/**
* @param RequestInterface $request
*
* @return ClientInterface
*/
protected static function make(RequestInterface $request): ClientInterface
{
return new static($request);
}
/**
* @return ResponseInterface
* @throws Exception
*/
public function send(): ResponseInterface
{
$content = $this->request->getPacket()->getContent();
file_put_contents('transfer.xml', $content);
try {
$response = $this->guzzleHttp->request($this->request->getMethod(), $this->request->getPath(), [
RequestOptions::FORM_PARAMS => [
'clientid' => $this->config['record_sn'],
'key' => $this->config['secret_key'],
'messageType' => $this->request->getMessageType(),
'messageText' => $content
]
]);
} catch (GuzzleException $e) {
throw new Exception($e);
}
return $response;
}
/**
* @param RequestInterface $request
*
* @return array
*/
public static function request(RequestInterface $request): array
{
$client = self::make($request);
/**
* @var ResponseInterface $response
*/
$response = $client->send();
$content = $response->getBody()->getContents();
$response->getBody()->rewind();
return (array)\json_decode($content, true);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Constant;
class Message
{
/**
* 电子订单
*/
public const KJ881111 = 'KJ881111';
/**
* 电子运单
*/
public const KJ881113 = 'KJ881113';
/**
* 电子支付单
*/
public const KJ881112 = 'KJ881112';
/**
* 电子清单
*/
public const KJ881110 = 'KJ881110';
/**
* 商品备案申请
*/
public const KJ881101 = 'KJ881101';
/**
* BBC进仓清单
*/
public const KJ881103 = 'KJ881103';
/**
* BBC货物装载清单
*/
public const KJ881105 = 'KJ881105';
/**
* BC货物装载清单
*/
public const KJ881116 = 'KJ881116';
/**
* BC进区总运单
*/
public const KJ881128 = 'KJ881128';
/**
* B2B电子订单
*/
public const B2B103 = 'B2B103';
/**
* 电子订单
*/
public const CEB311MESSAGE = 'CEB311Message';
/**
* 物流运单
*/
public const CEB511MESSAGE = 'CEB511Message';
/**
* 支付凭证
*/
public const CEB411MESSAGE = 'CEB411Message';
/**
* 进口清单
*/
public const CEB621MESSAGE = 'CEB621Message';
/**
* 入库明细数据
*/
public const CEB711MESSAGE = 'CEB711Message';
/**
* 撤销申请单
*/
public const CEB623MESSAGE = 'CEB623Message';
/**
* 退货申请单
*/
public const CEB625MESSAGE = 'CEB625Message';
/**
* 物流运输状态
*/
public const CEB513MESSAGE = 'CEB513Message';
}
... ...
<?php
namespace Lackoxygen\GzCbec\Constant;
class QueryType
{
/**
* 商品备案申请
*/
public const KJ881101 = 'KJ881101';
/**
* BBC进仓清单
*/
public const KJ881103 = 'KJ881103';
/**
* 电子订单
*/
public const KJ881111 = 'KJ881111';
/**
* 电子运单
*/
public const KJ881113 = 'KJ881113';
/**
* 电子支付单
*/
public const KJ881112 = 'KJ881112';
/**
* BBC货物装载清单
*/
public const KJ881105 = 'KJ881105';
/**
* 电子清单
*/
public const KJ881110 = 'KJ881110';
/**
* BC货物装载清单
*/
public const KJ881116 = 'KJ881116';
/**
* BC进区总运单
*/
public const KJ881114 = 'KJ881114';
/**
* BC理货报告
*/
public const KJ881115 = 'KJ881115';
/**
* BC过线报告
*/
public const KJ881119 = 'KJ881119';
/**
* 运单状态
*/
public const KJ881126 = 'KJ881126';
}
... ...
<?php
namespace Lackoxygen\GzCbec\Constant;
class XML
{
public const FIRST_LINE = '<?xml version="1.0" encoding="UTF-8"?>';
public const DATA = '<%s xmlns:ceb="http://www.chinaport.gov.cn/ceb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" guid="%s" version="%s"></%s>';
public const SIGNATURE = '<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"></Signature>';
public const TRANSFER = '<GzeportTransfer xmlns:n1="http://www.altova.com/samplexml/other-namespace" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"></GzeportTransfer>';
}
... ...
<?php
namespace Lackoxygen\GzCbec\Contract;
interface ClientInterface
{
public function send();
}
... ...
<?php
namespace Lackoxygen\GzCbec\Contract;
use Lackoxygen\GzCbec\Request\Report\CEB311Message;
interface ReportInterface
{
public function CEB311Message(CEB311Message $CEB311Message);
}
... ...
<?php
namespace Lackoxygen\GzCbec\Contract;
use Lackoxygen\GzCbec\Request\Packet;
interface RequestInterface
{
/**
* @return string
*/
public function getVersion(): string;
/**
* @return string
*/
public function getGuid(): string;
/**
* @return Packet
*/
public function getPacket(): Packet;
/**
* @return string
*/
public function getPath(): string;
/**
* @return string
*/
public function getMethod(): string;
/**
* @return string
*/
public function getMessageType(): string;
}
... ...
<?php
namespace Lackoxygen\GzCbec\Contract;
interface XMLInterface
{
/**
* @return string
*/
public function getFirstLabelPrefix(): string;
/**
* @return string
*/
public function getFirstLabelName(): string;
/**
* @param string $head
*
* @return string
*/
public function toXML(string $head): string;
}
... ...
<?php
namespace Lackoxygen\GzCbec\Exception;
class Exception extends \Exception
{
}
... ...
<?php
namespace Lackoxygen\GzCbec\Facade;
use Illuminate\Support\Facades\Facade;
use Lackoxygen\GzCbec\GzCBEC;
class GzCBECFacade extends Facade
{
/**
* @return string
*/
protected static function getFacadeAccessor(): string
{
return GzCBEC::class;
}
}
... ...
<?php
namespace Lackoxygen\GzCbec;
use Lackoxygen\GzCbec\Contract\ReportInterface;
use Lackoxygen\GzCbec\Factory\Report;
class Factory
{
public static function report(): ReportInterface
{
return new Report();
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Factory;
use Lackoxygen\GzCbec\Client;
use Lackoxygen\GzCbec\Contract\ReportInterface;
use Lackoxygen\GzCbec\Request\Report\CEB311Message;
class Report implements ReportInterface
{
public function CEB311Message(CEB311Message $CEB311Message)
{
return Client::request($CEB311Message);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec;
use Lackoxygen\GzCbec\Factory\Report;
class GzCBEC
{
public function report(): Report
{
return Factory::report();
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request;
use Lackoxygen\GzCbec\Contract\XMLInterface;
use Lackoxygen\GzCbec\Utils\Collection;
class CEBRequest extends Request implements XMLInterface
{
/**
* @var string
*/
protected $method = 'POST';
/**
* @var string
*/
protected $path = '/swcbes/client/declare/sendMessage.action';
/**
* @return string
*/
public function getFirstLabelPrefix(): string
{
return 'ceb';
}
/**
* @return string
*/
public function getFirstLabelName(): string
{
return class_basename($this);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Head;
use Lackoxygen\GzCbec\Request\Report\Node\Receiver;
use Lackoxygen\GzCbec\Utils\Collection;
class Head extends Collection
{
/**
* @return mixed
*/
public function getMessageID()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $messageId
*/
public function setMessageID(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getMessageType()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $messageType
*/
public function setMessageType(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getSender()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $sender
*/
public function setSender(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getReceivers()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $receivers
*/
public function pushReceivers(Receiver $receiver): void
{
$this->mPush(__FUNCTION__, $receiver);
}
/**
* @return mixed
*/
public function getSendTime()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $sendTime
*/
public function setSendTime(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getVersion()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $version
*/
public function setVersion(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getFileName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $fileName
*/
public function setFileName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getZipFlag()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $zipFlag
*/
public function setZipFlag(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request;
use Carbon\Carbon;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Lackoxygen\GzCbec\Constant\XML;
use Lackoxygen\GzCbec\Contract\RequestInterface;
use Lackoxygen\GzCbec\Contract\XMLInterface;
use Lackoxygen\GzCbec\Exception\Exception;
use Lackoxygen\GzCbec\Request\Head\Head;
use Lackoxygen\GzCbec\Request\Packet\GzReportTransfer;
use Lackoxygen\GzCbec\Request\Report\Node\Receiver;
use Lackoxygen\GzCbec\Utils\RSA;
use Lackoxygen\GzCbec\Utils\Signature;
class Packet
{
/**
* @var RequestInterface $request
*/
protected $request;
/**
* @var array
*/
protected $config = [];
/**
* Packet constructor.
*
* @param RequestInterface $request
*/
public function __construct(RequestInterface $request)
{
$this->request = $request;
$this->config = [
'base_uri' => 'https://open.singlewindow.gz.cn',
'record_sn' => 'C011111100414353',
'secret_key' => '12345678',
'company_cert_sn' => '20200000000652',
'sender_sn' => 'GEYOUSUOAI',
'receiver_sn' => 'KJPUBLICPT',
'signature' => "http://10.10.10.41:8080/signature.do"
];
}
/**
* @return string
*/
public function getContent(): string
{
try {
$head = new Head();
$head->setMessageId($this->request->getGuid());
$head->setMessageType($this->request->getMessageType());
$head->setSender($this->config['sender_sn']);
$receiver = new Receiver();
$receiver->setReceiver($this->config['receiver_sn']);
$head->pushReceivers($receiver);
$head->setSendTime(Carbon::now()->getPreciseTimestamp(4));
$head->setVersion($this->request->getVersion());
$head->setFileName('');
$head->setZipFlag(0);
$packet = new GzReportTransfer();
$packet->setHead($head);
if ($this->request instanceof XMLInterface) {
$firstLabel = $this->request->getFirstLabelPrefix() . ':' . $this->request->getFirstLabelName();
$xmlHead = sprintf(XML::DATA, $firstLabel, $this->request->getGuid(), $this->request->getVersion(),
$firstLabel);
$dataXml = $this->request->toXML($xmlHead);
file_put_contents('test.xml', $dataXml);
$data = base64_encode($dataXml);
$packet->setData($data);
}
$xml = $packet->toXML(XML::TRANSFER);
return $this->signature($xml);
} catch (Exception $exception) {
return '';
}
}
/**
* @param $signXml
*
* @return string
*/
protected function signature(string $signXml): string
{
$signature = Arr::get($this->config, 'signature');
if ($signature instanceof \Closure) {
$afterSignXml = call_user_func($signature, $signXml);
if (!is_null($afterSignXml)) {
return $afterSignXml;
}
} else {
return (new Signature($signature))($signXml);
}
return "";
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Packet;
use Lackoxygen\GzCbec\Utils\Collection;
class GzReportTransfer extends Collection
{
/**
* @return mixed
*/
public function getHead()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $head
*/
public function setHead(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getData()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $data
*/
public function setData(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getSignature()
{
return $this->mGet(__FUNCTION__);
}
public function setSignature()
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Report;
use Lackoxygen\GzCbec\Contract\RequestInterface;
use Lackoxygen\GzCbec\Contract\XMLInterface;
use Lackoxygen\GzCbec\Request\CEBRequest;
use Lackoxygen\GzCbec\Request\Report\Node\BaseTransfer;
use Lackoxygen\GzCbec\Request\Report\Node\Order;
class CEB311Message extends CEBRequest
{
protected $messageType = 'CEB311Message';
/**
* @param mixed $order
*/
public function setOrder(Order $order): void
{
$this->mSet(__FUNCTION__, $order, false);
}
/**
* @param mixed $baseTransfer
*/
public function setBaseTransfer(BaseTransfer $baseTransfer): void
{
$this->mSet(__FUNCTION__, $baseTransfer, false);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Report\Node;
use Lackoxygen\GzCbec\Utils\Collection;
class BaseTransfer extends Collection
{
/**
* @return mixed
*/
public function getCopCode()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $copCode
*/
public function setCopCode(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getCopName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $copName
*/
public function setCopName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getDxpMode()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $dxpMode
*/
public function setDxpMode($dxpMode): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getDxpId()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $dxpId
*/
public function setDxpId($dxpId): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getNote()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $note
*/
public function setNote(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Report\Node;
use Lackoxygen\GzCbec\Utils\Collection;
class Order extends Collection
{
/**
* @return mixed
*/
public function getOrderHead()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $orderHead
*/
public function setOrderHead(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
/**
* @return mixed
*/
public function getOrderList()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $orderList
*/
public function pushOrderList(OrderList $orderList): void
{
$this->mPush(__FUNCTION__, $orderList);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Report\Node;
use Lackoxygen\GzCbec\Utils\Collection;
class OrderHead extends Collection
{
/**
* @return mixed
*/
public function getGuid()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $guid
*/
public function setGuid(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getAppType()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $appType
*/
public function setAppType(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getAppTime()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $appTime
*/
public function setAppTime(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getAppStatus()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $appStatus
*/
public function setAppStatus(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getOrderType()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $orderType
*/
public function setOrderType(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getOrderNo()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $orderNo
*/
public function setOrderNo(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getEbpCode()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $ebpCode
*/
public function setEbpCode(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getEbpName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $ebpName
*/
public function setEbpName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getEbcCode()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $ebcCode
*/
public function setEbcCode(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getEbcName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $ebcName
*/
public function setEbcName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getGoodsValue()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $goodsValue
*/
public function setGoodsValue(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getFreight()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $freight
*/
public function setFreight(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getDiscount()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $discount
*/
public function setDiscount(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getTaxTotal()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $taxTotal
*/
public function setTaxTotal(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getActuralPaid()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $acturalPaid
*/
public function setActuralPaid(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getCurrency()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $currency
*/
public function setCurrency(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getBuyerRegNo()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $buyerRegNo
*/
public function setBuyerRegNo(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getBuyerName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $buyerName
*/
public function setBuyerName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getBuyerIdType()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $buyerIdType
*/
public function setBuyerIdType(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getBuyerIdNumber()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $buyerIdNumber
*/
public function setBuyerIdNumber(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getPayCode()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $payCode
*/
public function setPayCode(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getPayName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $payName
*/
public function setPayName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getPayTransactionId()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $payTransactionId
*/
public function setPayTransactionId(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getBatchNumbers()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $batchNumbers
*/
public function setBatchNumbers(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getConsignee()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $consignee
*/
public function setConsignee(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getConsigneeTelephone()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $consigneeTelephone
*/
public function setConsigneeTelephone(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getConsigneeAddress()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $consigneeAddress
*/
public function setConsigneeAddress(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getConsigneeDistrict()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $consigneeDistrict
*/
public function setConsigneeDistrict(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getNote()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $note
*/
public function setNote(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Report\Node;
use Lackoxygen\GzCbec\Utils\Collection;
class OrderList extends Collection
{
/**
* @return mixed
*/
public function getGnum()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $gnum
*/
public function setGnum(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getItemNo()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $itemNo
*/
public function setItemNo(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getItemName()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $itemName
*/
public function setItemName(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getItemDescribe()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $itemDescribe
*/
public function setItemDescribe(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getBarCode()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $barCode
*/
public function setBarCode(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getUnit()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $unit
*/
public function setUnit(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getQty()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $qty
*/
public function setQty(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getPrice()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $price
*/
public function setPrice(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getTotalPrice()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $totalPrice
*/
public function setTotalPrice(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getCurrency()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $currency
*/
public function setCurrency(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getCountry()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $country
*/
public function setCountry(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
/**
* @return mixed
*/
public function getNote()
{
return $this->mGet(__FUNCTION__);
}
/**
* @param mixed $note
*/
public function setNote(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0));
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request\Report\Node;
use Lackoxygen\GzCbec\Utils\Collection;
class Receiver extends Collection
{
/**
* @param mixed
*/
public function setReceiver(): void
{
$this->mSet(__FUNCTION__, func_get_arg(0), false);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Request;
use Lackoxygen\GzCbec\Contract\RequestInterface;
use Lackoxygen\GzCbec\Utils\Collection;
abstract class Request extends Collection implements RequestInterface
{
/**
* @var string
*/
protected $path = '';
/**
* @var string
*/
protected $method = 'POST';
/**
* @var string
*/
protected $messageType = '';
/**
* @inheritDoc
*/
public function getVersion(): string
{
return '1.0';
}
/**
* @inheritDoc
*/
public function getGuid(): string
{
return \Str::uuid();
}
/**
* @return Packet
*/
public function getPacket(): Packet
{
return new Packet($this);
}
/**
* @return string
*/
public function getPath(): string
{
return $this->path;
}
/**
* @return string
*/
public function getMethod(): string
{
return $this->method;
}
/**
* @return string
*/
public function getMessageType(): string
{
return $this->messageType;
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Traits;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection as BaseCollection;
use Lackoxygen\GzCbec\Contract\XMLInterface;
use Lackoxygen\GzCbec\Exception\Exception;
use Lackoxygen\GzCbec\Constant\XML as xmlConstant;
trait XML
{
/**
* @throws Exception
*/
public function toXML(string $head): string
{
if (!$this instanceof BaseCollection) {
throw new Exception('not support');
}
$simpleXML = new \SimpleXMLElement(xmlConstant::FIRST_LINE . $head);
$this->arrayToXML($this->toArray(), $simpleXML);
return $simpleXML->asXML();
}
/**
* @param \SimpleXMLElement $xmlObj
* @param $key
* @param null $value
*/
protected function appendChildToXMl(\SimpleXMLElement $xmlObj, $key, $value = null): \SimpleXMLElement
{
if ($this instanceof XMLInterface) {
$key = $this->getFirstLabelPrefix() . ':' . $key;
}
if (is_null($value)) {
//$xmlObj->addChild($key);
} else {
$xmlObj->addChild($key, $value);
}
return $xmlObj;
}
/**
* @param $array
* @param \SimpleXMLElement $xmlObj
*/
protected function arrayToXML($array, \SimpleXMLElement &$xmlObj)
{
foreach ($array as $key => $value) {
if (is_numeric($key)) {
$key = Arr::get($value, '__last_key');
unset($value['__last_key']);
}
if (is_array($value) || is_object($value)) {
if (Arr::exists($value, 0)) {
foreach ($value as &$item) {
Arr::set($item, '__last_key', $key);
}
$this->appendChildToXMl($xmlObj, $key);
$this->arrayToXML($value, $xmlObj);
} else {
$subNode = $xmlObj->addChild($key);
$this->arrayToXML($value, $subNode);
}
} else {
$this->appendChildToXMl($xmlObj, $key, $value);
}
}
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Utils;
use Illuminate\Support\Collection as BaseCollection;
use Lackoxygen\GzCbec\Traits\Xml;
class Collection extends BaseCollection
{
use Xml;
/**
* @param $method
* @param $value
* @param bool $lcfirst
*/
public function mSet($method, $value, $lcfirst = true)
{
parent::offsetSet($this->subKey($method, 3, $lcfirst), $value);
}
/**
* @param $method
* @param $value
*/
public function mPush($method, $value)
{
$key = $this->subKey($method, 4, false);
$listCollection = $this->get($key);
if (!$listCollection instanceof BaseCollection) {
$listCollection = BaseCollection::make();
}
$listCollection->push($value);
$this->offsetSet($key, $listCollection);
}
/**
* @param $method
* @param null $default
*
* @return mixed
*/
public function mGet($method, $default = null)
{
return parent::get($this->subKey($method, 3), $default);
}
/**
* @param string $key
* @param int $offset
* @param bool $lcfirst
*
* @return string
*/
public function subKey(string $key, int $offset = 0, $lcfirst = true): string
{
$afterKey = substr($key, $offset);
if ($lcfirst) {
return lcfirst($afterKey);
}
return ucfirst($afterKey);
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Utils;
use Lackoxygen\GzCbec\Exception\Exception;
class RSA
{
/**
* @param $key
*
* @return string
*/
public static function trimKey($key): string
{
return wordwrap(preg_replace('/[\r\n]/', '', $key), 64, "\n", true);
}
/**
* @param $data
* @param $key
*
* @return mixed
*/
public static function signPrivate($data, $key)
{
$key = self::trimKey($key);
$key = "-----BEGIN RSA PRIVATE KEY-----\n{$key}\n-----END RSA PRIVATE KEY-----";
openssl_sign($data, $sign, $key, \OPENSSL_ALGO_SHA1);
return $sign;
}
/**
* @param $data
* @param $fileName
*
* @return mixed
* @throws Exception
*/
public static function signPrivateFromFile($data, $fileName)
{
$key = file_get_contents($fileName);
$res = openssl_get_privatekey($key);
if (!$res) {
throw new Exception('Incorrect public key file format');
}
openssl_sign($data, $sign, $res, \OPENSSL_ALGO_SHA1);
openssl_free_key($res);
return $sign;
}
/**
* @param $data
* @param $key
* @param $sign
*
* @return bool
*/
public static function verifyPublic($data, $key, $sign)
{
$key = static::trimKey($key);
$key = "-----BEGIN PUBLIC KEY-----\n{$key}\n-----END PUBLIC KEY-----";
return 1 === openssl_verify($data, $sign, $key, \OPENSSL_ALGO_SHA1);
}
/**
* @param $data
* @param $fileName
* @param $sign
*
* @return bool
* @throws Exception
*/
public static function verifyPublicFromFile($data, $fileName, $sign): bool
{
$key = file_get_contents($fileName);
$res = openssl_get_publickey($key);
if (!$res) {
throw new Exception('Incorrect public key file format');
}
$result = openssl_verify($data, $sign, $res, \OPENSSL_ALGO_SHA1);
openssl_free_key($res);
return 1 === $result;
}
/**
* @param $data
* @param $fileName
*
* @return mixed
* @throws Exception
*/
public static function encryptPublicFromFile($data, $fileName)
{
$res = openssl_get_publickey(file_get_contents($fileName));
if (!$res) {
throw new Exception('公钥文件格式错误');
}
openssl_public_encrypt($data, $result, $res, \OPENSSL_PKCS1_OAEP_PADDING);
openssl_free_key($res);
return $result;
}
/**
* @param $data
* @param $public
*
* @return mixed
*/
public static function encryptPublic($data, $public)
{
openssl_public_encrypt($data, $result, $public, \OPENSSL_PKCS1_OAEP_PADDING);
return $result;
}
}
... ...
<?php
namespace Lackoxygen\GzCbec\Utils;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;
class Signature
{
/**
* @var string
*/
protected $uri;
protected $client;
/**
* Signature constructor.
*
* @param string $uri
*/
public function __construct(string $uri)
{
$this->uri = $uri;
$this->client = new Client;
}
/**
* @param string $signXml
*
* @return ResponseInterface
*/
protected function execute(string $signXml): ResponseInterface
{
return $this->client->post($this->uri, [
RequestOptions::FORM_PARAMS => [
'xml' => base64_encode($signXml)
],
RequestOptions::TIMEOUT => 60
]);
}
/**
* @param string $signXml
*
* @return string
*/
public function __invoke(string $signXml): string
{
$content = '';
try {
$response = $this->execute($signXml);
$content = $response->getBody()->getContents();
$array = \json_decode($content, true);
$data = \Arr::get($array, 'data');
if (!empty($data)) {
$content = html_entity_decode(base64_decode($data));
}
} catch (\Throwable $throwable) {
}
file_put_contents('tran.xml', $content);
return $content;
}
}
... ...