Created
October 2, 2013 04:29
-
-
Save yaowenqiang/6789171 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* sample_push_many.php | |
* | |
* Apns-php 文件夹地址:https://www.dropbox.com/sh/170mcjp39v5qwqe/IUv7IUmBcc | |
* Push demo | |
* | |
* LICENSE | |
* | |
* This source file is subject to the new BSD license that is bundled | |
* with this package in the file LICENSE.txt. | |
* It is also available through the world-wide-web at this URL: | |
* http://code.google.com/p/apns-php/wiki/License | |
* If you did not receive a copy of the license and are unable to | |
* obtain it through the world-wide-web, please send an email | |
* to [email protected] so we can send you a copy immediately. | |
* | |
* @author (C) 2010 Aldo Armiento ([email protected]) | |
* @version $Id$ | |
*/ | |
if(isset($_SERVER["HTTP_HOST"])){//定时脚本不能通过浏览器访问 | |
//die(); | |
} | |
include_once('/opt/ci123/www/html/markets/app2/baby/yunqi/inc/config.php'); | |
include_once('/opt/ci123/www/html/markets/app2/baby/yunqi/inc/function.php'); | |
include_once('/opt/ci123/www/html/markets/app2/baby/yunqi/inc/mysqlClass.php'); | |
define('MEMCACHE_HOST','192.168.1.116'); | |
define('MEMCACHE_PORT','11213'); | |
include_once('/opt/ci123/www/html/ci123libs/data/classes/hash/memcache/memcache.php'); | |
echo "----------------------\n"; | |
$cron = 1;//iphone文件 | |
$ms = new Mysqls(); | |
$now=date("Y-m-d H:i:s"); | |
$sql="select * from `yunqi_cms_urls` where dated<'{$now}' and category=7 order by dated desc limit 1"; | |
$postinfo=$ms->getRow($sql); | |
if(!$postinfo){ | |
echo "没有数据\n"; | |
echo "\n---------------------\n\n"; | |
die(); | |
} | |
$key='iphone_push_page'.$cron.'_'.$postinfo['id']; | |
#M::Set($key,0,60000);die(); | |
$page=(int)M::Get($key); | |
if($page==-1){//已经推送过 | |
echo $now."之前消息已经推送\n"; | |
echo "\n---------------------\n\n"; | |
die(); | |
} | |
$sql = "select id,user_id,ios_token from `yunqi_bbs_user` where uninstall_dated='0000-00-00 00:00:00' and bind_uid=0 and from_type=4 group by ios_token order by id asc"; | |
$data = $ms->getRows($sql); | |
// Adjust to your timezone | |
date_default_timezone_set('PRC'); | |
// Report all PHP errors | |
error_reporting(0); | |
// Using Autoload all classes are loaded on-demand | |
include_once('/opt/ci123/www/html/markets/app2/baby/yunqi/ios2/apn/ApnsPHP/Autoload.php'); | |
// Instanciate a new ApnsPHP_Push object | |
$push = new ApnsPHP_Push( | |
ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION, | |
'/opt/ci123/www/html/markets/app2/baby/yunqi/ios2/apn/ck_push.pem' | |
); | |
//iSet the Root Certificate Autority to verify the Apple remote peer | |
$push->setRootCertificationAuthority('/opt/ci123/www/html/markets/app2/baby/yunqi/ios2/apn/ck_push.pem'); | |
// Increase write interval to 100ms (default value is 10ms). | |
// This is an example value, the 10ms default value is OK in most cases. | |
// To speed up the sending operations, use Zero as parameter but | |
// some messages may be lost. | |
// $push->setWriteInterval(100 * 1000); | |
// Connect to the Apple Push Notification Service | |
$push->connect(); | |
$i=1; | |
foreach($data as $k=>$v){ | |
if(strlen($v['ios_token'])>10){ | |
//$token = str_replace(' ', '', '1ad90f24aa2b7a52cd626f09042362bcee5b84fcb1882ded94d06cd6978fc3c3'); | |
$token = str_replace(' ', '', $v['ios_token']); | |
$message = new ApnsPHP_Message($token); | |
$message->setCustomIdentifier(sprintf("Message-Badge-%06d", $i)); | |
$message->setText($postinfo['title']); | |
$message->setSound(); | |
$info = array('notice_id'=>(int)$postinfo['id'], 'id'=>(int)$postinfo['post_id']); | |
$message->setCustomProperty('info',$info); | |
$message->setExpiry(30); | |
$message->setBadge(2); | |
$push->add($message); | |
echo "执行第".$i."条id:".$v['id']."----------token:".$v['ios_token']."\r\n"; | |
$i++; | |
//if($i==3){break;} | |
} | |
} | |
M::Set($key,-1,30*24*60*60); | |
$i--; | |
$i=max(0,$i); | |
$sql="update `yunqi_cms_urls` set total_num=total_num+$i where id='".$postinfo['id']."' limit 1"; | |
$ms->query($sql); | |
echo "======共执行".$i."条\r\n"; | |
// Send all messages in the message queue | |
$push->send(); | |
// Disconnect from the Apple Push Notification Service | |
$push->disconnect(); | |
// Examine the error message container | |
$aErrorQueue = $push->getErrors(); | |
if (!empty($aErrorQueue)) { | |
var_dump($aErrorQueue); | |
} | |
echo "\n---------------------\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment