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. 在查找预编译头时遇到意外的文件结尾。是否忘记了向源中添加“#include "StdAfx.h"”?

    在查找预编译头时遇到意外的文件结尾.是否忘记了向源中添加“#include "StdAfx.h"”? 右键选择该文件.cpp格式的->属性->预编译头,→ 不使用预编译 ...

  2. ios数据缓存方法

    转载自:http://zhidao.baidu.com/link?url=jNTz6lkL1way8bJ-WPY197Pe9aEM_ql-MZbVJsM5tXr7Mv82W70QQ5a9UlvhMMS ...

  3. some words we should know

    2010年,芬兰艺术家Mikko Kuorinki做了一件独特的艺术品. 他在赫尔辛基的奇亚斯玛当代艺术博物馆(Kiasma museum),找了一堵墙,装了一个175 x 320cm的木架子,上面用 ...

  4. redis中5种数据结构的使用

    一.redis 数据结构使用场景 原来看过 redisbook 这本书,对 redis 的基本功能都已经熟悉了,从上周开始看 redis 的源码.目前目标是吃透 redis 的数据结构.我们都知道,在 ...

  5. #if...#endif的用法总结

    在写到  pwm音阶程序的时候,在代码中有#if...#endif的用法问题,相关音阶的代码如下: /************************************************* ...

  6. Nginx+FastCGI+C

    http://flandycheng.blog.51cto.com/855176/858946 http://www.cnblogs.com/xiaouisme/archive/2012/08/01/ ...

  7. [Yii2]Access to debugger is denied due to IP address restriction. The requesting IP address is

    在更新到正式平台,看到runtime/app.log 有 Access to debugger is denied due to IP address restriction. The request ...

  8. CSS3 媒体记

    css3 媒体 Media Type 媒体类型 媒体类型是CSS2中一个非常有用的属性.通过媒体类型可以对不同的设备指定不同的样式. W3C共列出十种媒体类型,如表: 值 设备类型 all 所有设备 ...

  9. MyBatis(3.2.3) - Configuring MyBatis using XML, Mappers

    Mapper XML files contain the mapped SQL statements that will be executed by the application using st ...

  10. lstm-思想

    RNN(Recurrent Neural Network) 今天我这里讲到的RNN主要是上图这种结构的,即是Hidden Layer会有连向下一时间Hidden Layer的边,还有一种结构是Bidi ...