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. AngularJS - 定时器 倒计时例子

    <body> <div ng-app="myApp"> <div ng-controller="firstController"& ...

  2. VIM标记 mark 详解

    转载:http://blog.163.com/lgh_2002/blog/static/44017526201081154512135/ 我的vim配置:http://pan.baidu.com/s/ ...

  3. C# 之 Stream 和 byte[] 的相关转换

    1.二进制转换为图片 MemoryStream ms = new MemoryStream(bytes); ms.Position = ; Image img = Image.FromStream(m ...

  4. request 和response 中的setCharacterEncoding区别

    response和request的setCharacterEncoding 一.request.setCharacterEncoding():是设置从request中取得的值或从数据库中取出的值. 指 ...

  5. storyBoard中的Segue跳转

    //———————————————--------------在不确定的Segue跳转-----------------------------------   多个按钮指向要跳转的视图 1.在一个恰 ...

  6. Installing MySQL Connector/Python using pip v1.5

    The latest pip versions will fail on you when the packages it needs to install are not hosted on PyP ...

  7. jquery中ajax向action传递对象参数,json ,spring注入对象

    首先,我这个程序的框架是spring+struts2+hibernate. 后端的action的需要接受从前端传进来的参数,由spring的注入,可知,如果前端用的是form的话,只需要在每个inpu ...

  8. tomcat部署应用的几种方式

    接着上篇 tomcat配置详解,再来学习下如何在tomcat下部署应用 1.部署方式 第一种,最常用,直接把WAR包或者文件夹直接放到webapps目录下面,这时访问路径就是WAR包或者文件夹的名称. ...

  9. poj 2411 状态压缩dp

    思路:将每一行看做一个二进制位,那么所有的合法状态为相邻为1的个数一定要为偶数个.这样就可以先把所有的合法状态找到.由于没一层的合法状态都是一样的,那么可以用一个数组保存.由第i-1行到第i行的状态转 ...

  10. Spring 数据源配置三:多数据源

    在上一节中,我们讲述了多数据的情况: 1. 数据源不同(数据库厂商不同, 业务范围不同, 业务数据不同) 2. SQL mapper 文件不同, 3. mybatis + 数据方言不同 即最为简单的多 ...