コード例 #1
0
ファイル: PushInfo.class.php プロジェクト: skyworld/SKY_PHP
 /**
  * 批量发送消息
  * @return [type] [description]
  */
 static function send($sendId)
 {
     $pushInfoModel = new PushInfoModel();
     $db = DB::getInstance();
     if (!empty($sendId)) {
         $andSql = "and a.id={$sendId}";
     }
     $sql = "select b.device_token,b.device_type,b.token, a.params, a.id, a.content from t_push_info a, t_login b where a.to_user = b.uid and b.device_token != '' and a.is_send = 0 {$andSql} and b.token not like 'expired at%' group by device_token";
     $infos = $db->get_all($sql);
     if (count($infos > 0)) {
         foreach ($infos as $info) {
             if ($info['device_type']) {
                 $push = new XingeApp(2200102180, "661fd033916fadbf4e0866a18978782a");
                 $mess = new MessageIOS();
                 $mess->setAlert($info['content']);
                 $params = json_decode($info['params'], true);
                 if (!empty($params['content'])) {
                     $params['content'] = urldecode($params['content']);
                 }
                 $mess->setCustom($params);
                 $raw = $push->PushSingleDevice($info['device_token'], $mess, XingeApp::IOSENV_PROD);
                 $ret = json_encode($raw, true);
                 if ($ret['ret_code'] == 0) {
                     $sql = "update t_push_info set is_send = 1 where id={$info['id']}";
                     $db->query($sql);
                 }
             } else {
                 // for android
                 $push = new XingeApp(2100117084, "13391a7ec8a47d5e30525a04bd04befa");
                 $mess = new Message();
                 $mess->setTitle('合租吧');
                 $mess->setContent($info['content']);
                 $params = json_decode($info['params'], true);
                 if (!empty($params['content'])) {
                     $params['content'] = urldecode($params['content']);
                 }
                 $mess->setCustom($params);
                 $mess->setType(Message::TYPE_NOTIFICATION);
                 $mess->setStyle(new Style(0, 1, 1, 0, 0));
                 $action = new ClickAction();
                 $action->setActionType(ClickAction::TYPE_ACTIVITY);
                 $mess->setAction($action);
                 $raw = $push->PushSingleDevice($info['device_token'], $mess);
                 //$raw = XingeApp::PushTokenAndroid(2100117084, "13391a7ec8a47d5e30525a04bd04befa", "标题", "大家好!", $info['device_token']);
                 var_dump($raw);
                 $ret = json_encode($raw, true);
                 if ($ret['ret_code'] == 0) {
                     $sql = "update t_push_info set is_send = 1 where id={$info['id']}";
                     $db->query($sql);
                 }
             }
         }
     }
 }
コード例 #2
0
 /**
  * [pushAction description]
  * @return [type] [description]
  */
 public function pushAction()
 {
     //var_dump(XingeApp::PushTokenIos(2200102180, "661fd033916fadbf4e0866a18978782a", "你好啊,我是彭庚庚", "334b890e1718a3616b306e7f7b8202365f04a86bd6d43dd586474f9eb5be7061",
     // XingeApp::IOSENV_DEV));
     //echo '123';
     $push = new XingeApp(2200102180, "661fd033916fadbf4e0866a18978782a");
     $mess = new MessageIOS();
     $mess->setAlert('你好嘛,我是庚庚');
     $mess->setCustom(array('aid' => '3'));
     $ret = $push->PushSingleDevice('334b890e1718a3616b306e7f7b8202365f04a86bd6d43dd586474f9eb5be7061', $mess, XingeApp::IOSENV_DEV);
     var_dump($ret);
 }
