Skip to content

Commit cbe4668

Browse files
authored
implement file sharing and open customer service; enhance debugging doc for HarmonyOS (#736)
2 parents 2ee1ce4 + 031542a commit cbe4668

File tree

7 files changed

+93
-12
lines changed

7 files changed

+93
-12
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
# 5.7.5
2+
* 更新:鸿蒙端支持分享文件
3+
* 更新:鸿蒙端支持打开客服会话
4+
* 修复: 鸿蒙端分享小程序类型错误的问题
5+
* 完善鸿蒙端调试文档
6+
17
# 5.7.4
28
* 鸿蒙SDK升级至1.0.15
39
* Fix #735
410

511
# 5.7.3
612
* Kotlin 升级至2.1.0
713

8-
* # 5.7.2
14+
# 5.7.2
915
* Fix #723
1016

1117
# 5.7.1

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ pod install
103103
}
104104
```
105105

106+
> HarmonyOS Debugging Notice: Do not use the IDE's automatic signing. You must manually apply for a debug certificate for signing and debugging.
107+
106108
## Register WxAPI
107109

108110
Register your app via `fluwx` if necessary.

README_CN.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ pod install
9898
}
9999
```
100100

101+
> HarmonyOS 调试须知:不要使用 IDE 的自动签名,务必手动申请调试证书进行签名并调试
102+
101103
## 注册 WxAPI
102104

103105
通过 `fluwx` 注册WxApi.

ohos/src/main/ets/components/plugin/FluwxPlugin.ets

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,10 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab
115115
this.extMsg = null;
116116
break;
117117
case "openWeChatCustomerServiceChat":
118-
// TODO
119-
result.notImplemented();
118+
this.openWeChatCustomerServiceChat(call, result);
120119
break;
121120
case "checkSupportOpenBusinessView":
122-
// TODO
123-
result.notImplemented();
121+
WXAPiHandler.checkSupportOpenBusinessView(result);
124122
break;
125123
case "openBusinessView":
126124
this.openBusinessView(call, result);
@@ -288,4 +286,14 @@ export default class FluwxPlugin implements FlutterPlugin, MethodCallHandler, Ab
288286

289287
result.success(done);
290288
}
289+
290+
async openWeChatCustomerServiceChat(call: MethodCall, result: MethodResult) {
291+
const request = new wechatSDK.OpenCustomerServiceChatReq();
292+
request.corpId = call.argument("corpId") ?? "";
293+
request.url = call.argument("url") ?? "";
294+
295+
const done = await WXAPiHandler.wxApi?.sendReq(this.uiContext, request);
296+
297+
result.success(done);
298+
}
291299
}

ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Any, MethodCall, MethodResult } from "@ohos/flutter_ohos"
22
import { buffer } from "@kit.ArkTS"
3-
import { fileUri } from "@kit.CoreFileKit"
3+
import { fileUri, fileIo as fs } from "@kit.CoreFileKit"
44
import * as wxopensdk from '@tencent/wechat_open_sdk';
55
import { WXAPiHandler } from "./WXAPiHandler"
66

@@ -32,8 +32,7 @@ export class FluwxShareHandler {
3232
this.shareWebPage(call, result);
3333
break;
3434
case "shareFile":
35-
// TODO
36-
result.notImplemented();
35+
this.shareFile(call, result);
3736
break;
3837
default:
3938
result.notImplemented();
@@ -108,6 +107,54 @@ export class FluwxShareHandler {
108107
result.success(done)
109108
}
110109

110+
async shareFile(call: MethodCall, result: MethodResult) {
111+
const source: Map<string, Any> = call.argument("source") ?? new Map();
112+
const schemaIndex: number = source.get("schema")
113+
let filePath: string = ""
114+
115+
// check schema is file or binary
116+
if (schemaIndex < 2) {
117+
result.error("ARG", "currently only file or binary schema is supported on ohos", null);
118+
return;
119+
}
120+
121+
// case schema is file
122+
if(schemaIndex == 2) {
123+
filePath = source.get("source")
124+
if (filePath.startsWith("file://")) {
125+
filePath = filePath;
126+
} else {
127+
filePath = fileUri.getUriFromPath(filePath);
128+
}
129+
} else {
130+
// case schema is binary, write to temp file first
131+
const bytes: Uint8Array = source.get("source");
132+
const suffix: string = source.get("suffix") ?? ".tmp";
133+
const fileName = `share_temp_${new Date().getTime()}${suffix}`;
134+
const tempFilePath = `${WXAPiHandler.uiContext?.tempDir}/${fileName}`;
135+
const tempFile = fs.openSync(tempFilePath, fs.OpenMode.READ_WRITE || fs.OpenMode.CREATE);
136+
await fs.write(tempFile.fd, bytes.buffer);
137+
await fs.close(tempFile.fd);
138+
filePath = fileUri.getUriFromPath(tempFilePath);
139+
}
140+
141+
const fileObject = new wxopensdk.WXFileObject()
142+
fileObject.fileUri = filePath
143+
144+
const mediaMessage = new wxopensdk.WXMediaMessage()
145+
mediaMessage.mediaObject = fileObject
146+
mediaMessage.title = call.argument("title") || ""
147+
mediaMessage.description = call.argument("description") || ""
148+
149+
const req = new wxopensdk.SendMessageToWXReq()
150+
this.setCommonArgs(call, req, mediaMessage)
151+
req.message = mediaMessage
152+
153+
const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req);
154+
155+
result.success(done)
156+
}
157+
111158
async shareMiniProgram(call: MethodCall, result: MethodResult) {
112159
const miniProgramObject = new wxopensdk.WXMiniProgramObject()
113160
miniProgramObject.userName = call.argument("userName")
@@ -118,7 +165,7 @@ export class FluwxShareHandler {
118165
let miniProgramTypeInt: number = call.argument("miniProgramType")
119166
if (miniProgramTypeInt === 1) {
120167
miniProgramType = wxopensdk.WXMiniProgramType.TEST
121-
} else if (miniProgramType === 2) {
168+
} else if (miniProgramTypeInt === 2) {
122169
miniProgramType = wxopensdk.WXMiniProgramType.PREVIEW
123170
}
124171

ohos/src/main/ets/components/plugin/handlers/WXAPiHandler.ets

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,26 @@ export class WXAPiHandler {
3737
}
3838

3939
static checkWeChatInstallation(result: MethodResult) {
40-
const isInstalled = bundleManager.canOpenLink("weixin://")
41-
result.success(isInstalled)
40+
const isInstalled = bundleManager.canOpenLink("weixin://") || WXAPiHandler.wxApi?.isWXAppInstalled() === true;
41+
result.success(isInstalled);
4242
}
4343

44+
static checkSupportOpenBusinessView(result: MethodResult) {
45+
if (!WXAPiHandler.wxApi) {
46+
result.error("Unassigned WxApi", "please config wxapi first", null);
47+
return;
48+
}
49+
50+
const isInstalled = bundleManager.canOpenLink("weixin://") || WXAPiHandler.wxApi?.isWXAppInstalled() === true;
51+
if (!isInstalled) {
52+
result.error("WeChat Not Installed", "Please install the WeChat first", null);
53+
return;
54+
}
55+
56+
result.success(true);
57+
}
58+
59+
4460
private static registerWxAPIInternal(appId: string) {
4561
let api = wechatOpenSDK.WXAPIFactory.createWXAPI(appId)
4662
WXAPiHandler.registered = true

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: fluwx
22
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.
3-
version: 5.7.4
3+
version: 5.7.5
44
homepage: https://github.com/OpenFlutter/fluwx
55

66
environment:

0 commit comments

Comments
 (0)