Commit 8ddaee68 authored by wwccw0591's avatar wwccw0591

push

parent 0db91099
...@@ -62,6 +62,84 @@ class ClientPush ...@@ -62,6 +62,84 @@ class ClientPush
} }
return $messageContent; return $messageContent;
} }
public function pushTest($pushData)
{
// $pushFlag=(APP_ENV=='product' || APP_ENV=='productone')?true:false;
$pushFlag=false;
// echo json_encode($pushData);
$title=$this->getMessageType($pushData['fromType']);
$messageContent=$this->getMessageContent($pushData['message']);
$pushObject=array('id'=>433,'memberName'=>'abc');
$messageContent="testMessage";
$title='tesetTitle';
$pushData['toId']=433;
echo $pushData['toId'];
try {
$response = $this->client->push()
->setPlatform('all')
// 一般情况下,关于 audience 的设置只需要调用 addAlias、addTag、addTagAnd 或 addRegistrationId
// 这四个方法中的某一个即可,这里仅作为示例,当然全部调用也可以,多项 audience 调用表示其结果的交集
// 即是说一般情况下,下面三个方法和没有列出的 addTagAnd 一共四个,只适用一个便可满足大多数的场景需求
->addAlias((string)$pushData['toId'])
// ->addTag(array($pushData['toId'], 'tag2'))
//->addRegistrationId($pushData['toId'])
->setNotificationAlert($title)
->iosNotification($messageContent, array(
'sound' => 'sound.caf',
// 'badge' => '+1',
// 'content-available' => true,
// 'mutable-content' => true,
'category' => 'shenbd',
'extras' => $pushData,
))
->androidNotification($messageContent, array(
'title' =>$title,
// 'builder_id' => 2,
'extras' => $pushData,
))
->message($messageContent, array(
'title' => $title,
'content_type' => $pushData['message']['type'],
'extras' => $pushData,
))
->options(array(
// sendno: 表示推送序号,纯粹用来作为 API 调用标识,
// API 返回时被原样返回,以方便 API 调用方匹配请求与返回
// 这里设置为 100 仅作为示例
// 'sendno' => 100,
// time_to_live: 表示离线消息保留时长(秒),
// 推送当前用户不在线时,为该用户保留多长时间的离线消息,以便其上线时再次推送。
// 默认 86400 (1 天),最长 10 天。设置为 0 表示不保留离线消息,只有推送当前在线的用户可以收到
// 这里设置为 1 仅作为示例
// 'time_to_live' => 1,
// apns_production: 表示APNs是否生产环境,
// True 表示推送生产环境,False 表示要推送开发环境;如果不指定则默认为推送生产环境
'apns_production' => $pushFlag,
// big_push_duration: 表示定速推送时长(分钟),又名缓慢推送,把原本尽可能快的推送速度,降低下来,
// 给定的 n 分钟内,均匀地向这次推送的目标用户推送。最大值为1400.未设置则不是定速推送
// 这里设置为 1 仅作为示例
// 'big_push_duration' => 1
))
->send();
print_r($response);
} catch (\JPush\Exceptions\APIConnectionException $e) {
// try something here
print $e;
} catch (\JPush\Exceptions\APIRequestException $e) {
// try something here
print $e;
}
}
public function push($pushData) public function push($pushData)
{ {
// $pushFlag=(APP_ENV=='product' || APP_ENV=='productone')?true:false; // $pushFlag=(APP_ENV=='product' || APP_ENV=='productone')?true:false;
......
<?php
/**
* 推送10秒推送一次
* 推送10秒推送一次
*
* @author chenjiebin <sjlinyu@qq.com>
*/
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../../../')); //指向public的上一级
require APPLICATION_PATH . '/scripts/crontab/baseCli.php';
require APPLICATION_PATH . '/scripts/crontab/common.php';
error_reporting(E_ALL ^ E_NOTICE);
class cliOrderClose extends basecli
{
const CLI_ADMIN_ID = 255;
private $bDoUnLock = FALSE; // 是否允许释放 LOCK 文件
private $_debug = 0;
private $lockFileName;
private $fromState;
private function mkdirs($dir, $mode = 0777)
{
if (is_dir($dir) || @mkdir($dir, $mode)){
return TRUE;
}
if (!$this->mkdirs(dirname($dir), $mode)){
return FALSE;
}
return @mkdir($dir, $mode);
}
/**
* 析构
*/
public function __destruct()
{
parent::__destruct();
if ($this->bDoUnLock)
{
@unlink($this->lockFileName);
}
}
protected function autoPushMessage(){
$conf = \Yaf\Registry::get('config')->get('redis.database.params');
$redis = new \Redis();
$redis->pconnect($conf['host'], $conf['port']);
if (!empty($conf['password'])) {
$redis->auth($conf['password']);
}
$clientPush=\JPush\ClientPush::getInstance();
$clientPush->pushTest(array());exit;
$memberCenterServiceDao=\Business\User\MemberCenterServiceModel::getInstance();
//$messageService=\DAO\MessageHistoryModel::getInstance();
while($pushData=$redis->rPop('push_center')){
$addData = unserialize($pushData);
$addData['message'] = unserialize($addData['message']);
$res=$memberCenterServiceDao->getMessageSet($addData['toId']);
if($res['canPush']!=\Our\ApiConst::one){
continue;
}
// else{
// if(!empty($res['timeDiff'])){
// $timeArr=explode('-',$res['timeDiff']);
// if(!empty($timeArr)){v
// if(\Our\Common::isCurentTimeInSection($timeArr[0],$timeArr[1])){
// continue;
// }
// }
// }
//
// }
$clientPush->push($addData);
}
$redis->close();
}
protected function autoPushClient(){
$push=\Our\Push::getInstance();
while($pushData=\Our\RedisHelper::lpop('client_push')){
$push->addOneToClient($pushData);
}
$goodsCommonService=\Business\Goods\GoodsCommonServiceModel::getInstance();
$storesBase=$goodsCommonService->getAlertGoods();
if($storesBase){
$storesIds=array_column($storesBase,'storeId');
$stores=$goodsCommonService->getGoodsCount($storesIds);
if(!empty($stores)){
foreach($stores as $store){
$addData=array('storeId'=>$store['storeId'],'type'=>\Our\ApiConst::messageGoodsAlert,'op'=>\Our\NameConst::set,'alertCount'=>$store['count'],'params'=>array());
$push->addOneToClient($addData);
}
}
}
$push->sendTcpMessage();
}
protected function _runCli()
{
$this->_debug = isset($this->aArgv[1]) ? intval($this->aArgv[1]) : 0;
if ($this->_debug)
{
echo "*** Debug mode ***\n";
}
// Step: 02 检查是否已有相同CLI在运行中
$lockDir=$this->_getBaseFileName('push');
if(!$this->mkdirs($lockDir)){
echo '****create dir fail ****';
exit;
}
$this->lockFileName = $lockDir .DS.'jpush.locks';
if( file_exists( $this->lockFileName ) )
{
$stat = stat($this->lockFileName);
if( (TIMESTAMP - $stat['mtime']) > 1800 )
{
echo "文件被锁超过1800秒,被强制删除";
@unlink($this->lockFileName);
}
else
{
$this->halt( '[' . date('Y-m-d H:i:s') .'] The CLI is running'."\n");
}
}
$this->bDoUnLock = true;
if(APP_ENV =='pre' || APP_ENV=='product'){
file_put_contents($this->lockFileName ,"running" ); // CLI 独占锁
}
$this->autoPushMessage();
echo date('Y-m-d H:i:s',TIMESTAMP).'消息推送成功'."\r\n";
$this->autoPushClient();
echo date('Y-m-d H:i:s',TIMESTAMP).'客户端消息推送成功'."\r\n";
}
}
$oCli = new cliOrderClose(TRUE);
EXIT;
?>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment