private function test_pushMessage_ios($user_id, $body) { $channel = new Channel($this->apiKey, $this->secretKey); $push_type = 1; //推送单播消息 $optional[Channel::USER_ID] = $user_id; //如果推送单播消息,需要指定user //指定发到ios设备 $optional[Channel::DEVICE_TYPE] = 4; //指定消息类型为通知 $optional[Channel::MESSAGE_TYPE] = 1; //如果ios应用当前部署状态为开发状态,指定DEPLOY_STATUS为1,默认是生产状态,值为2. //旧版本曾采用不同的域名区分部署状态,仍然支持。 $optional[Channel::DEPLOY_STATUS] = 2; //通知类型的内容必须按指定内容发送,示例如下: // $message = '{ // "aps":{ // "alert":"msg from baidu push", // "sound":"", // "badge":0 // } // }'; $message_key = "msg_key"; $ret = $channel->pushMessage($push_type, $body, $message_key, $optional); file_put_contents("/tmp/test.log", '########$bodyaps=' . $body . '#######' . "\n", FILE_APPEND); file_put_contents("/tmp/test.log", '########$ret=' . json_encode($ret) . '#######' . "\n", FILE_APPEND); if (false === $ret) { file_put_contents("/tmp/test.log", '########WRONG, ' . __FUNCTION__ . ' ERROR!!!!!#######' . "\n", FILE_APPEND); file_put_contents("/tmp/test.log", '########ERROR NUMBER: ' . $channel->errno() . '#######' . "\n", FILE_APPEND); file_put_contents("/tmp/test.log", '########ERROR MESSAGE: ' . $channel->errmsg() . '#######' . "\n", FILE_APPEND); file_put_contents("/tmp/test.log", '########REQUEST ID: ' . $channel->getRequestId() . '#######' . "\n", FILE_APPEND); return false; } else { //right_output ( 'SUCC, ' . __FUNCTION__ . ' OK!!!!!' ) ; //right_output ( 'result: ' . print_r ( $ret, true ) ) ; return TRUE; } }
function test_deleteAppIoscert() { global $apiKey; global $secretKey; $channel = new Channel($apiKey, $secretKey); //如果ios应用当前部署状态为开发状态,指定DEPLOY_STATUS为1,默认是生产状态,值为2. //旧版本曾采用不同的域名区分部署状态,仍然支持。 //$optional[Channel::DEPLOY_STATUS] = 1; $ret = $channel->deleteAppIoscert(); if (false === $ret) { error_output('WRONG, ' . __FUNCTION__ . ' ERROR!!!!'); error_output('ERROR NUMBER: ' . $channel->errno()); error_output('ERROR MESSAGE: ' . $channel->errmsg()); error_output('REQUEST ID: ' . $channel->getRequestId()); } else { right_output('SUCC, ' . __FUNCTION__ . ' OK!!!!!'); right_output('result: ' . print_r($ret, true)); } }
function test_deleteAppIoscert() { $apiKey = $this->apiKey; $secretKey = $this->secretKey; $channel = new Channel($apiKey, $secretKey); $ret = $channel->deleteAppIoscert(); if (false === $ret) { error_output('WRONG, ' . __FUNCTION__ . ' ERROR!!!!'); error_output('ERROR NUMBER: ' . $channel->errno()); error_output('ERROR MESSAGE: ' . $channel->errmsg()); error_output('REQUEST ID: ' . $channel->getRequestId()); } else { right_output('SUCC, ' . __FUNCTION__ . ' OK!!!!!'); right_output('result: ' . print_r($ret, true)); } }
/** * 设定用户的推送时间,使用TAG来标记,默认0-24 意味着全天可接受 * @param string $p_buserid 用户推送ID,百度里是buserid * @param bool $ispushallowed 是否接受推送 * @param integer $pushhourstart 推送开始时间0-23 * @param integer $pushhourend 推送结束时间1-24 */ public static function setTagWithPrefix($p_buserid, $p_tags = array(), $p_prefix = null) { $rets = array(); $channel = new Channel(W2PUSH::$API_KEY, W2PUSH::$SECRET_KEY); if (isset($p_prefix) && strlen($p_prefix) > 0) { $tagsList = $channel->queryUserTags($p_buserid); $optional[Channel::USER_ID] = $p_buserid; if (is_array($tagsList) && array_key_exists('response_params', $tagsList) && array_key_exists('tags', $tagsList['response_params'])) { foreach ($tagsList['response_params']['tags'] as $tag) { if (strpos($tag['name'], $p_prefix) === 0) { $ret = $channel->deleteTag($tag['name'], $optional); if (false === $ret) { $rets[] = array('WRONG' => __FUNCTION__ . ' ERROR!!!!', 'ERROR NUMBER' => $channel->errno(), 'ERROR MESSAGE' => $channel->errmsg(), 'REQUEST ID' => $channel->getRequestId()); } else { $rets[] = array('SUCC' => __FUNCTION__ . ' OK!!!!!', 'result' => print_r($ret, true)); } } } } } $countSucc = 0; $countWrong = 0; if (isset($p_tags)) { $p_tags = is_array($p_tags) ? $p_tags : explode(',', $p_tags); foreach ($p_tags as $tarName) { $ret = $channel->setTag($tarName, $optional); if (false === $ret) { $countWrong++; $rets[] = array('WRONG' => __FUNCTION__ . ' ERROR!!!!', 'ERROR NUMBER' => $channel->errno(), 'ERROR MESSAGE' => $channel->errmsg(), 'REQUEST ID' => $channel->getRequestId()); } else { $countSucc++; $rets[] = array('SUCC' => __FUNCTION__ . ' OK!!!!!', 'result' => print_r($ret, true)); } } } return array('countSucc' => $countSucc, 'countWrong' => $countWrong, 'rets' => $rets); }
static function pushBaidu($notifyMsg) { if ($notifyMsg->type === NotificationsManager::DEVICE_ISO) { $channel = NotificationsManager::initBaiduCertIOS($notifyMsg); } else { $channel = new Channel($notifyMsg->appid, $notifyMsg->restkey); } $message_key = md5(date('Y-m-d-H-M-S', time())); $optional[Channel::MESSAGE_TYPE] = 1; // if(isset($notifyMsg->channels) && is_array($notifyMsg->channels) && count($notifyMsg->channels)>0){ // $push_type = 2; // }else { // $push_type = 3; //推送广播消息 // } $push_type = 3; $message = array(); if ($notifyMsg->type === NotificationsManager::DEVICE_ISO) { $optional[Channel::DEVICE_TYPE] = 4; $apps = array(); if (isset($notifyMsg->title) && !is_null($notifyMsg->title)) { $message['title'] = $notifyMsg->title; } $optional[Channel::DEVICE_TYPE] = 4; if (isset($notifyMsg->prod_id) && !is_null($notifyMsg->prod_id)) { $message['prod_id'] = $notifyMsg->prod_id; } if (isset($notifyMsg->prod_type) && !is_null($notifyMsg->prod_type)) { $message['prod_type'] = $notifyMsg->prod_type; } if (isset($notifyMsg->push_type) && !is_null($notifyMsg->push_type)) { $message['push_type'] = $notifyMsg->push_type; } if (isset($notifyMsg->alert) && !is_null($notifyMsg->alert)) { $apps['alert'] = $notifyMsg->alert; } $apps['Sound'] = ''; $apps['Badge'] = 0; $message['aps'] = $apps; } else { if ($notifyMsg->type === NotificationsManager::DEVICE_ANDROID) { $custom_content = array(); if (isset($notifyMsg->title) && !is_null($notifyMsg->title)) { $message['title'] = $notifyMsg->title; } $optional[Channel::DEVICE_TYPE] = 3; if (isset($notifyMsg->prod_id) && !is_null($notifyMsg->prod_id)) { $custom_content['prod_id'] = $notifyMsg->prod_id; } if (isset($notifyMsg->prod_type) && !is_null($notifyMsg->prod_type)) { $custom_content['prod_type'] = $notifyMsg->prod_type; } if (isset($notifyMsg->push_type) && !is_null($notifyMsg->push_type)) { $custom_content['push_type'] = $notifyMsg->push_type; } if (isset($notifyMsg->alert) && !is_null($notifyMsg->alert)) { $message['description'] = $notifyMsg->alert; } $message['custom_content'] = $custom_content; } } // var_dump($message); var_dump($optional); $ret = $channel->pushMessage($push_type, $message, $message_key, $optional); if (false === $ret) { return array('code' => '201', 'response' => $channel->errmsg()); } else { return array('code' => '200', 'response' => $ret); } }