forked from blueseashore/hwpush
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample.php
57 lines (52 loc) · 1.34 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);