|
|
|
@@ -20,6 +20,9 @@ import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
/** |
|
|
|
* @author gongbiao |
|
|
|
*/ |
|
|
|
@Component |
|
|
|
public class MsgSendingSchedule { |
|
|
|
|
|
|
|
@@ -31,26 +34,25 @@ public class MsgSendingSchedule { |
|
|
|
@Autowired |
|
|
|
private WxMsgConfigMapper wxMsgConfigMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private PushLimitService pushLimitService; |
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0 46 * * * ?") // 每小时第一分钟执行 |
|
|
|
/** |
|
|
|
* 每小时第一分钟执行 |
|
|
|
*/ |
|
|
|
@Scheduled(cron = "0 1 * * * ?") |
|
|
|
public void sendmsgschedule() { |
|
|
|
logger.info("sendmsg定时任务启动"); |
|
|
|
String systemTime = DateUtils.getSystemTime("yyyy-MM-dd 14:00:00"); |
|
|
|
String systemTime = DateUtils.getSystemTime("yyyy-MM-dd HH:00:00"); |
|
|
|
WxMsg wxMsg = new WxMsg(); |
|
|
|
wxMsg.setIsright(0); |
|
|
|
wxMsg.setSendtime(systemTime); |
|
|
|
List<WxMsg> list = wxMsgMapper.findList(wxMsg); |
|
|
|
logger.info("将要发送的短信列表:" + JSONArray.toJSONString(list)); |
|
|
|
for(WxMsg msg:list){ |
|
|
|
for (WxMsg msg : list) { |
|
|
|
sendmsg(msg); |
|
|
|
} |
|
|
|
logger.info("sendmsg定时任务结束"); |
|
|
|
} |
|
|
|
|
|
|
|
public void sendmsg(WxMsg wxMsg){ |
|
|
|
public void sendmsg(WxMsg wxMsg) { |
|
|
|
logger.info("发送短信开始----------"); |
|
|
|
//从短信配置中查询密钥 bid 等信息 |
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
@@ -61,11 +63,11 @@ public class MsgSendingSchedule { |
|
|
|
return; |
|
|
|
} |
|
|
|
wxMsgConfig = wxMsgConfigs.get(0); |
|
|
|
if(wxMsgConfig.getRemains()==0){ |
|
|
|
if (wxMsgConfig.getRemains() == 0) { |
|
|
|
logger.info("短信数量为0"); |
|
|
|
return; |
|
|
|
} |
|
|
|
if(wxMsgConfig.getRemains()<wxMsg.getExpectSendNumber()){ |
|
|
|
if (wxMsgConfig.getRemains() < wxMsg.getExpectSendNumber()) { |
|
|
|
logger.info("短信数量不足"); |
|
|
|
return; |
|
|
|
} |
|
|
|
@@ -76,7 +78,7 @@ public class MsgSendingSchedule { |
|
|
|
String signature = wxMsg.getSignature(); |
|
|
|
String msg = wxMsg.getMsg(); |
|
|
|
String notifyUrl = wxMsgConfig.getNotifyurl(); |
|
|
|
String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl,EnumVerifyCode.NO.getCode().toString()); |
|
|
|
String result = WiwideUtil.sendMsg(secret, bid, publickey, phone, signature, msg, notifyUrl, EnumVerifyCode.NO.getCode().toString()); |
|
|
|
logger.info("短信返回结果:" + result); |
|
|
|
JSONObject jsonObjectResult = JSONObject.parseObject(result); |
|
|
|
String ret = jsonObjectResult.get("ret").toString(); |
|
|
|
|