public function pushMessage_all($msg) { $sdk = new \PushSDK($this->apiKey, $this->secretKey); // $message = array ( // 'aps' => array ( // // 消息内容 // 'alert' => "hello, this message from baidu push service.", // ), // ); // 设置消息类型为 通知类型. $opts = array('msg_type' => 1, 'deploy_status' => 1); // 向目标设备发送一条消息 $rs = $sdk->pushMsgToAll($msg, $opts); return $rs; }
public function setConfig($sm) { $bdConfig = $sm->get('Config')[getenv('APP_ENV')]['bd-config']; $this->pushSdkIos = new \PushSDK($bdConfig['ios']['ak'], $bdConfig['ios']['sk']); $this->pushSdkIos->setDeviceType(4); $this->opts['deploy_status'] = getenv('APP_ENV') == 'test' || getenv('APP_ENV') == 'staging' ? 1 : 2; $this->pushSdkAnd = new \PushSDK($bdConfig['and']['ak'], $bdConfig['and']['sk']); }
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); } }
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); } }
/** * @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"; }
* Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * ************************************************************************ */ /** * * @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); }
* Copyright (c) 2014 Baidu.com, Inc. All Rights Reserved * * ************************************************************************ */ /** * * @file hello.php * @encoding UTF-8 * * * @date 2015年3月10日 * */ require_once '../sdk.php'; // 创建SDK对象. $sdk = new PushSDK(); $channelId = '5490126185581469391'; // message content. $message = array('aps' => array('alert' => "乔丹早年精彩盖帽", 'sound' => 'sound.m4r'), 'push_id' => "post_player_michael_jordan_move_defense", 'header' => "乔丹早年精彩盖帽"); // 设置消息类型为 通知类型. $opts = array('msg_type' => 1, 'deploy_status' => 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);
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!"; }
// 设置消息类型为 通知类型. $opts = array('msg_type' => 1, 'deploy_status' => 2); // 向目标设备发送一条消息 // $rs = $sdk -> pushMsgToSingleDevice($channelId, $message, $opts); $rs = $sdk->pushMsgToAll($message, $opts); // 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息. $androidResult = false; $err = ""; if ($rs === false) { $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();