|
|
@ -141,6 +141,40 @@ public class JPushServer { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 待阅消息推送(使用别名) |
|
|
|
* @param title 标题 |
|
|
|
* @param content 内容 |
|
|
|
* @param msg_type 消息类别 |
|
|
|
*/ |
|
|
|
public static void sendPushAliass(String title, String content, String state, String name, String... alias) { |
|
|
|
Map<String, String> extras = new HashMap<>(); |
|
|
|
extras.put("class_name", "com.anrui.android.activity.ReadActivity"); |
|
|
|
extras.put("state", "0"); |
|
|
|
extras.put("name", name); |
|
|
|
ClientConfig clientConfig = ClientConfig.getInstance(); |
|
|
|
final JPushClient jpushClient = new JPushClient(MASTER_SECRET, APP_KEY, null, clientConfig); |
|
|
|
|
|
|
|
final PushPayload payload = buildPushObject_android_and_iosAlias(title, content, URIACTIVITY, extras, alias); |
|
|
|
try { |
|
|
|
PushResult result = jpushClient.sendPush(payload); |
|
|
|
System.out.println("Got result - " + result); |
|
|
|
// 如果使用 NettyHttpClient,需要手动调用 close 方法退出进程
|
|
|
|
// jpushClient.close();
|
|
|
|
} catch (APIConnectionException e) { |
|
|
|
System.out.println("Connection error. Should retry later. "+e); |
|
|
|
System.out.println("Sendno: " + payload.getSendno()); |
|
|
|
|
|
|
|
} catch (APIRequestException 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()); |
|
|
|
System.out.println("Sendno: " + payload.getSendno()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* (广播) |
|
|
|
* @param title 标题 |
|
|
|