add HarmonyOS debugging notice; implement openWeChatCustomerServiceChat and shareFile for ohos

Signed-off-by: yeliulee <yeliuleet@gmail.com>
This commit is contained in:
yeliulee
2025-11-07 17:22:01 +08:00
parent 2ee1ce4745
commit 06810af3c3
5 changed files with 85 additions and 10 deletions

View File

@@ -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.

View File

@@ -98,6 +98,8 @@ pod install
}
```
> HarmonyOS 调试须知:不要使用 IDE 的自动签名,务必手动申请调试证书进行签名并调试
## 注册 WxAPI
通过 `fluwx` 注册WxApi.

View File

@@ -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);
}
}

View File

@@ -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<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")
@@ -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
}

View File

@@ -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