PHP code example of riverslei / baidu-pusher
1. Go to this page and download the library: Download riverslei/baidu-pusher library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
riverslei / baidu-pusher example snippets
'providers' => [
Riverslei\Pusher\PusherServiceProvider::class,
...
]
'aliases' => [
...
'Pusher' => Riverslei\Pusher\Pusher::class,
]
Route::get('/pusher', 'TestController@pusher');
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Pusher;
class TestController extends Controller
{
public function pusher()
{
$channelId = '3785562685113372034';
// 消息内容.
$message = array (
// 消息的标题.
'title' => 'Hi!.',
// 消息内容
'description' => "hello!, this message from baidu push service."
);
// 设置消息类型为 通知类型.
$opts = array (
'msg_type' => 1
);
// 向目标设备发送一条消息
$rs = Pusher::pushMsgToSingleDevice($channelId, $message, $opts);
// 判断返回值,当发送失败时, $rs的结果为false, 可以通过getError来获得错误信息.
if($rs === false){
print_r(Pusher::getLastErrorCode());
print_r(Pusher::getLastErrorMsg());
}else{
// 将打印出消息的id,发送时间等相关信息.
var_dump($rs);
}
echo "done!";
}
}
html
array (size=2)
'msg_id' => string '2363629481259790251' (length=19)
'send_time' => int 1436930964
done!