实现能量兑换,trx兑换,联系客服,欢迎语Command

pull/520/head
dorion 2024-05-02 15:57:42 +08:00
parent 0cb2018931
commit f6d6b7b198
11 changed files with 204 additions and 55 deletions

View File

@ -147,7 +147,7 @@
</plugin> -->
</plugins>
<finalName>${project.artifactId}</finalName>
<!-- <resources>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
@ -155,7 +155,7 @@
<exclude>*.xml</exclude>
</excludes>
</resource>
</resources>-->
</resources>
</build>

View File

@ -4,14 +4,13 @@ import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.vo.TronInfoVO;
import com.ruoyi.system.service.IApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api")
@CrossOrigin
//@CrossOrigin
public class ApiController {
@Autowired
@ -19,6 +18,7 @@ public class ApiController {
/**
*
*
* @return
*/
@GetMapping("/tronInfo")

View File

@ -105,7 +105,10 @@
},
{
field: 'fromAddress',
title: '交易账户'
title: '交易账户',
formatter:function(value, row, index) {
return "<a href='https://www.oklink.com/zh-hans/trx/address/"+value+"' target='_blank'>" + value + "</a>";
}
},
{
field: 'toAddress',

View File

@ -80,11 +80,14 @@
},
{
field: 'fromAddress',
title: '转入地址'
title: '交易地址',
formatter:function(value, row, index) {
return "<a href='https://www.oklink.com/zh-hans/trx/address/"+value+"' target='_blank'>" + value + "</a>";
}
},
{
field: 'toAddress',
title: '转地址'
title: '转地址'
},
{
field: 'usdtTxId',

View File

@ -13,8 +13,8 @@ import java.util.List;
public class CustomBotCommands {
public void setCustomBotCommands(AbsSender sender) throws TelegramApiException {
List<BotCommand> commands = Arrays.asList(
new BotCommand("/start", "开始使用"),
new BotCommand("/rank", "汇率信息")
new BotCommand("/start", "开始使用")
// new BotCommand("/rank", "汇率信息")
/* new BotCommand("/ban", "!或/ban user 时间(可选) 原因(可选)"),
new BotCommand("/dban","可Ban掉用户的同时删除他的发言格式参考Ban"),
new BotCommand("/unban", "解封用户,!或/unban user"),

View File

@ -1,26 +1,27 @@
package com.ruoyi.system.bot;
import com.ruoyi.system.bot.handleService.NewMemberIntoGroup;
import com.ruoyi.system.bot.handle.NewMemberIntoGroup;
import com.ruoyi.system.bot.handle.UserChatHandle;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
@Component
@Slf4j
public class CustomBotFunction {
@Autowired
private NewMemberIntoGroup newMemberIntoGroup;
@Autowired
private UserChatHandle userChatHandle;
/**
@ -31,40 +32,36 @@ public class CustomBotFunction {
*/
public void mainFunc(AbsSender sender, Update update) throws TelegramApiException, IOException, NoSuchAlgorithmException, InvalidKeyException {
//
// if (update.getChatMember() != null && "left".equals(update.getChatMember().getOldChatMember().getStatus())
// && "member".equals(update.getChatMember().getNewChatMember().getStatus()) &&
// (update.getChatMember().getChat().isGroupChat() || update.getChatMember().getChat().isSuperGroupChat())) {
//
// newMemberIntoGroup.handleMessage(sender, update);
//
// return;
// }
if (update.getChatMember() != null && "left".equals(update.getChatMember().getOldChatMember().getStatus())
&& "member".equals(update.getChatMember().getNewChatMember().getStatus()) &&
(update.getChatMember().getChat().isGroupChat() || update.getChatMember().getChat().isSuperGroupChat())) {
newMemberIntoGroup.handleMessage(sender, update);
return;
if (update.hasMessage() && update.getMessage().hasText()) {
Chat chat = update.getMessage().getChat();
if (chat != null) {
if (chat.isGroupChat() || chat.isSuperGroupChat()) {
log.info("收到群组消息了:{},群组id:{}",update.getMessage().getText(),update.getMessage().getChatId());
// 收到的是群组内的消息
// 在这里处理群组内的消息
} else if (chat.isChannelChat()){
//频道的消息
log.info("收到频道消息了:{}",update.getMessage().getText());
}else {
log.info("收到用户消息了:{}",update.getMessage().getText());
// 收到的是私发给机器人的消息
// 在这里处理私发给机器人的消息
userChatHandle.doHandle(sender, update);
}
}
}else{
log.info("收到消息了1:{}",update.getEditedMessage().getText());
}
if ("/start".equals(update.getMessage().getText())) {
SendMessage message = new SendMessage();
message.setChatId(update.getMessage().getChatId().toString());
message.setText("Please select an option:");
// 创建一个 ReplyKeyboardMarkup 对象,用于存储按钮
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
List<KeyboardRow> keyboard = new ArrayList<>();
// 创建一个按钮行
KeyboardRow row = new KeyboardRow();
row.add("Option 1");
row.add("Option 2");
keyboard.add(row);
// 将按钮行添加到 ReplyKeyboardMarkup 对象中
keyboardMarkup.setKeyboard(keyboard);
message.setReplyMarkup(keyboardMarkup);
// 设置按钮显示在输入框底部
keyboardMarkup.setResizeKeyboard(true);
sender.execute(message);
}
}
}

View File

@ -55,11 +55,9 @@ public class TgLongPollingBot extends TelegramLongPollingBot {
@Override
@SneakyThrows
public void onUpdateReceived(Update update) {
// log.info("消息:{}",update.getMessage().getText());
// SendMessage sendMessage = SendMessage.builder().chatId(update.getMessage().getChatId().toString()).text("收到消息:"+update.getMessage().getChatId().toString()).build();
try {
customBotFunction.mainFunc(this,update);
// execute(sendMessage);
} catch (TelegramApiException e) {
log.error("ex:{}",e);

View File

@ -1,4 +1,4 @@
package com.ruoyi.system.bot.handleService;
package com.ruoyi.system.bot.handle;
import com.ruoyi.system.bot.utils.SendContent;
import com.ruoyi.system.handler.Usdt2TrxTransferHandler;

View File

@ -0,0 +1,110 @@
package com.ruoyi.system.bot.handle;
import com.ruoyi.system.bot.utils.SendContent;
import com.ruoyi.system.handler.Usdt2TrxTransferHandler;
import com.ruoyi.system.service.ISysConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import java.io.IOException;
import java.math.BigDecimal;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Component
@Slf4j
public class UserChatHandle {
@Autowired
private SendContent sendContent;
@Autowired
private ISysConfigService configService;
@Autowired
private Usdt2TrxTransferHandler usdt2TrxTransferHandler;
public void doHandle(AbsSender sender, Update update) throws TelegramApiException, NoSuchAlgorithmException, IOException, InvalidKeyException {
String text = update.getMessage().getText();
if ("/start".equals(text)) {
startCommandMessage(sender, update);
} else if ("\uD83E\uDDE9TRX兑换".equals(text)) {
String configValue = configService.selectConfigByKey("sys.usdt.group.topic");
configValue = StringUtils.isEmpty(configValue) ? "configKey is null" : configValue;
String message = "";
if (StringUtils.isNotEmpty(configValue)){
BigDecimal tenUsdtToTrx = usdt2TrxTransferHandler.getOneUsdtToTrx().multiply(BigDecimal.TEN);
Map<String, Object> arguments = new HashMap<>();
arguments.put("tenUsdtToTrx", tenUsdtToTrx);
StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}");
message = substitutor.replace(configValue);
}
SendMessage sendMessage = sendContent.messageText(update.getMessage().getChatId().toString(), message, ParseMode.MARKDOWN);
sender.execute(sendMessage);
} else if ("⏳能量闪租".equals(text)) {
SendMessage message = getSendMessage(update, "sys.energy.notice");
sender.execute(message);
} else if ("\uD83D\uDC69\u200D\uD83C\uDFED联系客服".equals(text)) {
SendMessage message = getSendMessage(update, "sys.customer.service.notice");
message.setReplyToMessageId(update.getMessage().getMessageId());
sender.execute(message);
} else {
log.info("收到消息了:{}", text);
SendMessage message = sendContent.messageText(update.getMessage().getChatId().toString(), "收到消息了:" + text, ParseMode.MARKDOWN);
sender.execute(message);
}
}
private SendMessage getSendMessage(Update update, String configKey) {
String configValue = configService.selectConfigByKey(configKey);
configValue = StringUtils.isEmpty(configValue) ? "configKey is null" : configValue;
SendMessage message = sendContent.messageText(update.getMessage().getChatId().toString(), configValue, ParseMode.MARKDOWN);
return message;
}
private void startCommandMessage(AbsSender sender, Update update) throws TelegramApiException {
// 创建一个 ReplyKeyboardMarkup 对象,用于存储按钮
ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup();
List<KeyboardRow> keyboard = new ArrayList<>();
// 创建一个按钮行
KeyboardRow row = new KeyboardRow();
row.add("\uD83E\uDDE9TRX兑换");
row.add("⏳能量闪租");
row.add("\uD83D\uDC69\u200D\uD83C\uDFED联系客服");
keyboard.add(row);
// 将按钮行添加到 ReplyKeyboardMarkup 对象中
keyboardMarkup.setKeyboard(keyboard);
keyboardMarkup.setResizeKeyboard(true);
// 设置按钮显示在输入框底部
// SendMessage message = new SendMessage();
// message.setChatId(update.getMessage().getChatId().toString());
// message.setText("Please select an option:");
// message.setParseMode(ParseMode.MARKDOWN);
// message.setReplyMarkup(keyboardMarkup);
SendMessage message = getSendMessage(update, "sys.start.notice");
message.setReplyMarkup(keyboardMarkup);
sender.execute(message);
}
}

View File

@ -11,8 +11,11 @@ import com.ruoyi.common.core.domain.entity.TrxExchangeInfo;
import com.ruoyi.common.utils.DictUtils;
import com.ruoyi.common.utils.ForwardCounter;
import com.ruoyi.common.utils.LogUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.encrpt.Dt;
import com.ruoyi.common.utils.http.RestTemplateUtils;
import com.ruoyi.system.bot.TgLongPollingBot;
import com.ruoyi.system.bot.utils.SendContent;
import com.ruoyi.system.domain.MonitorAddressAccount;
import com.ruoyi.system.dto.Contract;
import com.ruoyi.system.dto.Data;
@ -21,10 +24,10 @@ import com.ruoyi.system.dto.Value;
import com.ruoyi.system.mapper.ErrorLogMapper;
import com.ruoyi.system.mapper.TenantInfoMapper;
import com.ruoyi.system.mapper.TrxExchangeInfoMapper;
import com.ruoyi.system.service.IAccountAddressInfoService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.util.AddressUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.text.StrSubstitutor;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
@ -35,6 +38,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.util.UriComponentsBuilder;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.tron.trident.core.ApiWrapper;
import org.tron.trident.core.exceptions.IllegalException;
import org.tron.trident.proto.Chain;
@ -43,7 +48,9 @@ import org.tron.trident.proto.Response;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@Component
@ -52,8 +59,8 @@ public class TRX2EneryTransferHandler {
@Autowired
private ISysConfigService configService;
@Autowired
private IAccountAddressInfoService accountAddressInfoService;
@Autowired(required = false)
private TgLongPollingBot longPollingBot;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
@ -64,6 +71,8 @@ public class TRX2EneryTransferHandler {
private TenantInfoMapper tenantInfoMapper;
@Autowired
private TrxExchangeInfoMapper trxExchangeInfoMapper;
@Autowired
private SendContent sendContent;
public void doMonitorTrxTransferByMonitorAddressInfo(MonitorAddressAccount monitorAddressAccount) {
@ -338,8 +347,9 @@ public class TRX2EneryTransferHandler {
delegateResourceTxid = getDelegateResourceTxid(apiWrapper, accountAddress, balance, ownerAddress, lockPeriod);
}
String fromAddress = AddressUtil.hexToBase58(ownerAddress);
TrxExchangeInfo trxExchangeInfo = TrxExchangeInfo.builder()
.fromAddress(AddressUtil.hexToBase58(ownerAddress))
.fromAddress(fromAddress)
.toAddress(AddressUtil.hexToBase58(toAddress))
.accountAddress(accountAddress)
.price(price)
@ -357,6 +367,34 @@ public class TRX2EneryTransferHandler {
.lcu(currentUser)
.build();
trxExchangeInfoMapper.insertTrxExchangeInfo(trxExchangeInfo);
String sysenTrxTransferNotice = configService.selectConfigByKey("sys.energy.transaction.notice");
String sysTgGroupChatId = configService.selectConfigByKey("sys.tg.group.chat.id");
if (longPollingBot != null && StringUtils.isNotEmpty(sysenTrxTransferNotice) && StringUtils.isNotEmpty(sysTgGroupChatId)) {
/*
* TRX{trxAmount}
: {price}
: {transferCount}
{FromAddress}
{txId}
{txTime}
* */
Map<String, Object> arguments = new HashMap<>();
arguments.put("trxAmount", amount == null ? "" : amount.toString());
arguments.put("price", price == null ? "" : price.toString());
arguments.put("transferCount", transferCount);
arguments.put("FromAddress", fromAddress.replaceAll("(.{6})(.*)(.{8})", "$1********$3"));
arguments.put("txId", StringUtils.isEmpty(txID) ? "" : txID.replaceAll("(.{6})(.*)(.{8})", "$1*******************$3"));
arguments.put("txTime", DateUtil.format(new Date(),"yyyy-MM-dd HH:mm:ss"));
// String message = MessageFormat.format(sysUsdtTranferNotice, arguments);
StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}");
String message = substitutor.replace(sysenTrxTransferNotice);
SendMessage sendMessage = sendContent.messageText(sysTgGroupChatId, message, ParseMode.HTML);
longPollingBot.execute(sendMessage);
} else {
log.warn("longPollingBot OR sysUsdtTranferNotice OR sysTgGroupChatId is null");
}
}

View File

@ -213,7 +213,7 @@ public class Usdt2TrxTransferHandler {
// String message = MessageFormat.format(sysUsdtTranferNotice, arguments);
StrSubstitutor substitutor = new StrSubstitutor(arguments, "{", "}");
String message = substitutor.replace(sysUsdtTranferNotice);
SendMessage sendMessage = sendContent.messageText(sysTgGroupChatId, message, ParseMode.MARKDOWN);
SendMessage sendMessage = sendContent.messageText(sysTgGroupChatId, message, ParseMode.HTML);
longPollingBot.execute(sendMessage);
} else {
log.warn("longPollingBot OR sysUsdtTranferNotice OR sysTgGroupChatId is null");