zoukankan      html  css  js  c++  java
  • iOS推送原理和证书生成简介

    1. 推送流程:

    Provider: 我们自己的后台服务器;

    APNS: 苹果的消息推送服务器

    (1) 当Provider有消息要推送给手机的时候,先将消息和deviceToken等字段发送到APNS

    (2) APNS在已注册的设备列表中查找设备,并推送消息到设备;

    (3) iOS将消息传递给应用程序,或者显示通知等;

    2. 注册-推送完整流程:

    (1) App注册消息推送;

    (2) iOS向APNS请求DeviceToken,App获取DeviceToken;

    (3) App将DeviceToken发送至服务器;

    (4) 若有消息通知,则服务器将消息连同DeviceToken发送至APNS;

    (5) APNS查找设备,并且将消息推送至设备;

    3. 推送证书生成流程(开发版本):

    //(我这里证书全部新生成,若有可忽略,注意将以下步骤生成文件保存到同一个目录,方便确认和使用);

    --mac

    (1) 中使用钥匙串-->钥匙串访问-->证书助理-->从证书颁发机构申请证书,填写邮箱,选择保存到磁盘,将生产CSR文件;

    --developer

    (2) 在Identifiers中创建APPID,注意选择Explicit App ID,Bundle ID中不能包含通配符,必须是确定的ID;选择Push Notifications;

    (3) 在Certificates中创建开发证书,选择iOS App Development,选择AppID,导入前面生成的CSR文件,生成后Download下载证书;

    (4) 在Certificates中创建推送证书,选择App Push Notification service SSL (Sandbox),同样选择AppId,导入前面生成的CSR文件,生成后Download下载证书;

    (5) Provising Profiles中创建配置文件,选择iOS App Development,选择前面的AppID,选择前面的开发证书,选择包含的设备,输入名称,生成后Download下载;

    --mac

    (6) 双击(3)(4)步骤中生成的证书,双击Provising Profile文件,在xCode中配置Code Signing,选择对应的developer和profile文件;

    (7) 在钥匙串中找到(4)中证书Apple Devlopment IOS Push Services:xxxx,点击箭头展开,点击专有密钥,右键导出,输入密码如:hello123,保存,如testPush.p12;

    (8) 确认下文件,此时目录文件包含,CertificateSigningRequest.certSigningRequest,ios_development.cer,aps_development.cer,testPush.p12;

    (9) 将testPush.p12和aps_development.cer分别生成pem文件,注意生成testPush.p12对应的pem时候,需要输入密码,为了避免混淆,使用hello123;

    openssl x509 -in aps_development.cer -inform der -out PushChatCert.pem
    openssl pkcs12 -nocerts -out PushChatKey.pem -in testPush.p12

    Enter Import Password:
    MAC verified OK
    Enter PEM pass phrase:
    Verifying - Enter PEM pass phrase:

    (10) 将两个pem文件合并保存到一个pem文件中;

    cat PushChatCert.pem PushChatKey.pem > ck.pem

    (11) 测试是否能够telnet到苹果服务器;

    telnet gateway.sandbox.push.apple.com 2195
    Trying 17.110.226.164... Connected to gateway.sandbox.push-apple.com.akadns.net. Escape character is '^]'. ^]

    (12) 测试用生成的证书建立ssl安全连接到服务器,返回很多信息,表示成功了;

    openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
    Enter pass phrase
    for PushChatKey.pem: CONNECTED(00000003) depth=1 /C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust Certification Authority - L1C verify error:num=20:unable to get local issuer certificate verify return:0 --- Certificate chain 0 s:/C=US/ST=California/L=Cupertino/O=Apple Inc./CN=gateway.sandbox.push.apple.com i:/C=US/O=Entrust, Inc./OU=www.entrust.net/rpa is incorporated by reference/OU=(c) 2009 Entrust, Inc./CN=Entrust ... ... ... ... Key-Arg : None Start Time: 1458041365 Timeout : 300 (sec) Verify return code: 0 (ok) ---

    (13) 在项目的AppDelegate.m中加入推送相关代码;

    (14) 将ck.pem放到服务器,服务器创建消息推送服务,测试是否成功;

    感谢:

    https://developer.apple.com

    http://blog.csdn.net/shenjie12345678/article/details/41120637

    http://www.cocoachina.com/industry/20130321/5862.html

  • 相关阅读:
    python note 30 断点续传
    python note 29 线程创建
    python note 28 socketserver
    python note 27 粘包
    python note 26 socket
    python note 25 约束
    Sed 用法
    python note 24 反射
    python note 23 组合
    python note 22 面向对象成员
  • 原文地址:https://www.cnblogs.com/wanpengcoder/p/5281416.html
Copyright © 2011-2022 走看看