36 lines
1.1 KiB
PHP
36 lines
1.1 KiB
PHP
<?php
|
|
namespace Core\Payment;
|
|
|
|
use App\Models\Setting;
|
|
|
|
/**
|
|
* 支付网关工厂:根据后台「支付设置」构建对应通道
|
|
*/
|
|
class GatewayFactory
|
|
{
|
|
public static function make(string $channel): Gateway
|
|
{
|
|
$s = new Setting();
|
|
$mode = $s->get('pay_mode', 'demo');
|
|
$enabled = $s->get('pay_enabled', '1');
|
|
|
|
if ($channel === 'alipay') {
|
|
return new AlipayGateway([
|
|
'mode' => $mode,
|
|
'enabled' => $enabled,
|
|
'appid' => $s->get('pay_alipay_appid', ''),
|
|
'private_key' => $s->get('pay_alipay_private_key', ''),
|
|
'public_key' => $s->get('pay_alipay_public_key', ''),
|
|
'gateway' => $s->get('pay_alipay_gateway', 'https://openapi.alipay.com/gateway.do'),
|
|
]);
|
|
}
|
|
return new WechatGateway([
|
|
'mode' => $mode,
|
|
'enabled' => $enabled,
|
|
'mchid' => $s->get('pay_wechat_mchid', ''),
|
|
'appid' => $s->get('pay_wechat_appid', ''),
|
|
'key' => $s->get('pay_wechat_key', ''),
|
|
]);
|
|
}
|
|
}
|