package com.jpushtest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.jpush.api.JPushClient;
import cn.jpush.api.common.resp.APIConnectionException;
import cn.jpush.api.common.resp.APIRequestException;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.PushPayload;
public class Test {
protected static final Logger LOG = LoggerFactory.getLogger(Test.class);
private static final String appKey ="64dbecb8d59a8f0ca0f4c580";
private static final String masterSecret = "55082bff7312a4f822a5deea";
public static final String ALERT = "阳哥你好";
public static void main(String[] args){
testSendPush();
}
public static void testSendPush() {
// HttpProxy proxy = new HttpProxy("localhost", 3128);
// Can use this https proxy: https://github.com/Exa-Networks/exaproxy
JPushClient jpushClient = new JPushClient(masterSecret, appKey, 3);
// For push, all you need do is to build PushPayload object.
PushPayload payload = buildPushObject_all_all_alert();
try {
PushResult result = jpushClient.sendPush(payload);
LOG.info("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());
LOG.info("Msg ID: " + e.getMsgId());
}
}
public static PushPayload buildPushObject_all_all_alert() {
return PushPayload.alertAll(ALERT);
}
}
- 1
- 2
- 3
- 4
- 5
前往页