public function testHasMethods() { foreach ($this->messages as $message) { $m = new Message(); $m->setMessage($message['message']); $m->setPriority($message['priority']); $this->assertFalse($m->hasTitle()); $this->assertFalse($m->hasUrl()); $this->assertFalse($m->hasUrlTitle()); $this->assertFalse($m->hasSound()); $this->assertFalse($m->hasHtml()); $this->assertFalse($m->hasDate()); } foreach ($this->messages as $message) { $m = new Message(); $m->setTitle($message['title']); $m->setMessage($message['message']); $m->setUrl($message['url']); $m->setUrlTitle($message['url_title']); $m->setPriority($message['priority']); $m->setSound($message['sound']); $m->setHtml($message['html']); $m->setDate(new \DateTime($message['date'])); $this->assertTrue($m->hasTitle()); $this->assertTrue($m->hasUrl()); $this->assertTrue($m->hasUrlTitle()); $this->assertTrue($m->hasSound()); $this->assertTrue($m->hasHtml()); $this->assertTrue($m->hasDate()); } }
/** * 批量发送消息 * @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); } } } } }
/** * Tests Message->setTitle() */ public function testSetTitle() { $this->Message->setTitle('title'); $this->assertEquals('title', $this->Message->title); }
/** * 推送接口 * @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)); }
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(); }
function message_submit() { // get global user object global $user; // protect from unauthorized access if (!isset($user) || !isset($_POST['formMessageSubmit']) || !isset($_POST['formMessage'])) { logout(); die; } // get message data from $_POST $title = filter_input(INPUT_POST, 'messageTitle'); $text = filter_input(INPUT_POST, 'messageText'); $time_now = date("Y-m-d H:i:s"); // send mail send_mail($title, $text); // set message object $message = new Message(); $message->setIsActive(1); $message->setCreatedOn($time_now); $message->setLastEditedOn($time_now); $message->setUser($user->getId()); $message->setTitle($title); $message->setText($text); // store message object in db $message->store_in_db(); // set message cookie $cookie_key = 'msg'; $cookie_value = 'Благодарим Ви за съобщението!'; setcookie($cookie_key, $cookie_value, time() + 1); header('location:' . ROOT_DIR . '?page=survey_role'); }
/** * 使用默认设置推送消息给标签选中设备android版 */ public static function PushTagAndroid($accessId, $secretKey, $title, $content, $tag) { $push = new XingeApp($accessId, $secretKey); $mess = new Message(); $mess->setTitle($title); $mess->setContent($content); $mess->setType(Message::TYPE_NOTIFICATION); $mess->setStyle(new Style(0, 1, 1, 1, 0)); $action = new ClickAction(); $action->setActionType(ClickAction::TYPE_ACTIVITY); $mess->setAction($action); $ret = $push->PushTags(0, array(0 => $tag), 'OR', $mess); return $ret; }
function DemoPushDeviceListMultipleNotification() { $push = new XingeApp(00, 'secret_key'); $mess = new Message(); $mess->setExpireTime(86400); $mess->setTitle('title'); $mess->setContent('content'); $mess->setType(Message::TYPE_NOTIFICATION); $ret = $push->CreateMultipush($mess, XingeApp::IOSENV_DEV); if (!($ret['ret_code'] === 0)) { return $ret; } else { $result = array(); $deviceList1 = array('token1', 'token2', 'token3'); array_push($result, $push->PushDeviceListMultiple($ret['result']['push_id'], $deviceList1)); $deviceList2 = array('token4', 'token5', 'token6'); array_push($result, $push->PushDeviceListMultiple($ret['result']['push_id'], $deviceList2)); return $result; } }
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 DemoPushTags() { $push = new XingeApp(00, 'secret_key'); $mess = new Message(); $mess->setTitle('title'); $mess->setContent('content'); $mess->setType(Message::TYPE_MESSAGE); $tagList = array('Demo3'); $ret = $push->PushTags(XingeApp::DEVICE_ANDROID, $tagList, 'OR', $mess); return $ret; }
/** * 更改订单状态时,向手机端(包括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); } }