gpt4 book ai didi

JAVAPNS 2.2 成功推送但未在设备上接收

转载 作者:行者123 更新时间:2023-12-03 23:13:37 24 4
gpt4 key购买 nike

在此处输入代码我尝试使用 JAVAPNS 2.2 从 Java 推送

这是我的代码

import java.util.*;
import org.apache.log4j.BasicConfigurator;
import org.json.JSONException;
import javapns.*;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;
import javapns.notification.PushNotificationPayload;
import javapns.notification.PushedNotification;
import javapns.notification.ResponsePacket;



public class Test {

/**
* @param args
*/
public static void main(String[] args) {

BasicConfigurator.configure();

try {

PushNotificationPayload payload = PushNotificationPayload.complex();

payload.addAlert("Hello World");
payload.addBadge(1);
payload.addSound("default");
payload.addCustomDictionary("id", "1");


System.out.println(payload.toString());
List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\keystore1.p12", "123456", true, "AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D");

for (PushedNotification NOTIFICATION : NOTIFICATIONS) {
if (NOTIFICATION.isSuccessful()) {
/* APPLE ACCEPTED THE NOTIFICATION AND SHOULD DELIVER IT */
System.out.println("PUSH NOTIFICATION SENT SUCCESSFULLY TO: " +
NOTIFICATION.getDevice().getToken());
/* STILL NEED TO QUERY THE FEEDBACK SERVICE REGULARLY */
}
else {
String INVALIDTOKEN = NOTIFICATION.getDevice().getToken();
/* ADD CODE HERE TO REMOVE INVALIDTOKEN FROM YOUR DATABASE */

/* FIND OUT MORE ABOUT WHAT THE PROBLEM WAS */
Exception THEPROBLEM = NOTIFICATION.getException();
THEPROBLEM.printStackTrace();

/* IF THE PROBLEM WAS AN ERROR-RESPONSE PACKET RETURNED BY APPLE, GET IT */
ResponsePacket THEERRORRESPONSE = NOTIFICATION.getResponse();
if (THEERRORRESPONSE != null) {
System.out.println(THEERRORRESPONSE.getMessage());
}
}
}


} catch (CommunicationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (KeystoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

图书馆已成功发送,但我的设备上从未收到推送。我尝试了很多设备 token ,甚至尝试重新生成证书 .12,但仍然没有用。

日志

0 [main] DEBUG javapns.notification.Payload  - Adding alert [Hello World]

1 [main] DEBUG javapns.notification.Payload - Adding badge [1]

1 [main] DEBUG javapns.notification.Payload - Adding sound [default]

1 [main] DEBUG javapns.notification.Payload - Adding custom Dictionary [id] = [1]

{"id":"1","aps":{"sound":"default","alert":"Hello World","badge":1}}

292 [main] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocketFactory

341 [main] DEBUG javapns.communication.ConnectionToAppleServer - Creating SSLSocket to gateway.push.apple.com:2195

972 [main] DEBUG javapns.notification.PushNotificationManager - Initialized Connection to
Host: [gateway.push.apple.com] Port: [2195]: 1923e91b[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.push.apple.com/17.149.35.173,port=2195,localport=65225]]

974 [main] DEBUG javapns.notification.PushNotificationManager - Building Raw message from deviceToken and payload

974 [main] DEBUG javapns.notification.PushNotificationManager - Built raw message ID 1 of total length 113

974 [main] DEBUG javapns.notification.PushNotificationManager - Attempting to send notification: {"id":"1","aps":{"sound":"default","alert":"Hello World","badge":1}}

974 [main] DEBUG javapns.notification.PushNotificationManager - to device: AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D

1743 [main] DEBUG javapns.notification.PushNotificationManager - Flushing

1743 [main] DEBUG javapns.notification.PushNotificationManager - At this point, the entire 113-bytes message has been streamed out successfully through the SSL connection

1743 [main] DEBUG javapns.notification.PushNotificationManager - Notification sent on first attempt

1743 [main] DEBUG javapns.notification.PushNotificationManager - Reading responses

1744 [main] DEBUG javapns.notification.PushNotificationManager - Closing connection
PUSH NOTIFICATION SENT SUCCESSFULLY TO: AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D

有人知道吗?

最佳答案

这一行应该

List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\keystore1.p12", "123456", true, "AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D");

应该改成这个

List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\keystore1.p12", "123456", false, "AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D");

关于JAVAPNS 2.2 成功推送但未在设备上接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11342293/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com