mirror of
https://github.com/RxReader/tencent_kit.git
synced 2025-07-03 03:42:47 +08:00
add support for HarmonyOS
Signed-off-by: yeliulee <yeliuleet@gmail.com>
This commit is contained in:
@ -21,6 +21,9 @@ migration:
|
|||||||
- platform: ios
|
- platform: ios
|
||||||
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
|
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
|
||||||
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
|
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
|
||||||
|
- platform: ohos
|
||||||
|
create_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
|
||||||
|
base_revision: 9cd3d0d9ff05768afa249e036acc66e8abe93bff
|
||||||
|
|
||||||
# User provided section
|
# User provided section
|
||||||
|
|
||||||
|
45
README.md
45
README.md
@ -29,7 +29,7 @@ Flutter 版腾讯(QQ)SDK
|
|||||||
|
|
||||||
### Android
|
### Android
|
||||||
|
|
||||||
```
|
```txt
|
||||||
# 不需要做任何额外接入工作
|
# 不需要做任何额外接入工作
|
||||||
# 配置已集成到脚本里
|
# 配置已集成到脚本里
|
||||||
# 混淆已打入 Library,随 Library 引用,自动添加到 apk 打包混淆
|
# 混淆已打入 Library,随 Library 引用,自动添加到 apk 打包混淆
|
||||||
@ -39,7 +39,7 @@ Flutter 版腾讯(QQ)SDK
|
|||||||
|
|
||||||
> 暂不支持 SceneDelegate,详见文档 [iOS_SDK环境搭建](https://wiki.connect.qq.com/ios_sdk%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba)
|
> 暂不支持 SceneDelegate,详见文档 [iOS_SDK环境搭建](https://wiki.connect.qq.com/ios_sdk%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba)
|
||||||
|
|
||||||
```
|
```txt
|
||||||
# 不需要做任何额外接入工作
|
# 不需要做任何额外接入工作
|
||||||
# 配置已集成到脚本里
|
# 配置已集成到脚本里
|
||||||
```
|
```
|
||||||
@ -70,6 +70,44 @@ https://${your applinks domain}/universal_link/${example_app}/qq_conn/${appId}
|
|||||||
|
|
||||||
> ⚠️ 很多 SDK 都会用到 universal_link,可为不同 SDK 分配不同的 path 以作区分
|
> ⚠️ 很多 SDK 都会用到 universal_link,可为不同 SDK 分配不同的 path 以作区分
|
||||||
|
|
||||||
|
### HarmonyOS
|
||||||
|
|
||||||
|
> 当前在 `HarmonyOS` 平台, 仅支持 `setIsPermissionGranted/registerApp/isQQInstalled/loginServerSide`
|
||||||
|
>
|
||||||
|
> 由于 SDK 限制,当前仅支持 Server-Side 模式登录,auth code 在 accessToken 字段,获取后可自行在后端使用
|
||||||
|
|
||||||
|
项目中 module.json5 的 "module" 节点下配置 querySchemes
|
||||||
|
|
||||||
|
```json5
|
||||||
|
"querySchemes": [
|
||||||
|
"https",
|
||||||
|
"qqopenapi"
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
在 Ability 的 skills 节点中配置 scheme
|
||||||
|
|
||||||
|
```json5
|
||||||
|
"skills": [
|
||||||
|
{
|
||||||
|
"entities": [
|
||||||
|
"entity.system.browsable"
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
"ohos.want.action.viewData"
|
||||||
|
],
|
||||||
|
"uris": [
|
||||||
|
{
|
||||||
|
"scheme": "qqopenapi", // 接收 QQ 回调数据
|
||||||
|
"host": "102061317", // 业务申请的互联 appId
|
||||||
|
"path": "auth",
|
||||||
|
"linkFeature": "Login",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
### Flutter
|
### Flutter
|
||||||
|
|
||||||
|分享类型|说说(图/文/视频)|文本|图片|音乐|视频|网页|
|
|分享类型|说说(图/文/视频)|文本|图片|音乐|视频|网页|
|
||||||
@ -84,7 +122,8 @@ https://${your applinks domain}/universal_link/${example_app}/qq_conn/${appId}
|
|||||||
* 兼容
|
* 兼容
|
||||||
|
|
||||||
flutter 2.5 兼容问题 [issues/54](https://github.com/RxReader/tencent_kit/issues/54)
|
flutter 2.5 兼容问题 [issues/54](https://github.com/RxReader/tencent_kit/issues/54)
|
||||||
```
|
|
||||||
|
```ruby
|
||||||
post_install do |installer|
|
post_install do |installer|
|
||||||
installer.pods_project.targets.each do |target|
|
installer.pods_project.targets.each do |target|
|
||||||
flutter_additional_ios_build_settings(target)
|
flutter_additional_ios_build_settings(target)
|
||||||
|
19
example/ohos/.gitignore
vendored
Normal file
19
example/ohos/.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
/node_modules
|
||||||
|
/oh_modules
|
||||||
|
/local.properties
|
||||||
|
/.idea
|
||||||
|
**/build
|
||||||
|
/.hvigor
|
||||||
|
.cxx
|
||||||
|
/.clangd
|
||||||
|
/.clang-format
|
||||||
|
/.clang-tidy
|
||||||
|
**/.test
|
||||||
|
*.har
|
||||||
|
**/BuildProfile.ets
|
||||||
|
**/oh-package-lock.json5
|
||||||
|
|
||||||
|
**/src/main/resources/rawfile/flutter_assets/
|
||||||
|
**/libs/arm64-v8a/libapp.so
|
||||||
|
**/libs/arm64-v8a/libflutter.so
|
||||||
|
**/libs/arm64-v8a/libvmservice_snapshot.so
|
10
example/ohos/AppScope/app.json5
Normal file
10
example/ohos/AppScope/app.json5
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"bundleName": "io.github.v7lin.tencent_kit_example",
|
||||||
|
"vendor": "example",
|
||||||
|
"versionCode": 1000000,
|
||||||
|
"versionName": "1.0.0",
|
||||||
|
"icon": "$media:app_icon",
|
||||||
|
"label": "$string:app_name"
|
||||||
|
}
|
||||||
|
}
|
8
example/ohos/AppScope/resources/base/element/string.json
Normal file
8
example/ohos/AppScope/resources/base/element/string.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "app_name",
|
||||||
|
"value": "tencent_kit_example"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
example/ohos/AppScope/resources/base/media/app_icon.png
Normal file
BIN
example/ohos/AppScope/resources/base/media/app_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
52
example/ohos/build-profile.json5
Normal file
52
example/ohos/build-profile.json5
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
"app": {
|
||||||
|
"signingConfigs": [],
|
||||||
|
"products": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"signingConfig": "default",
|
||||||
|
"compatibleSdkVersion": "5.0.0(12)",
|
||||||
|
"runtimeOS": "HarmonyOS",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"name": "entry",
|
||||||
|
"srcPath": "./entry",
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"applyToProducts": [
|
||||||
|
"default"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "tencent_kit",
|
||||||
|
srcPath: "../../ohos",
|
||||||
|
targets: [
|
||||||
|
{
|
||||||
|
name: "default",
|
||||||
|
applyToProducts: ["default"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
7
example/ohos/entry/.gitignore
vendored
Normal file
7
example/ohos/entry/.gitignore
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
/node_modules
|
||||||
|
/oh_modules
|
||||||
|
/.preview
|
||||||
|
/build
|
||||||
|
/.cxx
|
||||||
|
/.test
|
29
example/ohos/entry/build-profile.json5
Normal file
29
example/ohos/entry/build-profile.json5
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
"apiType": 'stageMode',
|
||||||
|
"buildOption": {
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default",
|
||||||
|
"runtimeOS": "HarmonyOS"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ohosTest",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
17
example/ohos/entry/hvigorfile.ts
Normal file
17
example/ohos/entry/hvigorfile.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||||
|
export { hapTasks } from '@ohos/hvigor-ohos-plugin';
|
27
example/ohos/entry/oh-package.json5
Normal file
27
example/ohos/entry/oh-package.json5
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "entry",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Please describe the basic information.",
|
||||||
|
"main": "",
|
||||||
|
"author": "",
|
||||||
|
"license": "",
|
||||||
|
"dependencies": {
|
||||||
|
"tencent_kit": "../../../ohos"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FlutterAbility, FlutterEngine } from '@ohos/flutter_ohos';
|
||||||
|
import { GeneratedPluginRegistrant } from '../plugins/GeneratedPluginRegistrant';
|
||||||
|
|
||||||
|
export default class EntryAbility extends FlutterAbility {
|
||||||
|
configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||||
|
super.configureFlutterEngine(flutterEngine)
|
||||||
|
GeneratedPluginRegistrant.registerWith(flutterEngine)
|
||||||
|
}
|
||||||
|
}
|
38
example/ohos/entry/src/main/ets/pages/Index.ets
Normal file
38
example/ohos/entry/src/main/ets/pages/Index.ets
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import common from '@ohos.app.ability.common';
|
||||||
|
import { FlutterPage } from '@ohos/flutter_ohos'
|
||||||
|
|
||||||
|
let storage = LocalStorage.getShared()
|
||||||
|
const EVENT_BACK_PRESS = 'EVENT_BACK_PRESS'
|
||||||
|
|
||||||
|
@Entry(storage)
|
||||||
|
@Component
|
||||||
|
struct Index {
|
||||||
|
private context = getContext(this) as common.UIAbilityContext
|
||||||
|
@LocalStorageLink('viewId') viewId: string = "";
|
||||||
|
|
||||||
|
build() {
|
||||||
|
Column() {
|
||||||
|
FlutterPage({ viewId: this.viewId })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackPress(): boolean {
|
||||||
|
this.context.eventHub.emit(EVENT_BACK_PRESS)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
53
example/ohos/entry/src/main/module.json5
Normal file
53
example/ohos/entry/src/main/module.json5
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"name": "entry",
|
||||||
|
"type": "entry",
|
||||||
|
"description": "$string:module_desc",
|
||||||
|
"mainElement": "EntryAbility",
|
||||||
|
"deviceTypes": [
|
||||||
|
"phone"
|
||||||
|
],
|
||||||
|
"deliveryWithInstall": true,
|
||||||
|
"installationFree": false,
|
||||||
|
"pages": "$profile:main_pages",
|
||||||
|
"abilities": [
|
||||||
|
{
|
||||||
|
"name": "EntryAbility",
|
||||||
|
"srcEntry": "./ets/entryability/EntryAbility.ets",
|
||||||
|
"description": "$string:EntryAbility_desc",
|
||||||
|
"icon": "$media:icon",
|
||||||
|
"label": "$string:EntryAbility_label",
|
||||||
|
"startWindowIcon": "$media:icon",
|
||||||
|
"startWindowBackground": "$color:start_window_background",
|
||||||
|
"exported": true,
|
||||||
|
"skills": [
|
||||||
|
{
|
||||||
|
"entities": [
|
||||||
|
"entity.system.home"
|
||||||
|
],
|
||||||
|
"actions": [
|
||||||
|
"action.system.home"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"requestPermissions": [
|
||||||
|
{"name" : "ohos.permission.INTERNET"},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "start_window_background",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "module_desc",
|
||||||
|
"value": "module description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_label",
|
||||||
|
"value": "tencent_kit_example"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
example/ohos/entry/src/main/resources/base/media/icon.png
Normal file
BIN
example/ohos/entry/src/main/resources/base/media/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "enable_impeller",
|
||||||
|
"value": "true"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"src": [
|
||||||
|
"pages/Index"
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "module_desc",
|
||||||
|
"value": "module description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_label",
|
||||||
|
"value": "tencent_kit_example"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "module_desc",
|
||||||
|
"value": "模块描述"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_desc",
|
||||||
|
"value": "description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EntryAbility_label",
|
||||||
|
"value": "tencent_kit_example"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
50
example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets
Normal file
50
example/ohos/entry/src/ohosTest/ets/test/Ability.test.ets
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import hilog from '@ohos.hilog';
|
||||||
|
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'
|
||||||
|
|
||||||
|
export default function abilityTest() {
|
||||||
|
describe('ActsAbilityTest', function () {
|
||||||
|
// Defines a test suite. Two parameters are supported: test suite name and test suite function.
|
||||||
|
beforeAll(function () {
|
||||||
|
// Presets an action, which is performed only once before all test cases of the test suite start.
|
||||||
|
// This API supports only one parameter: preset action function.
|
||||||
|
})
|
||||||
|
beforeEach(function () {
|
||||||
|
// Presets an action, which is performed before each unit test case starts.
|
||||||
|
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||||
|
// This API supports only one parameter: preset action function.
|
||||||
|
})
|
||||||
|
afterEach(function () {
|
||||||
|
// Presets a clear action, which is performed after each unit test case ends.
|
||||||
|
// The number of execution times is the same as the number of test cases defined by **it**.
|
||||||
|
// This API supports only one parameter: clear action function.
|
||||||
|
})
|
||||||
|
afterAll(function () {
|
||||||
|
// Presets a clear action, which is performed after all test cases of the test suite end.
|
||||||
|
// This API supports only one parameter: clear action function.
|
||||||
|
})
|
||||||
|
it('assertContain',0, function () {
|
||||||
|
// Defines a test case. This API supports three parameters: test case name, filter parameter, and test case function.
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'it begin');
|
||||||
|
let a = 'abc'
|
||||||
|
let b = 'b'
|
||||||
|
// Defines a variety of assertion methods, which are used to declare expected boolean conditions.
|
||||||
|
expect(a).assertContain(b)
|
||||||
|
expect(a).assertEqual(a)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
20
example/ohos/entry/src/ohosTest/ets/test/List.test.ets
Normal file
20
example/ohos/entry/src/ohosTest/ets/test/List.test.ets
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import abilityTest from './Ability.test'
|
||||||
|
|
||||||
|
export default function testsuite() {
|
||||||
|
abilityTest()
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||||
|
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||||
|
import hilog from '@ohos.hilog';
|
||||||
|
import { Hypium } from '@ohos/hypium';
|
||||||
|
import testsuite from '../test/List.test';
|
||||||
|
import window from '@ohos.window';
|
||||||
|
|
||||||
|
export default class TestAbility extends UIAbility {
|
||||||
|
onCreate(want, launchParam) {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onCreate');
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'want param:' + JSON.stringify(want) ?? '');
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'launchParam:'+ JSON.stringify(launchParam) ?? '');
|
||||||
|
var abilityDelegator: any
|
||||||
|
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||||
|
var abilityDelegatorArguments: any
|
||||||
|
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'start run testcase!!!');
|
||||||
|
Hypium.hypiumTest(abilityDelegator, abilityDelegatorArguments, testsuite)
|
||||||
|
}
|
||||||
|
|
||||||
|
onDestroy() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onDestroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
onWindowStageCreate(windowStage: window.WindowStage) {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageCreate');
|
||||||
|
windowStage.loadContent('testability/pages/Index', (err, data) => {
|
||||||
|
if (err.code) {
|
||||||
|
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s',
|
||||||
|
JSON.stringify(data) ?? '');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onWindowStageDestroy() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onWindowStageDestroy');
|
||||||
|
}
|
||||||
|
|
||||||
|
onForeground() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onForeground');
|
||||||
|
}
|
||||||
|
|
||||||
|
onBackground() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility onBackground');
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import hilog from '@ohos.hilog';
|
||||||
|
|
||||||
|
@Entry
|
||||||
|
@Component
|
||||||
|
struct Index {
|
||||||
|
aboutToAppear() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'TestAbility index aboutToAppear');
|
||||||
|
}
|
||||||
|
@State message: string = 'Hello World'
|
||||||
|
build() {
|
||||||
|
Row() {
|
||||||
|
Column() {
|
||||||
|
Text(this.message)
|
||||||
|
.fontSize(50)
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
Button() {
|
||||||
|
Text('next page')
|
||||||
|
.fontSize(20)
|
||||||
|
.fontWeight(FontWeight.Bold)
|
||||||
|
}.type(ButtonType.Capsule)
|
||||||
|
.margin({
|
||||||
|
top: 20
|
||||||
|
})
|
||||||
|
.backgroundColor('#0D9FFB')
|
||||||
|
.width('35%')
|
||||||
|
.height('5%')
|
||||||
|
.onClick(()=>{
|
||||||
|
})
|
||||||
|
}
|
||||||
|
.width('100%')
|
||||||
|
}
|
||||||
|
.height('100%')
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import hilog from '@ohos.hilog';
|
||||||
|
import TestRunner from '@ohos.application.testRunner';
|
||||||
|
import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
|
||||||
|
|
||||||
|
var abilityDelegator = undefined
|
||||||
|
var abilityDelegatorArguments = undefined
|
||||||
|
|
||||||
|
async function onAbilityCreateCallback() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'onAbilityCreateCallback');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function addAbilityMonitorCallback(err: any) {
|
||||||
|
hilog.info(0x0000, 'testTag', 'addAbilityMonitorCallback : %{public}s', JSON.stringify(err) ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class OpenHarmonyTestRunner implements TestRunner {
|
||||||
|
constructor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
onPrepare() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner OnPrepare ');
|
||||||
|
}
|
||||||
|
|
||||||
|
async onRun() {
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun run');
|
||||||
|
abilityDelegatorArguments = AbilityDelegatorRegistry.getArguments()
|
||||||
|
abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator()
|
||||||
|
var testAbilityName = abilityDelegatorArguments.bundleName + '.TestAbility'
|
||||||
|
let lMonitor = {
|
||||||
|
abilityName: testAbilityName,
|
||||||
|
onAbilityCreate: onAbilityCreateCallback,
|
||||||
|
};
|
||||||
|
abilityDelegator.addAbilityMonitor(lMonitor, addAbilityMonitorCallback)
|
||||||
|
var cmd = 'aa start -d 0 -a TestAbility' + ' -b ' + abilityDelegatorArguments.bundleName
|
||||||
|
var debug = abilityDelegatorArguments.parameters['-D']
|
||||||
|
if (debug == 'true')
|
||||||
|
{
|
||||||
|
cmd += ' -D'
|
||||||
|
}
|
||||||
|
hilog.info(0x0000, 'testTag', 'cmd : %{public}s', cmd);
|
||||||
|
abilityDelegator.executeShellCommand(cmd,
|
||||||
|
(err: any, d: any) => {
|
||||||
|
hilog.info(0x0000, 'testTag', 'executeShellCommand : err : %{public}s', JSON.stringify(err) ?? '');
|
||||||
|
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.stdResult ?? '');
|
||||||
|
hilog.info(0x0000, 'testTag', 'executeShellCommand : data : %{public}s', d.exitCode ?? '');
|
||||||
|
})
|
||||||
|
hilog.info(0x0000, 'testTag', '%{public}s', 'OpenHarmonyTestRunner onRun end');
|
||||||
|
}
|
||||||
|
}
|
51
example/ohos/entry/src/ohosTest/module.json5
Normal file
51
example/ohos/entry/src/ohosTest/module.json5
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"name": "entry_test",
|
||||||
|
"type": "feature",
|
||||||
|
"description": "$string:module_test_desc",
|
||||||
|
"mainElement": "TestAbility",
|
||||||
|
"deviceTypes": [
|
||||||
|
"phone"
|
||||||
|
],
|
||||||
|
"deliveryWithInstall": true,
|
||||||
|
"installationFree": false,
|
||||||
|
"pages": "$profile:test_pages",
|
||||||
|
"abilities": [
|
||||||
|
{
|
||||||
|
"name": "TestAbility",
|
||||||
|
"srcEntry": "./ets/testability/TestAbility.ets",
|
||||||
|
"description": "$string:TestAbility_desc",
|
||||||
|
"icon": "$media:icon",
|
||||||
|
"label": "$string:TestAbility_label",
|
||||||
|
"exported": true,
|
||||||
|
"startWindowIcon": "$media:icon",
|
||||||
|
"startWindowBackground": "$color:start_window_background",
|
||||||
|
"skills": [
|
||||||
|
{
|
||||||
|
"actions": [
|
||||||
|
"action.system.home"
|
||||||
|
],
|
||||||
|
"entities": [
|
||||||
|
"entity.system.home"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"color": [
|
||||||
|
{
|
||||||
|
"name": "start_window_background",
|
||||||
|
"value": "#FFFFFF"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"string": [
|
||||||
|
{
|
||||||
|
"name": "module_test_desc",
|
||||||
|
"value": "test ability description"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "TestAbility_desc",
|
||||||
|
"value": "the test ability"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "TestAbility_label",
|
||||||
|
"value": "test label"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
BIN
example/ohos/entry/src/ohosTest/resources/base/media/icon.png
Normal file
BIN
example/ohos/entry/src/ohosTest/resources/base/media/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"src": [
|
||||||
|
"testability/pages/Index"
|
||||||
|
]
|
||||||
|
}
|
20
example/ohos/hvigor/hvigor-config.json5
Normal file
20
example/ohos/hvigor/hvigor-config.json5
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
"modelVersion": "5.0.0",
|
||||||
|
"dependencies": {
|
||||||
|
}
|
||||||
|
}
|
21
example/ohos/hvigorfile.ts
Normal file
21
example/ohos/hvigorfile.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { appTasks } from '@ohos/hvigor-ohos-plugin';
|
||||||
|
|
||||||
|
export default {
|
||||||
|
system: appTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
|
||||||
|
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
|
||||||
|
}
|
34
example/ohos/oh-package.json5
Normal file
34
example/ohos/oh-package.json5
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
"modelVersion": "5.0.0",
|
||||||
|
"name": "tencent_kit_example",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Please describe the basic information.",
|
||||||
|
"main": "",
|
||||||
|
"author": "",
|
||||||
|
"license": "",
|
||||||
|
"dependencies": {
|
||||||
|
"@ohos/flutter_ohos": "file:./har/flutter.har"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@ohos/hypium": "1.0.6"
|
||||||
|
},
|
||||||
|
"overrides": {
|
||||||
|
"@ohos/flutter_ohos": "file:./har/flutter.har",
|
||||||
|
"tencent_kit": "../../ohos",
|
||||||
|
}
|
||||||
|
}
|
12
ohos/.gitignore
vendored
Normal file
12
ohos/.gitignore
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
/node_modules
|
||||||
|
/oh_modules
|
||||||
|
/.preview
|
||||||
|
/.idea
|
||||||
|
/build
|
||||||
|
/.cxx
|
||||||
|
/.test
|
||||||
|
/BuildProfile.ets
|
||||||
|
/oh-package-lock.json5
|
||||||
|
/local.properties
|
||||||
|
*.har
|
||||||
|
!/src/libs/QQOpenSdk.har
|
10
ohos/build-profile.json5
Normal file
10
ohos/build-profile.json5
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"apiType": "stageMode",
|
||||||
|
"buildOption": {
|
||||||
|
},
|
||||||
|
"targets": [
|
||||||
|
{
|
||||||
|
"name": "default"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
2
ohos/hvigorfile.ts
Normal file
2
ohos/hvigorfile.ts
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
// Script for compiling build behavior. It is built in the build plug-in and cannot be modified currently.
|
||||||
|
export { harTasks } from '@ohos/hvigor-ohos-plugin';
|
17
ohos/index.ets
Normal file
17
ohos/index.ets
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023 Hunan OpenValley Digital Industry Development Co., Ltd.
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import TencentKitPlugin from './src/main/ets/components/plugin/TencentKitPlugin';
|
||||||
|
export default TencentKitPlugin;
|
12
ohos/oh-package.json5
Normal file
12
ohos/oh-package.json5
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"name": "tencent_kit",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Please describe the basic information.",
|
||||||
|
"main": "index.ets",
|
||||||
|
"author": "",
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"dependencies": {
|
||||||
|
"@ohos/flutter_ohos": "file:./har/flutter.har",
|
||||||
|
"@tencent/qq-open-sdk": "file:./src/libs/QQOpenSdk.har"
|
||||||
|
}
|
||||||
|
}
|
BIN
ohos/src/libs/QQOpenSdk.har
Normal file
BIN
ohos/src/libs/QQOpenSdk.har
Normal file
Binary file not shown.
159
ohos/src/main/ets/components/plugin/TencentKitPlugin.ets
Normal file
159
ohos/src/main/ets/components/plugin/TencentKitPlugin.ets
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
import {
|
||||||
|
AbilityAware,
|
||||||
|
AbilityPluginBinding,
|
||||||
|
Any,
|
||||||
|
FlutterManager,
|
||||||
|
FlutterPlugin,
|
||||||
|
FlutterPluginBinding,
|
||||||
|
MethodCall,
|
||||||
|
MethodCallHandler,
|
||||||
|
MethodChannel,
|
||||||
|
MethodResult,
|
||||||
|
NewWantListener,
|
||||||
|
} from '@ohos/flutter_ohos';
|
||||||
|
import { IQQOpenApi, QQOpenApiFactory, ApiCallback, AuthResponse } from '@tencent/qq-open-sdk'
|
||||||
|
import { AbilityConstant, Want } from '@kit.AbilityKit';
|
||||||
|
|
||||||
|
enum TencentRetCode {
|
||||||
|
RET_SUCCESS = 0,
|
||||||
|
RET_FAILED = 1,
|
||||||
|
RET_COMMON = -1,
|
||||||
|
RET_CANCEL = -2
|
||||||
|
}
|
||||||
|
|
||||||
|
const KEY_RET_CODE = "ret";
|
||||||
|
const KEY_RET_MSG = "msg";
|
||||||
|
|
||||||
|
/** TencentKitPlugin **/
|
||||||
|
export default class TencentKitPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware, NewWantListener {
|
||||||
|
private channel: MethodChannel | null = null;
|
||||||
|
private binding: AbilityPluginBinding | null = null;
|
||||||
|
private tencent: IQQOpenApi | null = null;
|
||||||
|
private modeServerSide: boolean = false;
|
||||||
|
|
||||||
|
getUniqueClassName(): string {
|
||||||
|
return "TencentKitPlugin"
|
||||||
|
}
|
||||||
|
|
||||||
|
onAttachedToEngine(binding: FlutterPluginBinding): void {
|
||||||
|
this.channel = new MethodChannel(binding.getBinaryMessenger(), "v7lin.github.io/tencent_kit");
|
||||||
|
this.channel.setMethodCallHandler(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
onDetachedFromEngine(binding: FlutterPluginBinding): void {
|
||||||
|
if (this.channel != null) {
|
||||||
|
this.channel.setMethodCallHandler(null)
|
||||||
|
}
|
||||||
|
this.channel = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
onAttachedToAbility(binding: AbilityPluginBinding): void {
|
||||||
|
this.binding = binding;
|
||||||
|
binding.addOnNewWantListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
onDetachedFromAbility(): void {
|
||||||
|
this.binding = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void {
|
||||||
|
this.tencent?.handleAuthResult(want)
|
||||||
|
}
|
||||||
|
|
||||||
|
authListener: ApiCallback<AuthResponse> = {
|
||||||
|
onComplete: (response: AuthResponse): void => {
|
||||||
|
const resp: Map<string, Any> = new Map();
|
||||||
|
try {
|
||||||
|
if (response.ret == TencentRetCode.RET_SUCCESS) {
|
||||||
|
// 服务端模式时, access_token 设置为为 authCode, 当前 SDK 不支持客户端模式(因此 null)
|
||||||
|
const accessToken: string | null = this.modeServerSide ? response.authCode : null;
|
||||||
|
resp.set(KEY_RET_CODE, TencentRetCode.RET_SUCCESS);
|
||||||
|
resp.set("openid", response.openId);
|
||||||
|
resp.set("access_token", accessToken);
|
||||||
|
resp.set("expires_in", response.expiresIn);
|
||||||
|
resp.set("create_at", response.authTime);
|
||||||
|
} else {
|
||||||
|
resp.set("ret", TencentRetCode.RET_COMMON);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
resp.set(KEY_RET_CODE, TencentRetCode.RET_COMMON);
|
||||||
|
resp.set(KEY_RET_MSG, `${e}`);
|
||||||
|
}
|
||||||
|
this.channel?.invokeMethod("onLoginResp", resp);
|
||||||
|
},
|
||||||
|
onError: (msg: string | null): void => {
|
||||||
|
const resp: Map<string, Any> = new Map();
|
||||||
|
resp.set(KEY_RET_CODE, TencentRetCode.RET_FAILED);
|
||||||
|
resp.set(KEY_RET_MSG, msg);
|
||||||
|
this.channel?.invokeMethod("onLoginResp", resp);
|
||||||
|
},
|
||||||
|
onCancel: (msg: string | null): void => {
|
||||||
|
const resp: Map<string, Any> = new Map();
|
||||||
|
resp.set(KEY_RET_CODE, TencentRetCode.RET_CANCEL);
|
||||||
|
resp.set(KEY_RET_MSG, msg);
|
||||||
|
this.channel?.invokeMethod("onLoginResp", resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMethodCall(call: MethodCall, result: MethodResult): void {
|
||||||
|
switch (call.method) {
|
||||||
|
case "setIsPermissionGranted":
|
||||||
|
// 当前 SDK 不支持此方法,暂时返回 null
|
||||||
|
result.success(null);
|
||||||
|
break;
|
||||||
|
case "registerApp":
|
||||||
|
this.registerApp(call, result);
|
||||||
|
break;
|
||||||
|
case "isQQInstalled":
|
||||||
|
result.success(this.tencent != null && this.tencent.isQQInstalled());
|
||||||
|
break;
|
||||||
|
case "isTIMInstalled":
|
||||||
|
// TIM 并未适配 harmonyOS, 暂时返回 false
|
||||||
|
result.success(false);
|
||||||
|
break;
|
||||||
|
case "login":
|
||||||
|
this.login(call, result);
|
||||||
|
break;
|
||||||
|
case "loginServerSide":
|
||||||
|
this.loginServerSide(call, result);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
result.notImplemented();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private getUIContext(): UIContext {
|
||||||
|
const uiAbility = this.binding!.getAbility();
|
||||||
|
const windowState = FlutterManager.getInstance().getWindowStage(uiAbility);
|
||||||
|
const window = windowState.getMainWindowSync();
|
||||||
|
return window.getUIContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
private registerApp(call: MethodCall, result: MethodResult) {
|
||||||
|
const appId: number = parseInt(call.argument("appId") as string);
|
||||||
|
this.tencent = QQOpenApiFactory.createApi(appId, {
|
||||||
|
autoHandleAuthResult: true,
|
||||||
|
forceEnableWeb: false,
|
||||||
|
});
|
||||||
|
result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private login(call: MethodCall, result: MethodResult) {
|
||||||
|
// this.modeServerSide = false; // 客户端授权
|
||||||
|
// 当前 SDK 仅支持 ServerSide 授权,暂时不处理
|
||||||
|
result.success(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private loginServerSide(call: MethodCall, result: MethodResult) {
|
||||||
|
this.modeServerSide = true; // 服务端授权
|
||||||
|
const scope: string = call.argument("scope");
|
||||||
|
const qrcode: boolean = call.argument("qrcode");
|
||||||
|
this.tencent?.login(this.getUIContext(), {
|
||||||
|
scope: scope,
|
||||||
|
useQrCode: qrcode,
|
||||||
|
forceWebLogin: qrcode || !this.tencent!.isQQInstalled(), // H5 授权, 二维码登录或 QQ 未安装时强制启用
|
||||||
|
networkTimeout: 0, // 不限制, 由 SDK 自行决定
|
||||||
|
}, this.authListener);
|
||||||
|
result.success(null);
|
||||||
|
}
|
||||||
|
}
|
10
ohos/src/main/module.json5
Normal file
10
ohos/src/main/module.json5
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"module": {
|
||||||
|
"name": "tencent_kit",
|
||||||
|
"type": "har",
|
||||||
|
"deviceTypes": [
|
||||||
|
"default",
|
||||||
|
"tablet"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -46,6 +46,8 @@ flutter:
|
|||||||
pluginClass: TencentKitPlugin
|
pluginClass: TencentKitPlugin
|
||||||
ios:
|
ios:
|
||||||
pluginClass: TencentKitPlugin
|
pluginClass: TencentKitPlugin
|
||||||
|
ohos:
|
||||||
|
pluginClass: TencentKitPlugin
|
||||||
|
|
||||||
# To add assets to your plugin package, add an assets section, like this:
|
# To add assets to your plugin package, add an assets section, like this:
|
||||||
# assets:
|
# assets:
|
||||||
|
Reference in New Issue
Block a user