极光推送

极光推送工具类

官方网址:

https://docs.jiguang.cn/jpush/server/push/rest_api_v3_push/#_20

上代码:


	public static void jpushAll(Map<String, String> parm) {
		 
		//创建JPushClient
		JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY);
		//创建option
		PushPayload payload = PushPayload.newBuilder()
				.setPlatform(Platform.all())  //所有平台的用户Android, iOS, Windows Phone 
				.setAudience(Audience.alias(parm.get("id")))//推送目标,向谁推送	
				.setNotification(Notification.newBuilder()//通知
						//发送ios
						.addPlatformNotification(IosNotification.newBuilder() 
													.setAlert(parm.get("msg")) //消息体
													.setBadge(+1)
													.setSound("happy") //ios提示音,如果识别不到,它会自己添加默认的
													.addExtras(parm) //附加参数,自己定义的
													.build())
						//发送android
						.addPlatformNotification(AndroidNotification.newBuilder() 
													.setAlert(parm.get("msg")) //消息体
													.addExtras(parm) //附加参数,自己定义的
													.build())
						.build())
				.setOptions(Options.newBuilder().setApnsProduction(true).build())//指定开发环境 true为生产模式 false 为测试模式 (android不区分模式,ios区分模式)
				.build();
		try {
			PushResult pu = jpushClient.sendPush(payload);
			System.out.println(pu.toString());
		} catch (APIConnectionException e) {
			e.printStackTrace();
		} catch (APIRequestException e) {
			e.printStackTrace();
		}    
	}
  pom.xml:
	<!-- 极光推送 https://mvnrepository.com/artifact/cn.jpush.api/jpush-client -->
		<dependency>
		    <groupId>cn.jpush.api</groupId>
		    <artifactId>jpush-client</artifactId>
		    <version>3.3.11</version>
		</dependency>

注释:

前端已经集成了极光推送,APP_KEY和MASTER_SECRET是此APP极光推送的key和密钥。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值