Unverified 提交 7c9e7c77 authored 作者: JarvanMo's avatar JarvanMo 提交者: GitHub

Merge pull request #172 from lichfy/master

分享文件
#Tue Aug 13 10:22:39 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
......@@ -20,6 +20,7 @@ public class WeChatPluginMethods {
public static final String SHARE_VIDEO = "shareVideo";
public static final String SHARE_WEB_PAGE = "shareWebPage";
public static final String SHARE_MINI_PROGRAM = "shareMiniProgram";
public static final String SHARE_FILE = "shareFile";
public static final String LAUNCH_MINI_PROGRAM = "launchMiniProgram";
public static final String PAY = "payWithFluwx";
......
......@@ -72,6 +72,7 @@ internal class FluwxShareHandler {
WeChatPluginMethods.SHARE_MUSIC -> shareMusic(call, result)
WeChatPluginMethods.SHARE_VIDEO -> shareVideo(call, result)
WeChatPluginMethods.SHARE_WEB_PAGE -> shareWebPage(call, result)
WeChatPluginMethods.SHARE_FILE -> shareFile(call,result)
else -> {
result.notImplemented()
}
......@@ -359,6 +360,36 @@ internal class FluwxShareHandler {
}
}
private fun shareFile(call:MethodCall,result:MethodChannel.Result){
val file = WXFileObject()
val filePath:String? = call.argument("filePath")
file.filePath = filePath
val msg = WXMediaMessage()
msg.mediaObject = file
msg.title = call.argument("title")
msg.description = call.argument("description")
val thumbnail: String? = call.argument("thumbnail")
GlobalScope.launch(Dispatchers.Main, CoroutineStart.DEFAULT) {
if (thumbnail != null && thumbnail.isNotBlank()) {
msg.thumbData = getThumbnailByteArrayCommon(registrar, thumbnail)
}
val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
val done = WXAPiHandler.wxApi?.sendReq(req)
result.success(
mapOf(
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID,
WechatPluginKeys.RESULT to done
)
)
}
}
// private fun createWxImageObject(imagePath:String):WXImageObject?{
// var imgObj: WXImageObject? = null
// var imageFile:File? = null
......
......@@ -124,3 +124,16 @@ Two kind of video:`videoUrl`和`videoLowBandUrl`.They are not coexisting,if bo
fluwx.share(model);
```
### Share File
```dart
var model = fluwx.WeChatShareFileModel(
filePath: _filePath,
scene: scene,
title: _title,
description: _description
);
fluwx.share(model);
```
File size is limited and cannot exceed 10M
......@@ -120,3 +120,16 @@
);
fluwx.share(model);
```
### 分享文件
```dart
var model = fluwx.WeChatShareFileModel(
filePath: _filePath,
scene: scene,
title: _title,
description: _description
);
fluwx.share(model);
```
文件有大小限制,不能超过10M;文件路径还要考虑权限
\ No newline at end of file
......@@ -12,6 +12,7 @@ extern NSString *const shareImage;
extern NSString *const shareMusic;
extern NSString *const shareVideo;
extern NSString *const shareWebPage;
extern NSString *const shareFile;
extern NSString *const shareMiniProgram;
extern NSString *const launchMiniProgram;
......
......@@ -11,6 +11,7 @@ NSString *const shareText = @"shareText";
NSString *const shareImage = @"shareImage";
NSString *const shareMusic = @"shareMusic";
NSString *const shareVideo = @"shareVideo";
NSString *const shareFile = @"shareFile";
NSString *const shareWebPage = @"shareWebPage";
NSString *const shareMiniProgram = @"shareMiniProgram";
NSString *const LaunchMiniProgram = @"launchMiniProgram";
......
......@@ -55,6 +55,8 @@ NSObject <FlutterPluginRegistrar> *_fluwxRegistrar;
[self shareVideo:call result:result];
} else if ([shareMiniProgram isEqualToString:call.method]) {
[self shareMiniProgram:call result:result];
} else if([shareFile isEqualToString:call.method]){
[self shareFile:call result:result];
}
......@@ -371,6 +373,28 @@ NSObject <FlutterPluginRegistrar> *_fluwxRegistrar;
}
- (void)shareFile:(FlutterMethodCall *)call result:(FlutterResult)result {
dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
dispatch_async(globalQueue, ^{
NSString *thumbnail = call.arguments[fluwxKeyThumbnail];
UIImage *thumbnailImage = [self getThumbnail:thumbnail size:32 * 1024];
NSString *filePath = call.arguments[@"filePath"];
NSData *data = [NSData dataWithContentsOfFile:filePath];
dispatch_async(dispatch_get_main_queue(), ^{
NSString *scene = call.arguments[fluwxKeyScene];
BOOL done = [WXApiRequestHandler sendFileData:data
fileExtension:call.arguments[@"fileExtension"]
Title:call.arguments[fluwxKeyTitle]
Description:call.arguments[fluwxKeyDescription]
ThumbImage:thumbnailImage
InScene:[StringToWeChatScene toScene:scene]];
result(@{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @(done)});
});
});
}
- (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result {
dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
dispatch_async(globalQueue, ^{
......
......@@ -582,7 +582,8 @@ const Map<Type, String> _shareModelMethodMapper = {
WeChatShareMusicModel: "shareMusic",
WeChatShareVideoModel: "shareVideo",
WeChatShareWebPageModel: "shareWebPage",
WeChatShareMiniProgramModel: "shareMiniProgram"
WeChatShareMiniProgramModel: "shareMiniProgram",
WeChatShareFileModel:"shareFile",
};
const Map<int, AuthByQRCodeErrorCode> _authByQRCodeErrorCodes = {
......
......@@ -385,3 +385,48 @@ class WeChatShareWebPageModel extends WeChatShareModel {
};
}
}
class WeChatShareFileModel extends WeChatShareModel {
final String transaction;
final String filePath;
final String fileExtension;
final String thumbnail;
final String title;
final String description;
WeChatShareFileModel({
String transaction,
this.filePath,
this.fileExtension:"pdf",
this.title: "",
this.description: "",
String thumbnail,
WeChatScene scene,
String messageExt,
String messageAction,
String mediaTagName,
}) : this.transaction = transaction ?? "text",
this.thumbnail = thumbnail ?? "",
assert(filePath != null),
super(
mediaTagName: mediaTagName,
messageAction: messageAction,
messageExt: messageExt,
scene: scene);
@override
Map toMap() {
return {
_transaction: transaction,
_scene: scene.toString(),
"filePath": filePath,
"fileExtension": fileExtension,
_thumbnail: thumbnail,
_title: title,
_description: description,
_mediaTagName: mediaTagName,
_messageAction: messageAction,
_messageExt: messageExt,
};
}
}
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论