博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java 极光推送
阅读量:7079 次
发布时间:2019-06-28

本文共 1777 字,大约阅读时间需要 5 分钟。

/** * 极光推送工具类 * @author why * */@SuppressWarnings("all")public class JPushAllUtil {	private final static String appKey = "";	private final static String masterSecret = "";	/**	 * 测试方法	 */	public static void main(String[] args) {		//发送通知		jSend_notification("0a139889879","您有一条新的物流消息_123");			}	/**	 * 发送通知	 * @param registrationId 设备标识	 * @param alert 推送内容	 */	public static void jSend_notification(String registrationId, String alert){		JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);		PushPayload payload = send_N(registrationId, alert);		try {            PushResult result = jpushClient.sendPush(payload);            System.out.println(result);                    } catch (APIConnectionException e) {            System.out.println(e);        } catch (APIRequestException e) {        	System.out.println(e);        	System.out.println("Error response from JPush server. Should review and fix it. "+ e);        	System.out.println("HTTP Status: " + e.getStatus());        	System.out.println("Error Code: " + e.getErrorCode());        	System.out.println("Error Message: " + e.getErrorMessage());        	System.out.println("Msg ID: " + e.getMsgId());        }	}		public static PushPayload send_N(String registrationId, String alert){		return PushPayload.newBuilder()    			.setPlatform(Platform.android_ios())//必填    推送平台设置    			.setAudience(Audience.registrationId(registrationId))    			.setNotification(Notification.alert(alert))    			/**    			 * 如果目标平台为 iOS 平台 需要在 options     			 * 中通过 apns_production 字段来制定推送环境。    			 * True 表示推送生产环境,False 表示要推送开发环境; 如    			 * 果不指定则为推送生产环境    			 */    			.setOptions(Options.newBuilder()    					.setApnsProduction(false)    					.build())    			.build();		}}

转载于:https://www.cnblogs.com/JOEH60/p/5781012.html

你可能感兴趣的文章
大型网站技术架构(一)大型网站架构演化
查看>>
CEPH集群RBD快照创建、恢复、删除、克隆
查看>>
大型网站技术架构(六)网站的伸缩性架构
查看>>
MyBatis学习总结(四)——解决字段名与实体类属性名不相同的冲突
查看>>
Linux发生问题怎么处理啊?建议流程是这样...[鸟哥的Linux私房菜]
查看>>
Mysql学习总结(6)——MySql之ALTER命令用法详细解读
查看>>
大型网站技术架构(五)网站高可用架构
查看>>
SVN学习总结(2)——SVN冲突解决
查看>>
MySQL基本
查看>>
<org manual>翻译--3.2 列的宽度与对齐
查看>>
我的友情链接
查看>>
《未测试》如何使用自己已经编译过的lamp安装cacti nagios zabbix
查看>>
SCVMM 2012 R2之为云分配虚拟机
查看>>
中国企业的等级制度
查看>>
pfSense安装和配置pfBlockerNg
查看>>
Ubuntu 14.04 X64 下安装Appcelerator Titanium Studio。
查看>>
R.java was modified manually! Reverting to generated version!(R文件丢失异常原因汇总)
查看>>
ASP.NET MVC Model验证(一)
查看>>
opensuse12.1安装VirtualBox
查看>>
获取系统特殊文件
查看>>