一、创建APNS推送证书
1.登录Apple的Developer Member Center
- 打开https://developer.apple.com/membercenter/index.action, 选择点击Certificates, Identifiers & Profiles., 打开后在左侧列表中选择Certificates大类下面的All子类,出现如下界面:
image.png
2.选择证书的类型,Sandbox或者Productuon
- 根据你的需求选择Apple Push Notification service SSL (Sandbox) 或者 Apple Push Notification service SSL (Sandbox & Production)类型的证书.
- 然后点击继续.
这里要注意一点,选择证书的正确类型非常重要:
一个用Development Provisioning Profile签名的App生成的 Device Token只能和Sandbox APNS Server结合使用(开发环境测试用).
一个用AdHoc Provisioning Profile或者AppStore Provisioning Profile签名的App生成的Device Token只能和Production APNS Server结合使用(生产环境发布使用).
提示: 有些用户已经报告过关于使用二合一的推送证书(Apple Push Notification service SSL (Sandbox & Production),新出的 )在调试测试环境进行推送时会出问题.


3.查看创建证书签名请求相关步骤信息
查看一下如何创建一个CSR文件的信息.

4.打开钥匙串,创建证书签名请求文件
点击钥匙串访问程序的菜单栏
选择证书助理子菜单
选择从证书颁发机构请求证书...子子菜单


5.填写证书签名请求文件详细信息
输入email地址,为了安全和保险起见,最好填写和你Apple开发者账号对应的email地址.
接着输入常用名称.

6.上传正确签名请求文件
选择 Choose File...来上传
在弹出的文件打开对话框中定位到刚刚存储的证书签名请求文件所在目录,并选择打开该CSR文件.

7.下载证书文件
点击下载按钮来下载证书
打开下载的证书文件

8.找到证书和私钥
在钥匙串访问程序中找到刚刚打开导入的证书
然后点击右三角展开证书,显示出对应的私钥
导出私钥文件,在私钥部分右键
在弹出的选择框中点击 导出常用名称 菜单


9. 保存导出的私钥文件
选中一个存储的位置并输入喜欢的私钥文件名
格式选择.p12格式

现在你已经拥有了一个.p12格式的文件,该文件包含了和Apple的APNS服务器建立SSL/TLS安全通信的私钥.
你可以把该.p12文件上传到你的推送服务器并配置使用了.
二、为服务器制作证书
将下载的证书制作成.pem 文件 打开终端,访问到你证书存放的那个目录下

进到文件夹目录后,输入以下命令将证书转换成.pem文件: openssl x509 -in 证书名字.cer -inform der -out push_developer_cer.pem


将.p12 证书制作成.pem文件 在终端输入: openssl pkcs12 -nocerts -out pushKey.pem -in p12名字.p12


接下来会让你输入两次新生成的.pem文件的密码,这个密码也是看不见的(这个密码以后要给服务器使用,要牢记)

可以看到,文件夹又生成了一个新的文件:pushKey.pem

合并两个.pem文件
将上述新产生的文件合并,在终端输入命令后敲回车: cat 下载证书生成的.pem p12生成的.pem > 最终证书的名字.pem

可以看到,文件夹又生成了一个新的文件:final_Push_developer.pem(这个密码要记住是pushKey.pem生成时要输入的密码,密码需要给到服务器)
5、测试证书是否有效
在终端输入(开发用的验证):
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert
下载证书生成的.pem -key p12生成的.pem
如果是发布证书的验证,输入:
openssl s_client -connect gateway.push.apple.com:2195 -cert
下载证书生成的.pem -key p12生成的.pem
之后会让你输入密码,输入密码后,会有大量openssl消息,当你任意输入几个字符时,服务器会提示断开


这时候你就可以把final_Push_developer.pem 和相应的密码 交给服务器端了,告诉他们这个证书是没有问题的
验证成功,最后将.pem文件生成p12文件
openssl pkcs12 -export -in iAppPlatformHD_production.pem -out AppPlatform_production_HD.p12
网友评论