欢迎来到天天文库
浏览记录
ID:40871601
大小:14.46 KB
页数:5页
时间:2019-08-09
《百度云推送Java端》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、packagenet;importcom.baidu.yun.channel.auth.ChannelKeyPair;importcom.baidu.yun.channel.client.BaiduChannelClient;importcom.baidu.yun.channel.exception.ChannelClientException;importcom.baidu.yun.channel.exception.ChannelServerException;importcom.baidu.y
2、un.channel.model.PushBroadcastMessageRequest;importcom.baidu.yun.channel.model.PushBroadcastMessageResponse;importcom.baidu.yun.channel.model.PushUnicastMessageRequest;importcom.baidu.yun.channel.model.PushUnicastMessageResponse;importcom.baidu.yun.cor
3、e.log.YunLogEvent;importcom.baidu.yun.core.log.YunLogHandler;publicclassTestPushMessage{/***测试推送*/publicstaticvoidmain(String[]args){Stringstring="{"title":"你有新消息","description":"今天下午全体员工发奖金","+""notification_builder_id":0,"notification_basi
4、c_style":2,"custom_content":{"id":"485446"},"open_type":"2"}";//Stringstring="hello";//intstatus=pushBroadcastMessage(string,3,1);intstatus=pushOnlyPleploMessage(string,3,1);System.out.println(status);}/***初始化百度推送*/privatestaticBaiduChannelC
5、lientinitPushClient(){//这两个key自己申请StringapiKey="自己申请的apikey";StringsecretKey="自己申请的secretKey";//1.设置developer平台的ApiKey/SecretKeyChannelKeyPairpair=newChannelKeyPair(apiKey,secretKey);//2.创建BaiduChannelClient对象实例BaiduChannelClientchannelClient=newBaiduC
6、hannelClient(pair);//3.若要了解交互细节,请注册YunLogHandler类channelClient.setChannelLogHandler(newYunLogHandler(){@OverridepublicvoidonHandle(YunLogEventevent){System.out.println(event.getMessage());}});returnchannelClient;}/***用百度推送向所有人发送消息或者通知*/publicstaticintp
7、ushBroadcastMessage(StringContent,intdevType,intpushType){BaiduChannelClientchannelClient=initPushClient();try{//4.创建请求类对象PushBroadcastMessageRequestrequest=newPushBroadcastMessageRequest();//devType=>1:web2:pc3:android4:ios5:wprequest.setDeviceType(de
8、vType);//pushType为0设置发送消息,为1设置发送通知request.setMessageType(pushType);request.setMessage(Content);//5.调用pushMessage接口PushBroadcastMessageResponseresponse=channelClient.pushBroadcastMessage(request);//6.认证推送成功System.out.println("认证推送成功pusha
此文档下载收益归作者所有