-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8f537ff
commit 0c5caf3
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
# Huawei Mobile Services | ||
# 支持的功能 | ||
-- 获取access_token | ||
-- 推送消息 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
define('HWPUSH_ROOT', dirname(__DIR__) . '/'); | ||
|
||
function hwpushAutoload(string $class) | ||
{ | ||
$parts = explode('\\', $class); | ||
$path = HWPUSH_ROOT . implode('/', $parts) . '.php'; | ||
if (file_exists($path)) { | ||
include_once($path); | ||
} | ||
} | ||
|
||
spl_autoload_register('hwpushAutoload'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
use hwpush\GetAccessToken; | ||
use hwpush\Sender; | ||
|
||
include_once(dirname(__FILE__) . '/autoload.php'); | ||
|
||
//APP ID | ||
$clientId = 'xxx'; | ||
//APP SECRET | ||
$clientSecret = 'xxx'; | ||
//获取【AccessToken】实例 | ||
$access = GetAccessToken::getInstance(); | ||
//设置通信参数 | ||
$access->setClient($clientId, $clientSecret); | ||
//获取access_token | ||
$response = $access->get(); | ||
$response = json_decode($response, true); | ||
/** | ||
* Array( | ||
* [access_token] => xxxx | ||
* [expires_in] => 3600 | ||
* [token_type] => Bearer | ||
* ) | ||
*/ | ||
print_r($response); | ||
|
||
|
||
//获取 【Sender】实例 | ||
$sender = Sender::getInstance(); | ||
//设置通信参数 | ||
$sender->setClient($clientId, $clientSecret); | ||
//设置通信令牌 | ||
$sender->setAccessToken($response['access_token']); | ||
//定义设备Token列表 | ||
$deviceTokenList = [ | ||
'0867778034447519300001659700CN01' | ||
]; | ||
//定义payload,下方使用的是:系统通知栏消息 | ||
$payload = ['hps' => [ | ||
'msg' => [ | ||
'type' => 3, | ||
'body' => [ | ||
'content' => 'Hello,is me !', | ||
'title' => 'Who are you?', | ||
], | ||
'action' => [ | ||
'type' => 1, | ||
'param' => [ | ||
"intent" => "#Intent;compo=com.rvr/.Activity;S.W=U;end" | ||
] | ||
], | ||
] | ||
]]; | ||
$response = $sender->send($deviceTokenList, $payload); | ||
//{"code":"80000000","msg":"Success","requestId":"154335160415079796001601"} | ||
print_r($response); |