diff --git a/ruoyi-admin/pom.xml b/ruoyi-admin/pom.xml index 7b062b0ca..c724f7288 100644 --- a/ruoyi-admin/pom.xml +++ b/ruoyi-admin/pom.xml @@ -147,7 +147,7 @@ --> ${project.artifactId} - + diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java index d0841069d..2db230ad0 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ApiController.java @@ -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") diff --git a/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html b/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html index 0a9f9c7c1..43b73cb3f 100644 --- a/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html +++ b/ruoyi-admin/src/main/resources/templates/trx2Energy/exchange/trx.html @@ -105,7 +105,10 @@ }, { field: 'fromAddress', - title: '交易账户' + title: '交易账户', + formatter:function(value, row, index) { + return "" + value + ""; + } }, { field: 'toAddress', diff --git a/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html b/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html index 9bbda0a0c..778dffb0b 100644 --- a/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html +++ b/ruoyi-admin/src/main/resources/templates/usdt2Trx/exchange/usdt.html @@ -80,11 +80,14 @@ }, { field: 'fromAddress', - title: '转入地址' + title: '交易地址', + formatter:function(value, row, index) { + return "" + value + ""; + } }, { field: 'toAddress', - title: '转出地址' + title: '转入地址' }, { field: 'usdtTxId', diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotCommands.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotCommands.java index fe2308e10..16d49f612 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotCommands.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotCommands.java @@ -13,8 +13,8 @@ import java.util.List; public class CustomBotCommands { public void setCustomBotCommands(AbsSender sender) throws TelegramApiException { List 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"), diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java index fb976bae7..a3da360f9 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/CustomBotFunction.java @@ -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 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); - } } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java index 45f70b464..f4e4f247b 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/TgLongPollingBot.java @@ -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); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java similarity index 98% rename from ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java rename to ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java index 5f700f79a..68fd501d0 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handleService/NewMemberIntoGroup.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/NewMemberIntoGroup.java @@ -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; diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java new file mode 100644 index 000000000..ffa58ae3d --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/bot/handle/UserChatHandle.java @@ -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 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 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); + } + + +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java index 4aa7640a9..d33e2e5ff 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/TRX2EneryTransferHandler.java @@ -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 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"); + } + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java b/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java index 89e79db2c..e28fbf888 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/handler/Usdt2TrxTransferHandler.java @@ -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");