Unverified 提交 7a55c5c9 authored 作者: JarvanMo's avatar JarvanMo 提交者: GitHub

Merge pull request #651 from yeliulee/ohos-flutter-3.22.0

add impl for fluwx on OpenHarmony
# Fluwx
![pub package](https://img.shields.io/pub/v/fluwx.svg)
[![pub package](https://img.shields.io/pub/v/fluwx.svg)](https://pub.dartlang.org/packages/fluwx)
![Build status](https://github.com/OpenFlutter/fluwx/actions/workflows/build_test.yml/badge.svg)
======
[![GitHub stars](https://img.shields.io/github/stars/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/network)
[![GitHub license](https://img.shields.io/github/license/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/issues)
<a target="_blank" href="https://qm.qq.com/q/TJ29rkzywM"><img border="0" src="https://pub.idqqimg.com/wpa/images/group.png" alt="OpenFlutter" title="OpenFlutter"></a>
---
![logo](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/fluwx_logo.png)
[中文请移步此处](./README_CN.md)
## What's Fluwx
`Fluwx` is flutter plugin for [WeChatSDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html) which allows developers to call
[WeChatSDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html) native APIs.
> Join QQ Group now: 1003811176
![QQGroup](https://gitee.com/OpenFlutter/resoures-repository/raw/master/common/flutter.png)
......@@ -45,13 +52,13 @@ Add the following dependencies in your `pubspec.yaml` file:
dependencies:
fluwx: ^${latestVersion}
```
![pub package](https://img.shields.io/pub/v/fluwx.svg)
`Fluwx` without pay:
> Developers who need to exclude payment for iOS can enable `no_pay` in [pubspec.yaml](./example/pubspec.yaml#L86).
> NOTE: Never forget to replace ^${latestVersion} with actual version.
## Configurations
......@@ -68,8 +75,9 @@ for more details.
- universal_link. Recommend for iOS. It'll be used to generate universal link on your projects.
- scene_delegate. Optional. Use `AppDelegate` or `SceneDelegate`. See [official documents](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) for more details.
* For iOS
- For iOS
If you are failing `cannot load such file -- plist` on iOS, please do the following steps:
```shell
# step.1 install missing dependencies
sudo gem install plist
......@@ -78,6 +86,19 @@ cd example/ios/
# step.3 execute
pod install
```
- On OpenHarmony, to check if WeChat is installed, add the following to the module.json5 in your project
```json5
{
"module": {
"querySchemes": [
"weixin"
],
}
}
```
## Register WxAPI
Register your app via `fluwx` if necessary.
......@@ -86,6 +107,7 @@ Register your app via `fluwx` if necessary.
Fluwx fluwx = Fluwx();
fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.univerallink.com/link/");
```
The param `universalLink` only works with iOS. You can read [this document](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html) to learn
how to create universalLink. You can also learn how to add URL schema, how to add `LSApplicationQueriesSchemes` in your iOS project. This is essential.
......@@ -109,13 +131,14 @@ For more capabilities, you can read the public functions of `fluwx`.
[These questions maybe help](./doc/QA_CN.md)
## Donate
Buy the writer a cup of coffee。
<img src="https://gitee.com/OpenFlutter/resoures-repository/raw/master/common/wx.jpeg" height="300"> <img src="https://gitee.com/OpenFlutter/resoures-repository/raw/master/common/ali.jpeg" height="300">
## Subscribe Us On WeChat
![subscribe](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/wx_subscription.png)
![subscribe](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/wx_subscription.png)
## Star history
......@@ -123,7 +146,6 @@ Buy the writer a cup of coffee。
## LICENSE
Copyright 2023 OpenFlutter Project
Licensed to the Apache Software Foundation (ASF) under one or more contributor
......@@ -140,8 +162,3 @@ Buy the writer a cup of coffee。
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
# Fluwx
![pub package](https://img.shields.io/pub/v/fluwx.svg)
[![pub package](https://img.shields.io/pub/v/fluwx.svg)](https://pub.dartlang.org/packages/fluwx)
![Build status](https://github.com/OpenFlutter/fluwx/actions/workflows/build_test.yml/badge.svg)
======
[![GitHub stars](https://img.shields.io/github/stars/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/network)
[![GitHub license](https://img.shields.io/github/license/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/blob/master/LICENSE)
[![GitHub issues](https://img.shields.io/github/issues/OpenFlutter/fluwx)](https://github.com/OpenFlutter/fluwx/issues)
<a target="_blank" href="https://qm.qq.com/q/TJ29rkzywM"><img border="0" src="https://pub.idqqimg.com/wpa/images/group.png" alt="OpenFlutter" title="OpenFlutter"></a>
---
![logo](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/fluwx_logo.png)
## 什么是Fluwx
`Fluwx` 是一个[微信SDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html)插件,它允许开发者调用
[微信原生SDK ](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html).
`Fluwx` 是一个[微信SDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html)插件,它允许开发者调用
[微信原生SDK](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html).
> 加入我们的QQ群: 1003811176
......@@ -30,11 +37,9 @@
> 破坏性更新 :从4.5.0起,当分享图片到微信时,如果不支持FileProvider方式分享,Fluwx不再尝试申请WRITE_EXTERNAL_STORAGE权限,这意味着你需要自己处理权限问题。
`Fluwx` 可以做很多工作但不是所有. 在集成之前,最好读一下[官方文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Resource_Center_Homepage.html).
然后你才知道怎么生成签名,怎么使用universal link以及怎么添加URL schema等.
## 安装
`pubspec.yaml` 文件中添加`fluwx`依赖:
......@@ -45,6 +50,7 @@
dependencies:
fluwx: ^${latestVersion}
```
![pub package](https://img.shields.io/pub/v/fluwx.svg)
不带支付的`Fluwx`:
......@@ -67,8 +73,9 @@ dependencies:
- universal_link. iOS 推荐. 它将用自动配置universal_link。
- scene_delegate. iOS 可选. 使用 `AppDelegate` 还是使用 `SceneDelegate`. 查阅[官方文档](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Access_Guide/iOS.html)了解更多.
* For iOS
- For iOS
如果你在iOS上遇到了 `cannot load such file -- plist`, 请按照以下步骤进行操作:
```shell
# step.1 安装必要依赖
sudo gem install plist
......@@ -78,6 +85,18 @@ cd example/ios/
pod install
```
- 在 OpenHarmony 上,要检查微信是否已安装,请在项目的 module.json5 中添加以下内容
```json5
{
"module": {
"querySchemes": [
"weixin"
],
}
}
```
## 注册 WxAPI
通过 `fluwx` 注册WxApi.
......@@ -109,11 +128,13 @@ fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.unive
[这些问题可能对你有帮助](./doc/QA_CN.md)
## 捐助
开源不易,请作者喝杯咖啡。
<img src="https://gitee.com/OpenFlutter/resoures-repository/raw/master/common/wx.jpeg" height="300"> <img src="https://gitee.com/OpenFlutter/resoures-repository/raw/master/common/ali.jpeg" height="300">
## 关注公众号
![subscribe](https://gitee.com/OpenFlutter/resoures-repository/raw/master/fluwx/wx_subscription.png)
## 关注趋势
......@@ -138,8 +159,3 @@ fluwx.registerApi(appId: "wxd930ea5d5a228f5f",universalLink: "https://your.unive
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations under
the License.
/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
{
"app": {
"bundleName": "com.jarvan.fluwx_example",
"vendor": "example",
"versionCode": 1000000,
"versionName": "1.0.0",
"icon": "$media:app_icon",
"label": "$string:app_name"
}
}
{
"string": [
{
"name": "app_name",
"value": "fluwx_example"
}
]
}
/*
* 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: "fluwx",
srcPath: "../../ohos",
targets: [
{
name: "default",
applyToProducts: ["default"],
},
],
},
],
}
/node_modules
/oh_modules
/.preview
/build
/.cxx
/.test
\ No newline at end of file
/*
* 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",
}
]
}
\ No newline at end of file
/*
* 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';
/*
* 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": {
"fluwx": "../../../ohos"
},
}
/*
* 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)
}
}
/*
* 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
}
}
\ No newline at end of file
/*
* 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"},
]
}
}
\ No newline at end of file
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "fluwx_example"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "module description"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "fluwx_example"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_desc",
"value": "模块描述"
},
{
"name": "EntryAbility_desc",
"value": "description"
},
{
"name": "EntryAbility_label",
"value": "fluwx_example"
}
]
}
\ No newline at end of file
/*
* 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)
})
})
}
\ No newline at end of file
/*
* 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()
}
\ No newline at end of file
/*
* 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');
}
}
\ No newline at end of file
/*
* 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%')
}
}
\ No newline at end of file
/*
* 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');
}
}
\ No newline at end of file
/*
* 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"
]
}
]
}
]
}
}
{
"color": [
{
"name": "start_window_background",
"value": "#FFFFFF"
}
]
}
\ No newline at end of file
{
"string": [
{
"name": "module_test_desc",
"value": "test ability description"
},
{
"name": "TestAbility_desc",
"value": "the test ability"
},
{
"name": "TestAbility_label",
"value": "test label"
}
]
}
\ No newline at end of file
/*
* 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": {
}
}
\ No newline at end of file
/*
* 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. */
}
\ No newline at end of file
/*
* 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": "fluwx_example",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "",
"author": "",
"license": "",
"dependencies": {
"@ohos/flutter_ohos": "file:./har/flutter.har",
"@tencent/wechat_open_sdk": "^1.0.0"
},
"devDependencies": {
"@ohos/hypium": "1.0.6"
},
"overrides": {
"@ohos/flutter_ohos": "file:./har/flutter.har",
"fluwx": "../../ohos",
}
}
/node_modules
/oh_modules
/.preview
/.idea
/build
/.cxx
/.test
/BuildProfile.ets
/oh-package-lock.json5
*.har
\ No newline at end of file
{
"apiType": "stageMode",
"buildOption": {
},
"targets": [
{
"name": "default"
}
]
}
// 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';
\ No newline at end of file
/*
* 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 FluwxPlugin from './src/main/ets/components/plugin/FluwxPlugin';
export default FluwxPlugin;
hwsdk.dir=/Applications/DevEco-Studio.app/Contents/sdk
\ No newline at end of file
{
"name": "fluwx",
"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/wechat_open_sdk": "^1.0.0"
}
}
import {
AbilityAware,
AbilityPluginBinding,
FlutterPlugin,
FlutterPluginBinding,
MethodCall,
MethodCallHandler,
MethodChannel,
MethodResult,
NewWantListener,
} from '@ohos/flutter_ohos';
import * as wechatSDK from "@tencent/wechat_open_sdk"
import { FluwxAuthHandler } from './handlers/FluwxAuthHandler';
import { AbilityConstant, common, Want } from '@kit.AbilityKit';
import { WXAPiHandler } from './handlers/WXAPiHandler';
import { FluwxShareHandler } from './handlers/FluwxShareHandler';
const MESSAGE_CHANNEL_NAME = "com.jarvanmo/fluwx"
const KEY_ERR_STR = "errStr"
const KEY_ERR_CODE = "errCode"
const KEY_OPEN_ID = "openId"
const KEY_TYPE = "type"
/** FluwxPlugin **/
export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware, NewWantListener, wechatSDK.WXApiEventHandler {
private channel: MethodChannel | null = null;
private appContext: common.Context | null = null;
private uiContext: common.UIAbilityContext | null = null;
private binding: AbilityPluginBinding | null = null
private authHandler: FluwxAuthHandler | null = null;
private shareHandler: FluwxShareHandler | null = null;
private extMsg: string | null = null;
getUniqueClassName(): string {
return "FluwxPlugin"
}
onAttachedToEngine(binding: FlutterPluginBinding): void {
this.channel = new MethodChannel(binding.getBinaryMessenger(), MESSAGE_CHANNEL_NAME);
this.channel.setMethodCallHandler(this)
this.appContext = binding.getApplicationContext();
this.authHandler = new FluwxAuthHandler(this.channel);
this.shareHandler = new FluwxShareHandler();
}
onDetachedFromEngine(binding: FlutterPluginBinding): void {
this.channel = null;
this.appContext = null;
this.authHandler = null;
this.shareHandler = null;
}
onAttachedToAbility(binding: AbilityPluginBinding): void {
this.binding = binding
this.uiContext = binding.getAbility().context;
WXAPiHandler.setContext(this.uiContext);
binding.addOnNewWantListener(this)
}
onDetachedFromAbility(): void {
this.binding?.removeOnNewWantListener(this)
this.binding = null
this.uiContext = null;
}
onMethodCall(call: MethodCall, result: MethodResult): void {
if (call.method.startsWith("share")) {
this.shareHandler?.share(call, result);
return;
}
switch (call.method) {
case "isWeChatInstalled":
WXAPiHandler.checkWeChatInstallation(result);
break;
case "registerApp":
WXAPiHandler.registerApp(call, result);
break;
case "sendAuth":
this.authHandler?.sendAuth(call, result);
break;
case "authByQRCode":
this.authHandler?.authByQRCode(call, result);
break;
case "stopAuthByQRCode":
this.authHandler?.stopAuthByQRCode(result);
break;
case "payWithFluwx":
this.handlePay(call, result);
break;
case "payWithHongKongWallet":
// TODO
result.notImplemented();
break;
case "launchMiniProgram":
// TODO
result.notImplemented();
break;
case "subscribeMsg":
// TODO
result.notImplemented();
break;
case "autoDeduct":
// TODO
result.notImplemented();
break;
case "autoDeductV2":
// TODO
result.notImplemented();
break;
case "openWXApp":
result.success(WXAPiHandler.wxApi?.openWechat(this.uiContext));
break;
case "getExtMsg":
result.success(this.extMsg);
this.extMsg = null;
break;
case "openWeChatCustomerServiceChat":
// TODO
result.notImplemented();
break;
case "checkSupportOpenBusinessView":
// TODO
result.notImplemented();
break;
case "openBusinessView":
// TODO
result.notImplemented();
break;
case "openWeChatInvoice":
// TODO
result.notImplemented();
break;
case "openUrl":
// TODO
result.notImplemented();
break;
case "openRankList":
// TODO
result.notImplemented();
break;
case "attemptToResumeMsgFromWx":
this.attemptToResumeMsgFromWx(result);
break;
case "selfCheck":
result.success(null)
break;
default:
result.notImplemented();
}
}
onNewWant(want: Want, launchParams: AbilityConstant.LaunchParam): void {
WXAPiHandler.wxApi?.handleWant(want, this);
}
// 微信回调 start
onReq = (req: wechatSDK.BaseReq): void => {
// TODO
}
onResp = (resp: wechatSDK.BaseResp): void => {
if (resp instanceof wechatSDK.SendAuthResp) {
this.onAuthResponse(resp);
return;
}
if (resp instanceof wechatSDK.SendMessageToWXResp) {
this.onSendMessageToWXResp(resp);
return;
}
if (resp instanceof wechatSDK.PayResp) {
this.onPayResp(resp);
return;
}
}
// 微信回调 end
onAuthResponse(resp: wechatSDK.SendAuthResp) {
const result: Map<string, ESObject> = new Map();
result.set(KEY_ERR_CODE, resp.errCode);
result.set(KEY_ERR_STR, resp.errStr);
result.set("code", resp.code);
result.set("state", resp.state);
result.set("lang", resp.lang);
result.set("country", resp.country);
result.set(KEY_OPEN_ID, resp.openId);
result.set("url", resp.url);
result.set(KEY_TYPE, resp.type);
this.channel?.invokeMethod("onAuthResponse", result);
}
onSendMessageToWXResp(resp: wechatSDK.SendMessageToWXResp) {
const _result: Map<string, ESObject> = new Map();
_result.set(KEY_ERR_CODE, resp.errCode);
_result.set(KEY_ERR_STR, resp.errStr);
_result.set(KEY_TYPE, resp.type);
_result.set(KEY_OPEN_ID, resp.openId);
this.channel?.invokeMethod("onShareResponse", _result);
}
onPayResp(resp: wechatSDK.PayResp) {
const _result: Map<string, ESObject> = new Map();
_result.set(KEY_ERR_CODE, resp.errCode);
_result.set(KEY_ERR_STR, resp.errStr);
_result.set(KEY_TYPE, resp.type);
_result.set("prepayId", resp.prepayId);
_result.set("returnKey", resp.returnKey);
_result.set("extData", resp.extData);
this.channel?.invokeMethod("onPayResponse", _result);
}
async handlePay(call: MethodCall, result: MethodResult) {
if (!WXAPiHandler.wxApi) {
result.error("Unassigned WxApi", "please config wxapi first", null);
return;
}
const request = new wechatSDK.PayReq();
request.appId = call.argument("appId");
request.partnerId = call.argument("partnerId");
request.prepayId = call.argument("prepayId");
request.packageValue = call.argument("packageValue");
request.nonceStr = call.argument("nonceStr");
request.timeStamp = call.argument("timeStamp").toString();
request.sign = call.argument("sign");
request.signType = call.argument("signType");
request.extData = call.argument("extData");
const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);
result.success(done);
}
attemptToResumeMsgFromWx(result: MethodResult) {
WXAPiHandler.wxApi?.handleWant(this.binding?.getAbility().launchWant, this)
}
}
\ No newline at end of file
import { MethodCall, MethodChannel, MethodResult } from "@ohos/flutter_ohos";
import { DiffDevOAuthFactory, IDiffDevOAuth, OAuthCallback, OAuthErrCode, SendAuthReq } from "@tencent/wechat_open_sdk";
import { WXAPiHandler } from "./WXAPiHandler";
import { util } from "@kit.ArkTS";
export class FluwxAuthHandler implements OAuthCallback {
private channel: MethodChannel;
private diffDevOauth: IDiffDevOAuth | null = null;
constructor(channel: MethodChannel) {
this.channel = channel;
}
onGotQRCode = (base64JpegImageBuffer: string) => {
const base64Codec = new util.Base64Helper()
const bytes = base64Codec.decodeSync(base64JpegImageBuffer)
this.channel.invokeMethod("onAuthGotQRCode", {
"errCode": 0,
"qrCode": bytes
})
}
onQRCodeScanned = () => {
this.channel.invokeMethod("onQRCodeScanned", {
"errCode": 0
})
}
onAuthFinish = (authCode: string) => {
this.channel.invokeMethod("onAuthByQRCodeFinished", {
"authCode": authCode,
"errCode": 0
})
}
onAuthError = (errCode: OAuthErrCode, errMsg: string) => {
this.channel.invokeMethod("onAuthByQRCodeFinished", {
"errCode": errCode,
"errStr": errMsg
})
}
getDiffDevOauth(): IDiffDevOAuth {
if (this.diffDevOauth) {
this.diffDevOauth.stopOAuth();
this.diffDevOauth = null;
}
this.diffDevOauth = DiffDevOAuthFactory.getDiffDevOAuth()!;
return this.diffDevOauth;
}
sendAuth(call: MethodCall, result: MethodResult) {
const req = new SendAuthReq();
req.isOption1 = false;
req.scope = call.argument("scope");
req.state = call.argument("state");
const openid: string | null = call.argument("openid");
if (openid) {
req.openId = openid;
}
req.nonAutomatic = call.argument("nonAutomatic") ?? false;
result.success(WXAPiHandler.wxApi?.sendReq(
WXAPiHandler.uiContext,
req
))
}
authByQRCode(call: MethodCall, result: MethodResult) {
const appId: string = call.argument("appId") ?? "";
const scope: string = call.argument("scope") ?? "";
const nonceStr: string = call.argument("nonceStr") ?? "";
const timeStamp: string = call.argument("timeStamp") ?? "";
const signature: string = call.argument("signature") ?? "";
const qrCodeAuth = this.getDiffDevOauth();
result.success(qrCodeAuth.startOAuth(
appId,
scope,
nonceStr,
timeStamp,
signature,
this
))
}
stopAuthByQRCode(result: MethodResult) {
result.success(this.diffDevOauth?.stopOAuth())
}
}
\ No newline at end of file
import { Any, MethodCall, MethodResult } from "@ohos/flutter_ohos"
import * as wechatSDK from "@tencent/wechat_open_sdk"
import { WXAPiHandler } from "./WXAPiHandler"
import { buffer } from "@kit.ArkTS"
import { fileUri } from "@kit.CoreFileKit"
export class FluwxShareHandler {
share(call: MethodCall, result: MethodResult) {
if (!WXAPiHandler.wxApi) {
result.error("Unassigned WxApi", "please config wxapi first", null);
return;
}
switch (call.method) {
case "shareText":
this.shareText(call, result);
break;
case "shareMiniProgram":
// TODO
result.notImplemented();
break;
case "shareImage":
this.shareImage(call, result);
break;
case "shareMusic":
// TODO
result.notImplemented();
break;
case "shareVideo":
// TODO
result.notImplemented();
break;
case "shareWebPage":
// TODO
result.notImplemented();
break;
case "shareFile":
// TODO
result.notImplemented();
break;
default:
result.notImplemented();
break;
}
}
async shareText(call: MethodCall, result: MethodResult) {
const textObj = new wechatSDK.WXTextObject();
textObj.text = call.argument("source");
const mediaMsg = new wechatSDK.WXMediaMessage();
mediaMsg.mediaObject = textObj;
const req = new wechatSDK.SendMessageToWXReq();
req.message = mediaMsg;
result.success(WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req))
}
async shareImage(call: MethodCall, result: MethodResult) {
const map: Map<string, Any> = call.argument("source") ?? new Map();
// const imageHash: string | null = call.argument("imgDataHash");
const bytes: Uint8Array | null = map.get("uint8List");
const imageObj = new wechatSDK.WXImageObject();
if (bytes) {
const buff: buffer.Buffer = buffer.from(bytes.buffer);
imageObj.imageData = buff.toString("base64", 0, buff.length);
} else {
const localImagePath: string | null = map.get("localImagePath");
if (localImagePath) {
imageObj.uri = localImagePath.startsWith("file://") ? localImagePath : fileUri.getUriFromPath(localImagePath)
}
}
const mediaMsg = new wechatSDK.WXMediaMessage();
mediaMsg.mediaObject = imageObj;
const req = new wechatSDK.SendMessageToWXReq();
req.message = mediaMsg;
result.success(WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req));
}
}
\ No newline at end of file
import * as wechatOpenSDK from "@tencent/wechat_open_sdk"
import { MethodCall, MethodResult } from '@ohos/flutter_ohos'
import { bundle, bundleManager, common } from '@kit.AbilityKit'
export class WXAPiHandler {
static wxApi: wechatOpenSDK.WXApi | null = null
private static registered: boolean = false
private static context: common.UIAbilityContext | null = null
static get wxApiRegistered() {
return WXAPiHandler.registered
}
static get uiContext() {
return WXAPiHandler.context
}
static coolBoot: boolean = false
static setContext(context: common.UIAbilityContext) {
WXAPiHandler.context = context
}
static registerApp(call: MethodCall, result: MethodResult) {
if (WXAPiHandler.wxApi != null) {
result.success(true)
return
}
const appId: string | null = call.argument("appId")
if (!appId) {
result.error("invalid app id", "are you sure your app id is correct ?", appId)
return
}
WXAPiHandler.registerWxAPIInternal(appId)
result.success(WXAPiHandler.registered)
}
static checkWeChatInstallation(result: MethodResult) {
const isInstalled = bundleManager.canOpenLink("weixin://")
result.success(isInstalled)
}
private static registerWxAPIInternal(appId: string) {
let api = wechatOpenSDK.WXAPIFactory.createWXAPI(appId)
WXAPiHandler.registered = true
WXAPiHandler.wxApi = api
}
}
\ No newline at end of file
{
"module": {
"name": "fluwx",
"type": "har",
"deviceTypes": [
"default",
"tablet"
]
}
}
......@@ -44,6 +44,8 @@ flutter:
web:
pluginClass: FluwxWeb
fileName: src/fluwx_web.dart
ohos:
pluginClass: FluwxPlugin
# To add assets to your plugin package, add an assets section, like this:
# assets:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论