IOS PushNotification - IOS推送测试 PHP 版
来源:互联网 发布:男人心目中的女神 知乎 编辑:程序博客网 时间:2024/05/16 05:27
这里讲的是如何给设备发送一个推送消息,不是如何获取Token哦!
<?php// Put your device token here (without spaces):$deviceToken = '获取到的Token';// Put your private key's passphrase here:$passphrase = '123456';// Put your alert message here:$message = 'My first push notification!';////////////////////////////////////////////////////////////////////////////////$ctx = stream_context_create();stream_context_set_option($ctx, 'ssl', 'local_cert', 'apans-dis.pem');stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);// Open a connection to the APNS server$fp = stream_socket_client('ssl://gateway.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);if (!$fp)exit("Failed to connect: $err $errstr" . PHP_EOL);echo 'Connected to APNS' . PHP_EOL;// Create the payload body$body['aps'] = array('alert' => $message,'sound' => 'default');// Encode the payload as JSON$payload = json_encode($body);// Build the binary notification$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;// Send it to the server$result = fwrite($fp, $msg, strlen($msg));if (!$result)echo 'Message not delivered' . PHP_EOL;elseecho 'Message successfully delivered' . PHP_EOL;// Close the connection to the serverfclose($fp);
修改devicetoken和passphrase这两个变量为获取到的token和证书密码。
保存上面代码为push.php ,把pem放到文件同目录。
然后执行 php push.php ,就会收到推送啦
上面代码使用的是发布证书,如果是测试证书需要修改ssl网址哦。
修改为:
ssl://gateway.sandbox.push.apple.com:2195
0 0
- IOS PushNotification - IOS推送测试 PHP 版
- iOS pushnotification
- ios--pushnotification学习与总结(推送机制)
- iOS消息推送之Voip 消息推送 服务器测试 PhP
- IOS推送消息 php推送
- ios 推送消息 php推送
- iOS推送测试方法
- iOS远程推送测试
- Mac iOS推送测试
- iOS 推送 通知 测试
- ios 推送测试
- iOS php消息推送
- php实现ios推送
- iOS推送&PHP后台
- PushNotification消息推送逻辑
- IOS 测试机进行推送
- ios测试推送工具介绍
- IOS 推送消息 php做推送服务端
- error C2784--------使用map遇到的小问题
- 搜狗网址导航带学子享受美好假期
- 类对象和类指针的区别
- 'IOKING' TCP Transmission Server Engine ('云猴'©TCP通讯服务器引擎)(预告版)
- 【LeetCode】Search Insert Position
- IOS PushNotification - IOS推送测试 PHP 版
- [LeetCode9] Palindrome Number
- 开发团队的效率
- 黑马程序员_泛型总结
- CallmeR
- Path Sum II
- 【C】刚开始学习C 的几个小错误
- 陆“脑震荡” 震出了夜半酒吧敲诈李天一黑幕(一)
- C语言之字节对齐解析