diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7959c1c..9dec404 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: - uses: actions/setup-java@v2 with: distribution: 'zulu' - java-version: '11' + java-version: '17' - uses: subosito/flutter-action@v2 with: channel: 'stable' diff --git a/CHANGELOG.md b/CHANGELOG.md index a8e8aed..58329b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.2.0 + +* HarmonyOS: 升级 QQ SDK 到 v1.0.3, 优化文档 + ## 6.1.0 * 新增: 对 `HarmonyOS` 的支持, 受限于 SDK, 仅支持部分功能 diff --git a/README.md b/README.md index 97c78df..90de5b5 100644 --- a/README.md +++ b/README.md @@ -72,9 +72,11 @@ https://${your applinks domain}/universal_link/${example_app}/qq_conn/${appId} ### HarmonyOS -> 当前在 `HarmonyOS` 平台, 仅支持 `setIsPermissionGranted/registerApp/isQQInstalled/loginServerSide` -> -> 由于 SDK 限制,当前仅支持 Server-Side 模式登录,auth code 在 accessToken 字段,获取后可自行在后端使用 +* 当前在 `HarmonyOS` 平台, 仅支持 `setIsPermissionGranted/registerApp/isQQInstalled/loginServerSide` +* 由于 SDK 限制,当前仅支持 Server-Side 模式登录,请调用 `loginServerSide` 方法登录, 支持拉起 App 授权或 H5 授权 (qrcode 为 true 即可) +* 为了 API 统一, Server-Side 模式授权返回的 auth code 存储在 `TencentLoginResp.accessToken` (不要当成客户端的 token 使用) +* 详情阅读官方文档: [harmonyos_sdk 环境搭建](https://wiki.connect.qq.com/harmonyos_sdk%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba), 并阅读最后的说明 +* 关于在后端使用 code 换取 access_token 的问题, 请参考官方文档: [通过Authorization Code获取Access Token](https://wiki.connect.qq.com/%E4%BD%BF%E7%94%A8authorization_code%E8%8E%B7%E5%8F%96access_token#:~:text=Step2%EF%BC%9A%E9%80%9A%E8%BF%87Authorization%20Code%E8%8E%B7%E5%8F%96Access%20Token) , `redirect_uri` 一般为 `auth://tauth.qq.com/` 项目中 module.json5 的 "module" 节点下配置 querySchemes diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index b5ccd8d..5725a50 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -1,3 +1,9 @@ +plugins { + id "com.android.application" + id "kotlin-android" + id "dev.flutter.flutter-gradle-plugin" +} + def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { @@ -6,33 +12,14 @@ if (localPropertiesFile.exists()) { } } -def flutterRoot = localProperties.getProperty('flutter.sdk') -if (flutterRoot == null) { - throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") -} - -def flutterVersionCode = localProperties.getProperty('flutter.versionCode') -if (flutterVersionCode == null) { - flutterVersionCode = '1' -} - -def flutterVersionName = localProperties.getProperty('flutter.versionName') -if (flutterVersionName == null) { - flutterVersionName = '1.0' -} - -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" - android { namespace "io.github.v7lin.tencent_kit_example" compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 + sourceCompatibility JavaVersion.VERSION_17 + targetCompatibility JavaVersion.VERSION_17 } defaultConfig { @@ -42,8 +29,8 @@ android { // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion - versionCode flutterVersionCode.toInteger() - versionName flutterVersionName + versionCode flutter.versionCode + versionName flutter.versionName } buildTypes { diff --git a/example/android/build.gradle b/example/android/build.gradle index f7eb7f6..8f31e8c 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,16 +1,3 @@ -buildscript { - ext.kotlin_version = '1.7.10' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath 'com.android.tools.build:gradle:7.3.0' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - } -} - allprojects { repositories { google() @@ -28,4 +15,4 @@ subprojects { tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 3c472b9..5e6b542 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip diff --git a/example/android/settings.gradle b/example/android/settings.gradle index 44e62bc..9188549 100644 --- a/example/android/settings.gradle +++ b/example/android/settings.gradle @@ -1,11 +1,25 @@ -include ':app' +pluginManagement { + def flutterSdkPath = { + def properties = new Properties() + file("local.properties").withInputStream { properties.load(it) } + def flutterSdkPath = properties.getProperty("flutter.sdk") + assert flutterSdkPath != null, "flutter.sdk not set in local.properties" + return flutterSdkPath + }() -def localPropertiesFile = new File(rootProject.projectDir, "local.properties") -def properties = new Properties() + includeBuild("$flutterSdkPath/packages/flutter_tools/gradle") -assert localPropertiesFile.exists() -localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) } + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} -def flutterSdkPath = properties.getProperty("flutter.sdk") -assert flutterSdkPath != null, "flutter.sdk not set in local.properties" -apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle" +plugins { + id "dev.flutter.flutter-plugin-loader" version "1.0.0" // apply true + id "com.android.application" version "8.3.1" apply false + id "org.jetbrains.kotlin.android" version "1.8.10" apply false +} + +include ':app' \ No newline at end of file diff --git a/example/ohos/build-profile.json5 b/example/ohos/build-profile.json5 index b0c07ec..3581622 100644 --- a/example/ohos/build-profile.json5 +++ b/example/ohos/build-profile.json5 @@ -1,18 +1,3 @@ -/* -* 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": [], @@ -21,7 +6,7 @@ "name": "default", "signingConfig": "default", "compatibleSdkVersion": "5.0.0(12)", - "runtimeOS": "HarmonyOS", + "runtimeOS": "HarmonyOS" } ] }, @@ -39,14 +24,17 @@ ] }, { - name: "tencent_kit", - srcPath: "../../ohos", - targets: [ - { - name: "default", - applyToProducts: ["default"], - }, - ], - }, + "tencent_kit": { + "srcPath": "../../ohos", + "targets": [ + { + "name": "default", + "applyToProducts": [ + "default" + ] + } + ] + } + } ] } \ No newline at end of file diff --git a/example/ohos/entry/oh-package.json5 b/example/ohos/entry/oh-package.json5 index b14e3c9..a5a348e 100644 --- a/example/ohos/entry/oh-package.json5 +++ b/example/ohos/entry/oh-package.json5 @@ -1,18 +1,3 @@ -/* -* 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", @@ -21,7 +6,6 @@ "author": "", "license": "", "dependencies": { - "tencent_kit": "../../../ohos" - }, -} - + "tencent_kit": "../../../ohos", + } +} \ No newline at end of file diff --git a/ohos/src/libs/QQOpenSdk.har b/ohos/src/libs/QQOpenSdk.har index d3a083b..e56bbc8 100644 Binary files a/ohos/src/libs/QQOpenSdk.har and b/ohos/src/libs/QQOpenSdk.har differ diff --git a/ohos/src/main/ets/components/plugin/TencentKitPlugin.ets b/ohos/src/main/ets/components/plugin/TencentKitPlugin.ets index a5a316a..27e2522 100644 --- a/ohos/src/main/ets/components/plugin/TencentKitPlugin.ets +++ b/ohos/src/main/ets/components/plugin/TencentKitPlugin.ets @@ -2,7 +2,6 @@ import { AbilityAware, AbilityPluginBinding, Any, - FlutterManager, FlutterPlugin, FlutterPluginBinding, MethodCall, @@ -11,7 +10,12 @@ import { MethodResult, NewWantListener, } from '@ohos/flutter_ohos'; -import { IQQOpenApi, QQOpenApiFactory, ApiCallback, AuthResponse } from '@tencent/qq-open-sdk' +import { + IQQOpenApi, + QQOpenApiFactory, + ApiCallback, + AuthResponse, +} from '@tencent/qq-open-sdk' import { AbilityConstant, Want } from '@kit.AbilityKit'; enum TencentRetCode { @@ -57,7 +61,7 @@ export default class TencentKitPlugin implements FlutterPlugin, MethodCallHandle } onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void { - this.tencent?.handleAuthResult(want) + this.tencent?.handleResult(want) } authListener: ApiCallback = { @@ -122,13 +126,6 @@ export default class TencentKitPlugin implements FlutterPlugin, MethodCallHandle } } - 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, { @@ -148,7 +145,7 @@ export default class TencentKitPlugin implements FlutterPlugin, MethodCallHandle this.modeServerSide = true; // 服务端授权 const scope: string = call.argument("scope"); const qrcode: boolean = call.argument("qrcode"); - this.tencent?.login(this.getUIContext(), { + this.tencent?.login({ scope: scope, useQrCode: qrcode, forceWebLogin: qrcode || !this.tencent!.isQQInstalled(), // H5 授权, 二维码登录或 QQ 未安装时强制启用 diff --git a/pubspec.yaml b/pubspec.yaml index 67f76f9..e40f738 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: tencent_kit -description: A powerful Flutter plugin allowing developers to auth/share with natvie Android & iOS Tencent SDKs. -version: 6.1.0 +description: A powerful Flutter plugin allowing developers to auth/share with natvie Android & iOS & HarmonyOS Tencent SDKs. +version: 6.2.0 homepage: https://github.com/RxReader/tencent_kit repository: https://github.com/RxReader/tencent_kit.git issue_tracker: https://github.com/RxReader/tencent_kit/issues