diff --git a/doc/SHARE_CN.md b/doc/SHARE_CN.md index 606331a6..0a3e0ce5 100644 --- a/doc/SHARE_CN.md +++ b/doc/SHARE_CN.md @@ -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 diff --git a/ohos/oh-package.json5 b/ohos/oh-package.json5 index 3d1dd098..221e4d6c 100644 --- a/ohos/oh-package.json5 +++ b/ohos/oh-package.json5 @@ -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" } } diff --git a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets index 2c0c05df..42c82fc8 100644 --- a/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets +++ b/ohos/src/main/ets/components/plugin/handlers/FluwxShareHandler.ets @@ -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) { @@ -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); @@ -31,8 +30,7 @@ export class FluwxShareHandler { result.notImplemented(); break; case "shareWebPage": - // TODO - result.notImplemented(); + this.shareWebPage(call, result); break; case "shareFile": // TODO @@ -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); @@ -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); @@ -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) + } } \ No newline at end of file