コード例 #1
0
ファイル: BaiduPushService.php プロジェクト: onlineshine/myzf
 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
 private function pushAndroidAll()
 {
     // 创建SDK对象.
     $sdk = new PushSDK();
     //  $channelId = '3785562685113372034';
     // message content.
     $message = array('title' => 'Hi!', 'description' => "hello, wanhao来了.");
     // 设置消息类型为 通知类型.
     $opts = array('msg_type' => 1);
     // 向目标设备发送一条消息
     //$rs = $sdk -> pushMsgToSingleDevice($channelId, $message, $opts);
     $rs = $sdk->pushMsgToAll($message, $opts);
     // 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息.
     if ($rs === false) {
         print_r($sdk->getLastErrorCode());
         print_r($sdk->getLastErrorMsg());
     } else {
         // 将打印出消息的id,发送时间等相关信息.
         print_r($rs);
     }
 }
コード例 #3
0
 public function pushAndroidAll($param)
 {
     // 创建SDK对象.
     $sdk = new PushSDK();
     //  $channelId = '3785562685113372034';
     // message content.
     $message = array('title' => $param['title'], 'description' => $param['content'], 'custom_content' => array('uri' => $param['uri'], 'invalid' => $param['invalid']));
     // 设置消息类型为 通知类型.
     $opts = array('msg_type' => 1);
     // 向目标设备发送一条消息
     //$rs = $sdk -> pushMsgToSingleDevice($channelId, $message, $opts);
     $rs = $sdk->pushMsgToAll($message, $opts);
     // 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息.
     if ($rs === false) {
         print_r($sdk->getLastErrorCode());
         print_r($sdk->getLastErrorMsg());
     } else {
         // 将打印出消息的id,发送时间等相关信息.
         print_r($rs);
     }
 }
コード例 #4
0
ファイル: check_sdk_test.php プロジェクト: fengyeno/fille
 /**
  * @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";
 }
コード例 #5
0
ファイル: hello.php プロジェクト: fengyeno/fille
 *
 * ************************************************************************
 */
/**
 *
 * @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!";
コード例 #6
0
 public function actionPush()
 {
     $sdk = new PushSDK();
     $channelId = '4483825412066692748';
     $message = array('title' => 'Hi!.', 'description' => "杨老板卧槽");
     // 设置消息类型为 通知类型.
     $opts = array('msg_type' => 1);
     // 向目标设备发送一条消息
     $rs = $sdk->pushMsgToAll($message, $opts);
     //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!";
 }
コード例 #7
0
ファイル: push.php プロジェクト: speedpursuer/fetcher
    $androidResult = false;
    $err = $sdk->getLastErrorMsg();
} else {
    $androidResult = true;
    // echo json_encode(array('success' => true));
}
$sdk = new PushSDK("10YipKN8jSfOn0t5e1NbBwXl", "1WcGMOFMGGGvYZqKkn53s2ooKpXmo6Et");
$message = array('aps' => array('alert' => $msg, 'sound' => 'sound.m4r'), 'push_id' => $push_id, 'header' => $title);
// 设置消息类型为 通知类型.
$opts = array('msg_type' => 1, 'deploy_status' => 2);
// 向目标设备发送一条消息
// $rs = $sdk -> pushMsgToSingleDevice($channelId, $message, $opts);
$rs = $sdk->pushMsgToAll($message, $opts);
$iosResult = false;
// 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息.
if ($rs === false) {
    // 	echo json_encode(array(
    // 			'errCode' => $sdk->getLastErrorCode(),
    // 			'errMsg' => $sdk->getLastErrorMsg()
    // 	));
    $iosResult = false;
    $err += $sdk->getLastErrorMsg();
} else {
    // 	echo json_encode(array('success' => true));
    $iosResult = true;
}
if ($iosResult && $androidResult) {
    echo json_encode(array('success' => true));
} else {
    echo json_encode(array('errMsg' => $err));
}