PushContentParser.ets
4.14 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import Want from '@ohos.app.ability.Want';
import { Logger } from 'wdKit/Index';
import { JSON } from '@kit.ArkTS';
import { AppInfo } from '@mpaas/framework';
import { AppInnerLink } from 'wdRouter/Index';
export interface PushContentBean {
isPush: boolean // 是否为推送数据
want?: Want // want参数 (用来在消费时,回执)
online: boolean // 解析want,是否为在线消息(在线走的是个推通道,离线走的是华为厂商通道)
pushLink?: string // 解析want,对应pushLink参数
}
/*
* */
export class PushContentParser {
private static LAUNCH_PARAM_GETUI_DATA = "gtdata"
private static LAUNCH_PARAM_GETUI_TASKID = "taskid"
private static LAUNCH_PARAM_GETUI_NOTIFYID = "_push_notifyid"
private static PUSH_PARAM_PUSH_LINK = "pushLink"
static getPushLinkFromWant(want: Want) : PushContentBean {
// 个推在线消息
if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_DATA]) {
/*
{
"age": 12,
"gtdata": {
"actionid": "10010",
"appid": "ZMi5AAXYHE84VN9p55YpW2",
"bigStyle": 0,
"checkpackage": "com.peopledailychina.hosactivity",
"content": "通知内容444",
"feedbackid": "0",
"isFloat": false,
"messageid": "44fd0876c9834214a6b7032b35d9826b",
"notifID": 62288,
"notifyStyle": 0,
"payload": "",
"taskid": "TEST_0516_03a84918e7df6191502497ed2cbef384",
"title": "测试通知444",
"wantUri": "{\"deviceId\":\"\",\"bundleName\":\"com.peopledailychina.hosactivity\",\"abilityName\":\"EntryAbility\",\"uri\":\"rmrbapp://rmrb.app:8080/openwith\",\"action\":\"com.test.pushaction\",\"parameters\":{\"pushLink\":\"Getui\",\"age\":12}}"
},
"isCallBySCB": false,
"moduleName": "phone",
"pushLink": "Getui",
"ohos.aafwk.param.callerAbilityName": "",
"ohos.aafwk.param.callerBundleName": "com.ohos.sceneboard",
"ohos.aafwk.param.callerPid": 44239,
"ohos.aafwk.param.callerToken": 537702494,
"ohos.aafwk.param.callerUid": 20020018,
"specifyTokenId": 537063794
}
},*/
let gtData = want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_DATA] as Record<string, string | number | object>
if (gtData[PushContentParser.LAUNCH_PARAM_GETUI_TASKID] != undefined) {
let json = JSON.parse(gtData["wantUri"] as string) as Record<string, string | number>
if (json && json[PushContentParser.PUSH_PARAM_PUSH_LINK] != null) {
const pushLink = json[PushContentParser.PUSH_PARAM_PUSH_LINK] as string
return {
isPush: true, online: true, pushLink: pushLink, want: want
}
}
}
}
/*
{
"deviceId": "",
"bundleName": "com.peopledailychina.hosactivity",
"abilityName": "EntryAbility",
"moduleName": "phone",
"uri": "rmrbapp://rmrb.app:8080/openwith",
"type": "",
"flags": 0,
"action": "com.test.pushaction",
"parameters": {
"_push_notifyid": 1,
"age": 12, // 自定义
"debugApp": false,
"isCallBySCB": false,
"moduleName": "phone",
"pushLink": "Getui", // 自定义
"ohos.aafwk.param.callerAbilityName": "PushServiceInnerAbility",
"ohos.aafwk.param.callerBundleName": "com.huawei.hms.pushservice",
"ohos.aafwk.param.callerPid": 22808,
"ohos.aafwk.param.callerToken": 537908725,
"ohos.aafwk.param.callerUid": 20004,
"ohos.dlp.params.sandbox": false
},
"entities": [
]
* */
// 离线消息,华为直接推送
if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_NOTIFYID]) {
if (want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK]) {
let pushLink = want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK] as string
return {
isPush: true, online: false, pushLink: pushLink, want: want
}
}
}
return {
isPush: false, online: false
}
}
static jumpWithPushLink(pushLink: string) {
AppInnerLink.jumpWithLink(pushLink)
}
}