コード例 #3
0
ファイル: W2PUSH.php プロジェクト: alonexy/lea
 /**
  * 推送接口
  * @param  int     $push_type       1单个设备 2部分人(*常用)
  * @param  int     $device_type 设备类型 1:浏览器设备 2:pc设备 3:Android设备 4:ios设备 5:windows phone设备
  * @param  string  $title        标题(仅安卓)
  * @param  string  $content      留言正文
  * @param  int     $customtype   自定义类型,t
  * @param  string  $customvalue  自定义值,v
  * @param  string  $p_deviceTokens 用户推送ID,百度里是buserid
  * @param  string  $tag_name     指定标签
  * @return array                 results
  */
 public static function pushMessage($push_type, $device_type, $title = '', $content, $customtype = null, $customvalue = null, $p_deviceTokens = null, $tag_name = null)
 {
     $push = null;
     $mess = null;
     $push = static::getPush($device_type);
     if ($push == null) {
         return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, '推送对象获取失败,无法创建推送任务。');
     }
     if ($device_type == 4) {
         $mess = new MessageIOS();
         $mess->setExpireTime(86400);
         //$mess->setSendTime("2014-03-13 16:00:00");
         $mess->setAlert($content);
         //$mess->setAlert(array('key1'=>'value1'));
         $mess->setBadge(0);
         $mess->setSound('');
         if (isset($customtype, $customvalue)) {
             $custom = array('t' => intval($customtype), 'v' => $customvalue);
             $mess->setCustom($custom);
         }
     } else {
         if ($device_type == 3) {
             $mess = new Message();
             if ($title == '') {
                 $title = $content;
             }
             $mess->setType(Message::TYPE_NOTIFICATION);
             $mess->setTitle($title);
             $mess->setContent($content);
             $mess->setExpireTime(86400);
             //$style = new Style(0);
             #含义:样式编号0,响铃,震动,不可从通知栏清除,不影响先前通知
             $style = new Style(0, 1, 1, 0, 0);
             $mess->setStyle($style);
             $action = new ClickAction();
             $action->setActionType(ClickAction::TYPE_ACTIVITY);
             $action->setActivity(' ');
             //扯淡的xinge sdk,isValid()方法判断m_activity默认值有点问题
             $mess->setAction($action);
             if (isset($customtype, $customvalue)) {
                 $custom = array('t' => intval($customtype), 'v' => $customvalue);
                 $mess->setCustom($custom);
             }
         } else {
             return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, '请传入正确的设备类型,iOS 还是 安卓');
         }
     }
     $params['production_mode'] = static::$DEPLOY_STATUS == 2;
     //是否正式环境
     $ret = array();
     switch ($push_type) {
         case 1:
             //指定token
             $p_deviceTokens = is_array($p_deviceTokens) ? $p_deviceTokens : explode(',', $p_deviceTokens);
             if (count($p_deviceTokens) == 0 || count($p_deviceTokens) == 1 && $p_deviceTokens[0] == null) {
                 return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, '请传入正确的用户推送token');
             }
             if (count($p_deviceTokens) > 5) {
                 $retMulti = $push->CreateMultipush($mess, $device_type == 3 ? 0 : (static::$DEPLOY_STATUS == 2 ? XingeApp::IOSENV_PROD : XingeApp::IOSENV_DEV));
                 $ret[] = array('action' => 'CreateMultipush', 'ret' => $retMulti);
                 if (is_array($retMulti) && array_key_exists('result', $retMulti) && array_key_exists('push_id', $retMulti['result'])) {
                     $maxCount = 1000;
                     //每次最大传输设备量
                     for ($i = 0; $i < count($p_deviceTokens); $i += $maxCount) {
                         $ret[] = array('action' => 'PushDeviceListMultiple', 'token' => $p_deviceTokens, 'ret' => $push->PushDeviceListMultiple($retMulti['result']['push_id'], array_slice($p_deviceTokens, $i, $maxCount)));
                     }
                 }
             } else {
                 foreach ($p_deviceTokens as $token) {
                     if ($device_type == 4) {
                         $ret[] = array('action' => 'PushSingleDevice', 'token' => $token, 'ret' => $push->PushSingleDevice($token, $mess, static::$DEPLOY_STATUS == 2 ? XingeApp::IOSENV_PROD : XingeApp::IOSENV_DEV));
                     } else {
                         if ($device_type == 3) {
                             $ret[] = array('action' => 'PushSingleDevice', 'token' => $token, 'ret' => $push->PushSingleDevice($token, $mess));
                         }
                     }
                 }
             }
             break;
         case 2:
             //指定设备群发
             if ($device_type == 4) {
                 $ret[] = array('action' => 'PushAllDevices', 'token' => '0', 'ret' => $push->PushAllDevices(0, $mess, static::$DEPLOY_STATUS == 2 ? XingeApp::IOSENV_PROD : XingeApp::IOSENV_DEV));
             } else {
                 if ($device_type == 3) {
                     $ret[] = array('action' => 'PushAllDevices', 'token' => '0', 'ret' => $push->PushAllDevices(0, $mess));
                 }
             }
             break;
         default:
             return Utility::getArrayForResults(RUNTIME_CODE_ERROR_PARAM, 'push_type 1:单个人 2部分人 3所有人');
     }
     return Utility::getArrayForResults(RUNTIME_CODE_OK, '', array('push_type' => $push_type, 'device_type' => $device_type, 'messages' => $mess, 'result' => $ret));
 }
コード例 #4
0
ファイル: XgPush.class.php プロジェクト: torry999/lingshi
 /**
  * 使用默认设置推送消息给标签选中设备ios版
  */
 public static function PushTagIos($accessId, $secretKey, $content, $tag, $environment)
 {
     $push = new XingeApp($accessId, $secretKey);
     $mess = new MessageIOS();
     $mess->setAlert($content);
     $ret = $push->PushTags(0, array(0 => $tag), 'OR', $mess, $environment);
     return $ret;
 }
コード例 #5
0
ファイル: demo.php プロジェクト: alonexy/lea
function DemoPushSingleAccountIOS()
{
    $push = new XingeApp(00, 'secret_key');
    $mess = new MessageIOS();
    $mess->setExpireTime(86400);
    $mess->setAlert("ios test");
    //$mess->setAlert(array('key1'=>'value1'));
    $mess->setBadge(1);
    $mess->setSound("beep.wav");
    $custom = array('key1' => 'value1', 'key2' => 'value2');
    $mess->setCustom($custom);
    $acceptTime1 = new TimeInterval(0, 0, 23, 59);
    $mess->addAcceptTime($acceptTime1);
    $ret = $push->PushSingleAccount(0, 'joelliu', $mess, XingeApp::IOSENV_DEV);
    return $ret;
}