Android java服务器端Jpush推送




服务器端代码:

public class main {

public static String push(List<String> username,String biaoti,String username1){
User user = new User();
user.setUsername(username1);
user.setPassword(biaoti);
String userjson = JSON.toJSONString(user);

String fhz = "loser";
String masterSecret = "cb79148f2b69efa00dbc16b0";
String appKey = "76a005b037fa2b8194fe412a";
JPushClient jpushClient = new JPushClient(masterSecret, appKey);

PushPayload payload = PushPayload.newBuilder()
.setMessage(Message.content(userjson))
               .setPlatform(Platform.android_ios())
               .setAudience(Audience.alias(username))
               .setNotification(Notification.newBuilder()
                       .addPlatformNotification(AndroidNotification.newBuilder()
                               .addExtra("type",userjson )
                               .setAlert("您有一条新消息!")
                               .build())
                       .addPlatformNotification(IosNotification.newBuilder()
                               .addExtra("type",userjson)
                               .setAlert("您有一条新消息!")
                               .build())
                       .build())
               .setOptions(Options.newBuilder()
                       .setApnsProduction(false)//true-推送生产环境 false-推送开发环境(测试使用参数)
                       .setTimeToLive(90)//消息在JPush服务器的失效时间(测试使用参数)
                       .build())
               .build();  
/*  
PushPayload payload = PushPayload.newBuilder()
.setPlatform(Platform.all())
.setAudience(Audience.alias("admin"))
.setNotification(Notification.alert("我是 alert"))
//.setMessage(Message.content("我是message"))
.build();*/
try {
jpushClient.sendPush(payload);
fhz = "success";
System.out.println("success");
//System.out.println(result.msg_id);
//System.out.println(result.sendno);

} catch (APIConnectionException e) {
// TODO Auto-generated catch block
System.out.println("APIConnectionException error");
e.printStackTrace();
} catch (APIRequestException e) {
System.out.println(" APIRequestException error");
// TODO Auto-generated catch block
e.printStackTrace();
}
return fhz;


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值