需求来源
当我们再日常工作中,需要每日定时的发送群消息,时间太早的话不想起来,想着可以用java显示定时发送消息的任务.在睡梦中让程序帮我们定时发送消息
功能介绍
定时生日祝福、每日早安、晚安问候
- 检测微信是否再后台运行
- 指定每天多个时间段发送可配置的消息
- 发送图片
- 每个时间段给多个人发送多个消息
- 设置间隔时间(如:两天发一次,一天发一次,每秒发一次)
代码如下
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.datatransfer.*;
import java.awt.event.KeyEvent;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.List;
import java.util.*;
/**
* @Author: xu
* @Description: 开启定时任务,指定时间,间隔给微信好友发送文本或图片
* @Date: 2021/12/20 20:28
*/
public class TimerTask {
// 设置定时任务区间,每隔一天发一次
private static final Long SECTION = (long) (24 * 60 * 60 * 1000);
public static void main(String[] args) throws Exception {
System.out.println("任务执行时间,请保证微信在登录状态并为最小化...");
int weChat = queryProcessCount("WeChat");
if (weChat<=0){
System.err.println("请登陆微信后再尝试运行");
return;
}
int year = LocalDateTime.now().getYear();
int month = LocalDateTime.now().getMonthValue();
int day = LocalDateTime.now().getDayOfMonth(); //任务默认从今天开始
List<String> resource = getResouce();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 遍历某个时间段需要做的事情
for (String todo : resource) {
String[] item = todo.split(" ");
String formatData = year+"-"+month+"-"+day+" "+item[0]+":00";
Date firstData = simpleDateFormat.parse(formatData);
List<Map<String,String>> sendData = new ArrayList<>();
String[] sends = todo.split(";");
int i = 0;
for (String send : sends) {
Map<String,

最低0.47元/天 解锁文章
2979

被折叠的 条评论
为什么被折叠?



