mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
70 lines
1.8 KiB
PHP
70 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Payments;
|
|
|
|
class EPay {
|
|
public function __construct($config)
|
|
{
|
|
$this->config = $config;
|
|
}
|
|
|
|
public function form()
|
|
{
|
|
return [
|
|
'url' => [
|
|
'label' => 'URL',
|
|
'description' => '',
|
|
'type' => 'input',
|
|
],
|
|
'pid' => [
|
|
'label' => 'PID',
|
|
'description' => '',
|
|
'type' => 'input',
|
|
],
|
|
'key' => [
|
|
'label' => 'KEY',
|
|
'description' => '',
|
|
'type' => 'input',
|
|
]
|
|
];
|
|
}
|
|
|
|
public function pay($order)
|
|
{
|
|
$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->config['pid']
|
|
];
|
|
ksort($params);
|
|
reset($params);
|
|
$str = stripslashes(urldecode(http_build_query($params))) . $this->config['key'];
|
|
$params['sign'] = md5($str);
|
|
$params['sign_type'] = 'MD5';
|
|
return [
|
|
'type' => 1, // 0:qrcode 1:url
|
|
'data' => $this->config['url'] . '/submit.php?' . http_build_query($params)
|
|
];
|
|
}
|
|
|
|
public function notify($params)
|
|
{
|
|
$sign = $params['sign'];
|
|
unset($params['sign']);
|
|
unset($params['sign_type']);
|
|
ksort($params);
|
|
reset($params);
|
|
$str = stripslashes(urldecode(http_build_query($params))) . $this->config['key'];
|
|
if ($sign !== md5($str)) {
|
|
return false;
|
|
}
|
|
return [
|
|
'trade_no' => $params['out_trade_no'],
|
|
'callback_no' => $params['trade_no']
|
|
];
|
|
}
|
|
}
|