增加鸿蒙分享网页和小程序,微信sdk升级1.0.6 (#681)

增加鸿蒙分享网页和小程序,微信sdk升级1.0.6

---------

Co-authored-by: luo <245842834@qq.com>
This commit is contained in:
WinterTech
2025-01-04 09:54:30 +08:00
committed by GitHub
parent bad9e51ef7
commit 7d55a3292a
3 changed files with 76 additions and 13 deletions

View File

@ -4,6 +4,23 @@
```dart ```dart
fluwx.share(WeChatShareTextModel("source text", scene: WeChatScene.SESSION)); 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 ```dart

View File

@ -7,6 +7,6 @@
"license": "Apache-2.0", "license": "Apache-2.0",
"dependencies": { "dependencies": {
"@ohos/flutter_ohos": "file:./har/flutter.har", "@ohos/flutter_ohos": "file:./har/flutter.har",
"@tencent/wechat_open_sdk": "1.0.3" "@tencent/wechat_open_sdk": "1.0.6"
} }
} }

View File

@ -1,8 +1,8 @@
import { Any, MethodCall, MethodResult } from "@ohos/flutter_ohos" 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 { buffer } from "@kit.ArkTS"
import { fileUri } from "@kit.CoreFileKit" import { fileUri } from "@kit.CoreFileKit"
import * as wxopensdk from '@tencent/wechat_open_sdk';
import { WXAPiHandler } from "./WXAPiHandler"
export class FluwxShareHandler { export class FluwxShareHandler {
share(call: MethodCall, result: MethodResult) { share(call: MethodCall, result: MethodResult) {
@ -16,8 +16,7 @@ export class FluwxShareHandler {
this.shareText(call, result); this.shareText(call, result);
break; break;
case "shareMiniProgram": case "shareMiniProgram":
// TODO this.shareMiniProgram(call, result);
result.notImplemented();
break; break;
case "shareImage": case "shareImage":
this.shareImage(call, result); this.shareImage(call, result);
@ -31,8 +30,7 @@ export class FluwxShareHandler {
result.notImplemented(); result.notImplemented();
break; break;
case "shareWebPage": case "shareWebPage":
// TODO this.shareWebPage(call, result);
result.notImplemented();
break; break;
case "shareFile": case "shareFile":
// TODO // TODO
@ -45,13 +43,13 @@ export class FluwxShareHandler {
} }
async shareText(call: MethodCall, result: MethodResult) { async shareText(call: MethodCall, result: MethodResult) {
const textObj = new wechatSDK.WXTextObject(); const textObj = new wxopensdk.WXTextObject();
textObj.text = call.argument("source"); textObj.text = call.argument("source");
const mediaMsg = new wechatSDK.WXMediaMessage(); const mediaMsg = new wxopensdk.WXMediaMessage();
mediaMsg.mediaObject = textObj; mediaMsg.mediaObject = textObj;
const req = new wechatSDK.SendMessageToWXReq(); const req = new wxopensdk.SendMessageToWXReq();
req.message = mediaMsg; req.message = mediaMsg;
const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req); const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req);
@ -64,7 +62,7 @@ export class FluwxShareHandler {
// const imageHash: string | null = call.argument("imgDataHash"); // const imageHash: string | null = call.argument("imgDataHash");
const bytes: Uint8Array | null = map.get("uint8List"); const bytes: Uint8Array | null = map.get("uint8List");
const imageObj = new wechatSDK.WXImageObject(); const imageObj = new wxopensdk.WXImageObject();
if (bytes) { if (bytes) {
const buff: buffer.Buffer = buffer.from(bytes.buffer); const buff: buffer.Buffer = buffer.from(bytes.buffer);
@ -76,13 +74,61 @@ export class FluwxShareHandler {
} }
} }
const mediaMsg = new wechatSDK.WXMediaMessage(); const mediaMsg = new wxopensdk.WXMediaMessage();
mediaMsg.mediaObject = imageObj; mediaMsg.mediaObject = imageObj;
const req = new wechatSDK.SendMessageToWXReq(); const req = new wxopensdk.SendMessageToWXReq();
req.message = mediaMsg; req.message = mediaMsg;
const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req); const done = await WXAPiHandler.wxApi?.sendReq(WXAPiHandler.uiContext, req);
result.success(done); 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)
}
} }