1. 本地证书合成

rm *.pem
echo "export cert..."
openssl pkcs12 -clcerts -nokeys -out push_cert.pem -in push_cert.p12
echo "export key..."
openssl pkcs12 -nocerts -out push_key.pem -in push_key.p12
openssl rsa -in push_key.pem -out push_key_noenc.pem
echo "combine together"
cat push_cert.pem push_key_noenc.pem > apns-dev.pem
echo "done"

其中push_cert.p12和push_key.p12分别是中keychain中根据开发证书导出来的证书和私钥。

上述脚本最终会导出一个名称为“apns-dev.pem”的认证文件。

下面会使用这个认证文件进行sanbox推送

2. 沙盒推送

<?php
$deviceToken= '86441e1421a239d0f7eed26ab4c8bd9a9ccec21b';
$body = array("aps" => array("alert" => 'message', "badge" => 2, "sound"=>'default'));
$ctx = stream_context_create();
stream_context_set_option($ctx,"ssl","local_cert","apns-dev.pem");
$pass = "aabb11";
stream_context_set_option($ctx, 'ssl', 'passphrase', $pass); //$fp = stream_socket_client("ssl://gateway.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); // for real push service
$fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx); //for sandbox if (!$fp)
{
echo "Failed to connect $err $errstrn";
return;
}
print "Connection OK\n";
$payload = json_encode($body);$msg = chr(0) . pack("n",32) . pack("H*", str_replace(' ', '', $deviceToken)) . pack("n",strlen($payload)) . $payload;
echo "sending message :" . $payload ."\n";
fwrite($fp, $msg);
fclose($fp);
?>

其中deviceToken是苹果手机的40位的UDID。

这是实习的时候学到的,但是最终这个方案没有测试成功:

问题是:

php pushtest.php

Warning: stream_socket_client(): Failed to enable crypto in pushtest.php on line 10

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in pushtest.php on line 10

真的非常遗憾,希望以后还有机会学习IOS方面的内容!

IOS Remote Notification的更多相关文章

  1. iOS 远程通知(Remote Notification)和本地通知(Local Notification)

    ios通知分为远程通知和本地通知,远程通知需要连接网络,本地通知是不需要的,不管用户是打开应用还是关闭应用,我们的通知都会发出,并被客户端收到 我们使用远程通知主要是随时更新最新的数据给用户,使用本地 ...

  2. iOS开发笔记8:Remote Notification远程消息推送处理

    远程消息推送处理场景有三种:分别是app还没有运行.app在前台运行以及app在后台运行,下面介绍相关流程及三种场景下处理步骤 1.流程 (1)注册通知 首先是在注册远程消息推送,需要注意的是iOS8 ...

  3. iOS remote debug & Android remote debug & Chrome & APP

    iOS remote debug & Android remote debug & Chrome & APP iOS remote debugging 如何在 iOS 真机上调 ...

  4. Android/iOS Remote debugging

    简单介绍 使用下面方法可以定位webview中的元素,无法定位view中的元素. 原文地址:http://mp.weixin.qq.com/s/y_UfdgjT_pkKgYivJmqt7Q webvi ...

  5. ios的notification机制是同步的还是异步的

    与javascript中的事件机制不同.ios里的事件广播机制是同步的,默认情况下.广播一个通知,会堵塞后面的代码: -(void) clicked { NSNotificationCenter *c ...

  6. Android 与 iOS 推送 Push Notification 的区别

    Android 安卓使用 GCM (Google Cloud Messaging) 接收推送,然后应用根据实际情况决定做什么反应,比如显示一个 Notification. 所以安卓下,推送 Push ...

  7. iOS web remote debug 正确的姿势

    在使用iOS Remote debug需要做以下准备 1. iOS devices 开启java script and web inspector 开启方式如下: 2. mac OS 自带的Safar ...

  8. [转载]iOS 10 UserNotifications 框架解析

    活久见的重构 - iOS 10 UserNotifications 框架解析 TL;DR iOS 10 中以前杂乱的和通知相关的 API 都被统一了,现在开发者可以使用独立的 UserNotifica ...

  9. iOS 10、Xcode 8 遇到部分问题解决记录

    今天把iphone 6 升级到ios10 后,用Xcode 7进行真机调试的时候提示: Could not find Developer Disk Image 果断准备升级到Xcode 8 .但是想保 ...

随机推荐

  1. Tiny210v2( S5PV210 )平台下创建基本根文件系统

    转自Tiny210v2( S5PV210 )平台下创建基本根文件系统 0. 概要介绍 ========================================================= ...

  2. 李洪强iOS开发Swift篇—03_字符串和数据类型

    李洪强iOS开发Swift篇—03_字符串和数据类型 一.字符串 字符串是String类型的数据,用双引号""包住文字内容  let website = "http:// ...

  3. mysql日志的查看与开启

    mysql的日志类型: 错误日志: log-error 查询日志: log 慢查询日志: log-slow-queries 更新日志: log-update 二进制日志: log-bin 开启错误日志 ...

  4. 学会使用git

    廖雪峰Git教程 这个教程较为简单,循序渐进 易百Git教程 较为系统 在线代码格式化 可以下载全球最大视频网站的视频支持搜索 点这里

  5. queue与topic的技术特点对比

    1    queue与topic的技术特点对比 Topic Queue 概要 Publish Subscribe messaging 发布订阅消息 Point-to-Point 点对点 有无状态 to ...

  6. Java序列化与Hessian序列化的区别

    Java序列化: Java序列化会把要序列化的对象类的元数据和业务数据全部序列化为字节流,而且是把整个继承关系上的东西全部序列化了.它序列化出来的字节流是对那个对象结构到内容的完全描述,包含所有的信息 ...

  7. [LeetCode] Burst Balloons (Medium)

    Burst Balloons (Medium) 这题没有做出来. 自己的思路停留在暴力的解法, 时间复杂度很高: 初始化maxCount = 0. 对于当前长度为k的数组nums, 从0到k - 1逐 ...

  8. IT传道解惑:心累了就读读

    写在开始 学习不是因为缺少时间而是缺少努力 Studies this matter, lacks the time, but is lacks diligently. 只要你想学好,用心去学,肯下功夫 ...

  9. message 匹配不上grok正则 也会写入到elasticsearch

    { "message" => "scan test 20161201", "@version" => "1" ...

  10. Android Intent.FLAG_NEW_TASK详解,包括其他的标记的一些解释

    本文大部分参考自 http://blog.csdn.net/mayingcai1987/article/details/6200909 ,对原文中的讲解FLAG_NEW_TASK地方加了一些自己的观点 ...