java批量发送短信_JAVA实现多线程处理批量发送短信、APP推送

这个博客演示了如何使用JPushClient Java SDK来创建和管理定时任务,包括单个接收者和全体用户的定时消息发送。示例代码详细展示了如何设置消息标题、内容、附加信息以及定时发送的时间,并提供了创建、更新、获取和删除定时任务的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

packagecom.bankhui.center.jpush;importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importorg.apache.shiro.util.CollectionUtils;importorg.slf4j.Logger;importorg.slf4j.LoggerFactory;importcn.jpush.api.JPushClient;importcn.jpush.api.common.TimeUnit;importcn.jpush.api.common.Week;importcn.jpush.api.common.resp.APIConnectionException;importcn.jpush.api.common.resp.APIRequestException;importcn.jpush.api.push.model.Platform;importcn.jpush.api.push.model.PushPayload;importcn.jpush.api.push.model.audience.Audience;importcn.jpush.api.schedule.ScheduleListResult;importcn.jpush.api.schedule.ScheduleResult;importcn.jpush.api.schedule.model.SchedulePayload;importcn.jpush.api.schedule.model.TriggerPayload;public classJPushScheduleClient {protected static final Logger LOG = LoggerFactory.getLogger(JPushScheduleClient.class);private static final String appKey ="*********";private static final String masterSecret = "*******";/** 保存离线的时长。秒为单位。最多支持10天(864000秒)。

* 0 表示该消息不保存离线。即:用户在线马上发出,当前不在线用户将不会收到此消息。

* 此参数不设置则表示默认,默认为保存1天的离线消息(86400秒*/

private static int timeToLive = 60 * 60 * 24;public static voidmain(String[] args) {

List list = new ArrayList();

list.add("22");//testGetScheduleList();//testUpdateSchedule();

String scheduleId = "***************";

String time= "2017-03-07 09:55:00";

String msgTitle= "push schedule jpush,TEST\"\"";

String msgContent= "测试定时发送";

String sysMsgId= "26";

String type= "1";

String url= "https://www.baidu.com";//指定接收者的定时发送

scheduleId =createSingleSchedule(list,time,msgTitle,msgContent,sysMsgId,type,url);//全部用户的定时发送//scheduleId = createSingleSchedule(time,msgTitle,msgContent,sysMsgId,type,url);

testGetSchedule(scheduleId);//testDeleteSchedule(scheduleId);

}/*** 添加指定接收者定时发送消息的

*@paramaliases List 接收者极光id列表

*@paramtime 定时发送时间(yyyy-MM-dd HH:mm:ss)

*@parammsgTitle 标题

*@parammsgContent 内容

*@paramsysMsgId 系统保存的消息id

*@paramtype 跳转类型0不带链接跳转,1带链接跳转

*@paramurl 跳转url

*@return*@authorwxz

* @date 2017年3月7日*/

public static String createSingleSchedule(Listaliases,

String time, String msgTitle, String msgContent,

String sysMsgId, String type, String url) {if(CollectionUtils.isEmpty(aliases)){

LOG.info("aliases is empty");return null;

}

JPushClient jpushClient= newJPushClient(masterSecret, appKey, timeToLive);

String name= "schedule_"+time.replaceAll(" ", "").replaceAll(":", "").replaceAll("-", "");

Map extra = new HashMap();

extra.put("sysMsgId", sysMsgId);

extra.put("type", type);//0不带链接跳转,1带链接跳转

extra.put("url", url);//Message message = new cn.jpush.api.push.model.Message.Builder()//.setMsgContent(msgContent).addExtras(extra)//.build();//Audience audience = new cn.jpush.api.push.model.audience.Audience.Builder().build().alias(aliases);//初始化android消息通知

cn.jpush.api.push.model.notification.AndroidNotification androidNotification = newcn.jpush.api.push.model.notification.Andro

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值