ref |> 新增个推推送接入
Signed-off-by: xugenyuan <xugenyuan@wondertek.com.cn>
Showing
13 changed files
with
607 additions
and
25 deletions
| @@ -48,4 +48,8 @@ export class SpConstants{ | @@ -48,4 +48,8 @@ export class SpConstants{ | ||
| 48 | //游客状态下首次评论时间 | 48 | //游客状态下首次评论时间 |
| 49 | static FIRSTCOMMENTTIME = 'firstCommentTime' | 49 | static FIRSTCOMMENTTIME = 'firstCommentTime' |
| 50 | static TOURIST_NICK_NAME = 'touristNickName' | 50 | static TOURIST_NICK_NAME = 'touristNickName' |
| 51 | + | ||
| 52 | + // 个推推送 | ||
| 53 | + static GETUI_PUSH_CID = "cid" | ||
| 54 | + static GETUI_PUSH_DEVICE_TOKEN = "deviceToken" | ||
| 51 | } | 55 | } |
| @@ -807,4 +807,9 @@ export class HttpUrlUtils { | @@ -807,4 +807,9 @@ export class HttpUrlUtils { | ||
| 807 | let url = HttpUrlUtils.getHost() + "/api/rmrb-user-center/common/user/c/device/push"; | 807 | let url = HttpUrlUtils.getHost() + "/api/rmrb-user-center/common/user/c/device/push"; |
| 808 | return url; | 808 | return url; |
| 809 | } | 809 | } |
| 810 | -} | ||
| 810 | + | ||
| 811 | + static getUploadPushInfoUrl() { | ||
| 812 | + let url = HttpUrlUtils.getHost() + "/api/rmrb-contact/contact/zh/c/push/device" | ||
| 813 | + return url | ||
| 814 | + } | ||
| 815 | +} |
| @@ -12,4 +12,6 @@ export { ProcessUtils } from './src/main/ets/utils/ProcessUtils' | @@ -12,4 +12,6 @@ export { ProcessUtils } from './src/main/ets/utils/ProcessUtils' | ||
| 12 | 12 | ||
| 13 | export { AssignChannelParam } from './src/main/ets/utils/HomeChannelUtils'; | 13 | export { AssignChannelParam } from './src/main/ets/utils/HomeChannelUtils'; |
| 14 | 14 | ||
| 15 | -export { RouterJumpInterceptor, JumpInterceptorAction } from './src/main/ets/router/RouterJumpInterceptor' | ||
| 15 | +export { RouterJumpInterceptor, JumpInterceptorAction } from './src/main/ets/router/RouterJumpInterceptor' | ||
| 16 | + | ||
| 17 | +export { AppInnerLink } from './src/main/ets/utils/AppInnerLink' |
| 1 | +import { url } from '@kit.ArkTS' | ||
| 2 | +import App from '@system.app' | ||
| 3 | +import { Logger } from 'wdKit/Index' | ||
| 4 | + | ||
| 5 | +const TAG = "AppInnerLink" | ||
| 6 | + | ||
| 7 | +export class AppInnerLink { | ||
| 8 | + | ||
| 9 | + static readonly INNER_LINK_PROTCOL = "rmrbapp:" | ||
| 10 | + static readonly INNER_LINK_HOSTNAME = "rmrb.app" | ||
| 11 | + static readonly INNER_LINK_PATHNAME = "openwith" | ||
| 12 | + | ||
| 13 | + // 内链跳转 | ||
| 14 | + // 内链地址例如:rmrbapp://rmrb.app/openwith?type=article&subType=h5_template_article&contentId=30000762651&relId=500000038702&skipType=1&relType=1 | ||
| 15 | + static jumpWithLink(innerLink: string) { | ||
| 16 | + | ||
| 17 | + let params = AppInnerLink.parseParams(innerLink) | ||
| 18 | + if (!params) { | ||
| 19 | + Logger.info(TAG, "跳转无效的链接地址 " + innerLink) | ||
| 20 | + return | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + switch (params.skipType) { | ||
| 24 | + case 1: { | ||
| 25 | + AppInnerLink.jumpParams(params) | ||
| 26 | + break | ||
| 27 | + } | ||
| 28 | + case 2: { | ||
| 29 | + AppInnerLink.jumpNoParams(params) | ||
| 30 | + break | ||
| 31 | + } | ||
| 32 | + case 3: { | ||
| 33 | + AppInnerLink.jumpAppH5(params) | ||
| 34 | + break | ||
| 35 | + } | ||
| 36 | + case 4: { | ||
| 37 | + AppInnerLink.jumpOutH5(params) | ||
| 38 | + break | ||
| 39 | + } | ||
| 40 | + case 5: { | ||
| 41 | + AppInnerLink.jumpThirdApp(params) | ||
| 42 | + break | ||
| 43 | + } | ||
| 44 | + default: { | ||
| 45 | + Logger.info(TAG, "跳转无效的链接地址 " + innerLink) | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + private static jumpParams(params: InnerLinkParam) { | ||
| 51 | + | ||
| 52 | + } | ||
| 53 | + private static jumpNoParams(params: InnerLinkParam) { | ||
| 54 | + | ||
| 55 | + } | ||
| 56 | + private static jumpAppH5(params: InnerLinkParam) { | ||
| 57 | + | ||
| 58 | + } | ||
| 59 | + private static jumpOutH5(params: InnerLinkParam) { | ||
| 60 | + | ||
| 61 | + } | ||
| 62 | + private static jumpThirdApp(params: InnerLinkParam) { | ||
| 63 | + | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + static parseParams(link: string) : InnerLinkParam | undefined { | ||
| 67 | + const that = url.URL.parseURL(link) | ||
| 68 | + if (that.protocol !== AppInnerLink.INNER_LINK_PROTCOL) { | ||
| 69 | + return | ||
| 70 | + } | ||
| 71 | + if (that.hostname !== AppInnerLink.INNER_LINK_HOSTNAME) { | ||
| 72 | + return | ||
| 73 | + } | ||
| 74 | + if (that.pathname !== AppInnerLink.INNER_LINK_PATHNAME) { | ||
| 75 | + return | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + let obj = {} as InnerLinkParam | ||
| 79 | + | ||
| 80 | + const params = that.params | ||
| 81 | + obj.type = params.get("type") as string | ||
| 82 | + obj.subType = params.get("subType") as string | ||
| 83 | + obj.contentId = params.get("contentId") as string | ||
| 84 | + obj.relId = params.get("relId") as string | ||
| 85 | + obj.relType = params.get("relType") as string | ||
| 86 | + obj.pageId = params.get("pageId") as string | ||
| 87 | + obj.url = params.get("url") as string | ||
| 88 | + obj.activityId = params.get("activityId") as string | ||
| 89 | + obj.activityType = params.get("activityType") as string | ||
| 90 | + obj.creatorId = params.get("creatorId") as string | ||
| 91 | + obj.firstChannelId = params.get("firstChannelId") as string | ||
| 92 | + obj.skipType = Number(params.get("skipType")) | ||
| 93 | + obj.isLogin = params.get("isLogin") as string | ||
| 94 | + return obj | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +interface InnerLinkParam { | ||
| 101 | + type?: string, | ||
| 102 | + subType?: string, | ||
| 103 | + contentId?: string, | ||
| 104 | + relId?: string, | ||
| 105 | + relType?: string | ||
| 106 | + pageId?: string, | ||
| 107 | + url?: string, | ||
| 108 | + activityId?: string, | ||
| 109 | + activityType?: string, | ||
| 110 | + creatorId?: string, | ||
| 111 | + firstChannelId?: string, | ||
| 112 | + skipType: number, | ||
| 113 | + isLogin?: string, | ||
| 114 | +} |
| @@ -2,4 +2,5 @@ export { add } from "./src/main/ets/utils/Calc" | @@ -2,4 +2,5 @@ export { add } from "./src/main/ets/utils/Calc" | ||
| 2 | 2 | ||
| 3 | export { HWLocationUtils } from './src/main/ets/location/HWLocationUtils' | 3 | export { HWLocationUtils } from './src/main/ets/location/HWLocationUtils' |
| 4 | 4 | ||
| 5 | -export { WDPushNotificationManager } from "./src/main/ets/notification/WDPushNotificationManager" | ||
| 5 | +// export { WDPushNotificationManager } from "./src/main/ets/notification/WDPushNotificationManager" | ||
| 6 | +export { GetuiPush } from "./src/main/ets/getuiPush/GetuiPush" |
| @@ -7,10 +7,12 @@ | @@ -7,10 +7,12 @@ | ||
| 7 | "license": "Apache-2.0", | 7 | "license": "Apache-2.0", |
| 8 | "packageType": "InterfaceHar", | 8 | "packageType": "InterfaceHar", |
| 9 | "dependencies": { | 9 | "dependencies": { |
| 10 | + "library": "file:./src/main/ets/getuiPush/GTSDK-1.0.1.0.har", | ||
| 10 | "wdConstant": "file:../../commons/wdConstant", | 11 | "wdConstant": "file:../../commons/wdConstant", |
| 11 | "wdLogin": "file:../../features/wdLogin", | 12 | "wdLogin": "file:../../features/wdLogin", |
| 12 | "wdKit": "file:../../commons/wdKit", | 13 | "wdKit": "file:../../commons/wdKit", |
| 13 | "wdBean": "file:../../features/wdBean", | 14 | "wdBean": "file:../../features/wdBean", |
| 15 | + "wdRouter": "file:../../commons/wdRouter", | ||
| 14 | "wdNetwork": "file:../../commons/wdNetwork" | 16 | "wdNetwork": "file:../../commons/wdNetwork" |
| 15 | } | 17 | } |
| 16 | } | 18 | } |
No preview for this file type
| 1 | +import { common, Want } from '@kit.AbilityKit'; | ||
| 2 | +import PushManager, { | ||
| 3 | + BindAliasCmdMessage, | ||
| 4 | + GTCmdMessage, GTNotificationMessage, GTTransmitMessage, PushConst, | ||
| 5 | + SetTagCmdMessage, | ||
| 6 | + Tag, | ||
| 7 | + UnBindAliasCmdMessage } from 'library'; | ||
| 8 | +import { AppUtils, DeviceUtil, EmitterEventId, EmitterUtils, Logger, SPHelper } from 'wdKit/Index'; | ||
| 9 | +import { HostEnum, HostManager, HttpBizUtil, HttpUrlUtils, HttpUtils, ResponseDTO } from 'wdNetwork/Index'; | ||
| 10 | +import { notificationManager } from '@kit.NotificationKit'; | ||
| 11 | +import { BusinessError } from '@kit.BasicServicesKit'; | ||
| 12 | +import { SpConstants } from 'wdConstant/Index'; | ||
| 13 | +import { PushContentBean, PushContentParser } from './PushContentParser'; | ||
| 14 | + | ||
| 15 | +const TAG = "GetuiPush" | ||
| 16 | + | ||
| 17 | +export class GetuiPush { | ||
| 18 | + | ||
| 19 | + private static GETUI_APPID_ONLINE = "sMkzgp09Ov82nU1MGk7Ae6" | ||
| 20 | + private static GETUI_APPID_TEST = "ZMi5AAXYHE84VN9p55YpW2" | ||
| 21 | + | ||
| 22 | + private readonly ALIAS_SN_USERID = "userID" | ||
| 23 | + private readonly TAG_SN_TAG = "tag1" | ||
| 24 | + private readonly TAG_PD_ZH = "peopledaily_zh" | ||
| 25 | + | ||
| 26 | + private cid: string = "" | ||
| 27 | + private deviceToken: string = "" | ||
| 28 | + private currentUserId = "" | ||
| 29 | + private lastPushContent?: PushContentBean | ||
| 30 | + | ||
| 31 | + private initialed = false | ||
| 32 | + | ||
| 33 | + private constructor() { | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + private static manager: GetuiPush | ||
| 37 | + static sharedInstance() : GetuiPush { | ||
| 38 | + if (!GetuiPush.manager) { | ||
| 39 | + GetuiPush.manager = new GetuiPush() | ||
| 40 | + } | ||
| 41 | + return GetuiPush.manager | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + init(context: common.UIAbilityContext) { | ||
| 45 | + | ||
| 46 | + const isOnlineEnv = HostManager.getHost() === HostEnum.HOST_PRODUCT | ||
| 47 | + | ||
| 48 | + PushManager.initialize({ | ||
| 49 | + appId:isOnlineEnv ? GetuiPush.GETUI_APPID_TEST : GetuiPush.GETUI_APPID_TEST, | ||
| 50 | + context: context, | ||
| 51 | + onSuccess: (cid:string) => { | ||
| 52 | + Logger.debug(TAG, "个推SDK初始化成功,cid = " + cid) | ||
| 53 | + this.initialed = true | ||
| 54 | + this.cid = cid | ||
| 55 | + this.registerEvents() | ||
| 56 | + this.checkSetup() | ||
| 57 | + }, | ||
| 58 | + onFailed: (error:string) => { | ||
| 59 | + Logger.error(TAG, "个推SDK初始化失败,error = " + error) | ||
| 60 | + } | ||
| 61 | + }) | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + async requestEnableNotifications(context: common.UIAbilityContext) : Promise<boolean> { | ||
| 65 | + let enabled = await notificationManager.isNotificationEnabled() | ||
| 66 | + if (!enabled) { | ||
| 67 | + try { | ||
| 68 | + await notificationManager.requestEnableNotification(context) | ||
| 69 | + enabled = true | ||
| 70 | + } catch (err) { | ||
| 71 | + Logger.error(TAG, "请求通知权限报错: " + JSON.stringify(err)) | ||
| 72 | + let error = err as BusinessError | ||
| 73 | + if (error.code == 1600004) { | ||
| 74 | + Logger.error(TAG, "请求通知权限 - 用户已拒绝") | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + Logger.info(TAG, "推送 enabled " + enabled) | ||
| 79 | + return enabled | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + checkSetup() { | ||
| 83 | + if (!this.initialed) { return } | ||
| 84 | + if (HttpUtils.isLogin()) { | ||
| 85 | + const userId = SPHelper.default.getSync(SpConstants.USER_ID, "") as string | ||
| 86 | + this.currentUserId = userId | ||
| 87 | + this.setAlias(true, userId) | ||
| 88 | + } | ||
| 89 | + let tags = [this.TAG_PD_ZH, AppUtils.getAppVersionCode()] | ||
| 90 | + this.setTags(tags) | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + // 默认是开启的 | ||
| 94 | + switchPush(turnOn: boolean) { | ||
| 95 | + turnOn ? PushManager.turnOnPush() : PushManager.turnOffPush() | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + registerEvents() { | ||
| 99 | + | ||
| 100 | + // 登录和退出 | ||
| 101 | + EmitterUtils.receiveEvent(EmitterEventId.LOGIN_SUCCESS, () => { | ||
| 102 | + const userId = SPHelper.default.getSync(SpConstants.USER_ID, "") as string | ||
| 103 | + this.currentUserId = userId | ||
| 104 | + this.setAlias(true, userId) | ||
| 105 | + }) | ||
| 106 | + EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => { | ||
| 107 | + if (this.currentUserId.length) { | ||
| 108 | + this.setAlias(false, this.currentUserId) | ||
| 109 | + } | ||
| 110 | + }) | ||
| 111 | + | ||
| 112 | + PushManager.setPushCallback({ | ||
| 113 | + // cid | ||
| 114 | + onReceiveClientId: (clientId: string) => { | ||
| 115 | + Logger.debug(TAG, "推送 接收到 clientId = " + clientId) | ||
| 116 | + this.cid = PushManager.getClientId() | ||
| 117 | + SPHelper.default.save(SpConstants.GETUI_PUSH_CID, this.cid) | ||
| 118 | + this.uploadPushInfo(this.cid) | ||
| 119 | + }, | ||
| 120 | + //接收⼚商token | ||
| 121 | + onReceiveDeviceToken: (deviceToken:string) => { | ||
| 122 | + Logger.debug(TAG, "推送 deviceToken = " + deviceToken) | ||
| 123 | + this.deviceToken = deviceToken; | ||
| 124 | + SPHelper.default.save(SpConstants.GETUI_PUSH_DEVICE_TOKEN, this.deviceToken) | ||
| 125 | + }, | ||
| 126 | + // cid 离线上线通知 | ||
| 127 | + onReceiveOnlineState: (onLine:boolean) => { | ||
| 128 | + Logger.debug(TAG, "推送 onLine State = " + onLine) | ||
| 129 | + }, | ||
| 130 | + //命令相应回复 | ||
| 131 | + onReceiveCommandResult: (result: GTCmdMessage) => { | ||
| 132 | + Logger.debug(TAG, "推送 Cmd Message = " + JSON.stringify(result)) | ||
| 133 | + this.dealWithCmdMessage(result) | ||
| 134 | + }, | ||
| 135 | + //sdk 收到透传消息 | ||
| 136 | + onReceiveMessageData: (message: GTTransmitMessage) => { | ||
| 137 | + Logger.debug(TAG, "推送 透传 Message = " + JSON.stringify(message)) | ||
| 138 | + this.dealWithTransmitMessage(message) | ||
| 139 | + }, | ||
| 140 | + //通知到达回调 | ||
| 141 | + onNotificationMessageArrived: (message: GTNotificationMessage) => { | ||
| 142 | + Logger.debug(TAG, "推送 通知到达回调 " + JSON.stringify(message)) | ||
| 143 | + }, | ||
| 144 | + //通知点击回调, 需要配合PushManager.setClickWant(want)使⽤ | ||
| 145 | + onNotificationMessageClicked: (message: GTNotificationMessage) => { | ||
| 146 | + Logger.debug(TAG, "推送 通知 点击 回调 " + JSON.stringify(message)) | ||
| 147 | + }, | ||
| 148 | + }) | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + setAlias(bind: boolean, alias: string, sn: string = this.ALIAS_SN_USERID) { | ||
| 152 | + if (!this.initialed) { return } | ||
| 153 | + if (bind) { | ||
| 154 | + Logger.debug(TAG, "推送 绑定别名 " + alias) | ||
| 155 | + PushManager.bindAlias(alias, sn) | ||
| 156 | + } else { | ||
| 157 | + Logger.debug(TAG, "推送 解绑别名 " + alias) | ||
| 158 | + PushManager.unBindAlias(alias, true, sn) | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + setTags(tags: string[], sn: string = this.TAG_SN_TAG) { | ||
| 163 | + if (!this.initialed) { return } | ||
| 164 | + Logger.debug(TAG, "推送 设置标签 " + tags) | ||
| 165 | + PushManager.setTag(tags.map((tag) => { | ||
| 166 | + return new Tag().setName(tag) | ||
| 167 | + }), sn) | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + setBadgeNumber(number: number) { | ||
| 171 | + Logger.debug(TAG, "推送 设置角标 " + number) | ||
| 172 | + PushManager.setBadgeNum(number) | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + // 接收推送数据,包括启动和二次点击拉起 | ||
| 176 | + // 参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides/push-dev-0000001727885258 | ||
| 177 | + onWant(want: Want) { | ||
| 178 | + this.onNewWant(want, true) | ||
| 179 | + } | ||
| 180 | + onNewWant(want: Want, startup: boolean = false) { | ||
| 181 | + Logger.debug(TAG, "want: " + JSON.stringify(want)) | ||
| 182 | + | ||
| 183 | + this.lastPushContent = undefined | ||
| 184 | + let pushContent = PushContentParser.getPushLinkFromWant(want) | ||
| 185 | + if (pushContent && pushContent.isPush) { | ||
| 186 | + Logger.debug(TAG, "接收到推送: " + JSON.stringify(want.parameters)) | ||
| 187 | + this.lastPushContent = pushContent | ||
| 188 | + if (this.initialed) { | ||
| 189 | + this.comsumeLastPushContent() | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + // 首次进入主页,即可解析跳转推送 | ||
| 195 | + onReachMainPage() { | ||
| 196 | + if (this.initialed) { | ||
| 197 | + this.comsumeLastPushContent() | ||
| 198 | + } else { | ||
| 199 | + this.lastPushContent = undefined | ||
| 200 | + } | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + comsumeLastPushContent() { | ||
| 204 | + if (!this.lastPushContent) { | ||
| 205 | + return | ||
| 206 | + } | ||
| 207 | + if (this.lastPushContent.online) { | ||
| 208 | + if (this.lastPushContent.want) { | ||
| 209 | + Logger.debug(TAG, "推送 回执: " + this.lastPushContent.want) | ||
| 210 | + PushManager.setClickWant(this.lastPushContent.want) | ||
| 211 | + } | ||
| 212 | + } | ||
| 213 | + if (this.lastPushContent.pushLink) { | ||
| 214 | + Logger.debug(TAG, "跳转对应页面: " + this.lastPushContent.pushLink) | ||
| 215 | + PushContentParser.jumpWithPushLink(this.lastPushContent.pushLink) | ||
| 216 | + } | ||
| 217 | + this.lastPushContent = undefined | ||
| 218 | + } | ||
| 219 | + | ||
| 220 | + private dealWithCmdMessage(result: GTCmdMessage) { | ||
| 221 | + let action: Number = result.action; | ||
| 222 | + if (action === PushConst.BIND_ALIAS_RESULT) { | ||
| 223 | + let bindAliasCmdMessage = result as BindAliasCmdMessage; | ||
| 224 | + /* code 结果说明 | ||
| 225 | + 0:成功 | ||
| 226 | + 10099:SDK 未初始化成功 | ||
| 227 | + 30001:绑定别名失败,频率过快,两次调⽤的间隔需⼤于 1s | ||
| 228 | + 30002:绑定别名失败,参数错误 | ||
| 229 | + 30003:当前 cid 绑定别名次数超限 | ||
| 230 | + 30004:绑定别名失败,未知异常 | ||
| 231 | + 30005:绑定别名时,cid 未获取到 | ||
| 232 | + 30006:绑定别名时,发⽣⽹络错误 | ||
| 233 | + 30007:别名⽆效 | ||
| 234 | + 30008:sn ⽆效 */ | ||
| 235 | + let code = bindAliasCmdMessage.code | ||
| 236 | + if (code == 0) { | ||
| 237 | + Logger.debug(TAG, "推送 Cmd BindAlias 成功 " + bindAliasCmdMessage.sn) | ||
| 238 | + } else { | ||
| 239 | + Logger.debug(TAG, "推送 Cmd BindAlias 失败 " | ||
| 240 | + + ",sn = "+bindAliasCmdMessage.sn | ||
| 241 | + + ",clinetId = "+bindAliasCmdMessage.clientId | ||
| 242 | + + ",pkgname = "+bindAliasCmdMessage.pkgName | ||
| 243 | + + ",appId = "+bindAliasCmdMessage.appId | ||
| 244 | + + ",action = "+result.action | ||
| 245 | + + ",code ="+bindAliasCmdMessage.code) | ||
| 246 | + } | ||
| 247 | + } else if (action === PushConst.UNBIND_ALIAS_RESULT) { | ||
| 248 | + let unBindAliasCmdMessage = result as UnBindAliasCmdMessage | ||
| 249 | + /* code 结果说明 | ||
| 250 | + 0:成功 | ||
| 251 | + 10099:SDK 未初始化成功 | ||
| 252 | + 30001:解绑别名失败,频率过快,两次调⽤的间隔需⼤于 1s | ||
| 253 | + 30002:解绑别名失败,参数错误 | ||
| 254 | + 30003:当前 cid 解绑别名次数超限 | ||
| 255 | + 30004:解绑别名失败,未知异常 | ||
| 256 | + 30005:解绑别名时,cid 未获取到 | ||
| 257 | + 30006:解绑别名时,发⽣⽹络错误 | ||
| 258 | + 30007:别名⽆效 | ||
| 259 | + 30008:sn ⽆效*/ | ||
| 260 | + let code = unBindAliasCmdMessage.code | ||
| 261 | + if (code == 0) { | ||
| 262 | + Logger.debug(TAG, "推送 Cmd UnBindAlias 成功 " + unBindAliasCmdMessage.sn) | ||
| 263 | + } else { | ||
| 264 | + Logger.debug(TAG, "推送 Cmd UnBindAlias 失败 " | ||
| 265 | + + ",sn = "+unBindAliasCmdMessage.sn | ||
| 266 | + + ",clinetId = "+unBindAliasCmdMessage.clientId | ||
| 267 | + + ",pkgname = "+unBindAliasCmdMessage.pkgName | ||
| 268 | + + ",appId = "+unBindAliasCmdMessage.appId | ||
| 269 | + + ",action = "+result.action | ||
| 270 | + + ",code ="+unBindAliasCmdMessage.code) | ||
| 271 | + } | ||
| 272 | + } else if (action === PushConst.SET_TAG_RESULT) { | ||
| 273 | + let setTagCmdMessage = result as SetTagCmdMessage | ||
| 274 | + /* code 值说明 | ||
| 275 | + 0:成功 | ||
| 276 | + 10099:SDK 未初始化成功 | ||
| 277 | + 20001:tag 数量过⼤(单次设置的 tag 数量不超过 100) | ||
| 278 | + 20002:调⽤次数超限(默认⼀天只能成功设置⼀次) | ||
| 279 | + 20003:标签重复 | ||
| 280 | + 20004:服务初始化失败 | ||
| 281 | + 20005:setTag 异常 | ||
| 282 | + 20006:tag 为空 | ||
| 283 | + 20007:sn 为空 | ||
| 284 | + 20008:离线,还未登陆成功 | ||
| 285 | + 20009:该 appid 已经在⿊名单列表(请联系技术⽀持处理) | ||
| 286 | + 20010:已存 tag 数⽬超限 | ||
| 287 | + 20011:tag 内容格式不正确 */ | ||
| 288 | + let code = setTagCmdMessage.code | ||
| 289 | + if (code == 0) { | ||
| 290 | + Logger.debug(TAG, "推送 Cmd SetTag 成功 " + setTagCmdMessage.sn) | ||
| 291 | + } else { | ||
| 292 | + Logger.debug(TAG, "推送 Cmd SetTag 失败 " | ||
| 293 | + + ",sn = "+setTagCmdMessage.sn | ||
| 294 | + + ",clinetId = "+setTagCmdMessage.clientId | ||
| 295 | + + ",pkgname = "+setTagCmdMessage.pkgName | ||
| 296 | + + ",appId = "+setTagCmdMessage.appId | ||
| 297 | + + ",action = "+result.action | ||
| 298 | + + ",code ="+setTagCmdMessage.code) | ||
| 299 | + } | ||
| 300 | + } | ||
| 301 | + } | ||
| 302 | + | ||
| 303 | + private dealWithTransmitMessage(message: GTTransmitMessage) { | ||
| 304 | + // const taskid = message.taskId | ||
| 305 | + // const messageId = message.messageId | ||
| 306 | + // /* 上报个推透传消息的展示回执。如果透传消息本地创建通知栏消息“展示”了,则调⽤此⽅法上报。 | ||
| 307 | + // */ | ||
| 308 | + // int gtactionid = 60001;//gtactionid传⼊60001表示个推渠道消息展示了 | ||
| 309 | + // boolean result = PushManager.sendFeedbackMessag(taskid, messageid, gtactionid); | ||
| 310 | + // /** | ||
| 311 | + // * 上报个推透传消息的点击回执。如果透传消息本地创建通知栏消息“点击”了,则调⽤此⽅法上报。 | ||
| 312 | + // */ | ||
| 313 | + // int gtactionid = 60002;//gtactionid传⼊60002表示个推渠道消息点击了 | ||
| 314 | + // boolean result = PushManager.sendFeedbackMessage(taskid, messageid, gtactionid); | ||
| 315 | + } | ||
| 316 | + | ||
| 317 | + private uploadPushInfo(cid: string) { | ||
| 318 | + const url = HttpUrlUtils.getUploadPushInfoUrl() | ||
| 319 | + let bean: Record<string, string | number> = {} | ||
| 320 | + bean["deviceId"] = DeviceUtil.clientId() | ||
| 321 | + bean["cid"] = cid | ||
| 322 | + bean["userId"] = SPHelper.default.getSync(SpConstants.USER_ID, "") as string | ||
| 323 | + bean["appVersion"] = AppUtils.getAppVersionName() | ||
| 324 | + bean["platform"] = 3 | ||
| 325 | + HttpBizUtil.post<ResponseDTO<string>>(url, bean).then((data) => { | ||
| 326 | + Logger.debug(TAG, "上传cid成功" + JSON.stringify(data)) | ||
| 327 | + }).catch((e: BusinessError) => { | ||
| 328 | + Logger.debug(TAG, "上传cid失败" + JSON.stringify(e)) | ||
| 329 | + }) | ||
| 330 | + } | ||
| 331 | +} |
| 1 | +import Want from '@ohos.app.ability.Want'; | ||
| 2 | +import { Logger } from 'wdKit/Index'; | ||
| 3 | +import { JSON } from '@kit.ArkTS'; | ||
| 4 | +import { AppInfo } from '@mpaas/framework'; | ||
| 5 | +import { AppInnerLink } from 'wdRouter/Index'; | ||
| 6 | + | ||
| 7 | +export interface PushContentBean { | ||
| 8 | + isPush: boolean // 是否为推送数据 | ||
| 9 | + want?: Want // want参数 (用来在消费时,回执) | ||
| 10 | + online: boolean // 解析want,是否为在线消息(在线走的是个推通道,离线走的是华为厂商通道) | ||
| 11 | + pushLink?: string // 解析want,对应pushLink参数 | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +/* | ||
| 15 | + | ||
| 16 | + * */ | ||
| 17 | +export class PushContentParser { | ||
| 18 | + | ||
| 19 | + private static LAUNCH_PARAM_GETUI_DATA = "gtdata" | ||
| 20 | + private static LAUNCH_PARAM_GETUI_TASKID = "taskid" | ||
| 21 | + private static LAUNCH_PARAM_GETUI_NOTIFYID = "_push_notifyid" | ||
| 22 | + private static PUSH_PARAM_PUSH_LINK = "pushLink" | ||
| 23 | + | ||
| 24 | + static getPushLinkFromWant(want: Want) : PushContentBean { | ||
| 25 | + // 个推在线消息 | ||
| 26 | + if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_DATA]) { | ||
| 27 | + /* | ||
| 28 | + { | ||
| 29 | + "age": 12, | ||
| 30 | + "gtdata": { | ||
| 31 | + "actionid": "10010", | ||
| 32 | + "appid": "ZMi5AAXYHE84VN9p55YpW2", | ||
| 33 | + "bigStyle": 0, | ||
| 34 | + "checkpackage": "com.peopledailychina.hosactivity", | ||
| 35 | + "content": "通知内容444", | ||
| 36 | + "feedbackid": "0", | ||
| 37 | + "isFloat": false, | ||
| 38 | + "messageid": "44fd0876c9834214a6b7032b35d9826b", | ||
| 39 | + "notifID": 62288, | ||
| 40 | + "notifyStyle": 0, | ||
| 41 | + "payload": "", | ||
| 42 | + "taskid": "TEST_0516_03a84918e7df6191502497ed2cbef384", | ||
| 43 | + "title": "测试通知444", | ||
| 44 | + "wantUri": "{\"deviceId\":\"\",\"bundleName\":\"com.peopledailychina.hosactivity\",\"abilityName\":\"EntryAbility\",\"uri\":\"rmrbapp://rmrb.app:8080/openwith\",\"action\":\"com.test.pushaction\",\"parameters\":{\"pushLink\":\"Getui\",\"age\":12}}" | ||
| 45 | + }, | ||
| 46 | + "isCallBySCB": false, | ||
| 47 | + "moduleName": "phone", | ||
| 48 | + "pushLink": "Getui", | ||
| 49 | + "ohos.aafwk.param.callerAbilityName": "", | ||
| 50 | + "ohos.aafwk.param.callerBundleName": "com.ohos.sceneboard", | ||
| 51 | + "ohos.aafwk.param.callerPid": 44239, | ||
| 52 | + "ohos.aafwk.param.callerToken": 537702494, | ||
| 53 | + "ohos.aafwk.param.callerUid": 20020018, | ||
| 54 | + "specifyTokenId": 537063794 | ||
| 55 | + } | ||
| 56 | + },*/ | ||
| 57 | + let gtData = want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_DATA] as Record<string, string | number | object> | ||
| 58 | + if (gtData[PushContentParser.LAUNCH_PARAM_GETUI_TASKID] != undefined) { | ||
| 59 | + let json = JSON.parse(gtData["wantUri"] as string) as Record<string, string | number> | ||
| 60 | + if (json && json[PushContentParser.PUSH_PARAM_PUSH_LINK] != null) { | ||
| 61 | + const pushLink = json[PushContentParser.PUSH_PARAM_PUSH_LINK] as string | ||
| 62 | + return { | ||
| 63 | + isPush: true, online: true, pushLink: pushLink, want: want | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /* | ||
| 70 | + { | ||
| 71 | + "deviceId": "", | ||
| 72 | + "bundleName": "com.peopledailychina.hosactivity", | ||
| 73 | + "abilityName": "EntryAbility", | ||
| 74 | + "moduleName": "phone", | ||
| 75 | + "uri": "rmrbapp://rmrb.app:8080/openwith", | ||
| 76 | + "type": "", | ||
| 77 | + "flags": 0, | ||
| 78 | + "action": "com.test.pushaction", | ||
| 79 | + "parameters": { | ||
| 80 | + "_push_notifyid": 1, | ||
| 81 | + "age": 12, // 自定义 | ||
| 82 | + "debugApp": false, | ||
| 83 | + "isCallBySCB": false, | ||
| 84 | + "moduleName": "phone", | ||
| 85 | + "pushLink": "Getui", // 自定义 | ||
| 86 | + "ohos.aafwk.param.callerAbilityName": "PushServiceInnerAbility", | ||
| 87 | + "ohos.aafwk.param.callerBundleName": "com.huawei.hms.pushservice", | ||
| 88 | + "ohos.aafwk.param.callerPid": 22808, | ||
| 89 | + "ohos.aafwk.param.callerToken": 537908725, | ||
| 90 | + "ohos.aafwk.param.callerUid": 20004, | ||
| 91 | + "ohos.dlp.params.sandbox": false | ||
| 92 | + }, | ||
| 93 | + "entities": [ | ||
| 94 | + | ||
| 95 | + ] | ||
| 96 | + * */ | ||
| 97 | + // 离线消息,华为直接推送 | ||
| 98 | + if (want && want.parameters && want.parameters[PushContentParser.LAUNCH_PARAM_GETUI_NOTIFYID]) { | ||
| 99 | + if (want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK]) { | ||
| 100 | + let pushLink = want.parameters[PushContentParser.PUSH_PARAM_PUSH_LINK] as string | ||
| 101 | + return { | ||
| 102 | + isPush: true, online: false, pushLink: pushLink, want: want | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + return { | ||
| 108 | + isPush: false, online: false | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + static jumpWithPushLink(pushLink: string) { | ||
| 113 | + AppInnerLink.jumpWithLink(pushLink) | ||
| 114 | + } | ||
| 115 | +} |
| @@ -7,7 +7,6 @@ import window from '@ohos.window'; | @@ -7,7 +7,6 @@ import window from '@ohos.window'; | ||
| 7 | import { BusinessError } from '@ohos.base'; | 7 | import { BusinessError } from '@ohos.base'; |
| 8 | import { DeviceUtil, EmitterEventId, EmitterUtils, WindowModel } from 'wdKit'; | 8 | import { DeviceUtil, EmitterEventId, EmitterUtils, WindowModel } from 'wdKit'; |
| 9 | import { ConfigurationConstant } from '@kit.AbilityKit'; | 9 | import { ConfigurationConstant } from '@kit.AbilityKit'; |
| 10 | -import { WDPushNotificationManager } from 'wdHwAbility/Index'; | ||
| 11 | import { StartupManager } from '../startupmanager/StartupManager'; | 10 | import { StartupManager } from '../startupmanager/StartupManager'; |
| 12 | 11 | ||
| 13 | let floatWindowClass: window.Window | null = null; | 12 | let floatWindowClass: window.Window | null = null; |
| @@ -28,7 +27,7 @@ export default class EntryAbility extends UIAbility { | @@ -28,7 +27,7 @@ export default class EntryAbility extends UIAbility { | ||
| 28 | 27 | ||
| 29 | // App活着情况下,点击推送通知进入 | 28 | // App活着情况下,点击推送通知进入 |
| 30 | onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { | 29 | onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void { |
| 31 | - WDPushNotificationManager.getInstance().onWant(want) | 30 | + StartupManager.sharedInstance().appOnNewWant(want, launchParam) |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | onDestroy(): void { | 33 | onDestroy(): void { |
| 1 | import { BottomNavigationComponent, LogoutViewModel, PermissionDesComponent } from 'wdComponent'; | 1 | import { BottomNavigationComponent, LogoutViewModel, PermissionDesComponent } from 'wdComponent'; |
| 2 | import { BreakpointConstants } from 'wdConstant'; | 2 | import { BreakpointConstants } from 'wdConstant'; |
| 3 | 3 | ||
| 4 | -import { HWLocationUtils, WDPushNotificationManager } from 'wdHwAbility/Index'; | ||
| 5 | import { common } from '@kit.AbilityKit'; | 4 | import { common } from '@kit.AbilityKit'; |
| 6 | import { BreakpointSystem, EmitterEventId, EmitterUtils, Logger, MpaasUpgradeCheck, WindowModel } from 'wdKit'; | 5 | import { BreakpointSystem, EmitterEventId, EmitterUtils, Logger, MpaasUpgradeCheck, WindowModel } from 'wdKit'; |
| 7 | import { promptAction, window } from '@kit.ArkUI'; | 6 | import { promptAction, window } from '@kit.ArkUI'; |
| @@ -33,16 +32,6 @@ struct MainPage { | @@ -33,16 +32,6 @@ struct MainPage { | ||
| 33 | 32 | ||
| 34 | this.breakpointSystem.register() | 33 | this.breakpointSystem.register() |
| 35 | 34 | ||
| 36 | - let context = getContext(this) as common.UIAbilityContext | ||
| 37 | - WDPushNotificationManager.getInstance().requestEnableNotifications(context).then((enabled) => { | ||
| 38 | - if (enabled) { | ||
| 39 | - WDPushNotificationManager.getInstance().fetchTokenAndBindProfileId() | ||
| 40 | - | ||
| 41 | - // WDPushNotificationManager.getInstance().sendLocalNotification() | ||
| 42 | - } | ||
| 43 | - HWLocationUtils.startLocationService() | ||
| 44 | - }) | ||
| 45 | - | ||
| 46 | Logger.info(TAG, `aboutToAppear `); | 35 | Logger.info(TAG, `aboutToAppear `); |
| 47 | EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => { | 36 | EmitterUtils.receiveEvent(EmitterEventId.FORCE_USER_LOGIN_OUT, () => { |
| 48 | LogoutViewModel.clearLoginInfo() | 37 | LogoutViewModel.clearLoginInfo() |
| 1 | import { AbilityConstant, common, Want } from '@kit.AbilityKit' | 1 | import { AbilityConstant, common, Want } from '@kit.AbilityKit' |
| 2 | -import { WDPushNotificationManager } from 'wdHwAbility/Index' | ||
| 3 | import { DeviceUtil, | 2 | import { DeviceUtil, |
| 4 | EmitterEventId, | 3 | EmitterEventId, |
| 5 | EmitterUtils, | 4 | EmitterUtils, |
| @@ -17,6 +16,7 @@ import { registerRouter } from 'wdRouter/Index' | @@ -17,6 +16,7 @@ import { registerRouter } from 'wdRouter/Index' | ||
| 17 | import { TrackingModule } from 'wdTracking/Index' | 16 | import { TrackingModule } from 'wdTracking/Index' |
| 18 | import { JSON } from '@kit.ArkTS' | 17 | import { JSON } from '@kit.ArkTS' |
| 19 | import app from '@system.app' | 18 | import app from '@system.app' |
| 19 | +import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index' | ||
| 20 | 20 | ||
| 21 | const TAG = "[StartupManager]" | 21 | const TAG = "[StartupManager]" |
| 22 | 22 | ||
| @@ -25,6 +25,8 @@ export class StartupManager { | @@ -25,6 +25,8 @@ export class StartupManager { | ||
| 25 | 25 | ||
| 26 | private context?: common.UIAbilityContext | 26 | private context?: common.UIAbilityContext |
| 27 | 27 | ||
| 28 | + private constructor() { | ||
| 29 | + } | ||
| 28 | private static _manger?: StartupManager | 30 | private static _manger?: StartupManager |
| 29 | static sharedInstance(): StartupManager { | 31 | static sharedInstance(): StartupManager { |
| 30 | if (!StartupManager._manger) { | 32 | if (!StartupManager._manger) { |
| @@ -60,10 +62,14 @@ export class StartupManager { | @@ -60,10 +62,14 @@ export class StartupManager { | ||
| 60 | this.preInitUmentStat() | 62 | this.preInitUmentStat() |
| 61 | 63 | ||
| 62 | // 通知栏点击后启动 | 64 | // 通知栏点击后启动 |
| 63 | - WDPushNotificationManager.getInstance().onWant(want) | 65 | + GetuiPush.sharedInstance().onWant(want) |
| 64 | Logger.debug(TAG, "App onCreate: finised") | 66 | Logger.debug(TAG, "App onCreate: finised") |
| 65 | } | 67 | } |
| 66 | 68 | ||
| 69 | + appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) { | ||
| 70 | + GetuiPush.sharedInstance().onNewWant(want) | ||
| 71 | + } | ||
| 72 | + | ||
| 67 | appOnDestory() { | 73 | appOnDestory() { |
| 68 | Logger.debug(TAG, "App onDestory") | 74 | Logger.debug(TAG, "App onDestory") |
| 69 | NetworkManager.getInstance().release() | 75 | NetworkManager.getInstance().release() |
| @@ -91,13 +97,19 @@ export class StartupManager { | @@ -91,13 +97,19 @@ export class StartupManager { | ||
| 91 | Logger.debug(TAG, "App 必要初始化完成") | 97 | Logger.debug(TAG, "App 必要初始化完成") |
| 92 | } | 98 | } |
| 93 | 99 | ||
| 94 | - // 到达主页后,初始化非必须部分 | 100 | + // 初次到达主页后,初始化非必须部分 |
| 95 | appReachMainPage() : Promise<void> { | 101 | appReachMainPage() : Promise<void> { |
| 96 | return new Promise((resolve) => { | 102 | return new Promise((resolve) => { |
| 97 | - Logger.debug(TAG, "App 进入首页,开始其他任务初始化") | 103 | + Logger.debug(TAG, "App 初次进入首页,开始其他任务初始化") |
| 98 | 104 | ||
| 99 | LoginModule.reportDeviceInfo() | 105 | LoginModule.reportDeviceInfo() |
| 100 | 106 | ||
| 107 | + GetuiPush.sharedInstance().requestEnableNotifications(this.context!).then((enabled) => { | ||
| 108 | + HWLocationUtils.startLocationService() | ||
| 109 | + }) | ||
| 110 | + | ||
| 111 | + GetuiPush.sharedInstance().onReachMainPage() | ||
| 112 | + | ||
| 101 | //TODO: | 113 | //TODO: |
| 102 | 114 | ||
| 103 | resolve() | 115 | resolve() |
| @@ -130,7 +142,8 @@ export class StartupManager { | @@ -130,7 +142,8 @@ export class StartupManager { | ||
| 130 | } | 142 | } |
| 131 | 143 | ||
| 132 | private initGeTuiPush() { | 144 | private initGeTuiPush() { |
| 133 | - // Logger.debug(TAG, "App 初始化") | 145 | + Logger.debug(TAG, "App 个推推送 初始化") |
| 146 | + GetuiPush.sharedInstance().init(this.context!) | ||
| 134 | } | 147 | } |
| 135 | 148 | ||
| 136 | private initLocation() { | 149 | private initLocation() { |
| @@ -170,4 +183,4 @@ export class StartupManager { | @@ -170,4 +183,4 @@ export class StartupManager { | ||
| 170 | private initOthers() { | 183 | private initOthers() { |
| 171 | 184 | ||
| 172 | } | 185 | } |
| 173 | -} | ||
| 186 | +} |
| @@ -14,7 +14,7 @@ | @@ -14,7 +14,7 @@ | ||
| 14 | "pages": "$profile:main_pages", | 14 | "pages": "$profile:main_pages", |
| 15 | "abilities": [ | 15 | "abilities": [ |
| 16 | { | 16 | { |
| 17 | - "name": "EntryAbility", | 17 | + "name": "EntryAbility", // 这里不能改动,和后台推送有绑定 |
| 18 | "srcEntry": "./ets/entryability/EntryAbility.ets", | 18 | "srcEntry": "./ets/entryability/EntryAbility.ets", |
| 19 | "description": "$string:EntryAbility_desc", | 19 | "description": "$string:EntryAbility_desc", |
| 20 | "icon": "$media:app_icon", | 20 | "icon": "$media:app_icon", |
| @@ -28,8 +28,15 @@ | @@ -28,8 +28,15 @@ | ||
| 28 | "entity.system.home" | 28 | "entity.system.home" |
| 29 | ], | 29 | ], |
| 30 | "actions": [ | 30 | "actions": [ |
| 31 | - "action.system.home" | ||
| 32 | - ] | 31 | + "action.system.home", |
| 32 | + "com.test.pushaction" | ||
| 33 | + ], | ||
| 34 | + "uris" : [{ | ||
| 35 | + "scheme": 'rmrbapp', | ||
| 36 | + "host": 'rmrb.app', | ||
| 37 | + 'port': '8080', | ||
| 38 | + "path": 'openwith' | ||
| 39 | + }] | ||
| 33 | } | 40 | } |
| 34 | ] | 41 | ] |
| 35 | } | 42 | } |
-
Please register or login to post a comment