41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
namespace Core\Payment;
|
|
|
|
/**
|
|
* 支付网关抽象基类
|
|
* 子类:AlipayGateway / WechatGateway
|
|
*
|
|
* 两种运行模式:
|
|
* - demo(默认):不接真实商户号,走「模拟支付」流程,整条下单→支付→查询链路可演示。
|
|
* - live:填入商户号与密钥后,构造真实支付请求(支付宝电脑网站支付 / 微信 NATIVE 扫码)。
|
|
*/
|
|
abstract class Gateway
|
|
{
|
|
protected $config = [];
|
|
|
|
public function __construct(array $config)
|
|
{
|
|
$this->config = $config;
|
|
}
|
|
|
|
/** 发起支付,返回渲染数据
|
|
* ['mode'=>'demo','channel'=>?,'simulate'=>url,'config_missing'=>bool]
|
|
* ['mode'=>'redirect','channel'=>'alipay','url'=>?]
|
|
* ['mode'=>'qrcode','channel'=>'wechat','qr'=>?]
|
|
*/
|
|
abstract public function pay(array $order): array;
|
|
|
|
/** 验证异步通知,成功返回订单号,否则返回 null */
|
|
abstract public function verifyNotify(array $data): ?string;
|
|
|
|
protected function isDemo(): bool
|
|
{
|
|
return ($this->config['mode'] ?? 'demo') === 'demo';
|
|
}
|
|
|
|
protected function money($v): string
|
|
{
|
|
return number_format((float) $v, 2, '.', '');
|
|
}
|
|
}
|