import javapns.back.PushNotificationManager; import javapns.back.SSLConnectionHelper; import javapns.data.Device; import javapns.data.PayLoad; public class a { public static void main(String[] args) throws Exception { try { // The deviceToken obtained from the client, here for the simplicity of the test, write a fixed test device ID. String deviceToken = "b606c95c4b3956de89d67ecfa02811ebc5d1a09c6f832c3be67b1d9554a66683"; System.out.println("Push Start deviceToken:" + deviceToken); // define the message mode PayLoad payLoad = new PayLoad(); payLoad.addAlert("this is test!"); payLoad.addBadge(1);// The number of message push tags, the number displayed in the small red circle. payLoad.addSound("default"); // register deviceToken PushNotificationManager pushManager = PushNotificationManager.getInstance(); pushManager.addDevice("iPhone", deviceToken); // connect to APNS String host = "gateway.sandbox.push.apple.com"; // String host = "gateway.push.apple.com"; int port = 2195; String certificatePath = "E:/123.p12";// The location of the *.p12 file generated earlier for the JAVA background connection APNS service String certificatePassword = "8dbmds";// p12 file password. pushManager.initializeConnection(host, port, certificatePath, certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12); // send push 991847304 Device client = pushManager.getDevice("iPhone"); System.out.println("推送消息: " + client.getToken() + "\n" + payLoad.toString() + " "); pushManager.sendNotification(client, payLoad); // Stop connecting to APNS pushManager.stopConnection(); // delete deviceToken pushManager.removeDevice("iPhone"); System.out.println("Push End"); } catch (Exception ex) { ex.printStackTrace(); } } }
Java implements apns message push
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326313861&siteId=291194637
Recommended
Ranking