45 lines
1.6 KiB
Plaintext
45 lines
1.6 KiB
Plaintext
package com.ifish.jpush;
|
|
|
|
import java.util.Map;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
import com.google.gson.JsonObject;
|
|
import com.ifish.jpush.common.resp.APIConnectionException;
|
|
import com.ifish.jpush.common.resp.APIRequestException;
|
|
import com.ifish.jpush.push.PushResult;
|
|
|
|
public class JPushNotification {
|
|
|
|
protected final Logger LOG = LoggerFactory.getLogger(JPushNotification.class);
|
|
JPushClient jpushClient = null;
|
|
|
|
public JPushNotification(String appKey,String masterSecret,boolean productionModel){
|
|
jpushClient = new JPushClient(masterSecret, appKey , productionModel ,86400);
|
|
}
|
|
|
|
public void sendIosNotification(String[] alias,String title,String body,Map<String,String> extras) {
|
|
try {
|
|
JsonObject json = new JsonObject();
|
|
json.addProperty("title", title);
|
|
json.addProperty("body", body);
|
|
PushResult result = jpushClient.sendIosNotificationWithAlias(json, extras, alias);
|
|
} catch (APIConnectionException e) {
|
|
LOG.error("Connection error. Should retry later. ", e);
|
|
} catch (APIRequestException e) {
|
|
LOG.error("Error Message: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/*public void sendAndroidNotification(String[] alias,String title,String alert,Map<String,String> map) {
|
|
try {
|
|
PushResult result = jpushClient.sendAndroidNotificationWithAlias(title ,alert, map, alias);
|
|
} catch (APIConnectionException e) {
|
|
LOG.error("Connection error. Should retry later. ", e);
|
|
} catch (APIRequestException e) {
|
|
LOG.error("Error Message: " + e.getMessage());
|
|
}
|
|
}*/
|
|
}
|