问题描述
- JPush极光推送,本地测试报错
-
最近有用到JPush,appkey和masterSecret都是注册的。在本地建立项目后,直接运行,报下列错误 at cn.jpush.api.common.connection.NativeHttpClient._doRequest(NativeHttpClient.java:208) at cn.jpush.api.common.connection.NativeHttpClient.doRequest(NativeHttpClient.java:72) at cn.jpush.api.common.connection.NativeHttpClient.sendPost(NativeHttpClient.java:64) at cn.jpush.api.push.PushClient.sendPush(PushClient.java:111) at cn.jpush.api.JPushClient.sendPush(JPushClient.java:88) at com.nlem.PushExample.testSendPush(PushExample.java:51) at com.nlem.PushExample.main(PushExample.java:37)
都是按照JPushExample运行的,不知道为什么会报这个错!求教
解决方案
信息给的不多,无法确定什么原因。
PushExample的51行 37行代码存在问题。贴出代码来看~~~~
解决方案二:
public class PushExample {
protected static final Logger LOG = LoggerFactory.getLogger(PushExample.class);
//真正的appkey masterSecret
private static final String appKey ="***********************";//公司的appkey
private static final String masterSecret = "***********************";//公司的secret,暂时隐藏
public static final String TITLE = "Test from API example";
public static final String ALERT = "Test from API Example - alert";
public static final String MSG_CONTENT = "Test from API Example - msgContent";
public static final String REGISTRATION_ID = "0900e8d85ef";
public static final String TAG = "tag_api";
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();
PushPayload payload = buildPushObject_android_myphone_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) {
e.printStackTrace();
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_android_myphone_alert() {
return PushPayload.newBuilder()
.setPlatform(Platform.android())
.setAudience(Audience.alias("111111"))//设置自己手机alians:111111,给自己手机推送信息
.setNotification(Notification.alert("Test"))
.build();
}
解决方案三:
能不能把api给我发下呀!谢谢了
时间: 2024-12-27 11:33:43