forked from v03413/epay_usdt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usdt_plugin.php
134 lines (111 loc) · 4.73 KB
/
usdt_plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
class usdt_plugin
{
public static $info = [
'name' => 'usdt',
'showname' => 'USDT 收款插件',
'author' => '莫名',
'link' => 'https://qzone.work/codes/741.html',
'types' => ['usdt'],
'inputs' => [
'appid' => [
'name' => 'USDT-TRC20 收款地址',
'type' => 'input',
'note' => '确保地址正确,收款错误无法追回',
],
'appkey' => [
'name' => '交易汇率(CNY)',
'type' => 'input',
'note' => '如果填AUTO则实时获取市场汇率,推荐填AUTO;举例:6.3',
],
'appurl' => [
'name' => '超时时长(秒)',
'type' => 'input',
'note' => '建议20分钟;填:1200',
],
],
'select' => null,
'note' => '',
];
public static function submit()
{
global $channel, $order, $conf, $DB, $cdnpublic;
$valid = (strtotime($order['addtime']) + intval($channel['appurl'])) * 1000;
$address = $channel['appid'];
$rate = self::getRate();
$usdt = round($order['realmoney'] / $rate, 2);
$expire = date('Y-m-d H:i:s', strtotime($order['addtime']) - intval($channel['appurl']));;
$params = [$channel['id'], 0, $expire, $order['trade_no'], $order['money']];
$row = $DB->getRow('select * from pre_order where channel = ? and status = ? and addtime >= ? and trade_no != ? and money = ? order by param desc limit 1', $params);
if ($row) {
$usdt = bcadd($row['param'], 0.01, 2);
}
$DB->exec('update pre_order set param = ? where trade_no = ?', [$usdt, $order['trade_no']]);
ob_clean();
header("application:text/html;charset=UTF-8");
define('PLUGIN_PATH', PLUGIN_ROOT . PAY_PLUGIN . '/');
define('PLUGIN_STATIC', 'https://epay-usdt.pages.dev');
require_once PLUGIN_PATH . '/pay.php';
exit(0);
}
public static function getRate(): float
{
global $channel;
if (isset($channel['appkey']) && $channel['appkey'] > 0) {
return floatval($channel['appkey']);
}
$api = 'https://api.coinmarketcap.com/data-api/v3/cryptocurrency/detail/chart?id=825&range=1H&convertId=2787';
$resp = get_curl($api);
$data = json_decode($resp, true);
$points = $data['data']['points'];
$point = array_pop($points);
return floatval($point['c'][0]);
}
public static function cron(array $channel)
{
global $DB;
$list = self::getTransferInList($channel['appid'], 24);
$addtime = date('Y-m-d H:i:s', time() - intval($channel['appurl']));
$rows = $DB->query('select * from pre_order where channel = ? and status = ? and addtime >= ?', [$channel['id'], 0, $addtime]);
while ($order = $rows->fetch(PDO::FETCH_ASSOC)) {
foreach ($list as $item) {
if ($item['money'] == $order['param'] && $item['time'] >= strtotime($order['addtime'])) {
processNotify($order, $item['trade_id'], $item['buyer']);
echo sprintf("订单回调成功:%s\n", $order['trade_no']);
}
}
}
echo "---[监控执行结束: " . date('Y-m-d H:i:s') . "]---\n";
}
public static function getTransferInList(string $address, int $hour = 3): array
{
$result = [];
$end = time() * 1000;
$start = strtotime("-$hour hour") * 1000;
$params = [
'limit' => 300,
'start' => 0,
'direction' => 'in',
'relatedAddress' => $address,
'start_timestamp' => $start,
'end_timestamp' => $end,
];
$api = "https://apilist.tronscan.org/api/token_trc20/transfers?" . http_build_query($params);
$resp = get_curl($api);
$data = json_decode($resp, true);
if (empty($data)) {
return $result;
}
foreach ($data['token_transfers'] as $transfer) {
if ($transfer['to_address'] == $address && $transfer['finalResult'] == 'SUCCESS') {
$result[] = [
'time' => $transfer['block_ts'] / 1000,
'money' => $transfer['quant'] / 1000000,
'trade_id' => $transfer['transaction_id'],
'buyer' => $transfer['from_address'],
];
}
}
return $result;
}
}