Store the customized Shopro mall so it can be kept on the remote.
Co-authored-by: Cursor <cursoragent@cursor.com>
这个提交包含在:
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Provider;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Yansongda\Artful\Artful;
|
||||
use Yansongda\Artful\Event;
|
||||
use Yansongda\Artful\Exception\ContainerException;
|
||||
use Yansongda\Artful\Exception\InvalidParamsException;
|
||||
use Yansongda\Artful\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Artful\Plugin\ParserPlugin;
|
||||
use Yansongda\Artful\Rocket;
|
||||
use Yansongda\Pay\Contract\ProviderInterface;
|
||||
use Yansongda\Pay\Event\CallbackReceived;
|
||||
use Yansongda\Pay\Event\MethodCalled;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\AddPayloadSignaturePlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\AddRadarPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\AppCallbackPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\CallbackPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\FormatPayloadBizContentPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\ResponsePlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\StartPlugin;
|
||||
use Yansongda\Pay\Plugin\Alipay\V2\VerifySignaturePlugin;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
/**
|
||||
* @method ResponseInterface|Rocket app(array $order) APP 支付
|
||||
* @method Collection|Rocket pos(array $order) 刷卡支付(付款码,被扫码)
|
||||
* @method Collection|Rocket scan(array $order) 扫码支付(摄像头,主动扫)
|
||||
* @method Collection|Rocket transfer(array $order) 帐户转账
|
||||
* @method ResponseInterface|Rocket h5(array $order) 手机网站支付
|
||||
* @method ResponseInterface|Rocket web(array $order) 电脑支付
|
||||
* @method Collection|Rocket mini(array $order) 小程序支付
|
||||
*/
|
||||
class Alipay implements ProviderInterface
|
||||
{
|
||||
public const URL = [
|
||||
Pay::MODE_NORMAL => 'https://openapi.alipay.com/gateway.do?charset=utf-8',
|
||||
Pay::MODE_SANDBOX => 'https://openapi-sandbox.dl.alipaydev.com/gateway.do?charset=utf-8',
|
||||
Pay::MODE_SERVICE => 'https://openapi.alipay.com/gateway.do?charset=utf-8',
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
$plugin = '\Yansongda\Pay\Shortcut\Alipay\\'.Str::studly($shortcut).'Shortcut';
|
||||
|
||||
return Artful::shortcut($plugin, ...$params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
return Artful::artful($plugins, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function query(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('query', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function cancel(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('cancel', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function close(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('close', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function refund(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('alipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('refund', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection
|
||||
{
|
||||
$request = $this->getCallbackParams($contents);
|
||||
|
||||
Event::dispatch(new CallbackReceived('alipay', $request->all(), $params, null));
|
||||
|
||||
return $this->pay([CallbackPlugin::class], $request->merge($params)->all());
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function appCallback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection
|
||||
{
|
||||
$request = $this->getCallbackParams($contents);
|
||||
|
||||
return $this->pay([AppCallbackPlugin::class], $request->merge($params)->all());
|
||||
}
|
||||
|
||||
public function success(): ResponseInterface
|
||||
{
|
||||
return new Response(200, [], 'success');
|
||||
}
|
||||
|
||||
public function mergeCommonPlugins(array $plugins): array
|
||||
{
|
||||
return array_merge(
|
||||
[StartPlugin::class],
|
||||
$plugins,
|
||||
[FormatPayloadBizContentPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class],
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCallbackParams(null|array|ServerRequestInterface $contents = null): Collection
|
||||
{
|
||||
if (is_array($contents)) {
|
||||
return Collection::wrap($contents);
|
||||
}
|
||||
|
||||
if ($contents instanceof ServerRequestInterface) {
|
||||
return Collection::wrap('GET' === $contents->getMethod() ? $contents->getQueryParams()
|
||||
: $contents->getParsedBody());
|
||||
}
|
||||
|
||||
$request = ServerRequest::fromGlobals();
|
||||
|
||||
return Collection::wrap(
|
||||
array_merge($request->getQueryParams(), $request->getParsedBody())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Provider;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Yansongda\Artful\Artful;
|
||||
use Yansongda\Artful\Event;
|
||||
use Yansongda\Artful\Exception\ContainerException;
|
||||
use Yansongda\Artful\Exception\InvalidParamsException;
|
||||
use Yansongda\Artful\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Artful\Plugin\AddPayloadBodyPlugin;
|
||||
use Yansongda\Artful\Plugin\AddRadarPlugin;
|
||||
use Yansongda\Artful\Plugin\ParserPlugin;
|
||||
use Yansongda\Artful\Plugin\StartPlugin;
|
||||
use Yansongda\Artful\Rocket;
|
||||
use Yansongda\Pay\Contract\ProviderInterface;
|
||||
use Yansongda\Pay\Event\CallbackReceived;
|
||||
use Yansongda\Pay\Event\MethodCalled;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Plugin\Douyin\V1\Pay\AddPayloadSignaturePlugin;
|
||||
use Yansongda\Pay\Plugin\Douyin\V1\Pay\CallbackPlugin;
|
||||
use Yansongda\Pay\Plugin\Douyin\V1\Pay\ResponsePlugin;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
/**
|
||||
* @method Collection|Rocket mini(array $order) 小程序支付
|
||||
*/
|
||||
class Douyin implements ProviderInterface
|
||||
{
|
||||
public const URL = [
|
||||
Pay::MODE_NORMAL => 'https://developer.toutiao.com/',
|
||||
Pay::MODE_SANDBOX => 'https://open-sandbox.douyin.com/',
|
||||
Pay::MODE_SERVICE => 'https://developer.toutiao.com/',
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
$plugin = '\Yansongda\Pay\Shortcut\Douyin\\'.Str::studly($shortcut).'Shortcut';
|
||||
|
||||
return Artful::shortcut($plugin, ...$params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
return Artful::artful($plugins, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function query(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('douyin', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('query', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function cancel(array $order): Collection|Rocket
|
||||
{
|
||||
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, '参数异常: 抖音不支持 cancel API');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function close(array $order): Collection|Rocket
|
||||
{
|
||||
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, '参数异常: 抖音不支持 close API');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function refund(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('douyin', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('refund', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket
|
||||
{
|
||||
$request = $this->getCallbackParams($contents);
|
||||
|
||||
Event::dispatch(new CallbackReceived('douyin', $request->all(), $params, null));
|
||||
|
||||
return $this->pay([CallbackPlugin::class], $request->merge($params)->all());
|
||||
}
|
||||
|
||||
public function success(): ResponseInterface
|
||||
{
|
||||
return new Response(
|
||||
200,
|
||||
['Content-Type' => 'application/json'],
|
||||
json_encode(['err_no' => 0, 'err_tips' => 'success']),
|
||||
);
|
||||
}
|
||||
|
||||
public function mergeCommonPlugins(array $plugins): array
|
||||
{
|
||||
return array_merge(
|
||||
[StartPlugin::class],
|
||||
$plugins,
|
||||
[AddPayloadSignaturePlugin::class, AddPayloadBodyPlugin::class, AddRadarPlugin::class, ResponsePlugin::class, ParserPlugin::class],
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCallbackParams(null|array|ServerRequestInterface $contents = null): Collection
|
||||
{
|
||||
if (is_array($contents)) {
|
||||
return Collection::wrap($contents);
|
||||
}
|
||||
|
||||
if (!$contents instanceof ServerRequestInterface) {
|
||||
$contents = ServerRequest::fromGlobals();
|
||||
}
|
||||
|
||||
$body = Collection::wrap($contents->getParsedBody());
|
||||
|
||||
if ($body->isNotEmpty()) {
|
||||
return $body;
|
||||
}
|
||||
|
||||
return Collection::wrapJson((string) $contents->getBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Provider;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Yansongda\Artful\Artful;
|
||||
use Yansongda\Artful\Event;
|
||||
use Yansongda\Artful\Exception\ContainerException;
|
||||
use Yansongda\Artful\Exception\InvalidParamsException;
|
||||
use Yansongda\Artful\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Artful\Plugin\ParserPlugin;
|
||||
use Yansongda\Artful\Rocket;
|
||||
use Yansongda\Pay\Contract\ProviderInterface;
|
||||
use Yansongda\Pay\Event\CallbackReceived;
|
||||
use Yansongda\Pay\Event\MethodCalled;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Plugin\Jsb\AddPayloadSignPlugin;
|
||||
use Yansongda\Pay\Plugin\Jsb\AddRadarPlugin;
|
||||
use Yansongda\Pay\Plugin\Jsb\CallbackPlugin;
|
||||
use Yansongda\Pay\Plugin\Jsb\ResponsePlugin;
|
||||
use Yansongda\Pay\Plugin\Jsb\StartPlugin;
|
||||
use Yansongda\Pay\Plugin\Jsb\VerifySignaturePlugin;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
/**
|
||||
* @method Collection|Rocket scan(array $order) 扫码支付[微信支付宝都可扫描]
|
||||
*/
|
||||
class Jsb implements ProviderInterface
|
||||
{
|
||||
public const URL = [
|
||||
Pay::MODE_NORMAL => 'https://mybank.jsbchina.cn:577/eis/merchant/merchantServices.htm',
|
||||
Pay::MODE_SANDBOX => 'https://epaytest.jsbchina.cn:9999/eis/merchant/merchantServices.htm',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param mixed $name
|
||||
* @param mixed $params
|
||||
*
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function __call($name, $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
$plugin = '\Yansongda\Pay\Shortcut\Jsb\\'.Str::studly($name).'Shortcut';
|
||||
|
||||
return Artful::shortcut($plugin, ...$params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
return Artful::artful($plugins, $params);
|
||||
}
|
||||
|
||||
public function mergeCommonPlugins(array $plugins): array
|
||||
{
|
||||
return array_merge(
|
||||
[StartPlugin::class],
|
||||
$plugins,
|
||||
[AddPayloadSignPlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function cancel(array $order): Collection|Rocket
|
||||
{
|
||||
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, 'Jsb does not support cancel api');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function close(array $order): Collection|Rocket
|
||||
{
|
||||
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, 'Jsb does not support close api');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function refund(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('jsb', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('refund', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket
|
||||
{
|
||||
$request = $this->getCallbackParams($contents);
|
||||
|
||||
Event::dispatch(new CallbackReceived('jsb', $request->all(), $params, null));
|
||||
|
||||
return $this->pay(
|
||||
[CallbackPlugin::class],
|
||||
['request' => $request, 'params' => $params]
|
||||
);
|
||||
}
|
||||
|
||||
public function success(): ResponseInterface
|
||||
{
|
||||
return new Response(
|
||||
200,
|
||||
['Content-Type' => 'text/html'],
|
||||
'success',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function query(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('jsb', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('query', [$order]);
|
||||
}
|
||||
|
||||
protected function getCallbackParams($contents = null): Collection
|
||||
{
|
||||
if (is_array($contents)) {
|
||||
return Collection::wrap($contents);
|
||||
}
|
||||
|
||||
if ($contents instanceof ServerRequestInterface) {
|
||||
return Collection::wrap($contents->getParsedBody());
|
||||
}
|
||||
|
||||
$request = ServerRequest::fromGlobals();
|
||||
|
||||
return Collection::wrap($request->getParsedBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Provider;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Yansongda\Artful\Artful;
|
||||
use Yansongda\Artful\Event;
|
||||
use Yansongda\Artful\Exception\ContainerException;
|
||||
use Yansongda\Artful\Exception\InvalidParamsException;
|
||||
use Yansongda\Artful\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Artful\Plugin\AddPayloadBodyPlugin;
|
||||
use Yansongda\Artful\Plugin\ParserPlugin;
|
||||
use Yansongda\Artful\Rocket;
|
||||
use Yansongda\Pay\Contract\ProviderInterface;
|
||||
use Yansongda\Pay\Event\CallbackReceived;
|
||||
use Yansongda\Pay\Event\MethodCalled;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Plugin\Unipay\AddRadarPlugin;
|
||||
use Yansongda\Pay\Plugin\Unipay\Open\AddPayloadSignaturePlugin;
|
||||
use Yansongda\Pay\Plugin\Unipay\Open\CallbackPlugin;
|
||||
use Yansongda\Pay\Plugin\Unipay\Open\StartPlugin;
|
||||
use Yansongda\Pay\Plugin\Unipay\Open\VerifySignaturePlugin;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
/**
|
||||
* @method ResponseInterface|Rocket web(array $order) 电脑支付
|
||||
* @method ResponseInterface|Rocket h5(array $order) H5支付
|
||||
* @method Collection|Rocket pos(array $order) 刷卡支付(付款码,被扫码)
|
||||
* @method Collection|Rocket scan(array $order) 扫码支付(摄像头,主动扫)
|
||||
*/
|
||||
class Unipay implements ProviderInterface
|
||||
{
|
||||
public const URL = [
|
||||
Pay::MODE_NORMAL => 'https://gateway.95516.com/',
|
||||
Pay::MODE_SANDBOX => 'https://gateway.test.95516.com/',
|
||||
Pay::MODE_SERVICE => 'https://gateway.95516.com/',
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
$plugin = '\Yansongda\Pay\Shortcut\Unipay\\'.Str::studly($shortcut).'Shortcut';
|
||||
|
||||
return Artful::shortcut($plugin, ...$params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
return Artful::artful($plugins, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function query(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('unipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('query', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function cancel(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('unipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('cancel', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function close(array $order): Collection|Rocket
|
||||
{
|
||||
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, '参数异常: 银联不支持 close API');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function refund(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('unipay', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('refund', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket
|
||||
{
|
||||
$request = $this->getCallbackParams($contents);
|
||||
|
||||
Event::dispatch(new CallbackReceived('unipay', $request->all(), $params, null));
|
||||
|
||||
return $this->pay(
|
||||
[CallbackPlugin::class],
|
||||
$request->merge($params)->all()
|
||||
);
|
||||
}
|
||||
|
||||
public function success(): ResponseInterface
|
||||
{
|
||||
return new Response(200, [], 'success');
|
||||
}
|
||||
|
||||
public function mergeCommonPlugins(array $plugins): array
|
||||
{
|
||||
return array_merge(
|
||||
[StartPlugin::class],
|
||||
$plugins,
|
||||
[AddPayloadSignaturePlugin::class, AddPayloadBodyPlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ParserPlugin::class],
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCallbackParams(null|array|ServerRequestInterface $contents = null): Collection
|
||||
{
|
||||
if (is_array($contents)) {
|
||||
return Collection::wrap($contents);
|
||||
}
|
||||
|
||||
if ($contents instanceof ServerRequestInterface) {
|
||||
return Collection::wrap($contents->getParsedBody());
|
||||
}
|
||||
|
||||
$request = ServerRequest::fromGlobals();
|
||||
|
||||
return Collection::wrap($request->getParsedBody());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Provider;
|
||||
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\Psr7\ServerRequest;
|
||||
use Psr\Http\Message\MessageInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Yansongda\Artful\Artful;
|
||||
use Yansongda\Artful\Event;
|
||||
use Yansongda\Artful\Exception\ContainerException;
|
||||
use Yansongda\Artful\Exception\InvalidParamsException;
|
||||
use Yansongda\Artful\Exception\ServiceNotFoundException;
|
||||
use Yansongda\Artful\Plugin\AddPayloadBodyPlugin;
|
||||
use Yansongda\Artful\Plugin\ParserPlugin;
|
||||
use Yansongda\Artful\Plugin\StartPlugin;
|
||||
use Yansongda\Artful\Rocket;
|
||||
use Yansongda\Pay\Contract\ProviderInterface;
|
||||
use Yansongda\Pay\Event\CallbackReceived;
|
||||
use Yansongda\Pay\Event\MethodCalled;
|
||||
use Yansongda\Pay\Exception\Exception;
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Plugin\Wechat\AddRadarPlugin;
|
||||
use Yansongda\Pay\Plugin\Wechat\ResponsePlugin;
|
||||
use Yansongda\Pay\Plugin\Wechat\V3\AddPayloadSignaturePlugin;
|
||||
use Yansongda\Pay\Plugin\Wechat\V3\CallbackPlugin;
|
||||
use Yansongda\Pay\Plugin\Wechat\V3\VerifySignaturePlugin;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
/**
|
||||
* @method Collection|Rocket app(array $order) APP 支付
|
||||
* @method Collection|Rocket mini(array $order) 小程序支付
|
||||
* @method Collection|Rocket mp(array $order) 公众号支付
|
||||
* @method Collection|Rocket scan(array $order) 扫码支付(摄像头,主动扫)
|
||||
* @method Collection|Rocket h5(array $order) H5 支付
|
||||
* @method Collection|Rocket transfer(array $order) 帐户转账
|
||||
*/
|
||||
class Wechat implements ProviderInterface
|
||||
{
|
||||
public const AUTH_TAG_LENGTH_BYTE = 16;
|
||||
|
||||
public const MCH_SECRET_KEY_LENGTH_BYTE = 32;
|
||||
|
||||
public const URL = [
|
||||
Pay::MODE_NORMAL => 'https://api.mch.weixin.qq.com/',
|
||||
Pay::MODE_SANDBOX => 'https://api.mch.weixin.qq.com/sandboxnew/',
|
||||
Pay::MODE_SERVICE => 'https://api.mch.weixin.qq.com/',
|
||||
];
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function __call(string $shortcut, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
$plugin = '\Yansongda\Pay\Shortcut\Wechat\\'.Str::studly($shortcut).'Shortcut';
|
||||
|
||||
return Artful::shortcut($plugin, ...$params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function pay(array $plugins, array $params): null|Collection|MessageInterface|Rocket
|
||||
{
|
||||
return Artful::artful($plugins, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function query(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('wechat', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('query', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function cancel(array $order): Collection|Rocket
|
||||
{
|
||||
throw new InvalidParamsException(Exception::PARAMS_METHOD_NOT_SUPPORTED, '参数异常: 微信不支持 cancel API');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function close(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('wechat', __METHOD__, $order, null));
|
||||
|
||||
$this->__call('close', [$order]);
|
||||
|
||||
return new Collection();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
* @throws ServiceNotFoundException
|
||||
*/
|
||||
public function refund(array $order): Collection|Rocket
|
||||
{
|
||||
Event::dispatch(new MethodCalled('wechat', __METHOD__, $order, null));
|
||||
|
||||
return $this->__call('refund', [$order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws ContainerException
|
||||
* @throws InvalidParamsException
|
||||
*/
|
||||
public function callback(null|array|ServerRequestInterface $contents = null, ?array $params = null): Collection|Rocket
|
||||
{
|
||||
$request = $this->getCallbackParams($contents);
|
||||
|
||||
Event::dispatch(new CallbackReceived('wechat', clone $request, $params, null));
|
||||
|
||||
return $this->pay(
|
||||
[CallbackPlugin::class],
|
||||
['_request' => $request, '_params' => $params]
|
||||
);
|
||||
}
|
||||
|
||||
public function success(): ResponseInterface
|
||||
{
|
||||
return new Response(
|
||||
200,
|
||||
['Content-Type' => 'application/json'],
|
||||
json_encode(['code' => 'SUCCESS', 'message' => '成功']),
|
||||
);
|
||||
}
|
||||
|
||||
public function mergeCommonPlugins(array $plugins): array
|
||||
{
|
||||
return array_merge(
|
||||
[StartPlugin::class],
|
||||
$plugins,
|
||||
[AddPayloadBodyPlugin::class, AddPayloadSignaturePlugin::class, AddRadarPlugin::class, VerifySignaturePlugin::class, ResponsePlugin::class, ParserPlugin::class],
|
||||
);
|
||||
}
|
||||
|
||||
protected function getCallbackParams(null|array|ServerRequestInterface $contents = null): ServerRequestInterface
|
||||
{
|
||||
if (is_array($contents) && isset($contents['body'], $contents['headers'])) {
|
||||
return new ServerRequest('POST', 'http://localhost', $contents['headers'], $contents['body']);
|
||||
}
|
||||
|
||||
if (is_array($contents)) {
|
||||
return new ServerRequest('POST', 'http://localhost', [], json_encode($contents));
|
||||
}
|
||||
|
||||
if ($contents instanceof ServerRequestInterface) {
|
||||
return $contents;
|
||||
}
|
||||
|
||||
return ServerRequest::fromGlobals();
|
||||
}
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户