小白在用java做服务端做ios推送出现了问题

iOS 码拜 8年前 (2016-09-18) 1910次浏览
public static void main(String[] args) {
		try {
			String certificatePath="C:/Users/Administrator/Desktop/ios_distribution.p12" ;

			//终端获得的DeviceToken
			  String deviceToken = "02d01fc03f8392b489ad1c1441fa42056ee7186083abed6c3deb93434538c3f6";

			  PayLoad payLoad = new PayLoad();
			  //发送内容
			  payLoad.addAlert("本人的push推送");
			  //消息推送标记数,小红圈中显示的数字
			  payLoad.addBadge(100);
			  //消息声音
			  payLoad.addSound("default");

			 PushNotificationManager pushManager = PushNotificationManager.getInstance();

			  pushManager.addDevice("iPhone", deviceToken);

			  //连接开发 APNs
			  String host= "gateway.sandbox.push.apple.com";
			  //连接产品 APNs
			  //String host= "gateway.push.apple.com";
			  
			  int port = 2195;
			  //push证书导出的p12文件
			  
			  
			  System.out.println(certificatePath);
			  //p12文件密码
			  String certificatePassword= "123456";
			  pushManager.initializeConnection(host,port, certificatePath,certificatePassword, SSLConnectionHelper.KEYSTORE_TYPE_PKCS12);

			  //发送推送
			 Device client = pushManager.getDevice("iPhone");
			  pushManager.sendNotification(client, payLoad);
			  //删除deviceToken
			  pushManager.removeDevice("iPhone");
			  //停止连接APNS
			  pushManager.stopConnection();
			 
			 }
			 catch (Exception e) {
			  e.printStackTrace();
			 }
	}

javax.net.ssl.SSLHandshakeException: Received fatal alert: certificate_unknown
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1959)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1077)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1312)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:702)
at sun.security.ssl.AppOutputStream.write(AppOutputStream.java:122)
at java.io.OutputStream.write(OutputStream.java:75)
at javapns.back.PushNotificationManager.sendNotification(Unknown Source)
at com.vo.Test.main(Test.java:149)
求高手

解决方案

40

证书的问题,分两步检查一下:
1. 检查你的证书path正不正确
2. 看证书(p12文件)是不是有效的

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明小白在用java做服务端做ios推送出现了问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)