Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.2.0

* HarmonyOS: 升级 QQ SDK 到 v1.0.3, 优化文档

## 6.1.0

* 新增: 对 `HarmonyOS` 的支持, 受限于 SDK, 仅支持部分功能
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 10 additions & 23 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -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()) {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
15 changes: 1 addition & 14 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -28,4 +15,4 @@ subprojects {

tasks.register("clean", Delete) {
delete rootProject.buildDir
}
}
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 22 additions & 8 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
38 changes: 13 additions & 25 deletions example/ohos/build-profile.json5
Original file line number Diff line number Diff line change
@@ -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": [],
Expand All @@ -21,7 +6,7 @@
"name": "default",
"signingConfig": "default",
"compatibleSdkVersion": "5.0.0(12)",
"runtimeOS": "HarmonyOS",
"runtimeOS": "HarmonyOS"
}
]
},
Expand All @@ -39,14 +24,17 @@
]
},
{
name: "tencent_kit",
srcPath: "../../ohos",
targets: [
{
name: "default",
applyToProducts: ["default"],
},
],
},
"tencent_kit": {
"srcPath": "../../ohos",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
}
]
}
22 changes: 3 additions & 19 deletions example/ohos/entry/oh-package.json5
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -21,7 +6,6 @@
"author": "",
"license": "",
"dependencies": {
"tencent_kit": "../../../ohos"
},
}

"tencent_kit": "../../../ohos",
}
}
Binary file modified ohos/src/libs/QQOpenSdk.har
Binary file not shown.
19 changes: 8 additions & 11 deletions ohos/src/main/ets/components/plugin/TencentKitPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
AbilityAware,
AbilityPluginBinding,
Any,
FlutterManager,
FlutterPlugin,
FlutterPluginBinding,
MethodCall,
Expand All @@ -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 {
Expand Down Expand Up @@ -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<AuthResponse> = {
Expand Down Expand Up @@ -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, {
Expand All @@ -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 未安装时强制启用
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down