Пример #1
0
 public function SendBatchUniMsg(array $channlIds, $title = null, $content, array &$err = array())
 {
     //andriod push start
     $sendAndInfo = array('title' => $title, 'description' => $content, "custom_content" => $this->getInfo());
     $ars = $this->pushSdkAnd->pushBatchUniMsg($channlIds, $sendAndInfo, $this->opts);
     //        if($ars === false) {
     $err['and']['code'] = $this->pushSdkAnd->getLastErrorCode();
     $err['and']['msg'] = $this->pushSdkAnd->getLastErrorMsg();
     //        }
     //andriod push end
     //ios push start
     $sendIosInfo = array_merge(array('aps' => array("alert" => $content)), $this->getInfo());
     foreach ($channlIds as $channlId) {
         $irs = $this->pushSdkIos->pushMsgToSingleDevice($channlId, $sendIosInfo, $this->opts);
         //            if($irs === false) {
         $err['ios']['code'] = $this->pushSdkIos->getLastErrorCode();
         $err['ios']['msg'] = $this->pushSdkIos->getLastErrorMsg();
         //            }
     }
     //ToDo 批量推送有问题
     //        $irs = $this->pushSdkIos->pushBatchUniMsg($channlIds, array('aps'=>array("alert"=>$content)),array('opt'=>array('deploy_status'=>1)));
     //        if($irs === false) {
     //            $err['code'] = $this->pushSdkIos->getLastErrorCode();
     //            $err['msg'] = $this->pushSdkIos->getLastErrorMsg();
     //        }
     return $ars || $irs;
     //        ios push end
 }
Пример #2
0
 public function pushMessage_ios($message, $msg_type = 1, $channelId = '')
 {
     $sdk = new \PushSDK($this->apiKey, $this->secretKey);
     //        $message = array (
     //            'aps' => array (
     //                // 消息内容
     //                'alert' => "hello, this message from baidu push service.",
     //            ),
     //        );
     // 设置消息类型为 通知类型.
     $opts = array('msg_type' => $msg_type, 'deploy_status' => 1);
     // 向目标设备发送一条消息
     $rs = $sdk->pushMsgToSingleDevice($channelId, $message, $opts);
     return $rs;
 }
Пример #3
0
 /**
  * @depends testConfig
  * @param string $channelId
  */
 function testSendMessage()
 {
     $channelId = null;
     $channelId = class_exists('BAIDU_PUSH_CONFIG') ? BAIDU_PUSH_CONFIG::test_channel_id : false;
     if (empty($channelId)) {
         echo "BAIDU_PUSH_CONFIG::test_channel_id not exisist, ignore the testSendMessage! \n";
         return;
     }
     // creaete SDK instance at default. and there is will be use the default_apik and default_secretkey.
     $sdk = new PushSDK();
     // message content.
     $message = array('title' => 'Hi!.', 'description' => "hello!, this message from baidu push service.");
     // option, set the msg_type is notice;
     $opts = array('msg_type' => 1);
     //send out;
     $rs = $sdk->pushMsgToSingleDevice($channelId, $message, $opts);
     // check the return;
     $this->assertNotFalse($rs, $sdk->getLastErrorMsg());
     $this->assertNotNull($sdk->getRequestId(), 'missing request_id');
     $this->assertTrue(array_key_exists('msg_id', $rs), 'missing msg_id');
     echo "finish the test and every thing is good!\n";
 }
Пример #4
0
 *
 * ************************************************************************
 */
/**
 *
 * @file hello.php
 * @encoding UTF-8
 * 
 * 
 *         @date 2015年3月10日
 *        
 */
require_once '../sdk.php';
// 创建SDK对象.
$sdk = new PushSDK();
$channelId = '3785562685113372034';
// message content.
$message = array('title' => 'Hi!', 'description' => "hello, this message from baidu push service.");
// 设置消息类型为 通知类型.
$opts = array('msg_type' => 1);
// 向目标设备发送一条消息
$rs = $sdk->pushMsgToSingleDevice($channelId, $message, $opts);
// 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息.
if ($rs === false) {
    print_r($sdk->getLastErrorCode());
    print_r($sdk->getLastErrorMsg());
} else {
    // 将打印出消息的id,发送时间等相关信息.
    print_r($rs);
}
echo "done!";