作者 竞泽

add:all

  1 +###广州单一窗口
  2 +
  3 +```
  4 +demo
  5 +
  6 +
  7 +```
  1 +<?php
  2 +
  3 +return [
  4 + 'base_uri' => 'https://open.singlewindow.gz.cn',
  5 + 'record_sn' => '4423968643',
  6 + 'secret_key' => '12345678',
  7 + 'company_cert_sn' => '20200000000652',
  8 + 'sender_sn' => 'GEYOUSUOAI',
  9 + 'receiver_sn' => 'KJPUBLICPT'
  10 +];
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec;
  5 +
  6 +use GuzzleHttp\Exception\GuzzleException;
  7 +use GuzzleHttp\RequestOptions;
  8 +use Illuminate\Support\Arr;
  9 +use Lackoxygen\GzCbec\Contract\ClientInterface;
  10 +use Lackoxygen\GzCbec\Contract\RequestInterface;
  11 +use GuzzleHttp\Client as GuzzleHttp;
  12 +use Lackoxygen\GzCbec\Exception\Exception;
  13 +use Psr\Http\Message\ResponseInterface;
  14 +
  15 +class Client implements ClientInterface
  16 +{
  17 + /**
  18 + * @var GuzzleHttp
  19 + */
  20 + protected $guzzleHttp;
  21 +
  22 + /**
  23 + * @var RequestInterface
  24 + */
  25 + protected $request;
  26 +
  27 + /**
  28 + * @var array
  29 + */
  30 + protected $config = [
  31 + 'base_uri' => 'https://open.singlewindow.gz.cn',
  32 + 'record_sn' => 'C011111100414353',
  33 + 'secret_key' => '12345678',
  34 + 'company_cert_sn' => '20200000000652',
  35 + 'sender_sn' => 'GEYOUSUOAI',
  36 + 'receiver_sn' => 'KJPUBLICPT'
  37 + ];
  38 +
  39 + protected function __construct(RequestInterface $request)
  40 + {
  41 + $this->guzzleHttp = new GuzzleHttp([
  42 + 'base_uri' => Arr::get($this->config, 'base_uri'),
  43 + 'verify' => false
  44 + ]);
  45 + $this->request = $request;
  46 + }
  47 +
  48 + /**
  49 + * @param RequestInterface $request
  50 + *
  51 + * @return ClientInterface
  52 + */
  53 + protected static function make(RequestInterface $request): ClientInterface
  54 + {
  55 + return new static($request);
  56 + }
  57 +
  58 +
  59 + /**
  60 + * @return ResponseInterface
  61 + * @throws Exception
  62 + */
  63 + public function send(): ResponseInterface
  64 + {
  65 + $content = $this->request->getPacket()->getContent();
  66 + file_put_contents('transfer.xml', $content);
  67 + try {
  68 + $response = $this->guzzleHttp->request($this->request->getMethod(), $this->request->getPath(), [
  69 + RequestOptions::FORM_PARAMS => [
  70 + 'clientid' => $this->config['record_sn'],
  71 + 'key' => $this->config['secret_key'],
  72 + 'messageType' => $this->request->getMessageType(),
  73 + 'messageText' => $content
  74 + ]
  75 + ]);
  76 + } catch (GuzzleException $e) {
  77 + throw new Exception($e);
  78 + }
  79 +
  80 + return $response;
  81 + }
  82 +
  83 + /**
  84 + * @param RequestInterface $request
  85 + *
  86 + * @return array
  87 + */
  88 + public static function request(RequestInterface $request): array
  89 + {
  90 + $client = self::make($request);
  91 + /**
  92 + * @var ResponseInterface $response
  93 + */
  94 + $response = $client->send();
  95 +
  96 + $content = $response->getBody()->getContents();
  97 +
  98 + $response->getBody()->rewind();
  99 +
  100 + return (array)\json_decode($content, true);
  101 + }
  102 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Constant;
  5 +
  6 +
  7 +class Message
  8 +{
  9 + /**
  10 + * 电子订单
  11 + */
  12 + public const KJ881111 = 'KJ881111';
  13 +
  14 + /**
  15 + * 电子运单
  16 + */
  17 + public const KJ881113 = 'KJ881113';
  18 +
  19 + /**
  20 + * 电子支付单
  21 + */
  22 + public const KJ881112 = 'KJ881112';
  23 +
  24 + /**
  25 + * 电子清单
  26 + */
  27 + public const KJ881110 = 'KJ881110';
  28 +
  29 + /**
  30 + * 商品备案申请
  31 + */
  32 + public const KJ881101 = 'KJ881101';
  33 +
  34 + /**
  35 + * BBC进仓清单
  36 + */
  37 + public const KJ881103 = 'KJ881103';
  38 +
  39 + /**
  40 + * BBC货物装载清单
  41 + */
  42 + public const KJ881105 = 'KJ881105';
  43 +
  44 + /**
  45 + * BC货物装载清单
  46 + */
  47 + public const KJ881116 = 'KJ881116';
  48 +
  49 + /**
  50 + * BC进区总运单
  51 + */
  52 + public const KJ881128 = 'KJ881128';
  53 +
  54 + /**
  55 + * B2B电子订单
  56 + */
  57 + public const B2B103 = 'B2B103';
  58 +
  59 + /**
  60 + * 电子订单
  61 + */
  62 + public const CEB311MESSAGE = 'CEB311Message';
  63 +
  64 + /**
  65 + * 物流运单
  66 + */
  67 + public const CEB511MESSAGE = 'CEB511Message';
  68 +
  69 + /**
  70 + * 支付凭证
  71 + */
  72 + public const CEB411MESSAGE = 'CEB411Message';
  73 +
  74 + /**
  75 + * 进口清单
  76 + */
  77 + public const CEB621MESSAGE = 'CEB621Message';
  78 +
  79 + /**
  80 + * 入库明细数据
  81 + */
  82 + public const CEB711MESSAGE = 'CEB711Message';
  83 +
  84 + /**
  85 + * 撤销申请单
  86 + */
  87 + public const CEB623MESSAGE = 'CEB623Message';
  88 +
  89 + /**
  90 + * 退货申请单
  91 + */
  92 + public const CEB625MESSAGE = 'CEB625Message';
  93 +
  94 + /**
  95 + * 物流运输状态
  96 + */
  97 + public const CEB513MESSAGE = 'CEB513Message';
  98 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Constant;
  5 +
  6 +
  7 +class QueryType
  8 +{
  9 + /**
  10 + * 商品备案申请
  11 + */
  12 + public const KJ881101 = 'KJ881101';
  13 +
  14 + /**
  15 + * BBC进仓清单
  16 + */
  17 + public const KJ881103 = 'KJ881103';
  18 +
  19 + /**
  20 + * 电子订单
  21 + */
  22 + public const KJ881111 = 'KJ881111';
  23 +
  24 + /**
  25 + * 电子运单
  26 + */
  27 + public const KJ881113 = 'KJ881113';
  28 +
  29 + /**
  30 + * 电子支付单
  31 + */
  32 + public const KJ881112 = 'KJ881112';
  33 +
  34 + /**
  35 + * BBC货物装载清单
  36 + */
  37 + public const KJ881105 = 'KJ881105';
  38 +
  39 + /**
  40 + * 电子清单
  41 + */
  42 + public const KJ881110 = 'KJ881110';
  43 +
  44 + /**
  45 + * BC货物装载清单
  46 + */
  47 + public const KJ881116 = 'KJ881116';
  48 +
  49 + /**
  50 + * BC进区总运单
  51 + */
  52 + public const KJ881114 = 'KJ881114';
  53 +
  54 + /**
  55 + * BC理货报告
  56 + */
  57 + public const KJ881115 = 'KJ881115';
  58 +
  59 + /**
  60 + * BC过线报告
  61 + */
  62 + public const KJ881119 = 'KJ881119';
  63 +
  64 + /**
  65 + * 运单状态
  66 + */
  67 + public const KJ881126 = 'KJ881126';
  68 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Constant;
  5 +
  6 +
  7 +class XML
  8 +{
  9 + public const FIRST_LINE = '<?xml version="1.0" encoding="UTF-8"?>';
  10 +
  11 + public const DATA = '<%s xmlns:ceb="http://www.chinaport.gov.cn/ceb"
  12 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" guid="%s" version="%s"></%s>';
  13 +
  14 + public const SIGNATURE = '<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"></Signature>';
  15 +
  16 + 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>';
  17 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Contract;
  5 +
  6 +
  7 +interface ClientInterface
  8 +{
  9 + public function send();
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Contract;
  5 +
  6 +use Lackoxygen\GzCbec\Request\Report\CEB311Message;
  7 +
  8 +interface ReportInterface
  9 +{
  10 + public function CEB311Message(CEB311Message $CEB311Message);
  11 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Contract;
  5 +
  6 +
  7 +use Lackoxygen\GzCbec\Request\Packet;
  8 +
  9 +interface RequestInterface
  10 +{
  11 + /**
  12 + * @return string
  13 + */
  14 + public function getVersion(): string;
  15 +
  16 + /**
  17 + * @return string
  18 + */
  19 + public function getGuid(): string;
  20 +
  21 + /**
  22 + * @return Packet
  23 + */
  24 + public function getPacket(): Packet;
  25 +
  26 + /**
  27 + * @return string
  28 + */
  29 + public function getPath(): string;
  30 +
  31 + /**
  32 + * @return string
  33 + */
  34 + public function getMethod(): string;
  35 +
  36 + /**
  37 + * @return string
  38 + */
  39 + public function getMessageType(): string;
  40 +
  41 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Contract;
  5 +
  6 +
  7 +interface XMLInterface
  8 +{
  9 + /**
  10 + * @return string
  11 + */
  12 + public function getFirstLabelPrefix(): string;
  13 +
  14 + /**
  15 + * @return string
  16 + */
  17 + public function getFirstLabelName(): string;
  18 +
  19 + /**
  20 + * @param string $head
  21 + *
  22 + * @return string
  23 + */
  24 + public function toXML(string $head): string;
  25 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Exception;
  5 +
  6 +
  7 +class Exception extends \Exception
  8 +{
  9 +
  10 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Facade;
  5 +
  6 +
  7 +use Illuminate\Support\Facades\Facade;
  8 +use Lackoxygen\GzCbec\GzCBEC;
  9 +
  10 +class GzCBECFacade extends Facade
  11 +{
  12 + /**
  13 + * @return string
  14 + */
  15 + protected static function getFacadeAccessor(): string
  16 + {
  17 + return GzCBEC::class;
  18 + }
  19 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec;
  5 +
  6 +
  7 +use Lackoxygen\GzCbec\Contract\ReportInterface;
  8 +use Lackoxygen\GzCbec\Factory\Report;
  9 +
  10 +class Factory
  11 +{
  12 + public static function report(): ReportInterface
  13 + {
  14 + return new Report();
  15 + }
  16 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Factory;
  5 +
  6 +
  7 +use Lackoxygen\GzCbec\Client;
  8 +use Lackoxygen\GzCbec\Contract\ReportInterface;
  9 +use Lackoxygen\GzCbec\Request\Report\CEB311Message;
  10 +
  11 +class Report implements ReportInterface
  12 +{
  13 + public function CEB311Message(CEB311Message $CEB311Message)
  14 + {
  15 + return Client::request($CEB311Message);
  16 + }
  17 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec;
  5 +
  6 +use Lackoxygen\GzCbec\Factory\Report;
  7 +
  8 +class GzCBEC
  9 +{
  10 + public function report(): Report
  11 + {
  12 + return Factory::report();
  13 + }
  14 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request;
  5 +
  6 +use Lackoxygen\GzCbec\Contract\XMLInterface;
  7 +use Lackoxygen\GzCbec\Utils\Collection;
  8 +
  9 +class CEBRequest extends Request implements XMLInterface
  10 +{
  11 + /**
  12 + * @var string
  13 + */
  14 + protected $method = 'POST';
  15 +
  16 + /**
  17 + * @var string
  18 + */
  19 + protected $path = '/swcbes/client/declare/sendMessage.action';
  20 +
  21 + /**
  22 + * @return string
  23 + */
  24 + public function getFirstLabelPrefix(): string
  25 + {
  26 + return 'ceb';
  27 + }
  28 +
  29 + /**
  30 + * @return string
  31 + */
  32 + public function getFirstLabelName(): string
  33 + {
  34 + return class_basename($this);
  35 + }
  36 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Head;
  5 +
  6 +
  7 +use Lackoxygen\GzCbec\Request\Report\Node\Receiver;
  8 +use Lackoxygen\GzCbec\Utils\Collection;
  9 +
  10 +class Head extends Collection
  11 +{
  12 + /**
  13 + * @return mixed
  14 + */
  15 + public function getMessageID()
  16 + {
  17 + return $this->mGet(__FUNCTION__);
  18 + }
  19 +
  20 + /**
  21 + * @param mixed $messageId
  22 + */
  23 + public function setMessageID(): void
  24 + {
  25 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  26 + }
  27 +
  28 + /**
  29 + * @return mixed
  30 + */
  31 + public function getMessageType()
  32 + {
  33 + return $this->mGet(__FUNCTION__);
  34 + }
  35 +
  36 + /**
  37 + * @param mixed $messageType
  38 + */
  39 + public function setMessageType(): void
  40 + {
  41 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  42 + }
  43 +
  44 + /**
  45 + * @return mixed
  46 + */
  47 + public function getSender()
  48 + {
  49 + return $this->mGet(__FUNCTION__);
  50 + }
  51 +
  52 + /**
  53 + * @param mixed $sender
  54 + */
  55 + public function setSender(): void
  56 + {
  57 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  58 + }
  59 +
  60 + /**
  61 + * @return mixed
  62 + */
  63 + public function getReceivers()
  64 + {
  65 + return $this->mGet(__FUNCTION__);
  66 + }
  67 +
  68 + /**
  69 + * @param mixed $receivers
  70 + */
  71 + public function pushReceivers(Receiver $receiver): void
  72 + {
  73 + $this->mPush(__FUNCTION__, $receiver);
  74 + }
  75 +
  76 + /**
  77 + * @return mixed
  78 + */
  79 + public function getSendTime()
  80 + {
  81 + return $this->mGet(__FUNCTION__);
  82 + }
  83 +
  84 + /**
  85 + * @param mixed $sendTime
  86 + */
  87 + public function setSendTime(): void
  88 + {
  89 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  90 + }
  91 +
  92 + /**
  93 + * @return mixed
  94 + */
  95 + public function getVersion()
  96 + {
  97 + return $this->mGet(__FUNCTION__);
  98 + }
  99 +
  100 + /**
  101 + * @param mixed $version
  102 + */
  103 + public function setVersion(): void
  104 + {
  105 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  106 + }
  107 +
  108 + /**
  109 + * @return mixed
  110 + */
  111 + public function getFileName()
  112 + {
  113 + return $this->mGet(__FUNCTION__);
  114 + }
  115 +
  116 + /**
  117 + * @param mixed $fileName
  118 + */
  119 + public function setFileName(): void
  120 + {
  121 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  122 + }
  123 +
  124 + /**
  125 + * @return mixed
  126 + */
  127 + public function getZipFlag()
  128 + {
  129 + return $this->mGet(__FUNCTION__);
  130 + }
  131 +
  132 + /**
  133 + * @param mixed $zipFlag
  134 + */
  135 + public function setZipFlag(): void
  136 + {
  137 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  138 + }
  139 +
  140 +
  141 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\GzCbec\Request;
  4 +
  5 +use Carbon\Carbon;
  6 +use Illuminate\Support\Arr;
  7 +use Illuminate\Support\Collection;
  8 +use Lackoxygen\GzCbec\Constant\XML;
  9 +use Lackoxygen\GzCbec\Contract\RequestInterface;
  10 +use Lackoxygen\GzCbec\Contract\XMLInterface;
  11 +use Lackoxygen\GzCbec\Exception\Exception;
  12 +use Lackoxygen\GzCbec\Request\Head\Head;
  13 +use Lackoxygen\GzCbec\Request\Packet\GzReportTransfer;
  14 +use Lackoxygen\GzCbec\Request\Report\Node\Receiver;
  15 +use Lackoxygen\GzCbec\Utils\RSA;
  16 +use Lackoxygen\GzCbec\Utils\Signature;
  17 +
  18 +class Packet
  19 +{
  20 + /**
  21 + * @var RequestInterface $request
  22 + */
  23 + protected $request;
  24 +
  25 + /**
  26 + * @var array
  27 + */
  28 + protected $config = [];
  29 +
  30 + /**
  31 + * Packet constructor.
  32 + *
  33 + * @param RequestInterface $request
  34 + */
  35 + public function __construct(RequestInterface $request)
  36 + {
  37 + $this->request = $request;
  38 +
  39 + $this->config = [
  40 + 'base_uri' => 'https://open.singlewindow.gz.cn',
  41 + 'record_sn' => 'C011111100414353',
  42 + 'secret_key' => '12345678',
  43 + 'company_cert_sn' => '20200000000652',
  44 + 'sender_sn' => 'GEYOUSUOAI',
  45 + 'receiver_sn' => 'KJPUBLICPT',
  46 + 'signature' => "http://10.10.10.41:8080/signature.do"
  47 + ];
  48 + }
  49 +
  50 +
  51 + /**
  52 + * @return string
  53 + */
  54 + public function getContent(): string
  55 + {
  56 + try {
  57 + $head = new Head();
  58 + $head->setMessageId($this->request->getGuid());
  59 + $head->setMessageType($this->request->getMessageType());
  60 + $head->setSender($this->config['sender_sn']);
  61 + $receiver = new Receiver();
  62 + $receiver->setReceiver($this->config['receiver_sn']);
  63 + $head->pushReceivers($receiver);
  64 + $head->setSendTime(Carbon::now()->getPreciseTimestamp(4));
  65 + $head->setVersion($this->request->getVersion());
  66 + $head->setFileName('');
  67 + $head->setZipFlag(0);
  68 + $packet = new GzReportTransfer();
  69 + $packet->setHead($head);
  70 + if ($this->request instanceof XMLInterface) {
  71 + $firstLabel = $this->request->getFirstLabelPrefix() . ':' . $this->request->getFirstLabelName();
  72 + $xmlHead = sprintf(XML::DATA, $firstLabel, $this->request->getGuid(), $this->request->getVersion(),
  73 + $firstLabel);
  74 + $dataXml = $this->request->toXML($xmlHead);
  75 + file_put_contents('test.xml', $dataXml);
  76 + $data = base64_encode($dataXml);
  77 + $packet->setData($data);
  78 + }
  79 + $xml = $packet->toXML(XML::TRANSFER);
  80 +
  81 + return $this->signature($xml);
  82 + } catch (Exception $exception) {
  83 + return '';
  84 + }
  85 + }
  86 +
  87 + /**
  88 + * @param $signXml
  89 + *
  90 + * @return string
  91 + */
  92 + protected function signature(string $signXml): string
  93 + {
  94 + $signature = Arr::get($this->config, 'signature');
  95 +
  96 + if ($signature instanceof \Closure) {
  97 + $afterSignXml = call_user_func($signature, $signXml);
  98 + if (!is_null($afterSignXml)) {
  99 + return $afterSignXml;
  100 + }
  101 + } else {
  102 + return (new Signature($signature))($signXml);
  103 + }
  104 +
  105 + return "";
  106 + }
  107 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Packet;
  5 +
  6 +use Lackoxygen\GzCbec\Utils\Collection;
  7 +
  8 +class GzReportTransfer extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getHead()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param mixed $head
  20 + */
  21 + public function setHead(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getData()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param mixed $data
  36 + */
  37 + public function setData(): void
  38 + {
  39 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  40 + }
  41 +
  42 + /**
  43 + * @return mixed
  44 + */
  45 + public function getSignature()
  46 + {
  47 + return $this->mGet(__FUNCTION__);
  48 + }
  49 +
  50 + public function setSignature()
  51 + {
  52 + $this->mSet(__FUNCTION__, func_get_arg(0));
  53 + }
  54 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Report;
  5 +
  6 +use Lackoxygen\GzCbec\Contract\RequestInterface;
  7 +use Lackoxygen\GzCbec\Contract\XMLInterface;
  8 +use Lackoxygen\GzCbec\Request\CEBRequest;
  9 +use Lackoxygen\GzCbec\Request\Report\Node\BaseTransfer;
  10 +use Lackoxygen\GzCbec\Request\Report\Node\Order;
  11 +
  12 +class CEB311Message extends CEBRequest
  13 +{
  14 + protected $messageType = 'CEB311Message';
  15 +
  16 + /**
  17 + * @param mixed $order
  18 + */
  19 + public function setOrder(Order $order): void
  20 + {
  21 + $this->mSet(__FUNCTION__, $order, false);
  22 + }
  23 +
  24 + /**
  25 + * @param mixed $baseTransfer
  26 + */
  27 + public function setBaseTransfer(BaseTransfer $baseTransfer): void
  28 + {
  29 + $this->mSet(__FUNCTION__, $baseTransfer, false);
  30 + }
  31 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Report\Node;
  5 +
  6 +use Lackoxygen\GzCbec\Utils\Collection;
  7 +
  8 +class BaseTransfer extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getCopCode()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param mixed $copCode
  20 + */
  21 + public function setCopCode(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, func_get_arg(0));
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getCopName()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param mixed $copName
  36 + */
  37 + public function setCopName(): void
  38 + {
  39 + $this->mSet(__FUNCTION__, func_get_arg(0));
  40 + }
  41 +
  42 + /**
  43 + * @return mixed
  44 + */
  45 + public function getDxpMode()
  46 + {
  47 + return $this->mGet(__FUNCTION__);
  48 + }
  49 +
  50 + /**
  51 + * @param mixed $dxpMode
  52 + */
  53 + public function setDxpMode($dxpMode): void
  54 + {
  55 + $this->mSet(__FUNCTION__, func_get_arg(0));
  56 + }
  57 +
  58 + /**
  59 + * @return mixed
  60 + */
  61 + public function getDxpId()
  62 + {
  63 + return $this->mGet(__FUNCTION__);
  64 + }
  65 +
  66 + /**
  67 + * @param mixed $dxpId
  68 + */
  69 + public function setDxpId($dxpId): void
  70 + {
  71 + $this->mSet(__FUNCTION__, func_get_arg(0));
  72 + }
  73 +
  74 + /**
  75 + * @return mixed
  76 + */
  77 + public function getNote()
  78 + {
  79 + return $this->mGet(__FUNCTION__);
  80 + }
  81 +
  82 + /**
  83 + * @param mixed $note
  84 + */
  85 + public function setNote(): void
  86 + {
  87 + $this->mSet(__FUNCTION__, func_get_arg(0));
  88 + }
  89 +
  90 +
  91 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Report\Node;
  5 +
  6 +use Lackoxygen\GzCbec\Utils\Collection;
  7 +
  8 +class Order extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getOrderHead()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param mixed $orderHead
  20 + */
  21 + public function setOrderHead(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getOrderList()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param mixed $orderList
  36 + */
  37 + public function pushOrderList(OrderList $orderList): void
  38 + {
  39 + $this->mPush(__FUNCTION__, $orderList);
  40 + }
  41 +
  42 +
  43 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Report\Node;
  5 +
  6 +use Lackoxygen\GzCbec\Utils\Collection;
  7 +
  8 +class OrderHead extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getGuid()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param mixed $guid
  20 + */
  21 + public function setGuid(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, func_get_arg(0));
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getAppType()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param mixed $appType
  36 + */
  37 + public function setAppType(): void
  38 + {
  39 + $this->mSet(__FUNCTION__, func_get_arg(0));
  40 + }
  41 +
  42 + /**
  43 + * @return mixed
  44 + */
  45 + public function getAppTime()
  46 + {
  47 + return $this->mGet(__FUNCTION__);
  48 + }
  49 +
  50 + /**
  51 + * @param mixed $appTime
  52 + */
  53 + public function setAppTime(): void
  54 + {
  55 + $this->mSet(__FUNCTION__, func_get_arg(0));
  56 + }
  57 +
  58 + /**
  59 + * @return mixed
  60 + */
  61 + public function getAppStatus()
  62 + {
  63 + return $this->mGet(__FUNCTION__);
  64 + }
  65 +
  66 + /**
  67 + * @param mixed $appStatus
  68 + */
  69 + public function setAppStatus(): void
  70 + {
  71 + $this->mSet(__FUNCTION__, func_get_arg(0));
  72 + }
  73 +
  74 + /**
  75 + * @return mixed
  76 + */
  77 + public function getOrderType()
  78 + {
  79 + return $this->mGet(__FUNCTION__);
  80 + }
  81 +
  82 + /**
  83 + * @param mixed $orderType
  84 + */
  85 + public function setOrderType(): void
  86 + {
  87 + $this->mSet(__FUNCTION__, func_get_arg(0));
  88 + }
  89 +
  90 + /**
  91 + * @return mixed
  92 + */
  93 + public function getOrderNo()
  94 + {
  95 + return $this->mGet(__FUNCTION__);
  96 + }
  97 +
  98 + /**
  99 + * @param mixed $orderNo
  100 + */
  101 + public function setOrderNo(): void
  102 + {
  103 + $this->mSet(__FUNCTION__, func_get_arg(0));
  104 + }
  105 +
  106 + /**
  107 + * @return mixed
  108 + */
  109 + public function getEbpCode()
  110 + {
  111 + return $this->mGet(__FUNCTION__);
  112 + }
  113 +
  114 + /**
  115 + * @param mixed $ebpCode
  116 + */
  117 + public function setEbpCode(): void
  118 + {
  119 + $this->mSet(__FUNCTION__, func_get_arg(0));
  120 + }
  121 +
  122 + /**
  123 + * @return mixed
  124 + */
  125 + public function getEbpName()
  126 + {
  127 + return $this->mGet(__FUNCTION__);
  128 + }
  129 +
  130 + /**
  131 + * @param mixed $ebpName
  132 + */
  133 + public function setEbpName(): void
  134 + {
  135 + $this->mSet(__FUNCTION__, func_get_arg(0));
  136 + }
  137 +
  138 + /**
  139 + * @return mixed
  140 + */
  141 + public function getEbcCode()
  142 + {
  143 + return $this->mGet(__FUNCTION__);
  144 + }
  145 +
  146 + /**
  147 + * @param mixed $ebcCode
  148 + */
  149 + public function setEbcCode(): void
  150 + {
  151 + $this->mSet(__FUNCTION__, func_get_arg(0));
  152 + }
  153 +
  154 + /**
  155 + * @return mixed
  156 + */
  157 + public function getEbcName()
  158 + {
  159 + return $this->mGet(__FUNCTION__);
  160 + }
  161 +
  162 + /**
  163 + * @param mixed $ebcName
  164 + */
  165 + public function setEbcName(): void
  166 + {
  167 + $this->mSet(__FUNCTION__, func_get_arg(0));
  168 + }
  169 +
  170 + /**
  171 + * @return mixed
  172 + */
  173 + public function getGoodsValue()
  174 + {
  175 + return $this->mGet(__FUNCTION__);
  176 + }
  177 +
  178 + /**
  179 + * @param mixed $goodsValue
  180 + */
  181 + public function setGoodsValue(): void
  182 + {
  183 + $this->mSet(__FUNCTION__, func_get_arg(0));
  184 + }
  185 +
  186 + /**
  187 + * @return mixed
  188 + */
  189 + public function getFreight()
  190 + {
  191 + return $this->mGet(__FUNCTION__);
  192 + }
  193 +
  194 + /**
  195 + * @param mixed $freight
  196 + */
  197 + public function setFreight(): void
  198 + {
  199 + $this->mSet(__FUNCTION__, func_get_arg(0));
  200 + }
  201 +
  202 + /**
  203 + * @return mixed
  204 + */
  205 + public function getDiscount()
  206 + {
  207 + return $this->mGet(__FUNCTION__);
  208 + }
  209 +
  210 + /**
  211 + * @param mixed $discount
  212 + */
  213 + public function setDiscount(): void
  214 + {
  215 + $this->mSet(__FUNCTION__, func_get_arg(0));
  216 + }
  217 +
  218 + /**
  219 + * @return mixed
  220 + */
  221 + public function getTaxTotal()
  222 + {
  223 + return $this->mGet(__FUNCTION__);
  224 + }
  225 +
  226 + /**
  227 + * @param mixed $taxTotal
  228 + */
  229 + public function setTaxTotal(): void
  230 + {
  231 + $this->mSet(__FUNCTION__, func_get_arg(0));
  232 + }
  233 +
  234 + /**
  235 + * @return mixed
  236 + */
  237 + public function getActuralPaid()
  238 + {
  239 + return $this->mGet(__FUNCTION__);
  240 + }
  241 +
  242 + /**
  243 + * @param mixed $acturalPaid
  244 + */
  245 + public function setActuralPaid(): void
  246 + {
  247 + $this->mSet(__FUNCTION__, func_get_arg(0));
  248 + }
  249 +
  250 + /**
  251 + * @return mixed
  252 + */
  253 + public function getCurrency()
  254 + {
  255 + return $this->mGet(__FUNCTION__);
  256 + }
  257 +
  258 + /**
  259 + * @param mixed $currency
  260 + */
  261 + public function setCurrency(): void
  262 + {
  263 + $this->mSet(__FUNCTION__, func_get_arg(0));
  264 + }
  265 +
  266 + /**
  267 + * @return mixed
  268 + */
  269 + public function getBuyerRegNo()
  270 + {
  271 + return $this->mGet(__FUNCTION__);
  272 + }
  273 +
  274 + /**
  275 + * @param mixed $buyerRegNo
  276 + */
  277 + public function setBuyerRegNo(): void
  278 + {
  279 + $this->mSet(__FUNCTION__, func_get_arg(0));
  280 + }
  281 +
  282 + /**
  283 + * @return mixed
  284 + */
  285 + public function getBuyerName()
  286 + {
  287 + return $this->mGet(__FUNCTION__);
  288 + }
  289 +
  290 + /**
  291 + * @param mixed $buyerName
  292 + */
  293 + public function setBuyerName(): void
  294 + {
  295 + $this->mSet(__FUNCTION__, func_get_arg(0));
  296 + }
  297 +
  298 + /**
  299 + * @return mixed
  300 + */
  301 + public function getBuyerIdType()
  302 + {
  303 + return $this->mGet(__FUNCTION__);
  304 + }
  305 +
  306 + /**
  307 + * @param mixed $buyerIdType
  308 + */
  309 + public function setBuyerIdType(): void
  310 + {
  311 + $this->mSet(__FUNCTION__, func_get_arg(0));
  312 + }
  313 +
  314 + /**
  315 + * @return mixed
  316 + */
  317 + public function getBuyerIdNumber()
  318 + {
  319 + return $this->mGet(__FUNCTION__);
  320 + }
  321 +
  322 + /**
  323 + * @param mixed $buyerIdNumber
  324 + */
  325 + public function setBuyerIdNumber(): void
  326 + {
  327 + $this->mSet(__FUNCTION__, func_get_arg(0));
  328 + }
  329 +
  330 + /**
  331 + * @return mixed
  332 + */
  333 + public function getPayCode()
  334 + {
  335 + return $this->mGet(__FUNCTION__);
  336 + }
  337 +
  338 + /**
  339 + * @param mixed $payCode
  340 + */
  341 + public function setPayCode(): void
  342 + {
  343 + $this->mSet(__FUNCTION__, func_get_arg(0));
  344 + }
  345 +
  346 + /**
  347 + * @return mixed
  348 + */
  349 + public function getPayName()
  350 + {
  351 + return $this->mGet(__FUNCTION__);
  352 + }
  353 +
  354 + /**
  355 + * @param mixed $payName
  356 + */
  357 + public function setPayName(): void
  358 + {
  359 + $this->mSet(__FUNCTION__, func_get_arg(0));
  360 + }
  361 +
  362 + /**
  363 + * @return mixed
  364 + */
  365 + public function getPayTransactionId()
  366 + {
  367 + return $this->mGet(__FUNCTION__);
  368 + }
  369 +
  370 + /**
  371 + * @param mixed $payTransactionId
  372 + */
  373 + public function setPayTransactionId(): void
  374 + {
  375 + $this->mSet(__FUNCTION__, func_get_arg(0));
  376 + }
  377 +
  378 + /**
  379 + * @return mixed
  380 + */
  381 + public function getBatchNumbers()
  382 + {
  383 + return $this->mGet(__FUNCTION__);
  384 + }
  385 +
  386 + /**
  387 + * @param mixed $batchNumbers
  388 + */
  389 + public function setBatchNumbers(): void
  390 + {
  391 + $this->mSet(__FUNCTION__, func_get_arg(0));
  392 + }
  393 +
  394 + /**
  395 + * @return mixed
  396 + */
  397 + public function getConsignee()
  398 + {
  399 + return $this->mGet(__FUNCTION__);
  400 + }
  401 +
  402 + /**
  403 + * @param mixed $consignee
  404 + */
  405 + public function setConsignee(): void
  406 + {
  407 + $this->mSet(__FUNCTION__, func_get_arg(0));
  408 + }
  409 +
  410 + /**
  411 + * @return mixed
  412 + */
  413 + public function getConsigneeTelephone()
  414 + {
  415 + return $this->mGet(__FUNCTION__);
  416 + }
  417 +
  418 + /**
  419 + * @param mixed $consigneeTelephone
  420 + */
  421 + public function setConsigneeTelephone(): void
  422 + {
  423 + $this->mSet(__FUNCTION__, func_get_arg(0));
  424 + }
  425 +
  426 + /**
  427 + * @return mixed
  428 + */
  429 + public function getConsigneeAddress()
  430 + {
  431 + return $this->mGet(__FUNCTION__);
  432 + }
  433 +
  434 + /**
  435 + * @param mixed $consigneeAddress
  436 + */
  437 + public function setConsigneeAddress(): void
  438 + {
  439 + $this->mSet(__FUNCTION__, func_get_arg(0));
  440 + }
  441 +
  442 + /**
  443 + * @return mixed
  444 + */
  445 + public function getConsigneeDistrict()
  446 + {
  447 + return $this->mGet(__FUNCTION__);
  448 + }
  449 +
  450 + /**
  451 + * @param mixed $consigneeDistrict
  452 + */
  453 + public function setConsigneeDistrict(): void
  454 + {
  455 + $this->mSet(__FUNCTION__, func_get_arg(0));
  456 + }
  457 +
  458 + /**
  459 + * @return mixed
  460 + */
  461 + public function getNote()
  462 + {
  463 + return $this->mGet(__FUNCTION__);
  464 + }
  465 +
  466 + /**
  467 + * @param mixed $note
  468 + */
  469 + public function setNote(): void
  470 + {
  471 + $this->mSet(__FUNCTION__, func_get_arg(0));
  472 + }
  473 +
  474 +
  475 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Report\Node;
  5 +
  6 +use Lackoxygen\GzCbec\Utils\Collection;
  7 +
  8 +class OrderList extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getGnum()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param mixed $gnum
  20 + */
  21 + public function setGnum(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, func_get_arg(0));
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getItemNo()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param mixed $itemNo
  36 + */
  37 + public function setItemNo(): void
  38 + {
  39 + $this->mSet(__FUNCTION__, func_get_arg(0));
  40 + }
  41 +
  42 + /**
  43 + * @return mixed
  44 + */
  45 + public function getItemName()
  46 + {
  47 + return $this->mGet(__FUNCTION__);
  48 + }
  49 +
  50 + /**
  51 + * @param mixed $itemName
  52 + */
  53 + public function setItemName(): void
  54 + {
  55 + $this->mSet(__FUNCTION__, func_get_arg(0));
  56 + }
  57 +
  58 + /**
  59 + * @return mixed
  60 + */
  61 + public function getItemDescribe()
  62 + {
  63 + return $this->mGet(__FUNCTION__);
  64 + }
  65 +
  66 + /**
  67 + * @param mixed $itemDescribe
  68 + */
  69 + public function setItemDescribe(): void
  70 + {
  71 + $this->mSet(__FUNCTION__, func_get_arg(0));
  72 + }
  73 +
  74 + /**
  75 + * @return mixed
  76 + */
  77 + public function getBarCode()
  78 + {
  79 + return $this->mGet(__FUNCTION__);
  80 + }
  81 +
  82 + /**
  83 + * @param mixed $barCode
  84 + */
  85 + public function setBarCode(): void
  86 + {
  87 + $this->mSet(__FUNCTION__, func_get_arg(0));
  88 + }
  89 +
  90 + /**
  91 + * @return mixed
  92 + */
  93 + public function getUnit()
  94 + {
  95 + return $this->mGet(__FUNCTION__);
  96 + }
  97 +
  98 + /**
  99 + * @param mixed $unit
  100 + */
  101 + public function setUnit(): void
  102 + {
  103 + $this->mSet(__FUNCTION__, func_get_arg(0));
  104 + }
  105 +
  106 + /**
  107 + * @return mixed
  108 + */
  109 + public function getQty()
  110 + {
  111 + return $this->mGet(__FUNCTION__);
  112 + }
  113 +
  114 + /**
  115 + * @param mixed $qty
  116 + */
  117 + public function setQty(): void
  118 + {
  119 + $this->mSet(__FUNCTION__, func_get_arg(0));
  120 + }
  121 +
  122 + /**
  123 + * @return mixed
  124 + */
  125 + public function getPrice()
  126 + {
  127 + return $this->mGet(__FUNCTION__);
  128 + }
  129 +
  130 + /**
  131 + * @param mixed $price
  132 + */
  133 + public function setPrice(): void
  134 + {
  135 + $this->mSet(__FUNCTION__, func_get_arg(0));
  136 + }
  137 +
  138 + /**
  139 + * @return mixed
  140 + */
  141 + public function getTotalPrice()
  142 + {
  143 + return $this->mGet(__FUNCTION__);
  144 + }
  145 +
  146 + /**
  147 + * @param mixed $totalPrice
  148 + */
  149 + public function setTotalPrice(): void
  150 + {
  151 + $this->mSet(__FUNCTION__, func_get_arg(0));
  152 + }
  153 +
  154 + /**
  155 + * @return mixed
  156 + */
  157 + public function getCurrency()
  158 + {
  159 + return $this->mGet(__FUNCTION__);
  160 + }
  161 +
  162 + /**
  163 + * @param mixed $currency
  164 + */
  165 + public function setCurrency(): void
  166 + {
  167 + $this->mSet(__FUNCTION__, func_get_arg(0));
  168 + }
  169 +
  170 + /**
  171 + * @return mixed
  172 + */
  173 + public function getCountry()
  174 + {
  175 + return $this->mGet(__FUNCTION__);
  176 + }
  177 +
  178 + /**
  179 + * @param mixed $country
  180 + */
  181 + public function setCountry(): void
  182 + {
  183 + $this->mSet(__FUNCTION__, func_get_arg(0));
  184 + }
  185 +
  186 + /**
  187 + * @return mixed
  188 + */
  189 + public function getNote()
  190 + {
  191 + return $this->mGet(__FUNCTION__);
  192 + }
  193 +
  194 + /**
  195 + * @param mixed $note
  196 + */
  197 + public function setNote(): void
  198 + {
  199 + $this->mSet(__FUNCTION__, func_get_arg(0));
  200 + }
  201 +
  202 +
  203 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request\Report\Node;
  5 +
  6 +
  7 +use Lackoxygen\GzCbec\Utils\Collection;
  8 +
  9 +class Receiver extends Collection
  10 +{
  11 + /**
  12 + * @param mixed
  13 + */
  14 + public function setReceiver(): void
  15 + {
  16 + $this->mSet(__FUNCTION__, func_get_arg(0), false);
  17 + }
  18 +
  19 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Request;
  5 +
  6 +use Lackoxygen\GzCbec\Contract\RequestInterface;
  7 +use Lackoxygen\GzCbec\Utils\Collection;
  8 +
  9 +abstract class Request extends Collection implements RequestInterface
  10 +{
  11 + /**
  12 + * @var string
  13 + */
  14 + protected $path = '';
  15 +
  16 + /**
  17 + * @var string
  18 + */
  19 + protected $method = 'POST';
  20 +
  21 + /**
  22 + * @var string
  23 + */
  24 + protected $messageType = '';
  25 +
  26 + /**
  27 + * @inheritDoc
  28 + */
  29 + public function getVersion(): string
  30 + {
  31 + return '1.0';
  32 + }
  33 +
  34 + /**
  35 + * @inheritDoc
  36 + */
  37 + public function getGuid(): string
  38 + {
  39 + return \Str::uuid();
  40 + }
  41 +
  42 +
  43 + /**
  44 + * @return Packet
  45 + */
  46 + public function getPacket(): Packet
  47 + {
  48 + return new Packet($this);
  49 + }
  50 +
  51 + /**
  52 + * @return string
  53 + */
  54 + public function getPath(): string
  55 + {
  56 + return $this->path;
  57 + }
  58 +
  59 + /**
  60 + * @return string
  61 + */
  62 + public function getMethod(): string
  63 + {
  64 + return $this->method;
  65 + }
  66 +
  67 + /**
  68 + * @return string
  69 + */
  70 + public function getMessageType(): string
  71 + {
  72 + return $this->messageType;
  73 + }
  74 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Traits;
  5 +
  6 +use Illuminate\Support\Arr;
  7 +use Illuminate\Support\Collection as BaseCollection;
  8 +use Lackoxygen\GzCbec\Contract\XMLInterface;
  9 +use Lackoxygen\GzCbec\Exception\Exception;
  10 +use Lackoxygen\GzCbec\Constant\XML as xmlConstant;
  11 +
  12 +trait XML
  13 +{
  14 + /**
  15 + * @throws Exception
  16 + */
  17 + public function toXML(string $head): string
  18 + {
  19 + if (!$this instanceof BaseCollection) {
  20 + throw new Exception('not support');
  21 + }
  22 + $simpleXML = new \SimpleXMLElement(xmlConstant::FIRST_LINE . $head);
  23 + $this->arrayToXML($this->toArray(), $simpleXML);
  24 +
  25 + return $simpleXML->asXML();
  26 + }
  27 +
  28 + /**
  29 + * @param \SimpleXMLElement $xmlObj
  30 + * @param $key
  31 + * @param null $value
  32 + */
  33 + protected function appendChildToXMl(\SimpleXMLElement $xmlObj, $key, $value = null): \SimpleXMLElement
  34 + {
  35 + if ($this instanceof XMLInterface) {
  36 + $key = $this->getFirstLabelPrefix() . ':' . $key;
  37 + }
  38 + if (is_null($value)) {
  39 + //$xmlObj->addChild($key);
  40 + } else {
  41 + $xmlObj->addChild($key, $value);
  42 + }
  43 +
  44 + return $xmlObj;
  45 + }
  46 +
  47 + /**
  48 + * @param $array
  49 + * @param \SimpleXMLElement $xmlObj
  50 + */
  51 + protected function arrayToXML($array, \SimpleXMLElement &$xmlObj)
  52 + {
  53 + foreach ($array as $key => $value) {
  54 + if (is_numeric($key)) {
  55 + $key = Arr::get($value, '__last_key');
  56 + unset($value['__last_key']);
  57 + }
  58 + if (is_array($value) || is_object($value)) {
  59 + if (Arr::exists($value, 0)) {
  60 + foreach ($value as &$item) {
  61 + Arr::set($item, '__last_key', $key);
  62 + }
  63 + $this->appendChildToXMl($xmlObj, $key);
  64 + $this->arrayToXML($value, $xmlObj);
  65 + } else {
  66 + $subNode = $xmlObj->addChild($key);
  67 + $this->arrayToXML($value, $subNode);
  68 + }
  69 + } else {
  70 + $this->appendChildToXMl($xmlObj, $key, $value);
  71 + }
  72 + }
  73 + }
  74 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Utils;
  5 +
  6 +use Illuminate\Support\Collection as BaseCollection;
  7 +use Lackoxygen\GzCbec\Traits\Xml;
  8 +
  9 +class Collection extends BaseCollection
  10 +{
  11 + use Xml;
  12 +
  13 + /**
  14 + * @param $method
  15 + * @param $value
  16 + * @param bool $lcfirst
  17 + */
  18 + public function mSet($method, $value, $lcfirst = true)
  19 + {
  20 + parent::offsetSet($this->subKey($method, 3, $lcfirst), $value);
  21 + }
  22 +
  23 + /**
  24 + * @param $method
  25 + * @param $value
  26 + */
  27 + public function mPush($method, $value)
  28 + {
  29 + $key = $this->subKey($method, 4, false);
  30 + $listCollection = $this->get($key);
  31 + if (!$listCollection instanceof BaseCollection) {
  32 + $listCollection = BaseCollection::make();
  33 + }
  34 + $listCollection->push($value);
  35 + $this->offsetSet($key, $listCollection);
  36 + }
  37 +
  38 + /**
  39 + * @param $method
  40 + * @param null $default
  41 + *
  42 + * @return mixed
  43 + */
  44 + public function mGet($method, $default = null)
  45 + {
  46 + return parent::get($this->subKey($method, 3), $default);
  47 + }
  48 +
  49 + /**
  50 + * @param string $key
  51 + * @param int $offset
  52 + * @param bool $lcfirst
  53 + *
  54 + * @return string
  55 + */
  56 + public function subKey(string $key, int $offset = 0, $lcfirst = true): string
  57 + {
  58 + $afterKey = substr($key, $offset);
  59 +
  60 + if ($lcfirst) {
  61 + return lcfirst($afterKey);
  62 + }
  63 +
  64 + return ucfirst($afterKey);
  65 + }
  66 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Utils;
  5 +
  6 +
  7 +use Lackoxygen\GzCbec\Exception\Exception;
  8 +
  9 +class RSA
  10 +{
  11 + /**
  12 + * @param $key
  13 + *
  14 + * @return string
  15 + */
  16 + public static function trimKey($key): string
  17 + {
  18 + return wordwrap(preg_replace('/[\r\n]/', '', $key), 64, "\n", true);
  19 + }
  20 +
  21 + /**
  22 + * @param $data
  23 + * @param $key
  24 + *
  25 + * @return mixed
  26 + */
  27 + public static function signPrivate($data, $key)
  28 + {
  29 + $key = self::trimKey($key);
  30 + $key = "-----BEGIN RSA PRIVATE KEY-----\n{$key}\n-----END RSA PRIVATE KEY-----";
  31 + openssl_sign($data, $sign, $key, \OPENSSL_ALGO_SHA1);
  32 +
  33 + return $sign;
  34 + }
  35 +
  36 + /**
  37 + * @param $data
  38 + * @param $fileName
  39 + *
  40 + * @return mixed
  41 + * @throws Exception
  42 + */
  43 + public static function signPrivateFromFile($data, $fileName)
  44 + {
  45 + $key = file_get_contents($fileName);
  46 + $res = openssl_get_privatekey($key);
  47 + if (!$res) {
  48 + throw new Exception('Incorrect public key file format');
  49 + }
  50 + openssl_sign($data, $sign, $res, \OPENSSL_ALGO_SHA1);
  51 + openssl_free_key($res);
  52 +
  53 + return $sign;
  54 + }
  55 +
  56 + /**
  57 + * @param $data
  58 + * @param $key
  59 + * @param $sign
  60 + *
  61 + * @return bool
  62 + */
  63 + public static function verifyPublic($data, $key, $sign)
  64 + {
  65 + $key = static::trimKey($key);
  66 + $key = "-----BEGIN PUBLIC KEY-----\n{$key}\n-----END PUBLIC KEY-----";
  67 +
  68 + return 1 === openssl_verify($data, $sign, $key, \OPENSSL_ALGO_SHA1);
  69 + }
  70 +
  71 + /**
  72 + * @param $data
  73 + * @param $fileName
  74 + * @param $sign
  75 + *
  76 + * @return bool
  77 + * @throws Exception
  78 + */
  79 + public static function verifyPublicFromFile($data, $fileName, $sign): bool
  80 + {
  81 + $key = file_get_contents($fileName);
  82 + $res = openssl_get_publickey($key);
  83 + if (!$res) {
  84 + throw new Exception('Incorrect public key file format');
  85 + }
  86 + $result = openssl_verify($data, $sign, $res, \OPENSSL_ALGO_SHA1);
  87 + openssl_free_key($res);
  88 +
  89 + return 1 === $result;
  90 + }
  91 +
  92 + /**
  93 + * @param $data
  94 + * @param $fileName
  95 + *
  96 + * @return mixed
  97 + * @throws Exception
  98 + */
  99 + public static function encryptPublicFromFile($data, $fileName)
  100 + {
  101 + $res = openssl_get_publickey(file_get_contents($fileName));
  102 + if (!$res) {
  103 + throw new Exception('公钥文件格式错误');
  104 + }
  105 + openssl_public_encrypt($data, $result, $res, \OPENSSL_PKCS1_OAEP_PADDING);
  106 + openssl_free_key($res);
  107 +
  108 + return $result;
  109 + }
  110 +
  111 + /**
  112 + * @param $data
  113 + * @param $public
  114 + *
  115 + * @return mixed
  116 + */
  117 + public static function encryptPublic($data, $public)
  118 + {
  119 + openssl_public_encrypt($data, $result, $public, \OPENSSL_PKCS1_OAEP_PADDING);
  120 +
  121 + return $result;
  122 + }
  123 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\GzCbec\Utils;
  5 +
  6 +
  7 +use GuzzleHttp\Client;
  8 +use GuzzleHttp\RequestOptions;
  9 +use Psr\Http\Message\ResponseInterface;
  10 +
  11 +class Signature
  12 +{
  13 + /**
  14 + * @var string
  15 + */
  16 + protected $uri;
  17 +
  18 + protected $client;
  19 +
  20 + /**
  21 + * Signature constructor.
  22 + *
  23 + * @param string $uri
  24 + */
  25 + public function __construct(string $uri)
  26 + {
  27 + $this->uri = $uri;
  28 + $this->client = new Client;
  29 + }
  30 +
  31 + /**
  32 + * @param string $signXml
  33 + *
  34 + * @return ResponseInterface
  35 + */
  36 + protected function execute(string $signXml): ResponseInterface
  37 + {
  38 + return $this->client->post($this->uri, [
  39 + RequestOptions::FORM_PARAMS => [
  40 + 'xml' => base64_encode($signXml)
  41 + ],
  42 + RequestOptions::TIMEOUT => 60
  43 + ]);
  44 + }
  45 +
  46 + /**
  47 + * @param string $signXml
  48 + *
  49 + * @return string
  50 + */
  51 + public function __invoke(string $signXml): string
  52 + {
  53 + $content = '';
  54 + try {
  55 + $response = $this->execute($signXml);
  56 + $content = $response->getBody()->getContents();
  57 + $array = \json_decode($content, true);
  58 + $data = \Arr::get($array, 'data');
  59 + if (!empty($data)) {
  60 + $content = html_entity_decode(base64_decode($data));
  61 + }
  62 + } catch (\Throwable $throwable) {
  63 + }
  64 + file_put_contents('tran.xml', $content);
  65 + return $content;
  66 + }
  67 +}