diff --git a/CHANGELOG.md b/CHANGELOG.md index d3e41a1d..c0e0999f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 5.7.5 +* 更新:鸿蒙端支持分享文件 +* 更新:鸿蒙端支持打开客服会话 +* 修复: 鸿蒙端分享小程序类型错误的问题 +* 完善鸿蒙端调试文档 + # 5.7.4 * 鸿蒙SDK升级至1.0.15 * Fix #735 @@ -5,7 +11,7 @@ # 5.7.3 * Kotlin 升级至2.1.0 -* # 5.7.2 +# 5.7.2 * Fix #723 # 5.7.1 diff --git a/README.md b/README.md index a05508b5..eb318ae2 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/README_CN.md b/README_CN.md index 61a49e12..211a9a78 100644 --- a/README_CN.md +++ b/README_CN.md @@ -98,6 +98,8 @@ pod install } ``` +> HarmonyOS 调试须知:不要使用 IDE 的自动签名,务必手动申请调试证书进行签名并调试 + ## 注册 WxAPI 通过 `fluwx` 注册WxApi. diff --git a/ohos/src/main/ets/components/plugin/FluwxPlugin.ets b/ohos/src/main/ets/components/plugin/FluwxPlugin.ets index 6dafaa30..a7996ad7 100644 --- a/ohos/src/main/ets/components/plugin/FluwxPlugin.ets +++ b/ohos/src/main/ets/components/plugin/FluwxPlugin.ets @@ -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); @@ -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); + } } diff --git a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets index c7447a16..515b735f 100644 --- a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets +++ b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets @@ -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" @@ -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(); @@ -108,6 +107,54 @@ export class FluwxShareHandler { result.success(done) } + async shareFile(call: MethodCall, result: MethodResult) { + const source: Map = 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") @@ -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 } diff --git a/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets b/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets index 5cb8f5fd..ce351205 100644 --- a/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets +++ b/ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index a8c469ea..125453ca 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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: