Showing
5 changed files
with
285 additions
and
18 deletions
| @@ -19,3 +19,5 @@ export { AppInnerLink } from './src/main/ets/utils/AppInnerLink' | @@ -19,3 +19,5 @@ export { AppInnerLink } from './src/main/ets/utils/AppInnerLink' | ||
| 19 | export { ContentType } from './src/main/ets/common/ContentType' | 19 | export { ContentType } from './src/main/ets/common/ContentType' |
| 20 | 20 | ||
| 21 | export { AppInnerLinkGenerator } from "./src/main/ets/utils/AppInnerLinkGenerator" | 21 | export { AppInnerLinkGenerator } from "./src/main/ets/utils/AppInnerLinkGenerator" |
| 22 | + | ||
| 23 | +export { AppLinkingManager } from "./src/main/ets/utils/AppLinkingManager" |
| @@ -19,10 +19,10 @@ export class AppInnerLinkGenerator { | @@ -19,10 +19,10 @@ export class AppInnerLinkGenerator { | ||
| 19 | return AppInnerLinkGenerator.generate(Number(content.newsType), content.newsId +'', content.newsRelId + '', content.linkUrl) | 19 | return AppInnerLinkGenerator.generate(Number(content.newsType), content.newsId +'', content.newsRelId + '', content.linkUrl) |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | - private static generate(contentType: number, contentId?: string, relId?: string, link?: string): string { | 22 | + static generate(contentType: number, contentId?: string, relId?: string, link?: string): string { |
| 23 | let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX | 23 | let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX |
| 24 | 24 | ||
| 25 | - let pubParam = `&contentId=${contentId}&relId=${relId}&skipType=1` | 25 | + let pubParam = `&contentId=${contentId ?? ""}&relId=${relId ?? ""}&skipType=1` |
| 26 | 26 | ||
| 27 | let type: ContentType = Number(contentType) | 27 | let type: ContentType = Number(contentType) |
| 28 | switch (type) { | 28 | switch (type) { |
| @@ -64,5 +64,17 @@ export class AppInnerLinkGenerator { | @@ -64,5 +64,17 @@ export class AppInnerLinkGenerator { | ||
| 64 | return deeplink | 64 | return deeplink |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | + static generateCreatorPage(creatorId: string): string { | ||
| 68 | + let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX | ||
| 69 | + deeplink += `?type=owner_page&creatorId=${creatorId}&skipType=1` | ||
| 70 | + return deeplink | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + static generateH5Topic(pageId:string, url:string) { | ||
| 74 | + // rmrbapp://rmrb.app/openwith?type=topic&subType=h5&pageId=124&relId=23&url=https%3A%2F%2Fbaidu.com&skipType=1 | ||
| 75 | + let deeplink = AppInnerLinkGenerator.DEEP_LINK_PREFIX | ||
| 76 | + deeplink += `?type=topic&subType=h5&pageId=${pageId}&relId=&url=${encodeURIComponent(url)}&skipType=1` | ||
| 77 | + return deeplink | ||
| 78 | + } | ||
| 67 | 79 | ||
| 68 | } | 80 | } |
| 1 | +import { Logger } from 'wdKit' | ||
| 2 | +import { Want } from '@kit.AbilityKit' | ||
| 3 | +import { url } from '@kit.ArkTS' | ||
| 4 | +import { AppInnerLinkGenerator } from './AppInnerLinkGenerator' | ||
| 5 | +import { ContentType } from '../common/ContentType' | ||
| 6 | +import { AppInnerLink } from './AppInnerLink' | ||
| 7 | +import { HttpBizUtil, HttpUrlUtils, ResponseDTO } from 'wdNetwork' | ||
| 8 | +import { ContentDetailDTO } from 'wdBean' | ||
| 9 | + | ||
| 10 | +const TAG = "AppLinkingManager" | ||
| 11 | + | ||
| 12 | +// 系统AppLinking拉起管理类 | ||
| 13 | +export class AppLinkingManager { | ||
| 14 | + static readonly TEST_HOST = "pd-people-uat.pdnews.cn" | ||
| 15 | + static readonly PRODUCT_HOST = "www.peopleapp.com" | ||
| 16 | + | ||
| 17 | + private hasEnterMain = false | ||
| 18 | + private lastUrlObj?: url.URL | ||
| 19 | + | ||
| 20 | + private static manager: AppLinkingManager | ||
| 21 | + private constructor() { | ||
| 22 | + } | ||
| 23 | + public static sharedInstance() { | ||
| 24 | + if (!AppLinkingManager.manager) { | ||
| 25 | + AppLinkingManager.manager = new AppLinkingManager() | ||
| 26 | + } | ||
| 27 | + return AppLinkingManager.manager | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + onWant(want: Want) { | ||
| 31 | + this.onNewWant(want, true) | ||
| 32 | + } | ||
| 33 | + onNewWant(want: Want, startup: boolean = false) { | ||
| 34 | + Logger.debug(TAG, "want: " + JSON.stringify(want)) | ||
| 35 | + let uri = want?.uri | ||
| 36 | + if (!uri) { | ||
| 37 | + return | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + let urlObject = url.URL.parseURL(want?.uri); | ||
| 41 | + if (urlObject.protocol != "https:") { | ||
| 42 | + return | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + if (urlObject.host != AppLinkingManager.PRODUCT_HOST && urlObject.host != AppLinkingManager.TEST_HOST) { | ||
| 46 | + return | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + this.lastUrlObj = urlObject | ||
| 50 | + if (this.hasEnterMain) { | ||
| 51 | + this.comsumeLastUriContent() | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + // 首次进入主页,即可解析跳转推送 | ||
| 56 | + onReachMainPage() { | ||
| 57 | + this.hasEnterMain = true | ||
| 58 | + this.comsumeLastUriContent() | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + comsumeLastUriContent() { | ||
| 62 | + Logger.debug(TAG, "尝试消费拉起链接: " + this.lastUrlObj?.toString()) | ||
| 63 | + if (!this.lastUrlObj) { | ||
| 64 | + return | ||
| 65 | + } | ||
| 66 | + let path = this.lastUrlObj?.pathname ?? "" | ||
| 67 | + | ||
| 68 | + if (this.dealWithRMHArticle() | ||
| 69 | + || this.dealWithNormalArticle() | ||
| 70 | + || this.dealWithCreator() | ||
| 71 | + || this.dealWithTopic()) { | ||
| 72 | + this.lastUrlObj = undefined | ||
| 73 | + return | ||
| 74 | + } | ||
| 75 | + Logger.debug(TAG, "未处理path: " + path) | ||
| 76 | + this.lastUrlObj = undefined | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + dealWithRMHArticle() { | ||
| 80 | + let path = this.lastUrlObj?.pathname ?? "" | ||
| 81 | + if (path.startsWith("/rmharticle")) { | ||
| 82 | + let contentId = path.split("/").pop() | ||
| 83 | + let innerLink = AppInnerLinkGenerator.generate(ContentType.ImageText, contentId, undefined, undefined) | ||
| 84 | + this.jumpInnerLink(innerLink) | ||
| 85 | + return true | ||
| 86 | + } | ||
| 87 | + if (path.startsWith("/rmhphotos")) { | ||
| 88 | + let contentId = path.split("/").pop() | ||
| 89 | + let innerLink = AppInnerLinkGenerator.generate(ContentType.Pictures, contentId, undefined, undefined) | ||
| 90 | + this.jumpInnerLink(innerLink) | ||
| 91 | + return true | ||
| 92 | + } | ||
| 93 | + if (path.startsWith("/rmhmoments")) { | ||
| 94 | + let contentId = path.split("/").pop() | ||
| 95 | + let innerLink = AppInnerLinkGenerator.generate(ContentType.DynamicImageText, contentId, undefined, undefined) | ||
| 96 | + this.jumpInnerLink(innerLink) | ||
| 97 | + return true | ||
| 98 | + } | ||
| 99 | + if (path.startsWith("/rmhvideo")) { | ||
| 100 | + let contentId = path.split("/").pop() | ||
| 101 | + let innerLink = AppInnerLinkGenerator.generate(ContentType.Video, contentId, undefined, undefined) | ||
| 102 | + this.jumpInnerLink(innerLink) | ||
| 103 | + return true | ||
| 104 | + } | ||
| 105 | + if (path.startsWith("/column")) { | ||
| 106 | + let contentId = path.split("/").pop() | ||
| 107 | + if (!contentId || contentId.includes("-")) { | ||
| 108 | + return false | ||
| 109 | + } | ||
| 110 | + let innerLink = AppInnerLinkGenerator.generate(ContentType.Live, contentId, undefined, undefined) | ||
| 111 | + this.jumpInnerLink(innerLink) | ||
| 112 | + return true | ||
| 113 | + } | ||
| 114 | + return false | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + dealWithCreator() { | ||
| 118 | + let path = this.lastUrlObj?.pathname ?? "" | ||
| 119 | + if (path.startsWith("/author")) { | ||
| 120 | + let creatorId = path.split("/").pop() | ||
| 121 | + let innerLink = AppInnerLinkGenerator.generateCreatorPage(creatorId ?? "") | ||
| 122 | + this.jumpInnerLink(innerLink) | ||
| 123 | + return true | ||
| 124 | + } | ||
| 125 | + return false | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + dealWithTopic() { | ||
| 129 | + let path = this.lastUrlObj?.pathname ?? "" | ||
| 130 | + let idArray = path.split("/").pop()?.split("-") | ||
| 131 | + if (idArray?.length != 2) { | ||
| 132 | + return false | ||
| 133 | + } | ||
| 134 | + let pageId = idArray[0] | ||
| 135 | + let topicId = idArray[1] | ||
| 136 | + let url = `${this.lastUrlObj!.protocol}//${this.lastUrlObj!.host}/h${path}` | ||
| 137 | + if (path.startsWith("/votetopic")) { | ||
| 138 | + let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url) | ||
| 139 | + this.jumpInnerLink(innerLink) | ||
| 140 | + return true | ||
| 141 | + } | ||
| 142 | + if (path.startsWith("/articletopic")) { | ||
| 143 | + let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url) | ||
| 144 | + this.jumpInnerLink(innerLink) | ||
| 145 | + } | ||
| 146 | + if (path.startsWith("/livetopic")) { | ||
| 147 | + let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url) | ||
| 148 | + this.jumpInnerLink(innerLink) | ||
| 149 | + } | ||
| 150 | + if (path.startsWith("/timelinetopic")) { | ||
| 151 | + let innerLink = AppInnerLinkGenerator.generateH5Topic(pageId, url) | ||
| 152 | + this.jumpInnerLink(innerLink) | ||
| 153 | + } | ||
| 154 | + return false | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + dealWithNormalArticle() { | ||
| 158 | + let path = this.lastUrlObj?.pathname ?? "" | ||
| 159 | + if (!path.startsWith("/column")) { | ||
| 160 | + return false | ||
| 161 | + } | ||
| 162 | + let idArray = path.split("/").pop()?.split("-") | ||
| 163 | + if (idArray?.length != 2) { | ||
| 164 | + return false | ||
| 165 | + } | ||
| 166 | + let contentId = idArray[0] | ||
| 167 | + let relId = idArray[1] | ||
| 168 | + | ||
| 169 | + let url = HttpUrlUtils.getHost() + HttpUrlUtils.DETAIL_PATH | ||
| 170 | + url = url + "?&contentId=" + contentId + "&relId=" + relId // + "&relType=" + relType | ||
| 171 | + | ||
| 172 | + HttpBizUtil.get<ResponseDTO<ContentDetailDTO[]>>(url).then((data: ResponseDTO<ContentDetailDTO[]>) => { | ||
| 173 | + if (data.code != 0) { | ||
| 174 | + Logger.warn(TAG, "error " + JSON.stringify(data)) | ||
| 175 | + return | ||
| 176 | + } | ||
| 177 | + if (!data.data || data.data.length == 0) { | ||
| 178 | + Logger.warn(TAG, "empty data!!!") | ||
| 179 | + return | ||
| 180 | + } | ||
| 181 | + let innerLink = AppInnerLinkGenerator.generateDeepLinkWithConent(data.data[0]) | ||
| 182 | + this.jumpInnerLink(innerLink) | ||
| 183 | + }, (error: Error) => { | ||
| 184 | + Logger.warn(TAG, "error " + JSON.stringify(error)) | ||
| 185 | + }) | ||
| 186 | + return true | ||
| 187 | + } | ||
| 188 | + | ||
| 189 | + jumpInnerLink(innerLink: string) { | ||
| 190 | + Logger.debug(TAG, "即将跳转链接: " + innerLink) | ||
| 191 | + AppInnerLink.jumpWithLink(innerLink) | ||
| 192 | + } | ||
| 193 | +} |
| @@ -12,7 +12,7 @@ import { DeviceUtil, | @@ -12,7 +12,7 @@ import { DeviceUtil, | ||
| 12 | UmengStats } from 'wdKit/Index' | 12 | UmengStats } from 'wdKit/Index' |
| 13 | import { LoginModule } from 'wdLogin/Index' | 13 | import { LoginModule } from 'wdLogin/Index' |
| 14 | import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index' | 14 | import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index' |
| 15 | -import { AppInnerLink, registerRouter } from 'wdRouter/Index' | 15 | +import { AppInnerLink, AppLinkingManager, registerRouter } from 'wdRouter/Index' |
| 16 | import { TrackingModule } from 'wdTracking/Index' | 16 | import { TrackingModule } from 'wdTracking/Index' |
| 17 | import { JSON } from '@kit.ArkTS' | 17 | import { JSON } from '@kit.ArkTS' |
| 18 | import app from '@system.app' | 18 | import app from '@system.app' |
| @@ -78,6 +78,10 @@ export class StartupManager { | @@ -78,6 +78,10 @@ export class StartupManager { | ||
| 78 | 78 | ||
| 79 | // 通知栏点击后启动 | 79 | // 通知栏点击后启动 |
| 80 | GetuiPush.sharedInstance().onWant(want) | 80 | GetuiPush.sharedInstance().onWant(want) |
| 81 | + | ||
| 82 | + // AppLinking拉起 | ||
| 83 | + AppLinkingManager.sharedInstance().onWant(want) | ||
| 84 | + | ||
| 81 | Logger.debug(TAG, "App onCreate: finised") | 85 | Logger.debug(TAG, "App onCreate: finised") |
| 82 | 86 | ||
| 83 | this.lastStartupWant = want | 87 | this.lastStartupWant = want |
| @@ -86,6 +90,9 @@ export class StartupManager { | @@ -86,6 +90,9 @@ export class StartupManager { | ||
| 86 | appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) { | 90 | appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) { |
| 87 | GetuiPush.sharedInstance().onNewWant(want) | 91 | GetuiPush.sharedInstance().onNewWant(want) |
| 88 | 92 | ||
| 93 | + // AppLinking拉起 | ||
| 94 | + AppLinkingManager.sharedInstance().onNewWant(want) | ||
| 95 | + | ||
| 89 | this.dealWithDeepLink(want) | 96 | this.dealWithDeepLink(want) |
| 90 | } | 97 | } |
| 91 | 98 | ||
| @@ -134,6 +141,9 @@ export class StartupManager { | @@ -134,6 +141,9 @@ export class StartupManager { | ||
| 134 | 141 | ||
| 135 | GetuiPush.sharedInstance().onReachMainPage() | 142 | GetuiPush.sharedInstance().onReachMainPage() |
| 136 | 143 | ||
| 144 | + // AppLinking拉起 | ||
| 145 | + AppLinkingManager.sharedInstance().onReachMainPage() | ||
| 146 | + | ||
| 137 | //TODO: | 147 | //TODO: |
| 138 | // 提前初始化webview | 148 | // 提前初始化webview |
| 139 | webview.WebviewController.initializeWebEngine() | 149 | webview.WebviewController.initializeWebEngine() |
| @@ -39,17 +39,67 @@ | @@ -39,17 +39,67 @@ | ||
| 39 | "com.test.pushaction", | 39 | "com.test.pushaction", |
| 40 | "ohos.want.action.viewData" | 40 | "ohos.want.action.viewData" |
| 41 | ], | 41 | ], |
| 42 | -// "uris": [{ | ||
| 43 | -// // 之前的 推送配置 | 42 | + "uris": [ |
| 43 | +// { // 之前的 推送配置 | ||
| 44 | // "scheme": 'rmrbapp', | 44 | // "scheme": 'rmrbapp', |
| 45 | // "host": 'rmrb.app', | 45 | // "host": 'rmrb.app', |
| 46 | // 'port': '8080', | 46 | // 'port': '8080', |
| 47 | -// "path": 'openwith' | ||
| 48 | -// }] | 47 | +// "path": 'openwith'} |
| 48 | + { | ||
| 49 | + "scheme": "https", | ||
| 50 | + "host": "pd-people-uat.pdnews.cn", | ||
| 51 | + "pathStartWith": "rmharticle" | ||
| 52 | + }, | ||
| 53 | + { | ||
| 54 | + "scheme": "https", | ||
| 55 | + "host": "pd-people-uat.pdnews.cn", | ||
| 56 | + "pathStartWith": "rmhphotos" | ||
| 57 | + }, | ||
| 58 | + { | ||
| 59 | + "scheme": "https", | ||
| 60 | + "host": "pd-people-uat.pdnews.cn", | ||
| 61 | + "pathStartWith": "rmhmoments" | ||
| 62 | + }, | ||
| 63 | + { | ||
| 64 | + "scheme": "https", | ||
| 65 | + "host": "pd-people-uat.pdnews.cn", | ||
| 66 | + "pathStartWith": "rmhvideo" | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + "scheme": "https", | ||
| 70 | + "host": "pd-people-uat.pdnews.cn", | ||
| 71 | + "pathStartWith": "author" | ||
| 72 | + }, | ||
| 73 | + { | ||
| 74 | + "scheme": "https", | ||
| 75 | + "host": "pd-people-uat.pdnews.cn", | ||
| 76 | + "pathStartWith": "column" | ||
| 77 | + }, | ||
| 78 | + { | ||
| 79 | + "scheme": "https", | ||
| 80 | + "host": "pd-people-uat.pdnews.cn", | ||
| 81 | + "pathStartWith": "votetopic" | ||
| 82 | + }, | ||
| 83 | + { | ||
| 84 | + "scheme": "https", | ||
| 85 | + "host": "pd-people-uat.pdnews.cn", | ||
| 86 | + "pathStartWith": "articletopic" | ||
| 87 | + }, | ||
| 88 | + { | ||
| 89 | + "scheme": "https", | ||
| 90 | + "host": "pd-people-uat.pdnews.cn", | ||
| 91 | + "pathStartWith": "livetopic" | ||
| 92 | + }, | ||
| 93 | + { | ||
| 94 | + "scheme": "https", | ||
| 95 | + "host": "pd-people-uat.pdnews.cn", | ||
| 96 | + "pathStartWith": "timelinetopic" | ||
| 97 | + }, | ||
| 98 | + ] | ||
| 49 | }, | 99 | }, |
| 50 | { | 100 | { |
| 51 | "uris": [ | 101 | "uris": [ |
| 52 | - { // 配置 - (播控中心用) | 102 | + { // 推送配置 - (播控中心共用) |
| 53 | "scheme": 'rmrbapp', | 103 | "scheme": 'rmrbapp', |
| 54 | "host": 'rmrb.app', | 104 | "host": 'rmrb.app', |
| 55 | 'port': '8080', | 105 | 'port': '8080', |
| @@ -60,16 +110,16 @@ | @@ -60,16 +110,16 @@ | ||
| 60 | "host": "rmrb.app", | 110 | "host": "rmrb.app", |
| 61 | "path": "openwith" | 111 | "path": "openwith" |
| 62 | }, | 112 | }, |
| 63 | - { // 分享用 - 正式环境地址 | ||
| 64 | - "scheme": "https", | ||
| 65 | - "host": "www.peopleapp.com", | ||
| 66 | - "pathStartWith": "column" | ||
| 67 | - }, | ||
| 68 | - { // 分享用 - 测试环境地址 | ||
| 69 | - "scheme": "https", | ||
| 70 | - "host": "pd-people-uat.pdnews.cn", | ||
| 71 | - "pathStartWith": "column" | ||
| 72 | - } | 113 | +// { // 分享用 - 正式环境地址 |
| 114 | +// "scheme": "https", | ||
| 115 | +// "host": "www.peopleapp.com", | ||
| 116 | +// "pathStartWith": "column" | ||
| 117 | +// }, | ||
| 118 | +// { // 分享用 - 测试环境地址 | ||
| 119 | +// "scheme": "https", | ||
| 120 | +// "host": "pd-people-uat.pdnews.cn", | ||
| 121 | +//// "pathStartWith": "column" | ||
| 122 | +// } | ||
| 73 | ], | 123 | ], |
| 74 | "domainVerify": true | 124 | "domainVerify": true |
| 75 | } | 125 | } |
-
Please register or login to post a comment