mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-02 04:08:21 +08:00
update
This commit is contained in:
parent
df8fbab183
commit
814ce4958a
@ -60,6 +60,8 @@ class Exception extends \Exception
|
||||
|
||||
public const REQUEST_NULL_ERROR = 4005;
|
||||
|
||||
public const MISSING_NECESSARY_PARAMS = 4006;
|
||||
|
||||
/**
|
||||
* 关于api.
|
||||
*/
|
||||
@ -79,6 +81,8 @@ class Exception extends \Exception
|
||||
|
||||
public const INVALID_REQUEST_ENCRYPTED_DATA = 5007;
|
||||
|
||||
public const INVALID_REQUEST_ENCRYPTED_METHOD = 5008;
|
||||
|
||||
/**
|
||||
* raw.
|
||||
*
|
||||
|
@ -85,14 +85,27 @@ class CallbackPlugin implements PluginInterface
|
||||
throw new InvalidConfigException(InvalidConfigException::WECHAT_CONFIG_ERROR, 'Missing Wechat Config -- [mch_secret_key]');
|
||||
}
|
||||
|
||||
switch ($resource['algorithm'] ?? '') {
|
||||
case 'AEAD_AES_256_GCM':
|
||||
return $this->decryptAes256Gcm($ciphertext, $secret, $resource['nonce'] ?? '', $resource['associated_data'] ?? '');
|
||||
default:
|
||||
throw new InvalidResponseException(InvalidResponseException::INVALID_REQUEST_ENCRYPTED_METHOD);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidResponseException
|
||||
*/
|
||||
protected function decryptAes256Gcm(string $ciphertext, string $secret, string $nonce, string $associatedData): array
|
||||
{
|
||||
$decrypted = json_decode(openssl_decrypt(
|
||||
substr($ciphertext, 0, -self::AUTH_TAG_LENGTH_BYTE),
|
||||
'aes-256-gcm',
|
||||
$secret,
|
||||
OPENSSL_RAW_DATA,
|
||||
$resource['nonce'] ?? '',
|
||||
$nonce,
|
||||
substr($ciphertext, -self::AUTH_TAG_LENGTH_BYTE),
|
||||
$resource['associated_data'] ?? ''
|
||||
$associatedData
|
||||
), true);
|
||||
|
||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||
|
@ -25,7 +25,7 @@ abstract class GeneralPlugin implements PluginInterface
|
||||
Logger::info('[wechat][GeneralPlugin] 通用插件开始装载', ['rocket' => $rocket]);
|
||||
|
||||
$rocket->setRadar($this->getRequest($rocket));
|
||||
$this->checkPayload($rocket);
|
||||
$this->doSomething($rocket);
|
||||
|
||||
Logger::info('[wechat][GeneralPlugin] 通用插件装载完毕', ['rocket' => $rocket]);
|
||||
|
||||
@ -71,7 +71,7 @@ abstract class GeneralPlugin implements PluginInterface
|
||||
];
|
||||
}
|
||||
|
||||
abstract protected function checkPayload(Rocket $rocket): void;
|
||||
abstract protected function doSomething(Rocket $rocket): void;
|
||||
|
||||
abstract protected function getUri(Rocket $rocket): string;
|
||||
}
|
||||
|
20
src/Plugin/Wechat/Marketing/Coupon/CreatePlugin.php
Normal file
20
src/Plugin/Wechat/Marketing/Coupon/CreatePlugin.php
Normal file
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class CreatePlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
}
|
||||
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/marketing/favor/coupon-stocks';
|
||||
}
|
||||
}
|
43
src/Plugin/Wechat/Marketing/Coupon/PausePlugin.php
Normal file
43
src/Plugin/Wechat/Marketing/Coupon/PausePlugin.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
class PausePlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_creator_mchid'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
$rocket->setPayload(new Collection([
|
||||
'stock_creator_mchid' => $payload->get('stock_creator_mchid'),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/marketing/favor/stocks/'.$payload->get('stock_id').'/pause';
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryCouponDetailPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
$appid = get_wechat_config($rocket->getParams())->get('mp_app_id');
|
||||
|
||||
if (is_null($payload->get('coupon_id')) ||
|
||||
is_null($payload->get('openid'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/marketing/favor/users/'.
|
||||
$payload->get('openid').
|
||||
'coupons/'.$payload->get('coupon_id').
|
||||
'?appid='.$appid;
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryStockDetailPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id')) || is_null($payload->get('stock_creator_mchid'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/marketing/favor/stocks/'.
|
||||
$payload->get('stock_id').
|
||||
'?stock_creator_mchid='.$payload->get('stock_creator_mchid');
|
||||
}
|
||||
}
|
36
src/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPlugin.php
Normal file
36
src/Plugin/Wechat/Marketing/Coupon/QueryStockItemsPlugin.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryStockItemsPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
$query = $payload->all();
|
||||
unset($query['stock_id']);
|
||||
|
||||
return 'v3/marketing/favor/stocks/'.
|
||||
$payload->get('stock_id').
|
||||
'/items?'.http_build_query($query);
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryStockMerchantsPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
$query = $payload->all();
|
||||
unset($query['stock_id']);
|
||||
|
||||
return 'v3/marketing/favor/stocks/'.
|
||||
$payload->get('stock_id').
|
||||
'/merchants?'.http_build_query($query);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryStockRefundFlowPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'vv3/marketing/favor/stocks/'.
|
||||
$payload->get('stock_id').
|
||||
'/refund-flow';
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryStockUseFlowPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'vv3/marketing/favor/stocks/'.
|
||||
$payload->get('stock_id').
|
||||
'/use-flow';
|
||||
}
|
||||
}
|
21
src/Plugin/Wechat/Marketing/Coupon/QueryStocksPlugin.php
Normal file
21
src/Plugin/Wechat/Marketing/Coupon/QueryStocksPlugin.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryStocksPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/marketing/favor/stocks?'.$rocket->getPayload()->query();
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryUserCouponsPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('openid'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
$query = $payload->all();
|
||||
unset($query['openid']);
|
||||
|
||||
return 'v3/marketing/favor/users/'.
|
||||
$payload->get('openid').
|
||||
'/coupons?'.http_build_query($query);
|
||||
}
|
||||
}
|
43
src/Plugin/Wechat/Marketing/Coupon/RestartPlugin.php
Normal file
43
src/Plugin/Wechat/Marketing/Coupon/RestartPlugin.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
class RestartPlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_creator_mchid'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
$rocket->setPayload(new Collection([
|
||||
'stock_creator_mchid' => $payload->get('stock_creator_mchid'),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/marketing/favor/stocks/'.$payload->get('stock_id').'/restart';
|
||||
}
|
||||
}
|
34
src/Plugin/Wechat/Marketing/Coupon/SendPlugin.php
Normal file
34
src/Plugin/Wechat/Marketing/Coupon/SendPlugin.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
class SendPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(new Collection([
|
||||
'stock_creator_mchid' => $rocket->getPayload()->get('stock_creator_mchid'),
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('openid'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/marketing/favor/users/'.$payload->get('openid').'/coupons';
|
||||
}
|
||||
}
|
30
src/Plugin/Wechat/Marketing/Coupon/SetCallbackPlugin.php
Normal file
30
src/Plugin/Wechat/Marketing/Coupon/SetCallbackPlugin.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class SetCallbackPlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
$rocket->mergePayload([
|
||||
'mchid' => $config->get('mch_id', ''),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/marketing/favor/callbacks';
|
||||
}
|
||||
}
|
31
src/Plugin/Wechat/Marketing/Coupon/StartPlugin.php
Normal file
31
src/Plugin/Wechat/Marketing/Coupon/StartPlugin.php
Normal file
@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Marketing\Coupon;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class StartPlugin extends GeneralPlugin
|
||||
{
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->getPayload()->forget('openid');
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('stock_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/marketing/favor/stocks/'.$payload->get('stock_id').'/start';
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Combine;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Collection;
|
||||
|
||||
@ -11,8 +12,15 @@ class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin
|
||||
{
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('combine_out_trade_no')) &&
|
||||
is_null($payload->get('out_trade_no'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/combine-transactions/out-trade-no/'.
|
||||
($rocket->getParams()['combine_out_trade_no'] ?? $rocket->getParams()['out_trade_no'] ?? '').
|
||||
$payload->get('combine_out_trade_no', $payload->get('out_trade_no')).
|
||||
'/close';
|
||||
}
|
||||
|
||||
@ -21,7 +29,7 @@ class ClosePlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\ClosePlugin
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
|
@ -4,15 +4,21 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Combine;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class QueryPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\QueryPlugin
|
||||
{
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$params = $rocket->getParams();
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('combine_out_trade_no')) &&
|
||||
is_null($payload->get('transaction_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/combine-transactions/out-trade-no/'.
|
||||
($params['combine_out_trade_no'] ?? $params['transaction_id'] ?? '');
|
||||
$payload->get('combine_out_trade_no', $payload->get('transaction_id'));
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Parser\OriginResponseParser;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
@ -11,10 +12,19 @@ use Yansongda\Supports\Collection;
|
||||
|
||||
class ClosePlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('out_trade_no'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/pay/transactions/out-trade-no/'.
|
||||
($rocket->getParams()['out_trade_no'] ?? '').
|
||||
$payload->get('out_trade_no').
|
||||
'/close';
|
||||
}
|
||||
|
||||
@ -23,7 +33,7 @@ class ClosePlugin extends GeneralPlugin
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setDirection(OriginResponseParser::class);
|
||||
|
||||
|
@ -20,7 +20,7 @@ class CombinePrepayPlugin extends GeneralPlugin
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
|
@ -4,14 +4,24 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class DownloadBillPlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return $rocket->getParams()['download_url'] ?? '';
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('download_url'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return $payload->get('download_url');
|
||||
}
|
||||
|
||||
protected function getMethod(): string
|
||||
@ -19,7 +29,7 @@ class DownloadBillPlugin extends GeneralPlugin
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
@ -4,14 +4,24 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
class FindRefundPlugin extends GeneralPlugin
|
||||
{
|
||||
/**
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
return 'v3/refund/domestic/refunds/'.($rocket->getParams()['out_refund_no'] ?? '');
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('out_refund_no'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/refund/domestic/refunds/'.$payload->get('out_refund_no');
|
||||
}
|
||||
|
||||
protected function getMethod(): string
|
||||
@ -19,7 +29,7 @@ class FindRefundPlugin extends GeneralPlugin
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class GetFlowBillPlugin extends GeneralPlugin
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ class GetTradeBillPlugin extends GeneralPlugin
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class PrepayPlugin extends GeneralPlugin
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
*/
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
|
||||
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\Common;
|
||||
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Plugin\Wechat\GeneralPlugin;
|
||||
use Yansongda\Pay\Rocket;
|
||||
|
||||
@ -13,13 +14,19 @@ class QueryPlugin extends GeneralPlugin
|
||||
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
|
||||
* @throws \Yansongda\Pay\Exception\ContainerException
|
||||
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
|
||||
* @throws \Yansongda\Pay\Exception\InvalidParamsException
|
||||
*/
|
||||
protected function getUri(Rocket $rocket): string
|
||||
{
|
||||
$config = get_wechat_config($rocket->getParams());
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (is_null($payload->get('transaction_id'))) {
|
||||
throw new InvalidParamsException(InvalidParamsException::MISSING_NECESSARY_PARAMS);
|
||||
}
|
||||
|
||||
return 'v3/pay/transactions/id/'.
|
||||
($rocket->getParams()['transaction_id'] ?? '').
|
||||
$payload->get('transaction_id').
|
||||
'?mchid='.$config->get('mch_id', '');
|
||||
}
|
||||
|
||||
@ -28,7 +35,7 @@ class QueryPlugin extends GeneralPlugin
|
||||
return 'GET';
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
$rocket->setPayload(null);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ class RefundPlugin extends GeneralPlugin
|
||||
return 'v3/refund/domestic/refunds';
|
||||
}
|
||||
|
||||
protected function checkPayload(Rocket $rocket): void
|
||||
protected function doSomething(Rocket $rocket): void
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use Closure;
|
||||
use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Logger;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
class PreparePlugin implements PluginInterface
|
||||
{
|
||||
@ -24,6 +25,8 @@ class PreparePlugin implements PluginInterface
|
||||
|
||||
protected function getPayload(array $params): array
|
||||
{
|
||||
return $params;
|
||||
return array_filter($params, function ($v, $k) {
|
||||
return !Str::startsWith(strval($k), '_');
|
||||
}, ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,13 @@ declare(strict_types=1);
|
||||
namespace Yansongda\Pay\Plugin\Wechat;
|
||||
|
||||
use Closure;
|
||||
use GuzzleHttp\Psr7\Utils;
|
||||
use Yansongda\Pay\Contract\PluginInterface;
|
||||
use Yansongda\Pay\Exception\InvalidConfigException;
|
||||
use Yansongda\Pay\Exception\InvalidParamsException;
|
||||
use Yansongda\Pay\Logger;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Collection;
|
||||
use Yansongda\Supports\Str;
|
||||
|
||||
class SignPlugin implements PluginInterface
|
||||
@ -21,26 +23,21 @@ class SignPlugin implements PluginInterface
|
||||
{
|
||||
Logger::info('[wechat][SignPlugin] 插件开始装载', ['rocket' => $rocket]);
|
||||
|
||||
$this->filterPayload($rocket);
|
||||
$body = $this->payloadToString($rocket->getPayload());
|
||||
$radar = $rocket->getRadar()
|
||||
->withAddedHeader('Authorization', $this->getAuthorization($rocket));
|
||||
|
||||
$rocket->setRadar($rocket->getRadar()
|
||||
->withAddedHeader('Authorization', $this->getAuthorization($rocket))
|
||||
);
|
||||
if (!empty($body)) {
|
||||
$radar->withBody(Utils::streamFor($body));
|
||||
}
|
||||
|
||||
$rocket->setRadar($radar);
|
||||
|
||||
Logger::info('[wechat][SignPlugin] 插件装载完毕', ['rocket' => $rocket]);
|
||||
|
||||
return $next($rocket);
|
||||
}
|
||||
|
||||
protected function filterPayload(Rocket $rocket): void
|
||||
{
|
||||
$payload = $rocket->getPayload()->filter(function ($v, $k) {
|
||||
return !Str::startsWith(strval($k), '_');
|
||||
});
|
||||
|
||||
$rocket->setPayload($payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
@ -83,7 +80,7 @@ class SignPlugin implements PluginInterface
|
||||
$uri->getPath().(empty($uri->getQuery()) ? '' : '?'.$uri->getQuery()).'\n'.
|
||||
$timestamp.'\n'.
|
||||
$random.'\n'.
|
||||
$request->getBody()->getContents().'\n';
|
||||
$this->payloadToString($rocket->getPayload()).'\n';
|
||||
|
||||
$privateKey = $this->getPrivateKey($rocket->getParams());
|
||||
|
||||
@ -133,4 +130,9 @@ class SignPlugin implements PluginInterface
|
||||
|
||||
return $ssl['serialNumberHex'];
|
||||
}
|
||||
|
||||
protected function payloadToString(?Collection $payload): string
|
||||
{
|
||||
return (is_null($payload) || 0 === $payload->count()) ? '' : $payload->toJson();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user