mirror of
http://124.126.16.154:8888/singularity/hdk-pay.git
synced 2026-01-15 05:35:08 +08:00
perf(callback): 增加了共用的通知业务系统的方法
This commit is contained in:
@@ -21,6 +21,8 @@ use Singularity\HDK\Core\Http\RequestServiceFactory;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
use Singularity\HDK\Pay\Resource\StripeConfiguration;
|
||||
|
||||
use Singularity\HDK\Pay\Trait\WebhooksNotificationHandler;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
/**
|
||||
@@ -32,6 +34,8 @@ use function Hyperf\Config\config;
|
||||
*/
|
||||
final class StripeRpc
|
||||
{
|
||||
use WebhooksNotificationHandler;
|
||||
|
||||
private RequestService $requestService;
|
||||
|
||||
public function __construct(?string $baseUrl = null)
|
||||
@@ -75,10 +79,13 @@ final class StripeRpc
|
||||
'amount' => $money->getAmount(),
|
||||
'currency' => $money->getCurrency(),
|
||||
'uid' => $uid,
|
||||
'goodsDetail' => array_replace($goodsDetail, [
|
||||
'id' => $goodsId,
|
||||
'goodsName' => $goodsName,
|
||||
]),
|
||||
'goodsDetail' => array_replace(
|
||||
$goodsDetail,
|
||||
[
|
||||
'id' => $goodsId,
|
||||
'goodsName' => $goodsName,
|
||||
]
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -86,9 +93,4 @@ final class StripeRpc
|
||||
$order = Json::decode($content);
|
||||
return Order::make($order);
|
||||
}
|
||||
|
||||
public function callback(RequestInterface $request): Order
|
||||
{
|
||||
return Order::make($request->post());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* WechatRpc.php@Pay
|
||||
@@ -11,15 +12,14 @@ declare(strict_types=1);
|
||||
namespace Singularity\HDK\Pay\Sdk;
|
||||
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use GuzzleHttp\RequestOptions;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Lmc\HttpConstants\Header;
|
||||
use Money\Money;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
use Singularity\HDK\Core\Http\RequestService;
|
||||
|
||||
use Singularity\HDK\Core\Http\RequestServiceFactory;
|
||||
use Singularity\HDK\Pay\Trait\WebhooksNotificationHandler;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
@@ -32,14 +32,16 @@ use function Hyperf\Config\config;
|
||||
*/
|
||||
final class WechatRpc
|
||||
{
|
||||
private RequestService $requestService;
|
||||
use WebhooksNotificationHandler;
|
||||
|
||||
private string $baseUrl;
|
||||
private RequestService $requestService;
|
||||
|
||||
public function __construct(?string $baseUrl = null)
|
||||
{
|
||||
$this->requestService = RequestServiceFactory::make();
|
||||
$this->baseUrl = $baseUrl ?? config('payment.base_uri');
|
||||
$this->requestService = RequestServiceFactory::make([
|
||||
'base_uri' => $baseUrl ?? config('payment.base_uri'),
|
||||
RequestOptions::ALLOW_REDIRECTS => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,23 +60,24 @@ final class WechatRpc
|
||||
Money $money,
|
||||
string $uid
|
||||
): array {
|
||||
$url = $this->baseUrl . '/rpc/v1/wechat/qrcode';
|
||||
$data = [
|
||||
'service' => config('payment.sp_id'),
|
||||
'amount' => (int)$money->getAmount(),
|
||||
'fileType' => $type,
|
||||
'uid' => $uid,
|
||||
'goods_detail' => [
|
||||
'goods_name' => $goodsName,
|
||||
],
|
||||
];
|
||||
$response = $this->requestService
|
||||
->setOptions([
|
||||
'headers' => [
|
||||
Header::ACCEPT => $request->getHeader(Header::ACCEPT),
|
||||
],
|
||||
])
|
||||
->requestPost($url, $data);
|
||||
->requestPost(
|
||||
url: '/rpc/v1/wechat/qrcode',
|
||||
data: [
|
||||
'service' => config('payment.sp_id'),
|
||||
'amount' => (int)$money->getAmount(),
|
||||
'fileType' => $type,
|
||||
'uid' => $uid,
|
||||
'goods_detail' => [
|
||||
'goods_name' => $goodsName,
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
$content = $response->getBody()->getContents();
|
||||
return Json::decode($content);
|
||||
|
||||
28
src/Trait/WebhooksNotificationHandler.php
Normal file
28
src/Trait/WebhooksNotificationHandler.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* Webhooks.php@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/22
|
||||
*/
|
||||
|
||||
namespace Singularity\HDK\Pay\Trait;
|
||||
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Singularity\HDK\Pay\Resource\Order;
|
||||
|
||||
/**
|
||||
* Singularity\HDK\Pay\Trait\Webhooks@Pay
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2023/9/22
|
||||
*/
|
||||
trait WebhooksNotificationHandler
|
||||
{
|
||||
public function callback(RequestInterface $request): Order
|
||||
{
|
||||
return Order::make($request->post());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user