iphone消息推送需要向APNS申请证书(如何申请,请参考:http://2015.iteye.com/blog/1337599 ),会生成三个文件:
1、Push.certSigningRequest
2、Push.p12
3、aps_developer_identity.cer
然后,java后台消息推送代码需要用到证书密码和路径,需要另外使用openssl生成,windows下的步骤如下:
打开openssl命令行:
1、将aps_developer_identity.cer转换成aps_developer_identity.pem格式
输入命令: x509 -in aps_developer_identity.cer -inform DER -out aps_developer_identity.pem -outform PEM
2、将p12格式的私钥转换成pem
pkcs12 -nocerts -out Push_Noenc.pem -in Push.p12
3、创建p12文件
pkcs12 -export -in aps_developer_identity.pem -inkey Push_Noenc.pem -certfile Push.certSigningRequest -name "aps_developer_identity" -out aps_developer_identity.p12
注意:-name 后面的名字 aps_developer_identity 与最后你生成的保持一致;
这样我们就得到了java等后台应用程序中使用的证书文件:aps_developer_identity.p12
如果linux下生成第三步报错,即可去掉 -certfile Push.certSigningRequest 生成(我是这样做的,也可以推送消息,去掉之前它老提示一个找不到cert的错误)
java 后台推送测试代码:(注意修改你的证书路径和密码,以及测试手机的token
/** * IPHONE推送 * * @param tokens * 设备ID列表 * @param message * 推送的消息 * @param badge * iphone应用图标上小红圈上的数值 * @param sound * 消息提醒铃音 * @param certificatePath * 证书路径 * @param certificatePassword * 证书密码 * @param single * true:单条 false:多条 */ public void sendpush(List<String> tokens, String message, int badge, String sound, String certificatePath, String certificatePassword, boolean single) { try { logger.info("----------------message:" + message); PushNotificationPayload payLoad = new PushNotificationPayload(); if(StringUtils.isNotEmpty(message)){ payLoad.addAlert(message); // 消息内容 } payLoad.addBadge(badge); // iphone应用图标上小红圈上的数值 if (!StringUtils.isBlank(sound)) { payLoad.addSound(sound);// 铃音 } PushNotificationManager pushManager = new PushNotificationManager(); // true:表示的是产品发布推送服务 false:表示的是产品测试推送服务 pushManager .initializeConnection(new AppleNotificationServerBasicImpl( certificatePath, certificatePassword, false)); List<PushedNotification> notifications = new ArrayList<PushedNotification>(); // 发送push消息 if (single) { Device device = new BasicDevice(); device.setToken(tokens.get(0)); PushedNotification notification = pushManager.sendNotification( device, payLoad, true); notifications.add(notification); } else { List<Device> device = new ArrayList<Device>(); for (String token : tokens) { device.add(new BasicDevice(token)); } notifications = pushManager.sendNotifications(payLoad, device); } List<PushedNotification> failedNotifications = PushedNotification .findFailedNotifications(notifications); // List<PushedNotification> successfulNotifications = // PushedNotification // .findSuccessfulNotifications(notifications); if (failedNotifications != null) { int failed = failedNotifications.size(); String errorLog = "失败条数=" + failed + "; "; for (PushedNotification failedNotification : failedNotifications) { Device d = failedNotification.getDevice(); errorLog += "deviceId=" + d.getDeviceId() + "; token=" + d.getToken(); } logger.info("消息推送失败记录:" + errorLog); } // int successful = successfulNotifications.size(); } catch (Exception e) { logger.error("消息推送异常...", e); } } public static void main(String[] args) { String classpath = IphonePushService.class.getResource("/").getPath(); PropertyConfigurator.configure(classpath + "/config/properties/pushLog4j.properties"); IphonePushService pushService = new IphonePushService(); List<String> token = new ArrayList<String>(); String device_token ="gt5a414g67a01183ef683r41e110ddrlof7d258h2c1678a99hj69586e589574"; token.add(device_token); String certificatePath = "F://duanrong_zeng//temp//cert//java_dev_identity.p12"; String certificatePassword = "123456"; pushService.sendpush(token, null, 5, "", certificatePath, certificatePassword, true); }
使用的jar包,openssl见附件
本文参考了 http://2015.iteye.com/blog/1337599
原文参考:http://it.5yun.com.cn/html/y2015/m01/22.html
相关推荐
APNS(Apple Push Notification Service)苹果推送通知服务。该技术由苹果公司提供的APNS服务。工作原理:首先,APNS会对用户进行物理连接认证,和设备令牌认证(简言之就是苹果的服务器检查设备里的证书已确定其为...
可实现向所有用户发送通知,实现群推送,java后台代码。网上简易代码一般只能单发
用https实现iphone消息推送,短连接形式 有问题,请留言
iphone 推送通知 服务器端java 实现 iphone 推送通知 APNS 包含所需jar包和实现代码
push独立证书,完美修复后台推送问题!iphone推送证书,iphone推送修复!定义.pdf
这个压缩包里面包含三个DOC文件:1.iphone推送java实现.doc 2.iphone推送简单JAVA示例.doc 3.实现iphone推送服务端原理.doc 三个文档很全面的指导学者学习怎么用java实现ios推送功能,不仅仅是讲解怎么实现,还讲解...
java给iphone应用实现推送
苹果推送项目源码,运行即用 语言:JAVA,开发IDE:eclipse 数据库:MYSQL 运行即用,附带API调用文档 超级硬通货,想不使用第三方苹果消息推送的千万不要错过
主要是通过iphone客户端访问java后台的webservice,然后用json解析xml文件,然后获取数据
关于IOS_APNS推送消息(iphone端+服务端)。关于IOS_APNS推送消息(iphone端+服务端)。
java 向iphone推送信息
JAVA JavaPNS_2.2 实现iphone的推送通知
用java实现了一个简单的iphone推送,能够进行简单的推送,已经过测试,iphone客户端能够接收到服务器推送的内容
mac 向iphone等发送消息推送的工具,需要p12证书和证书密码
.net推送消息到iphone
如果直接运行可能会报错,只需要将deviceToken换成你自己手机的token,还有将tinmanpush123.p12证书换成你自己的,就可以了.
第一阶段:Push服务器应用程序把要发送的消息、目的iPhone的标识打包,发给APNS。 第二阶段:APNS在自身的已注册Push服务的iPhone列表中,查找有相应标识的iPhone,并把消息发到iPhone。 第三阶段:iPhone把发来的...
iphone推送消息,通过苹果官方,后续还有
电脑需预先安装JDK 空间说说由iPhone发表,Java源代码
c#语言IOS推送服务端全程代码, windows服务全程代码, windows服务安装程序设置, 实现IOS推送服务C#语言服务端代码实现