TelegramService.java 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. package com.cyksj.service.telegram;
  2. import cn.hutool.http.HttpUtil;
  3. import com.cyksj.common.util.Jsons;
  4. import com.cyksj.dto.RedisKey;
  5. import com.cyksj.model.request.TelegramBotMsgReq;
  6. import com.cyksj.redis.RedisService;
  7. import lombok.RequiredArgsConstructor;
  8. import lombok.extern.slf4j.Slf4j;
  9. import org.springframework.stereotype.Service;
  10. /**
  11. * @author chan
  12. * @date 2023/9/12 14:17
  13. */
  14. @Service
  15. @RequiredArgsConstructor
  16. @Slf4j
  17. public class TelegramService {
  18. private final String URL = "https://yinhedvd.com/8082/api/movies/sendMsg";
  19. private final RedisService redisService;
  20. public void sendMsg(TelegramBotMsgReq botMsg) throws Exception {
  21. Boolean flag = redisService.hasKey(RedisKey.TELEGRAM_BOT_MSG);
  22. if(!flag){
  23. log.info("电报购买推送 推送内容:{}",botMsg);
  24. HttpUtil.post(URL, Jsons.toJson(botMsg));
  25. redisService.set(RedisKey.TELEGRAM_BOT_MSG,1,60L*3L);
  26. }else {
  27. log.info("推送未间隔2分钟,暂不推送.");
  28. }
  29. }
  30. }