定时任务的代码:
import com.google.gson.Gson;
import com.jianke.bid.common.SMSUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 定时器
*/
@Component
@Lazy(value=false)
public class TaskService {
@Autowired
private Gson gson;
/**
*@Description
*/
@Scheduled( cron = "0 0 * * * ?")//网上有cron表达式在线生成器,可定义执行的时间
public void sendSMSMsgTask() {
System.out.println("定时任务执行开始-----------"+ DateFormatUtils.toDateDoDateFormat(new Date()));
//获取短信模版
String messageTemplate = "XXXX";
//发送的手机
String phoneNum
阿里云API定时发送短信(小记)
最新推荐文章于 2024-05-04 01:25:30 发布
本文记录了使用SMSUtils工具在SpringBoot中配置定时器,实现阿里云API定时发送短信的功能。通过代码示例展示了如何集成和设置定时任务。
摘要由CSDN通过智能技术生成