/** * 批量发送消息 * @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); } } } } }
/** * [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); }
public function PushAllIos($content) { $iosConfig = $this->config['iOS']; $accessId = $iosConfig['accessId']; $secretKey = $iosConfig['secretKey']; $environment = $iosConfig['environment'] == 'production' ? XingeApp::IOSENV_PROD : XingeApp::IOSENV_DEV; return XingeApp::PushAllIos($accessId, $secretKey, $content, $environment); }
private function _sendAppNotice(&$rs, $title, $content) { T('other/xingeApp'); $sendInfo = array('title' => $title, 'content' => $content, 'custom' => array('mod' => 'orderdetail', 'para' => 'oid=' . $rs['order_id'])); $result = XingeApp::Push($sendInfo, (string) $rs['uid']); // print_r($result); $res = array('result' => 0, 'msg' => '-1-未知错误'); //安卓系统 if ($rs['order_source'] == 2 && isset($result['android']['ret_code'])) { if ($result['android']['ret_code'] == 0) { $res = array('result' => 1, 'msg' => 'ok'); } else { $res = array('result' => 0, 'msg' => $result['android']['ret_code'] . '-' . $result['android']['err_msg']); } } //IOS系统 if ($rs['order_source'] == 1 && isset($result['ios']['ret_code'])) { if ($result['ios']['ret_code'] == 0) { $res = array('result' => 1, 'msg' => 'ok'); } else { $res = array('result' => 0, 'msg' => $result['ios']['ret_code'] . '-' . $result['ios']['err_msg']); } } // z($res); return $res; }
private function push_notice($type) { $id = intval($this->input['id']); if ($type == 'update' && !$id) { $this->errorOutput('id不存在'); } $app_id = intval($this->input['app_push_id']); if (!$app_id) { $this->errorOutput('请选择应用'); } /**************权限控制开始**************/ //节点权限 if ($app_id && $this->user['group_type'] > MAX_ADMIN_TYPE) { $nodes['nodes'][$app_id] = $app_id; } $nodes['_action'] = 'notice_manage'; $this->verify_content_prms($nodes); /**************权限控制结束**************/ $content = trim($this->input['content']); if (!$content) { $this->errorOutput('请输入通知内容'); } $ios = $ios_dev = ''; if ($this->input['ios'] == 1) { $ios_dev = 1; } else { if ($this->input['ios'] == 2) { $ios = 1; } } $android_sys = $this->input['android']; $winphone = $this->input['winphone']; if (!$ios && !$ios_dev && !$android_sys && !$winphone) { $this->errorOutput('请选择客户端设备系统'); } //根据应用id查询注册应用信息 $sql = 'SELECT * FROM ' . DB_PREFIX . "app_info WHERE id = " . $app_id; $appinfo = array(); $appinfo = $this->db->query_first($sql); if (empty($appinfo)) { $this->errorOutput('注册应用信息不存在'); } //扩展字段 if ($this->input['extras']) { $extras = $this->input['extras']; } //通知离线时间 $expire_time = intval($this->input['expire_time']); //发送时间 $send_time = $this->input['send_time']; //platform_type:1信鸽,2极光,3AVOS $platform_type = $appinfo['platform_type']; //极光可以不写标题,不写标题,默认显示应用包名称 $title = trim($this->input['title']); if (!$title && $platform_type == 1) { $this->errorOutput('请输入通知标题'); } if ($platform_type == 1) { $accessId = $appinfo['access_id']; $secretKey = $appinfo['secret_key']; //$accessId = 2100033914; //$secretKey = '755776a7f60242ed472848ddf6b08197'; if (!$accessId || !$secretKey) { $this->errorOutput('请传入应用信息'); } include_once CUR_CONF_PATH . 'lib/XingeApp.php'; $push = new XingeApp($accessId, $secretKey); $mess = new Message(); $mess->setTitle($title); $mess->setContent($content); //0是通知,1是消息 $mess_type = intval($this->input['mess_type']); if ($mess_type) { $mess->setType(Message::TYPE_MESSAGE); } else { $mess->setType(Message::TYPE_NOTIFICATION); $style = new Style(0); #含义:样式编号0,响铃,震动,可从通知栏清除,不影响先前通知 $style = new Style(0, 1, 1, 1, 0); $mess->setStyle($style); #接收消息时间范围 $acceptTime1 = new TimeInterval(0, 0, 23, 59); $mess->addAcceptTime($acceptTime1); //发送时间 if ($send_time) { $send_time .= ':00'; $mess->setSendTime($send_time); } //离线时间 if ($expire_time) { $mess->setExpireTime($expireTime); } $action = new ClickAction(); $action_type = intval($this->input['action_type']); //点击通知操作 $action_url = $this->input['action_url']; //打开的url地址 $intent = $this->input['intent']; if (!$action_type) { #打开activity或app本身 $action->setActionType(ClickAction::TYPE_ACTIVITY); } else { if ($action_type == 1 && $action_url) { //打开链接 $action->setActionType(ClickAction::TYPE_URL); $action->setUrl($action_url); #打开url需要用户确认 $action_comfirm = intval($this->input['action_comfirm']); $action->setComfirmOnUrl($action_comfirm); } else { if ($action_type == 2 && $intent) { $action->setActionType(ClickAction::TYPE_INTENT); $action->setIntent($intent); } } } $mess->setAction($action); #自定义内容 if ($extras) { $mess->setCustom($extras); } } //设备标识 $device_token = trim($this->input['device_token']); //推送帐号 //$account = trim($this->input['account']); $environment = 0; //设备类型 $device_sys = ''; if (($ios || $ios_dev) && $android_sys && $winphone) { $device_sys = XingeApp::DEVICE_ALL; //向ios推送时启用,1生产,2开发 $environment = $ios_dev ? 2 : 1; } else { if ($ios || $ios_dev) { $device_sys = XingeApp::DEVICE_IOS; //向ios推送时启用,1生产,2开发 $environment = $ios_dev ? 2 : 1; } else { if ($android_sys) { $device_sys = XingeApp::DEVICE_ANDROID; } else { if ($winphone) { $device_sys = XingeApp::DEVICE_WINPHONE; } } } } $ret = $push->PushAllDevices($device_sys, $mess, $environment); if (!$ret['ret_code']) { $ret['errcode'] = 0; $ret['msg_id'] = $ret['result']['push_id']; $ret['errmsg'] = '发送成功'; } else { $ret['errcode'] = $ret['ret_code']; $errmsg = $this->XingeErrorMsg($ret['ret_code']); $ret['errmsg'] = $errmsg['errmsg']; } } else { if ($platform_type == 2) { include_once CUR_CONF_PATH . 'lib/jpush/JPushClient.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Audience.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Message.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/notification/Notification.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Options.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Platform.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/PushPayload.php'; $app_key = $appinfo['access_key']; $master_secret = $appinfo['secret_key']; //$master_secret = 'b10501ff90b68130097458bc'; //$app_key='2193f24f5975b39235afdc9a'; $client = new JPushClient($app_key, $master_secret); $platform = new Platform(); $audience = new Audience(); $message = new Message(); $options = new Options(); $notification = new Notification(); $extras = array(); $link_module = trim($this->input['link_module']); if ($link_module) { $extras = array($link_module => ''); if ($this->input['module_id']) { $extras[$link_module] = $this->input['module_id']; } } //set platform params if ($ios || $ios_dev) { include_once CUR_CONF_PATH . 'lib/jpush/model/notification/IOSNotification.php'; $ios_obj = new IOSNotification(); $platform->ios = true; //set notification params $ios_obj->alert = $content; $ios_obj->sound = "default"; $ios_obj->badge = 1; //$ios->extras = $extras; //静默推送 $ios_obj->content_available = null; $notification->ios = $ios_obj; $options->apns_production = $ios_dev ? false : true; } if ($android_sys) { include_once CUR_CONF_PATH . 'lib/jpush/model/notification/AndroidNotification.php'; $android = new AndroidNotification(); $platform->android = true; $android->alert = $content; $android->title = $title; $android->builder_id = 1; //$android->extras = $extras; $notification->android = $android; } if ($winphone) { include_once CUR_CONF_PATH . 'lib/jpush/model/notification/WinphoneNotification.php'; $winphone_obj = new WinphoneNotification(); $platform->winphone = true; $winphone_obj->alert = $content; $winphone_obj->title = $title; $winphone_obj->_open_page = "/friends.xaml"; //$winphone->extras = $extras; $notification->winphone = $winphone_obj; } //set options params设置选项 //$options->sendno = 10; $options->time_to_live = $expire_time; $notification->alert = $content; //发送广播通知 $payload = new PushPayload(); $payload->notification = $notification; //设置接受设备系统 //$payload->platform = $platform; $payload->options = $options; $ret = $client->sendPush($payload); $ret = json_decode($ret, 1); if ($ret['error']) { $ret['errcode'] = $ret['reeor']['code']; $errmsg = $this->JPushErrorMsg($ret['errcode']); $ret['errmsg'] = $errmsg['errmsg']; } else { $ret['errcode'] = 0; $ret['msg_id'] = $ret['msg_id']; $ret['errmsg'] = '发送成功'; } } else { if ($platform_type == 3) { if (!$appinfo['access_id'] || !$appinfo['access_key'] || !$appinfo['secret_key']) { $this->errorOutput('缺少应用配置'); } if (!$appinfo['channel']) { $this->errorOutput('订阅频道不存在'); } include_once CUR_CONF_PATH . 'lib/avos/AV.php'; include_once CUR_CONF_PATH . 'lib/avos/AVObject.php'; include_once CUR_CONF_PATH . 'lib/avos/AVQuery.php'; include_once CUR_CONF_PATH . 'lib/avos/AVUser.php'; include_once CUR_CONF_PATH . 'lib/avos/AVFile.php'; include_once CUR_CONF_PATH . 'lib/avos/AVPush.php'; include_once CUR_CONF_PATH . 'lib/avos/AVGeoPoint.php'; include_once CUR_CONF_PATH . 'lib/avos/AVACL.php'; include_once CUR_CONF_PATH . 'lib/avos/AVCloud.php'; $obj = new AVPush(); $app_info['access_id'] = $appinfo['access_id']; $app_info['access_key'] = $appinfo['access_key']; $app_info['secret_key'] = $appinfo['secret_key']; $app_info['action'] = $appinfo['action']; $app_info['avos_url'] = 'https://cn.avoscloud.com/1/'; //应用信息 $obj->app_info = $app_info; ############################################## if ($ios || $ios_dev) { $ios_info = array('alert' => $content); //声音 $sound = $this->input['sound']; if ($sound) { $ios_info['sound'] = $sound; } else { $ios_info['sound'] = 'UILocalNotificationDefaultSoundName'; } if ($this->input['badge']) { $ios_info['badge'] = $this->input['badge']; } else { $ios_info['badge'] = 'Increment'; } if ($this->input['link_module']) { $ios_info['module_id'] = $this->input['link_module']; } if ($this->input['content_id']) { $ios_info['id'] = $this->input['content_id']; } if ($ios_dev) { $obj->prod = 'dev'; } $obj->ios = $ios_info; } if ($android_sys) { $and_info = array(); if ($this->settings['push_type']) { $and_info['push_content'] = $content; $and_info['push_title'] = $title; } else { $and_info['alert'] = $content; $and_info['title'] = $title; } if ($this->input['link_module']) { $and_info['module_id'] = $this->input['link_module']; } if ($this->input['content_id']) { $and_info['id'] = $this->input['content_id']; } if ($app_info['action']) { $and_info['action'] = $app_info['action']; } else { $and_info['action'] = 'com.avos.UPDATE_STATUS'; } if ($appinfo['packagename']) { $and_info['packagename'] = $appinfo['packagename']; } if ($this->settings['push_app_id']) { $and_info['push_app_id'] = $this->settings['push_app_id']; } $obj->android = $and_info; } if ($appinfo['channel']) { $obj->channels = explode(',', $appinfo['channel']); } //指定设备 $intall_id = trim($this->input['intall_id']); if ($platform_id) { $obj->where = array('installationId' => $intall_id); } ############################################## if ($send_time) { $send_time = date('c', strtotime($send_time)); $send_time = explode('+', $send_time); $send_time = $send_time[0] . '.000Z'; //file_put_contents('4.txt', $send_time); $obj->push_time = $send_time; } //设置离线时间 if ($expire_time) { if ($send_time) { $obj->expiration_time_interval = $expire_time; } else { $expire_time += TIMENOW; $expire_time = date("c", $expire_time); $expire_time = explode('+', $expire_time); $expire_time = $expire_time[0] . '.000Z'; $obj->expiration_time = $expire_time; //$obj->expiration_time = '2014-07-22T17:24:13.145Z'; } } //通知推送 $return = $obj->send(); $return = object_array($return); if ($return['objectId']) { $ret['errcode'] = 0; $ret['msg_id'] = $return['objectId']; $ret['errmsg'] = '发送成功'; } else { $ret['errcode'] = 1; $ret['errmsg'] = '发送失败'; } //hg_pre($return); } } } if (!$send_time) { $send_time = TIMENOW; } else { $send_time = strtotime($this->input['send_time']); } $data = array('app_id' => $app_id, 'title' => $title, 'content' => $content, 'msg_id' => $ret['msg_id'], 'errcode' => $ret['errcode'], 'errmsg' => $ret['errmsg'], 'ios' => $ios, 'ios_dev' => $ios_dev, 'android' => $android_sys, 'winphone' => $winphone, 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'org_id' => $this->user['org_id'], 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'ip' => hg_getip(), 'platform_type' => $platform_type, 'send_time' => $send_time, 'expire_time' => $expire_time, 'intall_id' => $intall_id); //file_put_contents('3.txt', var_export($ret,1)); if ($type == 'create') { $sql = 'INSERT INTO ' . DB_PREFIX . 'notice SET '; foreach ($data as $k => $v) { $sql .= "{$k} = '" . $v . "',"; } $this->db->query(rtrim($sql, ',')); $data['id'] = $this->db->insert_id(); } else { if ($type == 'update') { $sql = 'UPDATE ' . DB_PREFIX . 'notice SET '; foreach ($data as $k => $v) { $sql .= "{$k} = '" . $v . "',"; } $sql = rtrim($sql, ','); $sql .= ' WHERE id=' . $id; $this->db->query($sql); $data['id'] = $id; } } $this->addItem($data); $this->output(); }
/** * 使用默认设置推送消息给标签选中设备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; }
function DemoQueryTokensOfAccount() { $push = new XingeApp(00, 'secret_key'); $ret = $push->QueryTokensOfAccount("nickName"); return $ret; }
public function show() { //如果应用在推送平台添加,需要传入应用id,然后根据应用id查询应用的密钥 $app_push_id = intval($this->input['app_id']); if ($app_push_id) { $sql = 'SELECT * FROM ' . DB_PREFIX . "app_info WHERE id = " . $app_push_id; $appinfo = $this->db->query_first($sql); } if (!$appinfo['access_id'] || !$appinfo['access_key']) { $this->errorOutput('缺少应用配置'); } $content = trim($this->input['content']); if (!$content) { $this->errorOutput('缺少通知内容'); } //platform_type:1信鸽,2极光,3AVOS $platform_type = $appinfo['platform_type']; //极光可以不写标题,不写标题,默认显示应用包名称 $title = trim($this->input['title']); if (!$title && ($platform_type = 1)) { $this->errorOutput('请输入通知标题'); } //通知离线时间 $expire_time = intval($this->input['expire_time']); //发送时间 $send_time = $this->input['send_time']; //扩展字段 if ($this->input['extras']) { $extras = $this->input['extras']; } $ios = $ios_dev = ''; if ($this->input['ios'] == 1) { $ios_dev = 1; } else { if ($this->input['ios'] == 2) { $ios = 1; } } $android_sys = $this->input['android']; $winphone = $this->input['winphone']; if (!$ios && !$ios_dev && !$android_sys && !$winphone) { $this->errorOutput('请选择客户端设备系统'); } if ($platform_type == 1) { $accessId = $appinfo['access_id']; $secretKey = $appinfo['access_key']; //$accessId = 2100033914; //$secretKey = '755776a7f60242ed472848ddf6b08197'; if (!$accessId || !$secretKey) { $this->errorOutput('请传入应用信息'); } include_once CUR_CONF_PATH . 'lib/XingeApp.php'; $push = new XingeApp($accessId, $secretKey); $mess = new Message(); $mess->setTitle($title); $mess->setContent($content); //0是通知,1是消息 $mess_type = intval($this->input['mess_type']); if ($mess_type) { $mess->setType(Message::TYPE_MESSAGE); } else { $mess->setType(Message::TYPE_NOTIFICATION); $style = new Style(0); #含义:样式编号0,响铃,震动,可从通知栏清除,不影响先前通知 $style = new Style(0, 1, 1, 1, 0); $mess->setStyle($style); #接收消息时间范围 $acceptTime1 = new TimeInterval(0, 0, 23, 59); $mess->addAcceptTime($acceptTime1); $action = new ClickAction(); $action_type = intval($this->input['action_type']); //点击通知操作 $action_url = $this->input['action_url']; //打开的url地址 if (!$action_type) { #打开activity或app本身 $action->setActionType(ClickAction::TYPE_ACTIVITY); } else { if ($action_type == 1 && $action_url) { //打开链接 $action->setActionType(ClickAction::TYPE_URL); $action->setUrl($action_url); #打开url需要用户确认 $action_comfirm = intval($this->input['action_comfirm']); $action->setComfirmOnUrl($action_comfirm); } else { if ($action_type == 2) { $intent = $this->input['intent']; $action->setActionType(ClickAction::TYPE_INTENT); $action->setIntent($intent); } } } $mess->setAction($action); #自定义内容 if ($extras) { $mess->setCustom($extras); } } //设备标识 $device_token = trim($this->input['device_token']); //推送帐号 //$account = trim($this->input['account']); //向ios推送时启用,1生产,2开发 $environment = intval($this->input['environment']); //设备类型 $device_type = intval($this->input['device_type']); $device_sys = ''; switch ($device_type) { case 0: $device_sys = XingeApp::DEVICE_ALL; break; case 1: $device_sys = XingeApp::DEVICE_BROWSER; break; case 2: $device_sys = XingeApp::DEVICE_PC; break; case 3: $device_sys = XingeApp::DEVICE_ANDROID; break; case 4: $device_sys = XingeApp::DEVICE_IOS; break; case 5: $device_sys = XingeApp::DEVICE_WINPHONE; break; default: $device_sys = XingeApp::DEVICE_ALL; } if ($device_token) { $ret = $push->PushSingleDevice($device_token, $mess, $environment); } else { $ret = $push->PushAllDevices($device_sys, $mess, $environment); } } else { if ($platform_type == 2) { if (!$appinfo['access_id'] || !$appinfo['access_key']) { $this->errorOutput('缺少应用配置'); } include_once CUR_CONF_PATH . 'lib/jpush/JPushClient.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Audience.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Message.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/notification/Notification.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/notification/IOSNotification.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/notification/AndroidNotification.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/notification/WinphoneNotification.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Options.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/Platform.php'; include_once CUR_CONF_PATH . 'lib/jpush/model/PushPayload.php'; $client = new JPushClient($app_key, $master_secret); $platform = new Platform(); $audience = new Audience(); $message = new Message(); $options = new Options(); $notification = new Notification(); $ios = new IOSNotification(); $android = new AndroidNotification(); $winphone = new WinphoneNotification(); //set platform params $platform->ios = true; $platform->winphone = true; //set options params设置选项 $options->sendno = 10; $options->apns_production = true; $options->time_to_live = 60; //set notification params $ios->alert = $content; $ios->sound = "default"; $ios->badge = 1; //$ios->extras = $extras; $ios->content_available = null; $android->alert = $content; $android->title = $title; $android->builder_id = 1; //$android->extras = $extras; $winphone->alert = $content; $winphone->title = $title; $winphone->_open_page = "/friends.xaml"; //$winphone->extras = $extras; $notification->alert = $content; $notification->android = $android; $notification->ios = $ios; $notification->winphone = $winphone; //发送广播通知 $payload = new PushPayload(); $payload->notification = $notification; //设置接受设备系统 //$payload->platform = $platform; $payload->options = $options; $ret = $client->sendPush($payload); } elseif ($platform_type == 3) { if (!$appinfo['access_id'] || !$appinfo['access_key'] || !$appinfo['secret_key']) { $this->errorOutput('缺少应用配置'); } if (!$appinfo['channel']) { $this->errorOutput('订阅频道不存在'); } include_once CUR_CONF_PATH . 'lib/avos/AV.php'; include_once CUR_CONF_PATH . 'lib/avos/AVObject.php'; include_once CUR_CONF_PATH . 'lib/avos/AVQuery.php'; include_once CUR_CONF_PATH . 'lib/avos/AVUser.php'; include_once CUR_CONF_PATH . 'lib/avos/AVFile.php'; include_once CUR_CONF_PATH . 'lib/avos/AVPush.php'; include_once CUR_CONF_PATH . 'lib/avos/AVGeoPoint.php'; include_once CUR_CONF_PATH . 'lib/avos/AVACL.php'; include_once CUR_CONF_PATH . 'lib/avos/AVCloud.php'; $obj = new AVPush(); $app_info['access_id'] = $appinfo['access_id']; $app_info['access_key'] = $appinfo['access_key']; $app_info['secret_key'] = $appinfo['secret_key']; $app_info['avos_url'] = 'https://cn.avoscloud.com/1/'; //应用信息 $obj->app_info = $app_info; //设置标题,不设置默认显示应用名称 $obj->title = $title; //通知内容 $obj->alert = $content; //$this->input['link_module'] = 'news'; //$this->input['content_id'] = 1; if ($this->input['link_module']) { $obj->module_id = $this->input['link_module']; } if ($this->input['content_id']) { $obj->id = $this->input['content_id']; } //$push->channels = array('123456'); if ($appinfo['channel']) { $obj->channels = explode(',', $appinfo['channel']); } if ($android_sys) { $obj->action = 'com.avos.UPDATE_STATUS'; } //声音 $sound = $this->input['sound']; if ($sound) { $obj->sound = $sound; } //指定设备 $platform_id = trim($this->input['platform_id']); if ($platform_id) { $obj->where = array('installationId' => $platform_id); } //发送时间 if ($send_time) { $send_time = date('c', strtotime($send_time)); $send_time = explode('+', $send_time); $send_time = $send_time[0] . '.000Z'; //file_put_contents('4.txt', $send_time); $obj->push_time = $send_time; } //设置离线时间 if ($expire_time) { if ($send_time) { $obj->expiration_time_interval = $expire_time; } else { $expire_time += TIMENOW; $expire_time = date("c", $expire_time); $expire_time = explode('+', $expire_time); $expire_time = $expire_time[0] . '.000Z'; $obj->expiration_time = $expire_time; //$obj->expiration_time = '2014-07-22T17:24:13.145Z'; } } //通知推送 $return = $obj->send(); $return = object_array($return); if ($return['objectId']) { $ret['errcode'] = 0; $ret['msg_id'] = $return['objectId']; $ret['errmsg'] = '发送成功'; } else { $ret['errcode'] = 1; $ret['errmsg'] = '发送失败'; } //file_put_contents('1.txt', var_export($return,1)); //hg_pre($return); } } if (!$send_time) { $send_time = TIMENOW; } else { $send_time = strtotime($send_time); } $data = array('app_id' => $app_id, 'title' => $title, 'content' => $content, 'msg_id' => $ret['msg_id'], 'errcode' => $ret['errcode'], 'errmsg' => $ret['errmsg'], 'ios' => $ios, 'ios_dev' => $ios_dev, 'android' => $android_sys, 'winphone' => $winphone, 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'user_id' => $this->user['user_id'], 'user_name' => $this->user['user_name'], 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'ip' => hg_getip(), 'platform_type' => $platform_type, 'send_time' => $send_time, 'expire_time' => $expire_time); $sql = 'INSERT INTO ' . DB_PREFIX . 'notice SET '; foreach ($data as $k => $v) { $sql .= "{$k} = '" . $v . "',"; } $this->db->query(rtrim($sql, ',')); $data['id'] = $this->db->insert_id(); $this->addItem($data); $this->output(); }
function DemoBatchDelTag() { // 切记把这里的示例tag和示例token修改为你的真实tag和真实token $pairs = array(); array_push($pairs, new TagTokenPair("tag1", "token00000000000000000000000000000000001")); array_push($pairs, new TagTokenPair("tag1", "token00000000000000000000000000000000001")); $push = new XingeApp(00, 'secret_key'); $ret = $push->BatchDelTag($pairs); return $ret; }
<?php require_once 'XingeApp.php'; //Android 版 //给单个设备下发通知 var_dump(XingeApp::PushTokenAndroid(10000, "secretKey", "title", "content", "token")); //给单个帐号下发通知 var_dump(XingeApp::PushAccountAndroid(10000, "secretKey", "title", "content", "account")); //给所有设备下发通知 var_dump(XingeApp::PushAllAndroid(10000, "secretKey", "title", "content")); //给标签选中设备下发通知 var_dump(XingeApp::PushTagAndroid(10000, "secretKey", "title", "content", "tag")); //IOS版 //开发环境下 给单个设备下发通知 var_dump(XingeApp::PushTokenIos(10000, "secretKey", "content", "token", XingeApp::IOSENV_DEV)); //开发环境下 给单个帐号下发通知 var_dump(XingeApp::PushAccountIos(10000, "secretKey", "content", "account", XingeApp::IOSENV_DEV)); //开发环境下 给所有设备下发通知 var_dump(XingeApp::PushAllAndroid(10000, "secretKey", "content", XingeApp::IOSENV_DEV)); //开发环境下 给标签选中设备下发通知 var_dump(XingeApp::PushTagAndroid(10000, "secretKey", "content", "tag", XingeApp::IOSENV_DEV));
/** * 更改订单状态时,向手机端(包括Android和IOS)发送提醒信息 * * @param [object] $[shop] [店铺对象] * @param [object] $[mainOrder] [主订单] * @param [int] $[toBeStatus] [要改变状态] * * @return Response */ protected function pushOrderInfo($shop, $mainOrder, $toBeStatus) { //获取信鸽系统配置 $accessId = Config::get('xinge.accessId'); $secretKey = Config::get('xinge.secretKey'); $xingeApp = new XingeApp($accessId, $secretKey); //根据mainorder中的userid获取token和设备类型 $userTokens = UserToken::where('wy_user_id', $mainOrder->wy_user_id)->where('wy_user_type', USER_TYPE_1)->where('wy_status', LOGIN_STATUS_1)->get(); if (!empty($userTokens->toArray())) { foreach ($userTokens as $index => $userToken) { if (DEVICE_TYPE_1 == $userToken->wy_device_type) { //根据不同状态获取不同的模板信息 switch ($toBeStatus) { case ORDER_STATE_2: //接单 $orderMessage = Config::get('xinge.androidRecvMessage'); break; case ORDER_STATE_3: //配送中 $orderMessage = Config::get('xinge.androidDeliveryMessage'); break; case ORDER_STATE_4: //完成 $orderMessage = Config::get('xinge.androidFinishMessage'); break; case ORDER_STATE_6: //拒单 $orderMessage = Config::get('xinge.androidRefuseMessage'); break; default: break; } if (isset($orderMessage)) { //单击动作 $action = new ClickAction(); $action->setActionType(ClickAction::TYPE_ACTIVITY); $action->setActivity($orderMessage['activity']); //显示样式 $styleParams = $orderMessage['style']; $style = new Style($styleParams['builderId'], $styleParams['ring'], $styleParams['vibrate'], $styleParams['clearable'], $styleParams['nId'], $styleParams['lights'], $styleParams['iconType'], $styleParams['styleId']); //Android平台的消息 $message = new Message(); $message->setTitle($orderMessage['title']); $message->setContent($orderMessage['content']); $message->setExpireTime($orderMessage['expireTime']); $message->setType(Message::TYPE_NOTIFICATION); $message->setStyle($style); $message->setAction($action); } else { $context = array("errorCode" => -10054, "userID" => $mainOrder->wy_user_id, "toBeStatus" => $toBeStatus); Log::error(Lang::get('errormessages.-10054'), $context); } } elseif (DEVICE_TYPE_2 == $userToken->wy_device_type) { //根据不同状态获取不同的模板信息 switch ($toBeStatus) { case ORDER_STATE_2: //接单 $orderMessage = Config::get('xinge.iosRecvMessage'); break; case ORDER_STATE_3: //配送中 $orderMessage = Config::get('xinge.iosDeliveryMessage'); break; case ORDER_STATE_4: //完成 $orderMessage = Config::get('xinge.iosFinishMessage'); break; case ORDER_STATE_6: //拒单 $orderMessage = Config::get('xinge.iosRefuseMessage'); break; default: break; } if (isset($orderMessage)) { //IOS平台的消息,需要IOS文档 $message = new MessageIOS(); $message->setTitle($orderMessage['title']); } else { $context = array("errorCode" => -10055, "userID" => $mainOrder->wy_user_id, "toBeStatus" => $toBeStatus); Log::error(Lang::get('errormessages.-10055'), $context); } } else { $context = array("errorCode" => -10056, "userID" => $mainOrder->wy_user_id, "deviceType" => $userToken->wy_device_type); Log::error(Lang::get('errormessages.-10056'), $context); } //自定义参数,key-value形式的 if (isset($message)) { $custom = array('shop_name' => $shop->wy_shop_name, 'main_order_id' => $mainOrder->wy_main_order_id); $message->setCustom($custom); $result = $xingeApp->PushSingleDevice($userToken->wy_token, $message); Log::info($result); } else { $context = array("errorCode" => -10057, "userID" => $mainOrder->wy_user_id, "deviceType" => $userToken->wy_device_type, "toBeStatus" => $toBeStatus); Log::error(Lang::get('errormessages.-10057'), $context); } } } else { $context = array("errorCode" => -10053, "userID" => $mainOrder->wy_user_id); Log::error(Lang::get('errormessages.-10053'), $context); } }