Skip to content

Commit

Permalink
增加鸿蒙分享网页和小程序,微信sdk升级1.0.6 (#681)
Browse files Browse the repository at this point in the history
增加鸿蒙分享网页和小程序,微信sdk升级1.0.6

---------

Co-authored-by: luo <[email protected]>
  • Loading branch information
winter-tech and LuoGuoXin authored Jan 4, 2025
1 parent bad9e51 commit 7d55a32
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 13 deletions.
17 changes: 17 additions & 0 deletions doc/SHARE_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
```dart
fluwx.share(WeChatShareTextModel("source text", scene: WeChatScene.SESSION));
```

鸿蒙分享网页:
```dart
fluwx.share(WeChatShareWebPageModel("https://www.",title: "标题",description: "描述",thumbData: data));
```

鸿蒙分享小程序:
```dart
fluwx.share(WeChatShareMiniProgramModel(
thumbData: data ,//64kb内
webPageUrl: 'https://www.',
userName: 'gh_b6cxxxxxx',
path: path,
title: title,
));
```

绝大部分分享可以分享到会话,朋友圈,收藏(小程序目前只能分享到会话)。默认分享到会话。

```dart
Expand Down
2 changes: 1 addition & 1 deletion ohos/oh-package.json5
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"license": "Apache-2.0",
"dependencies": {
"@ohos/flutter_ohos": "file:./har/flutter.har",
"@tencent/wechat_open_sdk": "1.0.3"
"@tencent/wechat_open_sdk": "1.0.6"
}
}
70 changes: 58 additions & 12 deletions ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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"
import * as wxopensdk from '@tencent/wechat_open_sdk';
import { WXAPiHandler } from "./WXAPiHandler"

export class FluwxShareHandler {
share(call: MethodCall, result: MethodResult) {
Expand All @@ -16,8 +16,7 @@ export class FluwxShareHandler {
this.shareText(call, result);
break;
case "shareMiniProgram":
// TODO
result.notImplemented();
this.shareMiniProgram(call, result);
break;
case "shareImage":
this.shareImage(call, result);
Expand All @@ -31,8 +30,7 @@ export class FluwxShareHandler {
result.notImplemented();
break;
case "shareWebPage":
// TODO
result.notImplemented();
this.shareWebPage(call, result);
break;
case "shareFile":
// TODO
Expand All @@ -45,13 +43,13 @@ export class FluwxShareHandler {
}

async shareText(call: MethodCall, result: MethodResult) {
const textObj = new wechatSDK.WXTextObject();
const textObj = new wxopensdk.WXTextObject();
textObj.text = call.argument("source");

const mediaMsg = new wechatSDK.WXMediaMessage();
const mediaMsg = new wxopensdk.WXMediaMessage();
mediaMsg.mediaObject = textObj;

const req = new wechatSDK.SendMessageToWXReq();
const req = new wxopensdk.SendMessageToWXReq();
req.message = mediaMsg;

const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req);
Expand All @@ -64,7 +62,7 @@ export class FluwxShareHandler {
// const imageHash: string | null = call.argument("imgDataHash");
const bytes: Uint8Array | null = map.get("uint8List");

const imageObj = new wechatSDK.WXImageObject();
const imageObj = new wxopensdk.WXImageObject();

if (bytes) {
const buff: buffer.Buffer = buffer.from(bytes.buffer);
Expand All @@ -76,13 +74,61 @@ export class FluwxShareHandler {
}
}

const mediaMsg = new wechatSDK.WXMediaMessage();
const mediaMsg = new wxopensdk.WXMediaMessage();
mediaMsg.mediaObject = imageObj;

const req = new wechatSDK.SendMessageToWXReq();
const req = new wxopensdk.SendMessageToWXReq();
req.message = mediaMsg;

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

async shareWebPage(call: MethodCall, result: MethodResult) {
const webpageObject = new wxopensdk.WXWebpageObject()
webpageObject.webpageUrl = call.argument("webPage")

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

const thumbData: Uint8Array | null = call.argument("thumbData");
if (thumbData) {
mediaMessage.thumbData = thumbData;
}

const req = new wxopensdk.SendMessageToWXReq()
req.scene = wxopensdk.SendMessageToWXReq.WXSceneSession
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")
miniProgramObject.path = call.argument("path")
miniProgramObject.miniprogramType = wxopensdk.WXMiniProgramType.RELEASE

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

const thumbData: Uint8Array | null = call.argument("thumbData");
if (thumbData) {
mediaMessage.thumbData = thumbData;
}

const req = new wxopensdk.SendMessageToWXReq()
req.scene = wxopensdk.SendMessageToWXReq.WXSceneSession
req.message = mediaMessage

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

result.success(done)
}
}

0 comments on commit 7d55a32

Please sign in to comment.