PHP code example of n2boost / laravel-huawei-push
1. Go to this page and download the library: Download n2boost/laravel-huawei-push 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/ */
n2boost / laravel-huawei-push example snippets
$push = new HuaweiPush();
$title = 'APP Name';
$message = 'This is a Message, Click Me!';
$accessToken = $push->getAccessToken(); // 获取AccessToken 可以保存起来
$data = [
'type' => 'scheme',
'data' => "app://www.app.com/activity?id=123456789"
];
$push = $push->setTitle($title)
->setMessage($message)
->setAccessToken($accessToken)
->setCustomize($data);
$push->addDeviceToken("aBX471FWGHmiYZbZyE7o8WWISWYYQuVTEkJIbChBomv6mH3RWiTVOCDtJ-Hc-_E5rMPXzzIVjexXQHbN1GKmLhJqKqxJ4E86MyoUvw");
$push->sendMessage(); // 执行推送消息。
dump($push->isSendSuccess()); // 是否推送成功
dump($push->isSendFail()); // 是否推送失败
dump($push->getAccessTokenExpiresTime()); // 获取 AccessToken 过期时间
dump($push->getSendSuccessRequestId()); // 获取推送成功后接口返回的请求 id
return [
/*
* 用户在华为开发者联盟申请的appId和appSecret(会员中心->应用管理,点击应用名称的链接)
*/
"APP_ID" => '12345678',
"APP_SECRET" => 'appSecret',
/*
* 获取认证 Token 的 URL
*/
"APP_PKG_NAME" => 'com.company_name.pkg_name',
/*
* 获取认证 Token 的 URL
*/
"TOKEN_URL" => 'https://login.vmall.com/oauth2/token',
/*
* 应用级消息下发 API
*/
"API_URL" => 'https://api.push.hicloud.com/pushsend.do',
];
bash
php artisan vendor:publish --provider="N2boost\LaravelHuaweiPush\HuaweiPushServiceProvider" --tag="config"