$chat_id = "123456789";
$token = "1212124545:AAF0kLKEDSIgJSgjSA3qSIyA8RDSDPuFFDF";
$address = "TNWkwmdDa5Sz3D1qMUDyu1xmSDD73oDDNS";
$interval = 60; #每60秒查询一下 过去的60秒内是否有新的交易
$chat_id = isset($_GET['chat_id'])?$_GET['chat_id']:$chat_id;
$token = isset($_GET['token'])?$_GET['token']:$token;
$address = isset($_GET['address'])?$_GET['address']:$address;
$interval = isset($_GET['interval'])?$_GET['interval']:$interval;
function checkBalance($address,$interval) {
$response = file_get_contents("https://api.trongrid.io/v1/accounts/{$address}/transactions/trc20? min_timestamp=".((time()-$interval)*1000));
$data = json_decode($response, true);
return $data;
}
// 定义一个函数来发送通知
function sendNotification($token, $chat_id, $msg) {
$message = urlencode($msg);
$res = file_get_contents("https://api.telegram.org/bot{$token}/sendMessage?chat_id={$chat_id}&text={$message}");
echo $res;
}
$data = checkBalance($address,$interval);
if(count($data['data'])>0){
foreach ($data['data'] as $d){
$msg = "交易哈希值:".$d['transaction_id'];
$msg .= "\n发送地址:".$d['from'];
$msg .= "\n接收地址:".$d['to'];
$msg .= "\n金额数量:".($d['value']/1000000)." ".$d['token_info']['symbol'];
$msg .= "\n交易时间:".date("Y-m-d H:i:s",$d['block_timestamp']/1000);
sendNotification($token, $chat_id, $msg);
}
}else{
echo json_encode($data);
}
使用方法:
创建一个网页 复制代码 将参数修改成自己的信息
然后创建一个循环任务 每分钟访问一次网页 即可将一分钟内的交易情况 发给我们