mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 11:20:53 +08:00
feat: enhance plugin management
- Add command support for plugin management - Optimize plugin management page layout - Add email copy functionality for users - Convert payment methods and Telegram Bot to plugin system
This commit is contained in:
100
plugins/Epay/Plugin.php
Normal file
100
plugins/Epay/Plugin.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
namespace Plugin\Epay;
|
||||
|
||||
use App\Services\Plugin\AbstractPlugin;
|
||||
use App\Contracts\PaymentInterface;
|
||||
|
||||
class Plugin extends AbstractPlugin implements PaymentInterface
|
||||
{
|
||||
public function boot(): void
|
||||
{
|
||||
$this->filter('available_payment_methods', function ($methods) {
|
||||
if ($this->getConfig('enabled', true)) {
|
||||
$methods['EPay'] = [
|
||||
'name' => $this->getConfig('display_name', '易支付'),
|
||||
'icon' => $this->getConfig('icon', '💳'),
|
||||
'plugin_code' => $this->getPluginCode(),
|
||||
'type' => 'plugin'
|
||||
];
|
||||
}
|
||||
return $methods;
|
||||
});
|
||||
}
|
||||
|
||||
public function form(): array
|
||||
{
|
||||
return [
|
||||
'url' => [
|
||||
'label' => '支付网关地址',
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'description' => '请填写完整的支付网关地址,包括协议(http或https)'
|
||||
],
|
||||
'pid' => [
|
||||
'label' => '商户ID',
|
||||
'type' => 'string',
|
||||
'description' => '请填写商户ID',
|
||||
'required' => true
|
||||
],
|
||||
'key' => [
|
||||
'label' => '通信密钥',
|
||||
'type' => 'string',
|
||||
'required' => true,
|
||||
'description' => '请填写通信密钥'
|
||||
],
|
||||
'type' => [
|
||||
'label' => '支付类型',
|
||||
'type' => 'select',
|
||||
'options' => [
|
||||
['value' => 'alipay', 'label' => '支付宝'],
|
||||
['value' => 'wxpay', 'label' => '微信支付'],
|
||||
['value' => 'qqpay', 'label' => 'QQ钱包']
|
||||
]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function pay($order): array
|
||||
{
|
||||
$params = [
|
||||
'money' => $order['total_amount'] / 100,
|
||||
'name' => $order['trade_no'],
|
||||
'notify_url' => $order['notify_url'],
|
||||
'return_url' => $order['return_url'],
|
||||
'out_trade_no' => $order['trade_no'],
|
||||
'pid' => $this->getConfig('pid')
|
||||
];
|
||||
|
||||
if ($paymentType = $this->getConfig('type')) {
|
||||
$params['type'] = $paymentType;
|
||||
}
|
||||
|
||||
ksort($params);
|
||||
$str = stripslashes(urldecode(http_build_query($params))) . $this->getConfig('key');
|
||||
$params['sign'] = md5($str);
|
||||
$params['sign_type'] = 'MD5';
|
||||
|
||||
return [
|
||||
'type' => 1,
|
||||
'data' => $this->getConfig('url') . '/submit.php?' . http_build_query($params)
|
||||
];
|
||||
}
|
||||
|
||||
public function notify($params): array|bool
|
||||
{
|
||||
$sign = $params['sign'];
|
||||
unset($params['sign'], $params['sign_type']);
|
||||
ksort($params);
|
||||
$str = stripslashes(urldecode(http_build_query($params))) . $this->getConfig('key');
|
||||
|
||||
if ($sign !== md5($str)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return [
|
||||
'trade_no' => $params['out_trade_no'],
|
||||
'callback_no' => $params['trade_no']
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user