Files
Xboard/plugins/Epay/Plugin.php
xboard 58868268dd 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
2025-07-26 18:49:58 +08:00

100 lines
3.0 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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']
];
}
}