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;
     }
 }
Esempio n. 2
0
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));
    }
}
Esempio n. 3
0
 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));
     }
 }
Esempio n. 4
0
 /**
  * @param $user_id 用户标识
  * @param $pType   推送类型:
  * 	推送消息到某个user,设置push_type = 1;
  *  推送消息到一个tag中的全部user,设置push_type = 2;
  *  推送消息到该app中的全部user,设置push_type = 3;
  * @param $message   指定消息内容
  * @param $device_type 设备类型:Android:3;Ios:4
  */
 function push_message_customer($user_id, $pType, $message, $device_type, $msg_key)
 {
     //		header("Content-Type:text/html; charset=utf-8");
     $log = new Log();
     import('@.ORG.Channel');
     global $api_key;
     global $secret_key;
     $api_key = "V7yX7yY8tbvcsBchBSyTDc8n";
     $secret_key = "IbsBMY4ebgPlyayj3o2m4ZhKxqu18fb8";
     $channel = new Channel($api_key, $secret_key);
     $push_type = $pType;
     $optional[Channel::USER_ID] = $user_id;
     //如果推送单播消息,需要指定user
     //optional[Channel::TAG_NAME] = "xxxx";  //如果推送tag消息,需要指定tag_name
     //指定发到哪种设备
     $optional[Channel::DEVICE_TYPE] = $device_type;
     //指定消息类型为通知
     if ($device_type == 3) {
         $optional[Channel::MESSAGE_TYPE] = 0;
         //0:消息;
         $log->write('向 android 发送消息');
     } else {
         if ($device_type == 4) {
             //如果ios应用当前部署状态为开发状态,指定DEPLOY_STATUS为1,默认是生产状态,值为2.
             //旧版本曾采用不同的域名区分部署状态,仍然支持。
             $optional[Channel::DEPLOY_STATUS] = 1;
             $optional[Channel::MESSAGE_TYPE] = 1;
             //1:通知;
             $log->write('向 ios 发送通知');
         }
     }
     //通知类型的内容必须按指定内容发送,示例如下:
     $message_key = $msg_key;
     $ret = $channel->pushMessage($push_type, $message, $message_key, $optional);
     if (false === $ret) {
         $log->write('WRONG, ' . __FUNCTION__ . ' ERROR!!!!<br/>');
         $log->write('ERROR NUMBER: ' . $channel->errno() . '<br/>');
         //	        $log->write ( 'ERROR MESSAGE: ' . $channel->errmsg ( ) . '<br/>' );
         //	        $log->write ( 'REQUEST ID: ' . $channel->getRequestId ( ) . '<br/>' );
         return false;
     } else {
         $log->write('SUCC, ' . __FUNCTION__ . ' OK!!!!!' . '<br/>');
         //	        $log->write ( 'result: ' . print_r ( $ret, true ) . '<br/>' );
         return true;
     }
 }
Esempio n. 5
0
 /**
  * 设定用户的推送时间,使用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);
 }