123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- <?php
-
- require_once 'DB_PDO.class.php';
- require_once 'conf.class.php';
- require_once 'HuaweiPush.php';
-
- //设置时区
- date_default_timezone_set('PRC');
- /*
- $desc = array();
-
- $desc['appid'] = '100228763';
- $desc['appsecret'] = '6170edadd53e02e02139d5b532c84cd7';
- $desc['package'] = 'com.kuxuan.coupon';
- $desc['device_token'] = ['0869381031509981300002338700CN01'];
- $desc['message'] = '贴身的东西,就要用高档的一等品超大浴巾,随意一擦就干了>>';
- $desc['title'] = '【南极人】超大浴巾【券后28元】包邮';
-
- $res = HuaweiPush::pushAndroid($desc);
- var_dump($res);
- exit;
- */
- $time = time();
- $stime = $time-1000;//误差10m
- $etime = $time+1000;
-
- echo "\n time:".date('Y-m-d H:i:s');
- $sql = "SELECT * FROM message_push where type=2 and message_type=2 and push_at>:stime and push_at<:etime order by id desc ";
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':stime'=>$stime,'etime'=>$etime));
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
- if(empty($result)){
- exit(' 此时段不存在定时推送任务');
- }
- foreach($result as $k => $v){
- if($v['app'] == 4){
- $appArr = [2];
- foreach( $appArr as $app ){
- $config = getpushconfig($app);
- if( !empty($config) ){
- $v['appid'] = $config['appid'];
- $v['appsecret'] = $config['appsecret'];
- $v['package'] = $config['package'];
- $device_token = getUserDevice($app);
- echo "\nusers:";
- var_dump($device_token);
- $n = ceil(count($device_token)/1000);
- for($i=1;$i<=$n;$i++){
- $pageSize = 1000;
- $offset = ($i-1)*1000;
- $v['device_token'] = array_slice($device_token,$offset,$pageSize);
- $res = HuaweiPush::pushAndroid($v);
- echo "\napp:".$app;
- var_dump($res);
- }
- }
- }
- }else{
- $app = $v['app'];
- $config = getpushconfig($app);
- if( !empty($config) ){
- $v['appid'] = $config['appid'];
- $v['appsecret'] = $config['appsecret'];
- $v['package'] = $config['package'];
- $device_token = getUserDevice($app);
- $n = ceil(count($device_token)/1000);
- for($i=1;$i<=$n;$i++){
- $pageSize = 1000;
- $offset = ($i-1)*1000;
- $v['device_token'] = array_slice($device_token,$offset,$pageSize);
- $res = HuaweiPush::pushAndroid($v);
- echo "\napp:".$app;
- var_dump($res);
- }
- }
- }
- }
-
- function getpushconfig( $app ){
- $sql = "SELECT * FROM push_config where type=3 and app=:app and s_type=1 ";
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':app'=>$app));
- $result = $stmt->fetch(PDO::FETCH_ASSOC);
- return $result;
- }
-
- function getUserDevice( $app ){
- $sql = " SELECT device_token FROM user_device_token where type=2 and app = :app ";
- $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
- $stmt = $_PDO->prepare($sql);
- $stmt->execute(array(':app'=>$app));
- $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
- $retArr = array();
- $retArr = i_array_column($result, 'device_token');
- $retArr = array_unique($retArr);
- return $retArr;
- }
-
- function i_array_column($input, $columnKey, $indexKey=null){
- if(!function_exists('array_column')){
- $columnKeyIsNumber = (is_numeric($columnKey))?true:false;
- $indexKeyIsNull = (is_null($indexKey))?true :false;
- $indexKeyIsNumber = (is_numeric($indexKey))?true:false;
- $result = array();
- foreach((array)$input as $key=>$row){
- if($columnKeyIsNumber){
- $tmp= array_slice($row, $columnKey, 1);
- $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null;
- }else{
- $tmp= isset($row[$columnKey])?$row[$columnKey]:null;
- }
- if(!$indexKeyIsNull){
- if($indexKeyIsNumber){
- $key = array_slice($row, $indexKey, 1);
- $key = (is_array($key) && !empty($key))?current($key):null;
- $key = is_null($key)?0:$key;
- }else{
- $key = isset($row[$indexKey])?$row[$indexKey]:0;
- }
- }
- $result[$key] = $tmp;
- }
- return $result;
- }else{
- return array_column($input, $columnKey, $indexKey);
- }
- }
|