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
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# 5.7.5
* 更新:鸿蒙端支持分享文件
* 更新:鸿蒙端支持打开客服会话
* 修复: 鸿蒙端分享小程序类型错误的问题
* 完善鸿蒙端调试文档

# 5.7.4
* 鸿蒙SDK升级至1.0.15
* Fix #735

# 5.7.3
* Kotlin 升级至2.1.0

* # 5.7.2
# 5.7.2
* Fix #723

# 5.7.1
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ pod install
}
```

> HarmonyOS Debugging Notice: Do not use the IDE's automatic signing. You must manually apply for a debug certificate for signing and debugging.

## Register WxAPI

Register your app via `fluwx` if necessary.
Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ pod install
}
```

> HarmonyOS 调试须知:不要使用 IDE 的自动签名,务必手动申请调试证书进行签名并调试

## 注册 WxAPI

通过 `fluwx` 注册WxApi.
Expand Down
16 changes: 12 additions & 4 deletions ohos/src/main/ets/components/plugin/FluwxPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,10 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab
this.extMsg = null;
break;
case "openWeChatCustomerServiceChat":
// TODO
result.notImplemented();
this.openWeChatCustomerServiceChat(call, result);
break;
case "checkSupportOpenBusinessView":
// TODO
result.notImplemented();
WXAPiHandler.checkSupportOpenBusinessView(result);
break;
case "openBusinessView":
this.openBusinessView(call, result);
Expand Down Expand Up @@ -288,4 +286,14 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab

result.success(done);
}

async openWeChatCustomerServiceChat(call: MethodCall, result: MethodResult) {
const request = new wechatSDK.OpenCustomerServiceChatReq();
request.corpId = call.argument("corpId") ?? "";
request.url = call.argument("url") ?? "";

const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);

result.success(done);
}
}
55 changes: 51 additions & 4 deletions ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Any, MethodCall, MethodResult } from "@ohos/flutter_ohos"
import { buffer } from "@kit.ArkTS"
import { fileUri } from "@kit.CoreFileKit"
import { fileUri, fileIo as fs } from "@kit.CoreFileKit"
import * as wxopensdk from '@tencent/wechat_open_sdk';
import { WXAPiHandler } from "./WXAPiHandler"

Expand Down Expand Up @@ -32,8 +32,7 @@ export class FluwxShareHandler {
this.shareWebPage(call, result);
break;
case "shareFile":
// TODO
result.notImplemented();
this.shareFile(call, result);
break;
default:
result.notImplemented();
Expand Down Expand Up @@ -108,6 +107,54 @@ export class FluwxShareHandler {
result.success(done)
}

async shareFile(call: MethodCall, result: MethodResult) {
const source: Map<string, Any> = call.argument("source") ?? new Map();
const schemaIndex: number = source.get("schema")
let filePath: string = ""

// check schema is file or binary
if (schemaIndex < 2) {
result.error("ARG", "currently only file or binary schema is supported on ohos", null);
return;
}

// case schema is file
if(schemaIndex == 2) {
filePath = source.get("source")
if (filePath.startsWith("file://")) {
filePath = filePath;
} else {
filePath = fileUri.getUriFromPath(filePath);
}
} else {
// case schema is binary, write to temp file first
const bytes: Uint8Array = source.get("source");
const suffix: string = source.get("suffix") ?? ".tmp";
const fileName = `share_temp_${new Date().getTime()}${suffix}`;
const tempFilePath = `${WXAPiHandler.uiContext?.tempDir}/${fileName}`;
const tempFile = fs.openSync(tempFilePath, fs.OpenMode.READ_WRITE || fs.OpenMode.CREATE);
await fs.write(tempFile.fd, bytes.buffer);
await fs.close(tempFile.fd);
filePath = fileUri.getUriFromPath(tempFilePath);
}

const fileObject = new wxopensdk.WXFileObject()
fileObject.fileUri = filePath

const mediaMessage = new wxopensdk.WXMediaMessage()
mediaMessage.mediaObject = fileObject
mediaMessage.title = call.argument("title") || ""
mediaMessage.description = call.argument("description") || ""

const req = new wxopensdk.SendMessageToWXReq()
this.setCommonArgs(call, req, mediaMessage)
req.message = mediaMessage

const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req);

result.success(done)
}

async shareMiniProgram(call: MethodCall, result: MethodResult) {
const miniProgramObject = new wxopensdk.WXMiniProgramObject()
miniProgramObject.userName = call.argument("userName")
Expand All @@ -118,7 +165,7 @@ export class FluwxShareHandler {
let miniProgramTypeInt: number = call.argument("miniProgramType")
if (miniProgramTypeInt === 1) {
miniProgramType = wxopensdk.WXMiniProgramType.TEST
} else if (miniProgramType === 2) {
} else if (miniProgramTypeInt === 2) {
miniProgramType = wxopensdk.WXMiniProgramType.PREVIEW
}

Expand Down
20 changes: 18 additions & 2 deletions ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,26 @@ export class WXAPiHandler {
}

static checkWeChatInstallation(result: MethodResult) {
const isInstalled = bundleManager.canOpenLink("weixin://")
result.success(isInstalled)
const isInstalled = bundleManager.canOpenLink("weixin://") || WXAPiHandler.wxApi?.isWXAppInstalled() === true;
result.success(isInstalled);
}

static checkSupportOpenBusinessView(result: MethodResult) {
if (!WXAPiHandler.wxApi) {
result.error("Unassigned WxApi", "please config wxapi first", null);
return;
}

const isInstalled = bundleManager.canOpenLink("weixin://") || WXAPiHandler.wxApi?.isWXAppInstalled() === true;
if (!isInstalled) {
result.error("WeChat Not Installed", "Please install the WeChat first", null);
return;
}

result.success(true);
}


private static registerWxAPIInternal(appId: string) {
let api = wechatOpenSDK.WXAPIFactory.createWXAPI(appId)
WXAPiHandler.registered = true
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: fluwx
description: The capability of implementing WeChat SDKs in Flutter. With Fluwx, developers can use WeChatSDK easily, such as sharing, payment, lanuch mini program and etc.
version: 5.7.4
version: 5.7.5
homepage: https://github.com/OpenFlutter/fluwx

environment:
Expand Down