服务器端代码:
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;
}

1069

被折叠的 条评论
为什么被折叠?



