Showing
3 changed files
with
120 additions
and
2 deletions
| @@ -8,10 +8,14 @@ import PushManager, { | @@ -8,10 +8,14 @@ import PushManager, { | ||
| 8 | import { AppUtils, DeviceUtil, EmitterEventId, EmitterUtils, Logger, SPHelper } from 'wdKit/Index'; | 8 | import { AppUtils, DeviceUtil, EmitterEventId, EmitterUtils, Logger, SPHelper } from 'wdKit/Index'; |
| 9 | import { HostEnum, HostManager, HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index'; | 9 | import { HostEnum, HostManager, HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index'; |
| 10 | import { notificationManager } from '@kit.NotificationKit'; | 10 | import { notificationManager } from '@kit.NotificationKit'; |
| 11 | -import { BusinessError } from '@kit.BasicServicesKit'; | 11 | +import { AsyncCallback, BusinessError } from '@kit.BasicServicesKit'; |
| 12 | import { SpConstants } from 'wdConstant/Index'; | 12 | import { SpConstants } from 'wdConstant/Index'; |
| 13 | import { PushContentBean, PushContentParser } from './PushContentParser'; | 13 | import { PushContentBean, PushContentParser } from './PushContentParser'; |
| 14 | import { ParamType, Tracking } from 'wdTracking/Index'; | 14 | import { ParamType, Tracking } from 'wdTracking/Index'; |
| 15 | +import { PushTransmitMessageBean, PushTransmitMessagePayloadBean } from './PushTransmitMessageBean'; | ||
| 16 | +import { JSON } from '@kit.ArkTS'; | ||
| 17 | +import wantAgent from '@ohos.app.ability.wantAgent'; | ||
| 18 | +import { WantAgent } from '@ohos.app.ability.wantAgent'; | ||
| 15 | 19 | ||
| 16 | const TAG = "GetuiPush" | 20 | const TAG = "GetuiPush" |
| 17 | 21 | ||
| @@ -209,7 +213,11 @@ export class GetuiPush { | @@ -209,7 +213,11 @@ export class GetuiPush { | ||
| 209 | return | 213 | return |
| 210 | } | 214 | } |
| 211 | if (this.lastPushContent.online) { | 215 | if (this.lastPushContent.online) { |
| 212 | - if (this.lastPushContent.want) { | 216 | + if (this.lastPushContent.localNotify == true) { |
| 217 | + Logger.debug(TAG, "推送 回执???: " + this.lastPushContent.want) | ||
| 218 | + let gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了 | ||
| 219 | + PushManager.sendFeedbackMessage(this.lastPushContent.messageId || "", this.lastPushContent.taskId || "", gtactionid) | ||
| 220 | + } else if (this.lastPushContent.want) { | ||
| 213 | Logger.debug(TAG, "推送 回执: " + this.lastPushContent.want) | 221 | Logger.debug(TAG, "推送 回执: " + this.lastPushContent.want) |
| 214 | PushManager.setClickWant(this.lastPushContent.want) | 222 | PushManager.setClickWant(this.lastPushContent.want) |
| 215 | } | 223 | } |
| @@ -325,6 +333,81 @@ export class GetuiPush { | @@ -325,6 +333,81 @@ export class GetuiPush { | ||
| 325 | // */ | 333 | // */ |
| 326 | // int gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了 | 334 | // int gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了 |
| 327 | // boolean result = PushManager.sendFeedbackMessage(taskid, messageid, gtactionid); | 335 | // boolean result = PushManager.sendFeedbackMessage(taskid, messageid, gtactionid); |
| 336 | + this.sendLocalNotification(message) | ||
| 337 | + } | ||
| 338 | + | ||
| 339 | + private sendLocalNotification(message: GTTransmitMessage) { | ||
| 340 | + let jsonMsgObj = JSON.parse(message.payload) as PushTransmitMessageBean | ||
| 341 | + if (!jsonMsgObj) { | ||
| 342 | + return | ||
| 343 | + } | ||
| 344 | + if (jsonMsgObj && jsonMsgObj.payload) { | ||
| 345 | + jsonMsgObj.payloadObj = JSON.parse(jsonMsgObj.payload) as PushTransmitMessagePayloadBean | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + let pushLink = jsonMsgObj.payloadObj?.pushLink || "" | ||
| 349 | + | ||
| 350 | + let params: Record<string, string> = { | ||
| 351 | + "title": jsonMsgObj.title, | ||
| 352 | + "content": jsonMsgObj.body, | ||
| 353 | + "pushLink": pushLink, | ||
| 354 | + "taskid": message.taskId, | ||
| 355 | + "messageId": message.messageId, | ||
| 356 | + "gtTransmitMsgLocalNotify": "1", | ||
| 357 | + } | ||
| 358 | + | ||
| 359 | + this.getWantAgent(params, (error, want) => { | ||
| 360 | + if (error) { | ||
| 361 | + return | ||
| 362 | + } | ||
| 363 | + let notificationRequest: notificationManager.NotificationRequest = { | ||
| 364 | + id: Date.now(), | ||
| 365 | + content: { | ||
| 366 | + notificationContentType: notificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT, | ||
| 367 | + normal: { | ||
| 368 | + title: jsonMsgObj.title, | ||
| 369 | + text: jsonMsgObj.body, | ||
| 370 | + } | ||
| 371 | + }, | ||
| 372 | + notificationSlotType: notificationManager.SlotType.CONTENT_INFORMATION, | ||
| 373 | + wantAgent:want, | ||
| 374 | + }; | ||
| 375 | + notificationManager.publish(notificationRequest).then(() => { | ||
| 376 | + Logger.debug(TAG, "本地发送系统通知完成") | ||
| 377 | + }).catch((err: BusinessError) => { | ||
| 378 | + Logger.debug(TAG, "本地发送系统通知失败:" + JSON.stringify(err)) | ||
| 379 | + }); | ||
| 380 | + }) | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | + private getWantAgent(parameters:Record<string, string>, callback: AsyncCallback<WantAgent>) { | ||
| 384 | + | ||
| 385 | + // 通过WantAgentInfo的operationType设置动作类型 | ||
| 386 | + let wantAgentInfo:wantAgent.WantAgentInfo = { | ||
| 387 | + wants: [ | ||
| 388 | + { | ||
| 389 | + deviceId: '', | ||
| 390 | + bundleName: 'com.peopledailychina.hosactivity', | ||
| 391 | + abilityName: 'EntryAbility', | ||
| 392 | + action: 'com.test.pushaction', | ||
| 393 | + entities: [], | ||
| 394 | + uri: "rmrbapp://rmrb.app:8080/openwith", | ||
| 395 | + parameters: parameters | ||
| 396 | + } | ||
| 397 | + ], | ||
| 398 | + operationType: wantAgent.OperationType.START_ABILITY, | ||
| 399 | + requestCode: 0, | ||
| 400 | + wantAgentFlags:[wantAgent.WantAgentFlags.CONSTANT_FLAG] | ||
| 401 | + }; | ||
| 402 | + | ||
| 403 | + wantAgent.getWantAgent(wantAgentInfo, (err:BusinessError, data:WantAgent) => { | ||
| 404 | + if (err) { | ||
| 405 | + Logger.error(TAG, `Failed to get want agent. Code is ${err.code}, message is ${err.message}`) | ||
| 406 | + } | ||
| 407 | + if (callback) { | ||
| 408 | + callback(err, data) | ||
| 409 | + } | ||
| 410 | + }); | ||
| 328 | } | 411 | } |
| 329 | 412 | ||
| 330 | private uploadPushInfo(cid: string) { | 413 | private uploadPushInfo(cid: string) { |
| @@ -11,6 +11,12 @@ export interface PushContentBean { | @@ -11,6 +11,12 @@ export interface PushContentBean { | ||
| 11 | pushLink?: string // 解析want,对应pushLink参数 | 11 | pushLink?: string // 解析want,对应pushLink参数 |
| 12 | notifyTitle?: string | 12 | notifyTitle?: string |
| 13 | notifyContent?: string | 13 | notifyContent?: string |
| 14 | + | ||
| 15 | + | ||
| 16 | + // 透传消息发送的本地测试通知 | ||
| 17 | + localNotify?:boolean | ||
| 18 | + taskId?: string | ||
| 19 | + messageId?: string | ||
| 14 | } | 20 | } |
| 15 | 21 | ||
| 16 | /* | 22 | /* |
| @@ -18,6 +24,8 @@ export interface PushContentBean { | @@ -18,6 +24,8 @@ export interface PushContentBean { | ||
| 18 | * */ | 24 | * */ |
| 19 | export class PushContentParser { | 25 | export class PushContentParser { |
| 20 | 26 | ||
| 27 | + | ||
| 28 | + private static LAUNCH_PARAM_GETUI_TRANSMIT_MSG_LOCAL_NOTIFY = "gtTransmitMsgLocalNotify" | ||
| 21 | private static LAUNCH_PARAM_GETUI_DATA = "gtdata" | 29 | private static LAUNCH_PARAM_GETUI_DATA = "gtdata" |
| 22 | private static LAUNCH_PARAM_GETUI_TASKID = "taskid" | 30 | private static LAUNCH_PARAM_GETUI_TASKID = "taskid" |
| 23 | private static LAUNCH_PARAM_GETUI_NOTIFYID = "_push_notifyid" | 31 | private static LAUNCH_PARAM_GETUI_NOTIFYID = "_push_notifyid" |
| @@ -116,6 +124,21 @@ export class PushContentParser { | @@ -116,6 +124,21 @@ export class PushContentParser { | ||
| 116 | } | 124 | } |
| 117 | } | 125 | } |
| 118 | 126 | ||
| 127 | + | ||
| 128 | + // 本地发送的测试通知 | ||
| 129 | + if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_TRANSMIT_MSG_LOCAL_NOTIFY]) { | ||
| 130 | + if (want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK]) { | ||
| 131 | + let pushLink = want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK] as string | ||
| 132 | + return { | ||
| 133 | + isPush: true, online: true, pushLink: pushLink, want: want, | ||
| 134 | + notifyTitle: want.parameters["title"] as string, | ||
| 135 | + notifyContent: want.parameters["content"] as string, | ||
| 136 | + localNotify: true, | ||
| 137 | + taskId: want.parameters["taskId"] as string, | ||
| 138 | + messageId: want.parameters["messageId"] as string, | ||
| 139 | + } | ||
| 140 | + } | ||
| 141 | + } | ||
| 119 | return { | 142 | return { |
| 120 | isPush: false, online: false | 143 | isPush: false, online: false |
| 121 | } | 144 | } |
-
Please register or login to post a comment