This commit is contained in:
22
app/Service/Test/Adapter/CacheService.php
Normal file
22
app/Service/Test/Adapter/CacheService.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Adapter;
|
||||
|
||||
use App\Service\Test\TestBaseService;
|
||||
|
||||
class CacheService extends TestBaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
//todo Write logic
|
||||
}
|
||||
}
|
||||
36
app/Service/Test/Adapter/Pay/AlipayAdapter.php
Normal file
36
app/Service/Test/Adapter/Pay/AlipayAdapter.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Adapter\Pay;
|
||||
|
||||
use App\Interface\Test\Adapter\PaymentGateway;
|
||||
|
||||
class AlipayAdapter implements PaymentGateway
|
||||
{
|
||||
/**
|
||||
* @var AlipayService
|
||||
*/
|
||||
private AlipayService $alipay;
|
||||
|
||||
public function __construct(AlipayService $alipay)
|
||||
{
|
||||
$this->alipay = $alipay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
* @return array
|
||||
*/
|
||||
public function pay(float $amount): array
|
||||
{
|
||||
return $this->alipay->sendPayment($amount);
|
||||
}
|
||||
}
|
||||
27
app/Service/Test/Adapter/Pay/AlipayService.php
Normal file
27
app/Service/Test/Adapter/Pay/AlipayService.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Adapter\Pay;
|
||||
|
||||
class AlipayService
|
||||
{
|
||||
/**
|
||||
* @param float $amount
|
||||
* @return array
|
||||
*/
|
||||
public function sendPayment(float $amount): array
|
||||
{
|
||||
return [
|
||||
'code' => 'success',
|
||||
'amount' => $amount,
|
||||
];
|
||||
}
|
||||
}
|
||||
36
app/Service/Test/Adapter/Pay/WechatPayAdapter.php
Normal file
36
app/Service/Test/Adapter/Pay/WechatPayAdapter.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Adapter\Pay;
|
||||
|
||||
use App\Interface\Test\Adapter\PaymentGateway;
|
||||
|
||||
class WechatPayAdapter implements PaymentGateway
|
||||
{
|
||||
/**
|
||||
* @var WechatPayService
|
||||
*/
|
||||
private WechatPayService $wechatPay;
|
||||
|
||||
public function __construct(WechatPayService $wechatPay)
|
||||
{
|
||||
$this->wechatPay = $wechatPay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $amount
|
||||
* @return array
|
||||
*/
|
||||
public function pay(float $amount): array
|
||||
{
|
||||
return $this->wechatPay->makePayment($amount);
|
||||
}
|
||||
}
|
||||
28
app/Service/Test/Adapter/Pay/WechatPayService.php
Normal file
28
app/Service/Test/Adapter/Pay/WechatPayService.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Adapter\Pay;
|
||||
|
||||
class WechatPayService
|
||||
{
|
||||
/**
|
||||
* @param float $amount
|
||||
* @return array
|
||||
*/
|
||||
public function makePayment(float $amount): array
|
||||
{
|
||||
return [
|
||||
'code' => 'error',
|
||||
'status' => 'fail',
|
||||
'amount' => $amount,
|
||||
];
|
||||
}
|
||||
}
|
||||
39
app/Service/Test/Adapter/PayService.php
Normal file
39
app/Service/Test/Adapter/PayService.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test\Adapter;
|
||||
|
||||
use App\Service\Test\Adapter\Pay\AlipayAdapter;
|
||||
use App\Service\Test\Adapter\Pay\AlipayService;
|
||||
use App\Service\Test\Adapter\Pay\WechatPayAdapter;
|
||||
use App\Service\Test\Adapter\Pay\WechatPayService;
|
||||
use App\Service\Test\TestBaseService;
|
||||
|
||||
class PayService extends TestBaseService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
|
||||
$alipayRes = (new AlipayAdapter(new AlipayService))->pay(100.00);
|
||||
echo 'alipayRes:'. json_encode($alipayRes).PHP_EOL;
|
||||
|
||||
$wechatPay = new WechatPayService();
|
||||
$wechatPayAdapter = new WechatPayAdapter($wechatPay);
|
||||
$wechatPayRes = $wechatPayAdapter->pay(100.00);
|
||||
|
||||
echo 'wechatPayRes:'. json_encode($wechatPayRes).PHP_EOL;
|
||||
|
||||
return $this->return->success('success',[
|
||||
'alipayRes' => $alipayRes,
|
||||
'wechatPayRes' => $wechatPayRes,
|
||||
]);
|
||||
}
|
||||
}
|
||||
22
app/Service/Test/AdapterTestService.php
Normal file
22
app/Service/Test/AdapterTestService.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
* @web_site https://ctexthuang.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Test;
|
||||
|
||||
use App\Service\BaseService;
|
||||
|
||||
class AdapterTestService extends TestBaseService
|
||||
{
|
||||
public function handle(): array
|
||||
{
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
18
app/Service/Test/TestBaseService.php
Normal file
18
app/Service/Test/TestBaseService.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Test;
|
||||
|
||||
use App\Lib\Return\TestReturn;
|
||||
use App\Service\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
abstract class TestBaseService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var TestReturn
|
||||
*/
|
||||
#[Inject]
|
||||
protected TestReturn $return;
|
||||
|
||||
abstract public function handle();
|
||||
}
|
||||
Reference in New Issue
Block a user