Skip to content

Commit d3a9697

Browse files
committed
support hmos for pushapi
1 parent ebb191e commit d3a9697

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

doc/api.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,28 @@ $push->iosNotification('hello', [
137137
| intent | 表示扩展字段,接受一个数组,自定义 Key/value 信息以供业务使用 |
138138
| extras | 表示扩展字段,接受一个数组,自定义 Key/value 信息以供业务使用 |
139139

140+
**hmos Notification**
141+
142+
```php
143+
// hmosNotification($alert = '', $category = '', array $notification = array())
144+
// 数组 $notification 的键支持 'title', 'category', 'large_icon', 'intent', 'badge_add_num', 'test_message', 'receipt_id', 'extras' 中的一个或多个
145+
// 注意category为必填项,若$category为空字符串则会从$notification中取'category'的值
146+
```
147+
148+
参数说明:
149+
150+
| 参数 | 说明 |
151+
| --- | --- |
152+
| alert | 表示通知内容,会覆盖上级统一指定的 alert 信息;默认内容可以为空字符串,表示不展示到通知栏 |
153+
| title | 表示通知标题,会替换通知里原来展示 App 名称的地方 |
154+
| category | 通知栏消息分类条目;对应官方「本地通知」category取值,开发者通过极光服务发起推送时如果传递了此字段值,请务必按照官方要求传递 |
155+
| badge_add_num | 设置角标数字累加值;不填则不改变角标数字,取值范围为1-99 |
156+
| test_message | 测试消息标识;false为正常消息(默认值),true为测试消息 |
157+
| receipt_id | 华为回执 ID;输入一个唯一的回执 ID 指定本次下行消息的回执地址及配置,该回执 ID 可以在鸿蒙回执参数配置中查看 |
158+
| large_icon | 表示通知栏大图标,图标路径可以是以 http 或 https 开头的网络图片,如:"http:jiguang.cn/logo.png",图标大小不超过 30k; 也可以是位于 drawable 资源文件夹的图标路径,如:"R.drawable.lg_icon";|
159+
| intent | 表示扩展字段,接受一个数组,自定义 Key/value 信息以供业务使用 |
160+
| extras | 表示扩展字段,接受一个数组,自定义 Key/value 信息以供业务使用 |
161+
140162
**WinPhone Notification**
141163

142164
```php

src/JPush/PushPayload.php

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class PushPayload {
66

7-
private static $EFFECTIVE_DEVICE_TYPES = array('ios', 'android', 'winphone');
7+
private static $EFFECTIVE_DEVICE_TYPES = array('ios', 'android', 'winphone', 'hmos');
88

99
private $client;
1010
private $url;
@@ -25,6 +25,7 @@ class PushPayload {
2525
private $iosNotification;
2626
private $androidNotification;
2727
private $winPhoneNotification;
28+
private $hmosNotification;
2829
private $voip;
2930
private $smsMessage;
3031
private $message;
@@ -52,7 +53,7 @@ public function setCid($cid) {
5253
}
5354

5455
public function setPlatform($platform) {
55-
# $required_keys = array('all', 'android', 'ios', 'winphone');
56+
# $required_keys = array('all', 'android', 'ios', 'winphone', 'hmos');
5657
if (is_string($platform)) {
5758
$ptf = strtolower($platform);
5859
if ('all' === $ptf) {
@@ -287,6 +288,20 @@ public function build() {
287288
}
288289
}
289290

291+
if (!is_null($this->hmosNotification)) {
292+
$notification['hmos'] = $this->hmosNotification;
293+
if (is_null($this->hmosNotification['alert'])) {
294+
if (is_null($this->hmosNotification)) {
295+
throw new InvalidArgumentException("hmos alert can not be null");
296+
} else {
297+
$notification['hmos']['alert'] = $this->notificationAlert;
298+
}
299+
}
300+
if (is_null($this->hmosNotification['category'])) {
301+
throw new InvalidArgumentException("hmos category can not be null");
302+
}
303+
}
304+
290305
if (!is_null($this->voip)) {
291306
$notification['voip'] = $this->voip;
292307
}
@@ -448,6 +463,50 @@ public function androidNotification($alert = '', array $notification = array())
448463
return $this;
449464
}
450465

466+
public function hmosNotification($alert = '', $category='', array $notification = array()) {
467+
$hmos = array();
468+
$hmos['alert'] = is_string($alert) ? $alert : '';
469+
$hmos['category'] = is_string($category) ? $category : '';
470+
if (!empty($notification)) {
471+
if (isset($notification['badge_add_num'])) {
472+
if (is_int($notification['badge_add_num']) && $notification['badge_add_num'] >= 1 && $notification['badge_add_num']<=99) {
473+
$hmos['badge_add_num'] = $notification['badge_add_num'];
474+
} else {
475+
unset($notification['badge_add_num']);
476+
}
477+
}
478+
if (isset($notification['test_message'])) {
479+
if (is_bool($notification['test_message'])) {
480+
$hmos['test_message'] = $notification['test_message'];
481+
} else {
482+
unset($notification['test_message']);
483+
}
484+
}
485+
if (isset($notification['intent'])) {
486+
if (is_array($notification['intent']) && !empty($notification['intent'])) {
487+
$hmos['intent'] = $notification['intent'];
488+
} else {
489+
unset($notification['intent']);
490+
}
491+
}
492+
if (isset($notification['extras'])) {
493+
if (is_array($notification['extras']) && !empty($notification['extras'])) {
494+
$hmos['extras'] = $notification['extras'];
495+
} else {
496+
unset($notification['extras']);
497+
}
498+
}
499+
if ($hmos['category'] === '' && isset($notification['category'])) {
500+
if (is_string($notification['category']) && $notification['category'] !== '') {
501+
$hmos['category'] = $notification['category'];
502+
}
503+
}
504+
$hmos = array_merge($notification, $hmos);
505+
}
506+
$this->hmosNotification = $hmos;
507+
return $this;
508+
}
509+
451510
/**
452511
* Voip in notification
453512
* could add any custom key/value into it

0 commit comments

Comments
 (0)