优惠券订单及其他脚本

message_push1.php 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. require_once 'DB_PDO.class.php';
  3. require_once 'conf.class.php';
  4. require_once 'HuaweiPush.php';
  5. //设置时区
  6. date_default_timezone_set('PRC');
  7. /*
  8. $desc = array();
  9. $desc['appid'] = '100228763';
  10. $desc['appsecret'] = '6170edadd53e02e02139d5b532c84cd7';
  11. $desc['package'] = 'com.kuxuan.coupon';
  12. $desc['device_token'] = ['0869381031509981300002338700CN01'];
  13. $desc['message'] = '贴身的东西,就要用高档的一等品超大浴巾,随意一擦就干了>>';
  14. $desc['title'] = '【南极人】超大浴巾【券后28元】包邮';
  15. $res = HuaweiPush::pushAndroid($desc);
  16. var_dump($res);
  17. exit;
  18. */
  19. $time = time();
  20. $stime = $time-1000;//误差10m
  21. $etime = $time+1000;
  22. echo "\n time:".date('Y-m-d H:i:s');
  23. $sql = "SELECT * FROM message_push where type=2 and message_type=2 and push_at>:stime and push_at<:etime order by id desc ";
  24. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  25. $stmt = $_PDO->prepare($sql);
  26. $stmt->execute(array(':stime'=>$stime,'etime'=>$etime));
  27. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  28. if(empty($result)){
  29. exit(' 此时段不存在定时推送任务');
  30. }
  31. foreach($result as $k => $v){
  32. if($v['app'] == 4){
  33. $appArr = [2];
  34. foreach( $appArr as $app ){
  35. $config = getpushconfig($app);
  36. if( !empty($config) ){
  37. $v['appid'] = $config['appid'];
  38. $v['appsecret'] = $config['appsecret'];
  39. $v['package'] = $config['package'];
  40. $device_token = getUserDevice($app);
  41. echo "\nusers:";
  42. var_dump($device_token);
  43. $n = ceil(count($device_token)/1000);
  44. for($i=1;$i<=$n;$i++){
  45. $pageSize = 1000;
  46. $offset = ($i-1)*1000;
  47. $v['device_token'] = array_slice($device_token,$offset,$pageSize);
  48. $res = HuaweiPush::pushAndroid($v);
  49. echo "\napp:".$app;
  50. var_dump($res);
  51. }
  52. }
  53. }
  54. }else{
  55. $app = $v['app'];
  56. $config = getpushconfig($app);
  57. if( !empty($config) ){
  58. $v['appid'] = $config['appid'];
  59. $v['appsecret'] = $config['appsecret'];
  60. $v['package'] = $config['package'];
  61. $device_token = getUserDevice($app);
  62. $n = ceil(count($device_token)/1000);
  63. for($i=1;$i<=$n;$i++){
  64. $pageSize = 1000;
  65. $offset = ($i-1)*1000;
  66. $v['device_token'] = array_slice($device_token,$offset,$pageSize);
  67. $res = HuaweiPush::pushAndroid($v);
  68. echo "\napp:".$app;
  69. var_dump($res);
  70. }
  71. }
  72. }
  73. }
  74. function getpushconfig( $app ){
  75. $sql = "SELECT * FROM push_config where type=3 and app=:app and s_type=1 ";
  76. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  77. $stmt = $_PDO->prepare($sql);
  78. $stmt->execute(array(':app'=>$app));
  79. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  80. return $result;
  81. }
  82. function getUserDevice( $app ){
  83. $sql = " SELECT device_token FROM user_device_token where type=2 and app = :app ";
  84. $_PDO=DB_PDO::getInstance( conf::$DB_CONF );
  85. $stmt = $_PDO->prepare($sql);
  86. $stmt->execute(array(':app'=>$app));
  87. $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
  88. $retArr = array();
  89. $retArr = i_array_column($result, 'device_token');
  90. $retArr = array_unique($retArr);
  91. return $retArr;
  92. }
  93. function i_array_column($input, $columnKey, $indexKey=null){
  94. if(!function_exists('array_column')){
  95. $columnKeyIsNumber = (is_numeric($columnKey))?true:false;
  96. $indexKeyIsNull = (is_null($indexKey))?true :false;
  97. $indexKeyIsNumber = (is_numeric($indexKey))?true:false;
  98. $result = array();
  99. foreach((array)$input as $key=>$row){
  100. if($columnKeyIsNumber){
  101. $tmp= array_slice($row, $columnKey, 1);
  102. $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null;
  103. }else{
  104. $tmp= isset($row[$columnKey])?$row[$columnKey]:null;
  105. }
  106. if(!$indexKeyIsNull){
  107. if($indexKeyIsNumber){
  108. $key = array_slice($row, $indexKey, 1);
  109. $key = (is_array($key) && !empty($key))?current($key):null;
  110. $key = is_null($key)?0:$key;
  111. }else{
  112. $key = isset($row[$indexKey])?$row[$indexKey]:0;
  113. }
  114. }
  115. $result[$key] = $tmp;
  116. }
  117. return $result;
  118. }else{
  119. return array_column($input, $columnKey, $indexKey);
  120. }
  121. }