header('content-type:text/html;charset=utf-8');

require_once 'ApnsPHP/Autoload.php';
require_once 'ApnsPHP/Push.php';
require_once 'ApnsPHP/Message.php';
require_once 'ApnsPHP/Push/Exception.php'; function push_ios_message($fans, $push_id, $text, $message_type, $artist_id)
{
$user_count = count($fans); if ($user_count == 0) {
return;
} $pem = './aaa.pem';
$password = '1234'; //$mode = ApnsPHP_Abstract::ENVIRONMENT_SANDBOX;
$mode = ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION; // Instanciate a new ApnsPHP_Push object
$push = new ApnsPHP_Push($mode, $pem, $password);
// Set the Root Certificate Autority to verify the Apple remote peer
$push->setRootCertificationAuthority($pem); // Connect to the Apple Push Notification Service
$push->connect(); $message = '';
for ($i = 0; $i < $user_count; $i++) {
$fans[$i]['device_token'] = trim($fans[$i]['device_token']); try {
// Instantiate a new Message with a single recipient
$message = new ApnsPHP_Message($fans[$i]['device_token']);
// Set a custom identifier. To get back this identifier use the getCustomIdentifier() method
// over a ApnsPHP_Message object retrieved with the getErrors() message.
$message->setCustomIdentifier("Message-Badge-3");
// Set badge icon to "3"
$message->setBadge(8);
// Set a simple welcome text
$message->setText($text);
// Play the default sound
$message->setSound();
$message->setCustomProperty('push_id', $push_id);
$message->setCustomProperty('message_type', $message_type);
// Set the expiry value to 30 seconds
$message->setExpiry(30);
// Add the message to the message queue
$push->add($message);
} catch (Exception $e) {
$message = '';
var_dump($e->getMessage());
} } try{
$push->send();
$push->disconnect(); // Examine the error message container
$aErrorQueue = $push->getErrors();
if (!empty($aErrorQueue)) {
var_dump($aErrorQueue);
var_dump(serialize($aErrorQueue));
}
} catch(Exception $e) {
echo 'Exception:';
var_dump($e->getMessage());
} }

三方包下载地址

https://github.com/zhoutingze/adtuu.git

利用ApnsPHP包向IOS推送消息的更多相关文章

  1. IOS 推送消息 php做推送服务端

    IOS推送消息是许多IOS应用都具备的功能,最近也在研究这个功能,参考了很多资料终于搞定了,下面就把步骤拿出来分享下: iOS消息推送的工作机制可以简单的用下图来概括: Provider是指某个iPh ...

  2. iOS 推送消息长度

    iOS最大推送消息长度 官方要求是256个字节 实际测试为1005个字节 在iPhone6上测试 锁屏时收到消息时只显示76个汉字,剩下的被隐藏 程序进入后台时只显示47个汉字,剩下的被隐藏

  3. python使用pyapns进行ios推送消息

    Pyapns 提供了通用的Apple Push Notification Service (APNS).该解决方案使用了开源的Twisted server,支持原生的Python和Ruby API. ...

  4. ThinkPHP 使用极光推送给ios推送消息

    HTML <div id="wrap"><a href="<{:U('Push/pushData')}>">推送</a ...

  5. 使用PushSharp给iOS应用推送消息

    PushSharp是一个C#编写的服务端类库,用于推送消息到各种客户端,支持iOS(iPhone/iPad).Android.Windows Phone.Windows 8.Amazo.Blackbe ...

  6. iOS点击推送消息跳到应用指定页面

    现在的推送用的越来越频繁,几乎每个应用都开始用到了.其实又有几个用户会去看推送消息呢?没办法,产品经理最大啊,只是苦了我们这一帮程序员啊!闲话少说,进入正题.兄弟我用的是极光推送,自然是以极光推送为例 ...

  7. IOS中程序如何进行推送消息(本地推送,远程推送)

    [1]-------------什么是推送消息? 我就以一张图解释------------ [2]-----------IOS程序中如何进行本地推送?----------- 2.1,先征求用户同意 1 ...

  8. IOS 推送-客户端处理推送消息

    IOS 推送-客户端处理推送消息 1.推送调用顺序 APN push的消息到达后,UIApplicationDelegate有两个方法和处理消息有关: 1)application:didReceive ...

  9. phonegap创建的ios项目推送消息出现闪退现象

    使用phonegap创建的ios项目,推送消息时,当程序在前台运行或者在后台运行状态下,推送消息过来,可以解析并且跳转: 但是在程序从后台退出的状态下,当消息推送过来的时候,点击通知栏,打开程序,程序 ...

随机推荐

  1. 怎样用通用pe工具箱制作U盘启动盘

    U盘启动盘制作过程,随着网络的普及,电脑已经成为我们日常生活中的重要一环,最近自己重装了下电脑系统,无意中发现一个傻瓜式的U盘装系统方法,就把怎么制作通用pe工具箱u盘启动盘的经验拿出来跟大家分享下. ...

  2. win7关机命令

    通过 DOS 命令 “shutdown” 来实现 Windows7 系统下的定时关机功能. 使用at 命令 at 12:00 shutdown -s,取消:at/delete shutdown -s ...

  3. 解决ajax回调函数无返回值得问题

    这里以编辑验证角色名为例: 首先,定义一个flag全局变量. 然后,在回调函数resp()中根据判断将flag的值设为true或false. 最后,在调用函数ckrname()中,return fla ...

  4. (转)嵌入式学习准备---linux c 文件锁

    (1)fcntl函数说明 前面的这5个基本函数实现了文件的打开.读写等基本操作,这一节将讨论的是,在文 件已经共享的情况下如何操作,也就是当多个用户共同使用.操作一个文件的情况,这时,Linux 通常 ...

  5. LeetCode 42

    Trapping Rain Water Given n non-negative integers representing an elevation map where the width of e ...

  6. MyBatis(3.2.3) - Paginated ResultSets using RowBounds

    Sometimes, we may need to work with huge volumes of data, such as with tables with millions of recor ...

  7. asp.net mvc开发的社区产品相关开发文档分享

    分享一款基于asp.net mvc框架开发的社区产品--近乎.目前可以在官网免费下载,下载地址:http://www.jinhusns.com/Products/Download?type=whp 1 ...

  8. 每天一道LeetCode--119.Pascal's Triangle II(杨辉三角)

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  9. Core Bluetooth Programming Guide

    https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth ...

  10. js中小数的操作及数字类型的验证

    1.丢弃小数部分,保留整数部分js:parseInt(7/2) 2.向上取整,有小数就整数部分加1js: Math.ceil(7/2) 3,四舍五入. js: Math.round(7/2) 4,向下 ...