作者 竞泽

add:all

  1 +/vendor/
  1 +{
  2 + "name": "lackoxygen/customs",
  3 + "type": "library",
  4 + "description": "海关总署179",
  5 + "license": "MIT",
  6 + "authors": [
  7 + {
  8 + "name": "jz",
  9 + "email": "jingzeou@outlook.com"
  10 + }
  11 + ],
  12 + "require": {
  13 + "php": ">=7.1",
  14 + "illuminate/support": "^5.8"
  15 + },
  16 + "require-dev": {
  17 + "phpunit/phpunit": "~4.0"
  18 + },
  19 + "autoload": {
  20 + "psr-4": {
  21 + "Lackoxygen\\Customs\\": "src/"
  22 + }
  23 + },
  24 + "extra": {
  25 + "laravel": {
  26 + "providers": [
  27 + "Lackoxygen\\Customs\\CustomsProvider"
  28 + ]
  29 + }
  30 + }
  31 +}
  1 +<?php
  2 +
  3 +return [
  4 + 'host' => 'https://swapptest.singlewindow.cn',
  5 + 'cert_no' => '015ffaef',
  6 + 'client' => [
  7 + 'timeout' => 60
  8 + ]
  9 +];
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs;
  5 +
  6 +use GuzzleHttp\Client as GuzzleHttp;
  7 +use GuzzleHttp\Exception\GuzzleException;
  8 +use GuzzleHttp\RequestOptions;
  9 +use Lackoxygen\Customs\Contract\RequestInterface;
  10 +use Lackoxygen\Customs\Exception\Exception;
  11 +use Psr\Http\Message\ResponseInterface;
  12 +
  13 +class Client
  14 +{
  15 + /**
  16 + * @var GuzzleHttp
  17 + */
  18 + protected $guzzleHttp;
  19 +
  20 + /**
  21 + * @var RequestInterface
  22 + */
  23 + protected $request;
  24 +
  25 + /**
  26 + * Client constructor.
  27 + */
  28 + protected function __construct(RequestInterface $request)
  29 + {
  30 + $clientConfig = (array)config('customs.client', [
  31 + 'timeout' => 30
  32 + ]);
  33 + $config = $clientConfig + [
  34 + 'base_uri' => config('customs.host')
  35 + ];
  36 + $this->guzzleHttp = new GuzzleHttp($config);
  37 + $this->request = $request;
  38 + }
  39 +
  40 + /**
  41 + * @return ResponseInterface
  42 + * @throws GuzzleException
  43 + */
  44 + protected function send(): ResponseInterface
  45 + {
  46 + return $this->guzzleHttp->request($this->request->getMethod(), $this->request->getPath(), $this->getOptions());
  47 + }
  48 +
  49 + /**
  50 + * @return array
  51 + */
  52 + protected function getOptions(): array
  53 + {
  54 + $requestArray = ['payExInfoStr' => $this->request->toJson(JSON_UNESCAPED_UNICODE)];
  55 + $options = [];
  56 + if ($this->request->getMethod() === "GET") {
  57 + $options[RequestOptions::QUERY] = $requestArray;
  58 + } elseif ($this->request->getContentType() === 'application/x-www-form-urlencoded') {
  59 + $options[RequestOptions::FORM_PARAMS] = $requestArray;
  60 + $options[RequestOptions::HEADERS] = ['Content-Type' => 'application/x-www-form-urlencoded'];
  61 + } elseif (strpos($this->request->getContentType(), 'application/json') !== false) {
  62 + $options[RequestOptions::JSON] = $requestArray;
  63 + $options[RequestOptions::HEADERS] = ['Content-Type' => 'application/json'];
  64 + }
  65 +
  66 + return $options;
  67 + }
  68 +
  69 +
  70 + /**
  71 + * @param RequestInterface $request
  72 + *
  73 + * @return string
  74 + * @throws Exception
  75 + */
  76 + public static function request(RequestInterface $request): string
  77 + {
  78 + $client = new static($request);
  79 +
  80 + try {
  81 + $response = $client->send();
  82 + } catch (\Throwable $e) {
  83 + throw new Exception($e);
  84 + }
  85 + $content = $response->getBody()->getContents();
  86 +
  87 + $response->getBody()->rewind();
  88 +
  89 + return $content;
  90 + }
  91 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Customs\Contract;
  4 +
  5 +interface RequestInterface
  6 +{
  7 + /**
  8 + * @return string
  9 + */
  10 + public function getPath(): string;
  11 +
  12 + /**
  13 + * @return string
  14 + */
  15 + public function getMethod(): string;
  16 +
  17 + /**
  18 + * @return string
  19 + */
  20 + public function getContentType(): string;
  21 +
  22 + /**
  23 + * @return array
  24 + */
  25 + public function toArray(): array;
  26 +
  27 + /**
  28 + * @return string
  29 + */
  30 + public function toJson($options = 0): string;
  31 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Customs;
  4 +
  5 +use Lackoxygen\Customs\Request\PayExInfo;
  6 +use Lackoxygen\Customs\Utils\Trigger;
  7 +
  8 +class Customs
  9 +{
  10 + /**
  11 + * @param callable $func
  12 + *
  13 + * @return string
  14 + * @throws Exception\Exception
  15 + */
  16 + public function report(callable $func)
  17 + {
  18 + $payExInfo = PayExInfo::make();
  19 + Trigger::closure($func, $payExInfo);
  20 +
  21 + return Client::request($payExInfo);
  22 + }
  23 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Customs;
  4 +
  5 +use Illuminate\Support\ServiceProvider;
  6 +
  7 +class CustomsProvider extends ServiceProvider
  8 +{
  9 +
  10 + /**
  11 + * @var bool
  12 + */
  13 + protected $defer = true;
  14 +
  15 + /**
  16 + * @var array
  17 + */
  18 + protected $commands = [];
  19 +
  20 + /**
  21 + * Register any application services.
  22 + *
  23 + * @return void
  24 + */
  25 + public function register()
  26 + {
  27 + $this->commands($this->commands);
  28 + }
  29 +
  30 + public function boot()
  31 + {
  32 + $this->publishes([__DIR__ . '/../config/customs.php' => config_path('customs.php')]);
  33 + }
  34 +
  35 + /**
  36 + * @return string[]
  37 + */
  38 + public function provides()
  39 + {
  40 + return ['customs', Customs::class];
  41 + }
  42 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Customs\Exception;
  4 +
  5 +class Exception extends \Exception
  6 +{
  7 +
  8 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Customs\Facade;
  4 +
  5 +use Illuminate\Support\Facades\Facade;
  6 +use Lackoxygen\Customs\Customs;
  7 +
  8 +/**
  9 + * Class CustomsFacade
  10 + *
  11 + * @method static report(callable $func)
  12 + */
  13 +class CustomsFacade extends Facade
  14 +{
  15 + /**
  16 + * @return string
  17 + */
  18 + protected static function getFacadeAccessor(): string
  19 + {
  20 + return Customs::class;
  21 + }
  22 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Request;
  5 +
  6 +use Lackoxygen\Customs\Request\Struct\PayExchangeInfoHead;
  7 +use Lackoxygen\Customs\Request\Struct\PayExchangeInfoItem;
  8 +
  9 +class PayExInfo extends Request
  10 +{
  11 + /**
  12 + * @return mixed
  13 + */
  14 + public function getSessionID()
  15 + {
  16 + return $this->mGet(__FUNCTION__);
  17 + }
  18 +
  19 + /**
  20 + * @param string 海关发起请求时,平台接收的会话ID。
  21 + */
  22 + public function setSessionID(): void
  23 + {
  24 + $this->mSet(__FUNCTION__, func_get_arg(0));
  25 + }
  26 +
  27 + /**
  28 + * @return mixed
  29 + */
  30 + public function getPayExchangeInfoHead()
  31 + {
  32 + return $this->mGet(__FUNCTION__);
  33 + }
  34 +
  35 + /**
  36 + * @param mixed $payExchangeInfoHead 支付原始数据表头
  37 + */
  38 + public function setPayExchangeInfoHead(PayExchangeInfoHead $payExchangeInfoHead): void
  39 + {
  40 + $this->mSet(__FUNCTION__, $payExchangeInfoHead);
  41 + }
  42 +
  43 + /**
  44 + * @return mixed
  45 + */
  46 + public function getPayExchangeInfoLists()
  47 + {
  48 + return $this->mGet(__FUNCTION__);
  49 + }
  50 +
  51 +
  52 + /**
  53 + * @param PayExchangeInfoItem $payExchangeInfoItem 支付原始数据表体
  54 + */
  55 + public function pushPayExchangeInfoLists(PayExchangeInfoItem $payExchangeInfoItem): void
  56 + {
  57 + $this->mPush(__FUNCTION__, $payExchangeInfoItem);
  58 + }
  59 +
  60 + /**
  61 + * @return mixed
  62 + */
  63 + public function getServiceTime()
  64 + {
  65 + return $this->mGet(__FUNCTION__);
  66 + }
  67 +
  68 + /**
  69 + * @param string 调用时的系统时间
  70 + */
  71 + public function setServiceTime(): void
  72 + {
  73 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  74 + }
  75 +
  76 + /**
  77 + * @return mixed
  78 + */
  79 + public function getCertNo()
  80 + {
  81 + return $this->mGet(__FUNCTION__);
  82 + }
  83 +
  84 + /**
  85 + * @param string 证书编号
  86 + */
  87 + public function setCertNo(): void
  88 + {
  89 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  90 + }
  91 +
  92 + /**
  93 + * @return mixed
  94 + */
  95 + public function getSignValue()
  96 + {
  97 + return $this->mGet(__FUNCTION__);
  98 + }
  99 +
  100 + /**
  101 + * @param string 签名结果值
  102 + */
  103 + public function setSignValue(): void
  104 + {
  105 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  106 + }
  107 +
  108 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Request;
  5 +
  6 +
  7 +use Lackoxygen\Customs\Contract\RequestInterface;
  8 +use Lackoxygen\Customs\Utils\Collection;
  9 +
  10 +class Request extends Collection implements RequestInterface
  11 +{
  12 + /**
  13 + * @var string
  14 + */
  15 + protected $path = '/ceb2grab/grab/realTimeDataUpload';
  16 +
  17 + /**
  18 + * @var string
  19 + */
  20 + protected $method = 'POST';
  21 +
  22 + /**
  23 + * @var string
  24 + */
  25 + protected $contentType = 'application/x-www-form-urlencoded';
  26 +
  27 + /**
  28 + * @inheritDoc
  29 + */
  30 + public function getPath(): string
  31 + {
  32 + return $this->path;
  33 + }
  34 +
  35 + /**
  36 + * @inheritDoc
  37 + */
  38 + public function getMethod(): string
  39 + {
  40 + return $this->method;
  41 + }
  42 +
  43 + /**
  44 + * @inheritDoc
  45 + */
  46 + public function getContentType(): string
  47 + {
  48 + return $this->contentType;
  49 + }
  50 +
  51 + /**
  52 + * @inheritDoc
  53 + */
  54 + public function toArray(): array
  55 + {
  56 + return parent::toArray();
  57 + }
  58 +
  59 + /**
  60 + * @inheritDoc
  61 + */
  62 + public function toJson($options = 0): string
  63 + {
  64 + return parent::toJson($options);
  65 + }
  66 +}
  1 +<?php
  2 +
  3 +namespace Lackoxygen\Customs\Request\Struct;
  4 +
  5 +use Lackoxygen\Customs\Utils\Collection;
  6 +
  7 +class GoodsInfoItem extends Collection
  8 +{
  9 + /**
  10 + * @return string
  11 + */
  12 + public function getGname()
  13 + {
  14 + return $this->mGet(__FUNCTION__);
  15 + }
  16 +
  17 + /**
  18 + * @param string 商品名称
  19 + */
  20 + public function setGname(): void
  21 + {
  22 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  23 + }
  24 +
  25 + /**
  26 + * @return mixed
  27 + */
  28 + public function getItemLink()
  29 + {
  30 + return $this->mGet(__FUNCTION__);
  31 + }
  32 +
  33 + /**
  34 + * @param string 商品展示链接地址
  35 + */
  36 + public function setItemLink(): void
  37 + {
  38 + $itemLink = func_get_arg(0);
  39 + if (!empty($itemLink)) {
  40 + $itemLink = urlencode($itemLink);
  41 + }
  42 + $this->mSet(__FUNCTION__, (string)$itemLink);
  43 + }
  44 +
  45 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Request\Struct;
  5 +
  6 +use Lackoxygen\Customs\Utils\Collection;
  7 +
  8 +class PayExchangeInfoHead extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getGuid()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param string 企业系统生成36位唯一序号(英文字母大写)
  20 + */
  21 + public function setGuid(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getInitalRequest()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param string 跨境电商平台企业向支付企业发送的原始信息
  36 + */
  37 + public function setInitalRequest(): void
  38 + {
  39 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  40 + }
  41 +
  42 + /**
  43 + * @return mixed
  44 + */
  45 + public function getInitalResponse()
  46 + {
  47 + return $this->mGet(__FUNCTION__);
  48 + }
  49 +
  50 + /**
  51 + * @param string 支付企业向跨境电商平台企业反馈的原始信息
  52 + */
  53 + public function setInitalResponse(): void
  54 + {
  55 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  56 + }
  57 +
  58 + /**
  59 + * @return mixed
  60 + */
  61 + public function getEbpCode()
  62 + {
  63 + return $this->mGet(__FUNCTION__);
  64 + }
  65 +
  66 + /**
  67 + * @param string 电商平台的海关注册登记编号
  68 + */
  69 + public function setEbpCode(): void
  70 + {
  71 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  72 + }
  73 +
  74 + /**
  75 + * @return mixed
  76 + */
  77 + public function getPayCode()
  78 + {
  79 + return $this->mGet(__FUNCTION__);
  80 + }
  81 +
  82 + /**
  83 + * @param string 支付企业的海关注册登记编号
  84 + */
  85 + public function setPayCode(): void
  86 + {
  87 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  88 + }
  89 +
  90 + /**
  91 + * @return mixed
  92 + */
  93 + public function getPayTransactionId()
  94 + {
  95 + return $this->mGet(__FUNCTION__);
  96 + }
  97 +
  98 + /**
  99 + * @param string 交易唯一编号(可在央行认可的机构验证)
  100 + */
  101 + public function setPayTransactionId(): void
  102 + {
  103 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  104 + }
  105 +
  106 + /**
  107 + * @return mixed
  108 + */
  109 + public function getTotalAmount()
  110 + {
  111 + return $this->mGet(__FUNCTION__);
  112 + }
  113 +
  114 + /**
  115 + * @param float 实际交易金额
  116 + */
  117 + public function setTotalAmount(): void
  118 + {
  119 + $this->mSet(__FUNCTION__, func_get_arg(0));
  120 + }
  121 +
  122 + /**
  123 + * @return mixed
  124 + */
  125 + public function getCurrency()
  126 + {
  127 + return $this->mGet(__FUNCTION__);
  128 + }
  129 +
  130 + /**
  131 + * @param string 实际交易币制(海关编码
  132 + */
  133 + public function setCurrency(): void
  134 + {
  135 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  136 + }
  137 +
  138 + /**
  139 + * @return mixed
  140 + */
  141 + public function getVerDept()
  142 + {
  143 + return $this->mGet(__FUNCTION__);
  144 + }
  145 +
  146 + /**
  147 + * @param string 1-银联 2-网联 3-其他
  148 + */
  149 + public function setVerDept(): void
  150 + {
  151 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  152 + }
  153 +
  154 + /**
  155 + * @return mixed
  156 + */
  157 + public function getPayType()
  158 + {
  159 + return $this->mGet(__FUNCTION__);
  160 + }
  161 +
  162 + /**
  163 + * @param string 用户支付的类型。1-APP 2-PC 3-扫码 4-其他
  164 + */
  165 + public function setPayType(): void
  166 + {
  167 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  168 + }
  169 +
  170 + /**
  171 + * @return mixed
  172 + */
  173 + public function getTradingTime()
  174 + {
  175 + return $this->mGet(__FUNCTION__);
  176 + }
  177 +
  178 + /**
  179 + * @param string 交易支付时间
  180 + */
  181 + public function setTradingTime(): void
  182 + {
  183 + $this->mSet(__FUNCTION__, (string)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 string 备注
  196 + */
  197 + public function setNote(): void
  198 + {
  199 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  200 + }
  201 +
  202 +
  203 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Request\Struct;
  5 +
  6 +use Lackoxygen\Customs\Utils\Collection;
  7 +
  8 +class PayExchangeInfoItem extends Collection
  9 +{
  10 + /**
  11 + * @return mixed
  12 + */
  13 + public function getOrderNo()
  14 + {
  15 + return $this->mGet(__FUNCTION__);
  16 + }
  17 +
  18 + /**
  19 + * @param string 交易平台向海关申报订单的的订单编号。需返回原始请求内的所有订单
  20 + */
  21 + public function setOrderNo(): void
  22 + {
  23 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  24 + }
  25 +
  26 + /**
  27 + * @return mixed
  28 + */
  29 + public function getGoodsInfo()
  30 + {
  31 + return $this->mGet(__FUNCTION__);
  32 + }
  33 +
  34 + /**
  35 + * @param GoodsInfoItem $goodsInfoItem
  36 + */
  37 + public function pushGoodsInfo(GoodsInfoItem $goodsInfoItem): void
  38 + {
  39 + $this->mPush(__FUNCTION__, $goodsInfoItem);
  40 + }
  41 +
  42 + /**
  43 + * @return mixed
  44 + */
  45 + public function getRecpAccount()
  46 + {
  47 + return $this->mGet(__FUNCTION__);
  48 + }
  49 +
  50 + /**
  51 + * @param string 交易商品的卖方商户账号。电商平台自营商户应填写自营商户的收款账户;非自营电商应填写非自营商户的收款账户
  52 + */
  53 + public function setRecpAccount(): void
  54 + {
  55 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  56 + }
  57 +
  58 + /**
  59 + * @return mixed
  60 + */
  61 + public function getRecpCode()
  62 + {
  63 + return $this->mGet(__FUNCTION__);
  64 + }
  65 +
  66 + /**
  67 + * @param string 应填写收款企业代码(境内企业为统一社会信用代码;境外企业可不填写)
  68 + */
  69 + public function setRecpCode(): void
  70 + {
  71 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  72 + }
  73 +
  74 + /**
  75 + * @return mixed
  76 + */
  77 + public function getRecpName()
  78 + {
  79 + return $this->mGet(__FUNCTION__);
  80 + }
  81 +
  82 + /**
  83 + * @param string 应填写收款企业名称
  84 + */
  85 + public function setRecpName(): void
  86 + {
  87 + $this->mSet(__FUNCTION__, (string)func_get_arg(0));
  88 + }
  89 +
  90 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Utils;
  5 +
  6 +use Illuminate\Support\Collection as BaseCollection;
  7 +
  8 +class Collection extends BaseCollection
  9 +{
  10 + /**
  11 + * @param $method
  12 + * @param $value
  13 + */
  14 + public function mSet($method, $value)
  15 + {
  16 + parent::offsetSet($this->cutKey($method, 3), $value);
  17 + }
  18 +
  19 + /**
  20 + * @param $method
  21 + * @param $value
  22 + */
  23 + public function mPush($method, $value)
  24 + {
  25 + $key = $this->cutKey($method, 4);
  26 + $listCollection = $this->get($key);
  27 + if (!$listCollection instanceof BaseCollection) {
  28 + $listCollection = BaseCollection::make();
  29 + }
  30 + $listCollection->push($value);
  31 + $this->offsetSet($key, $listCollection);
  32 + }
  33 +
  34 + /**
  35 + * @param $method
  36 + * @param null $default
  37 + *
  38 + * @return mixed
  39 + */
  40 + public function mGet($method, $default = null)
  41 + {
  42 + return parent::get($this->cutKey($method, 3), $default);
  43 + }
  44 +
  45 + /**
  46 + * @param string $key
  47 + * @param int $offset
  48 + *
  49 + * @return string
  50 + */
  51 + public function cutKey(string $key, int $offset = 0): string
  52 + {
  53 + return lcfirst(substr($key, $offset));
  54 + }
  55 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Utils;
  5 +
  6 +use Lackoxygen\Customs\Request\PayExInfo;
  7 +
  8 +class Signature
  9 +{
  10 + /**
  11 + * @var PayExInfo $exInfo
  12 + */
  13 + protected $exInfo;
  14 +
  15 + /**
  16 + * Signature constructor.
  17 + *
  18 + * @param PayExInfo $exInfo
  19 + */
  20 + public function __construct(PayExInfo $exInfo)
  21 + {
  22 + $this->exInfo = $exInfo;
  23 + }
  24 +
  25 +
  26 + /**
  27 + * @return string
  28 + */
  29 + public function signatureString(): string
  30 + {
  31 + $buffer = "\"sessionID\":\"{$this->exInfo->getSessionID()}\"";
  32 + $buffer .= "||";
  33 + $buffer .= "\"payExchangeInfoHead\":\"{$this->exInfo->getPayExchangeInfoHead()->toJson(JSON_UNESCAPED_UNICODE)}\"";
  34 + $buffer .= "||";
  35 + $buffer .= "\"payExchangeInfoLists\":\"{$this->exInfo->getPayExchangeInfoLists()->toJson(JSON_UNESCAPED_UNICODE)}\"";
  36 + $buffer .= "||";
  37 + $buffer .= "\"serviceTime\":\"{$this->exInfo->getServiceTime()}\"";
  38 +
  39 + return $buffer;
  40 + }
  41 +}
  1 +<?php
  2 +
  3 +
  4 +namespace Lackoxygen\Customs\Utils;
  5 +
  6 +
  7 +class Trigger
  8 +{
  9 + /**
  10 + * @param $func
  11 + * @param ...$argv
  12 + *
  13 + * @return false|mixed|null
  14 + */
  15 + public static function closure($func, ...$argv)
  16 + {
  17 + if (!$func instanceof \Closure) {
  18 + return null;
  19 + }
  20 +
  21 + return call_user_func($func, ...$argv);
  22 + }
  23 +}
  1 +<?php
  2 +
  3 +use Carbon\Carbon;
  4 +use Illuminate\Support\Str;
  5 +use Lackoxygen\Customs\Facade\CustomsFacade;
  6 +use Lackoxygen\Customs\Request\PayExInfo;
  7 +use Lackoxygen\Customs\Request\Struct\GoodsInfoItem;
  8 +use Lackoxygen\Customs\Request\Struct\PayExchangeInfoHead;
  9 +use Lackoxygen\Customs\Request\Struct\PayExchangeInfoItem;
  10 +
  11 +foreach (['./', '../', '../../', '../../../'] as $pathPrefix) {
  12 + $loaderFile = $pathPrefix . 'vendor/autoload.php';
  13 + if (file_exists($loaderFile)) {
  14 + require_once $loaderFile;
  15 + break;
  16 + }
  17 +}
  18 +
  19 +$response = CustomsFacade::report(function (PayExInfo $exInfo) {
  20 + $collection = $exInfo;
  21 + $payExchangeInfoItem = PayExchangeInfoItem::make();
  22 +
  23 + $guid = Str::uuid()->toString();
  24 +
  25 + $tradingTime = date('YmdHis');
  26 +
  27 + $serviceTime = Carbon::now()->getPreciseTimestamp(3);
  28 +
  29 + $uuid = "8D5925BF-4DC7-4CC5-AE0B-AB9AA0800E5C";
  30 +
  31 + $sid = '4BE53EF8-2432-432C-A102-D33835D2C153';
  32 +
  33 + $tradingTime = "20210716101722";
  34 +
  35 + $serviceTime = "1626401880241";
  36 +
  37 + $collection->setSessionID($sid);
  38 +
  39 + $payExchangeInfoHead = PayExchangeInfoHead::make();
  40 + $payExchangeInfoHead->setGuid($uuid);
  41 + $payExchangeInfoHead->setInitalRequest('原始请求');//支付原始请求
  42 + $payExchangeInfoHead->setInitalResponse('ok');//支付原始返回
  43 + $payExchangeInfoHead->setEbpCode('4423968643');
  44 + $payExchangeInfoHead->setPayCode('312226T001');
  45 + $payExchangeInfoHead->setPayTransactionId('b201907311451410140026320');
  46 + $payExchangeInfoHead->setTotalAmount(1);
  47 + $payExchangeInfoHead->setCurrency(502);
  48 + $payExchangeInfoHead->setVerDept(3);
  49 + $payExchangeInfoHead->setPayType(1);
  50 + $payExchangeInfoHead->setTradingTime($tradingTime);
  51 +
  52 + $payExchangeInfoHead->setNote('测试订单');
  53 + $collection->setPayExchangeInfoHead($payExchangeInfoHead);
  54 +
  55 + $goodsItem1 = GoodsInfoItem::make();
  56 + $goodsItem1->setGname('测试商品01');
  57 + $goodsItem1->setItemLink('https://test.m.vodeshop.com/o2o/pages/seckill/goodsDetail?activityGoodsId=261&retail_goods_id=21&groupType=3');
  58 +
  59 + $goodsItem2 = GoodsInfoItem::make();
  60 + $goodsItem2->setGname('测试商品2');
  61 + $goodsItem2->setItemLink('https://test.m.vodeshop.com/o2o/pages/seckill/goodsDetail?activityGoodsId=441&retail_goods_id=34&groupType=3');
  62 +
  63 + $payExchangeInfoItem->setOrderNo('RE202102252327330035730408');
  64 + $payExchangeInfoItem->pushGoodsInfo($goodsItem1);
  65 + $payExchangeInfoItem->pushGoodsInfo($goodsItem2);
  66 +
  67 + $payExchangeInfoItem->setRecpAccount('OSA571908863132601');
  68 + $payExchangeInfoItem->setRecpCode('91440113304476710E');
  69 + $payExchangeInfoItem->setRecpName('guangdongloveback');
  70 +
  71 +
  72 + $collection->pushPayExchangeInfoLists($payExchangeInfoItem);
  73 +
  74 +
  75 + $collection->setServiceTime($serviceTime);
  76 +
  77 +
  78 + $collection->setCertNo(config('customs.cert_no'));
  79 +
  80 + $collection->setSignValue("n48bqbODd6cNU/RDErvHHb/4+65ePk1MTxVL5Kln+dwM7K2f/BLvCv0OwUN2j7qeFvvJFTfTfpDzb2xc+OwGc/U0ZTWby9BDV47eXQE+o6JoNtXJ5yR6+lje620tW987Pzd4kO9+gwmNKJoufwwaCUTEm6tGNlzaYliOpxaiYS4=");
  81 +
  82 +});
  83 +
  84 +var_dump($response);