quartzPro/.svn/pristine/60/60a87169046c865c51affb11d96...

81 lines
2.9 KiB
Plaintext

package com.ifish.jpush.examples;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.ifish.jpush.JPushClient;
import com.ifish.jpush.common.TimeUnit;
import com.ifish.jpush.common.resp.APIConnectionException;
import com.ifish.jpush.common.resp.APIRequestException;
import com.ifish.jpush.report.MessagesResult;
import com.ifish.jpush.report.ReceivedsResult;
import com.ifish.jpush.report.UsersResult;
public class ReportsExample {
protected static final Logger LOG = LoggerFactory.getLogger(ReportsExample.class);
// demo App defined in resources/jpush-api.conf
private static final String appKey = "dd1066407b044738b6479275";
private static final String masterSecret = "2b38ce69b1de2a7fa95706ea";
public static void main(String[] args) {
testGetReport();
testGetMessages();
testGetUsers();
}
public static void testGetReport() {
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
try {
ReceivedsResult result = jpushClient.getReportReceiveds("1942377665");
LOG.debug("Got result - " + result);
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Code: " + e.getErrorCode());
LOG.info("Error Message: " + e.getErrorMessage());
}
}
public static void testGetUsers() {
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
try {
UsersResult result = jpushClient.getReportUsers(TimeUnit.DAY, "2014-06-10", 3);
LOG.debug("Got result - " + result);
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Code: " + e.getErrorCode());
LOG.info("Error Message: " + e.getErrorMessage());
}
}
public static void testGetMessages() {
JPushClient jpushClient = new JPushClient(masterSecret, appKey);
try {
MessagesResult result = jpushClient.getReportMessages("269978303");
LOG.debug("Got result - " + result);
} catch (APIConnectionException e) {
LOG.error("Connection error. Should retry later. ", e);
} catch (APIRequestException e) {
LOG.error("Error response from JPush server. Should review and fix it. ", e);
LOG.info("HTTP Status: " + e.getStatus());
LOG.info("Error Code: " + e.getErrorCode());
LOG.info("Error Message: " + e.getErrorMessage());
}
}
}