图文分享 & 大图分享
This commit is contained in:
parent
eddbe9d4aa
commit
4eeff2435f
@ -20,6 +20,13 @@ flutter版新浪微博SDK
|
||||
|
||||
* [simple_pub_server](https://github.com/v7lin/simple_pub_server)
|
||||
|
||||
## docs
|
||||
|
||||
* [Android 应用接入](https://open.weibo.com/wiki/Sdk/android)
|
||||
* [iOS 应用接入](https://open.weibo.com/wiki/Sdk/ios)
|
||||
* [Android Github](https://github.com/sinaweibosdk/weibo_android_sdk)
|
||||
* [iOS Github](https://github.com/sinaweibosdk/weibo_ios_sdk)
|
||||
|
||||
## android
|
||||
|
||||
````
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.github.v7lin.fakeweibo;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.sina.weibo.sdk.WbSdk;
|
||||
@ -72,6 +73,7 @@ public class FakeWeiboPlugin implements MethodCallHandler, PluginRegistry.Activi
|
||||
private static final String ARGUMENT_KEY_DESCRIPTION = "description";
|
||||
private static final String ARGUMENT_KEY_THUMBDATA = "thumbData";
|
||||
private static final String ARGUMENT_KEY_IMAGEDATA = "imageData";
|
||||
private static final String ARGUMENT_KEY_IMAGEURI = "imageUri";
|
||||
private static final String ARGUMENT_KEY_WEBPAGEURL = "webpageUrl";
|
||||
|
||||
private static final String ARGUMENT_KEY_RESULT_ERRORCODE = "errorCode";
|
||||
@ -182,8 +184,20 @@ public class FakeWeiboPlugin implements MethodCallHandler, PluginRegistry.Activi
|
||||
WeiboMultiMessage message = new WeiboMultiMessage();
|
||||
|
||||
if (METHOD_SHAREIMAGE.equals(call.method)) {
|
||||
if (call.hasArgument(ARGUMENT_KEY_TEXT)) {
|
||||
TextObject object = new TextObject();
|
||||
object.text = call.argument(ARGUMENT_KEY_TEXT);// 1024
|
||||
|
||||
message.textObject = object;
|
||||
}
|
||||
|
||||
ImageObject object = new ImageObject();
|
||||
object.imageData = call.argument(ARGUMENT_KEY_IMAGEDATA);// 2 * 1024 * 1024
|
||||
if (call.hasArgument(ARGUMENT_KEY_IMAGEDATA)) {
|
||||
object.imageData = call.argument(ARGUMENT_KEY_IMAGEDATA);// 2 * 1024 * 1024
|
||||
} else if (call.hasArgument(ARGUMENT_KEY_IMAGEURI)) {
|
||||
String imageUri = call.argument(ARGUMENT_KEY_IMAGEURI);
|
||||
object.imagePath = Uri.parse(imageUri).getPath();// 512 - 10 * 1024 * 1024
|
||||
}
|
||||
|
||||
message.mediaObject = object;
|
||||
} else if (METHOD_SHAREWEBPAGE.equals(call.method)) {
|
||||
|
@ -143,6 +143,7 @@ class _HomeState extends State<Home> {
|
||||
await image.obtainKey(createLocalImageConfiguration(context));
|
||||
ByteData imageData = await key.bundle.load(key.name);
|
||||
await _weibo.shareImage(
|
||||
text: 'Share Text',
|
||||
imageData: imageData.buffer.asUint8List(),
|
||||
);
|
||||
},
|
||||
|
@ -36,6 +36,7 @@ static NSString * const ARGUMENT_KEY_TITLE = @"title";
|
||||
static NSString * const ARGUMENT_KEY_DESCRIPTION = @"description";
|
||||
static NSString * const ARGUMENT_KEY_THUMBDATA = @"thumbData";
|
||||
static NSString * const ARGUMENT_KEY_IMAGEDATA = @"imageData";
|
||||
static NSString * const ARGUMENT_KEY_IMAGEURI = @"imageUri";
|
||||
static NSString * const ARGUMENT_KEY_WEBPAGEURL = @"webpageUrl";
|
||||
|
||||
static NSString * const ARGUMENT_KEY_RESULT_ERRORCODE = @"errorCode";
|
||||
@ -95,9 +96,16 @@ static NSString * const ARGUMENT_KEY_RESULT_EXPIRESIN = @"expiresIn";
|
||||
WBSendMessageToWeiboRequest * request = [WBSendMessageToWeiboRequest request];
|
||||
WBMessageObject * message = [WBMessageObject message];
|
||||
if ([METHOD_SHAREIMAGE isEqualToString:call.method]) {
|
||||
message.text = call.arguments[ARGUMENT_KEY_TEXT];
|
||||
WBImageObject * object = [WBImageObject object];
|
||||
FlutterStandardTypedData * imageData = call.arguments[ARGUMENT_KEY_IMAGEDATA];
|
||||
object.imageData = imageData.data;
|
||||
if (imageData != nil) {
|
||||
object.imageData = imageData.data;
|
||||
} else {
|
||||
NSString * imageUri = call.arguments[ARGUMENT_KEY_IMAGEURI];
|
||||
NSURL * imageUrl = [NSURL URLWithString:imageUri];
|
||||
object.imageData = [NSData dataWithContentsOfFile:imageUrl.path];
|
||||
}
|
||||
message.imageObject = object;
|
||||
} else if ([METHOD_SHAREWEBPAGE isEqualToString:call.method]) {
|
||||
WBWebpageObject * object = [WBWebpageObject object];
|
||||
|
@ -28,19 +28,22 @@ class Weibo {
|
||||
static const String _ARGUMENT_KEY_DESCRIPTION = 'description';
|
||||
static const String _ARGUMENT_KEY_THUMBDATA = 'thumbData';
|
||||
static const String _ARGUMENT_KEY_IMAGEDATA = 'imageData';
|
||||
static const String _ARGUMENT_KEY_IMAGEURI = 'imageUri';
|
||||
static const String _ARGUMENT_KEY_WEBPAGEURL = 'webpageUrl';
|
||||
|
||||
static const String _SCHEME_FILE = 'file';
|
||||
|
||||
static const String _DEFAULT_REDIRECTURL =
|
||||
'https://api.weibo.com/oauth2/default.html';
|
||||
|
||||
final MethodChannel _channel =
|
||||
const MethodChannel('v7lin.github.io/fake_weibo');
|
||||
const MethodChannel('v7lin.github.io/fake_weibo');
|
||||
|
||||
final StreamController<WeiboAuthResp> _authRespStreamController =
|
||||
StreamController<WeiboAuthResp>.broadcast();
|
||||
StreamController<WeiboAuthResp>.broadcast();
|
||||
|
||||
final StreamController<WeiboSdkResp> _shareMsgRespStreamController =
|
||||
StreamController<WeiboSdkResp>.broadcast();
|
||||
StreamController<WeiboSdkResp>.broadcast();
|
||||
|
||||
Future<void> registerApp({
|
||||
@required String appKey,
|
||||
@ -119,7 +122,7 @@ class Weibo {
|
||||
};
|
||||
return HttpClient()
|
||||
.getUrl(_encodeUrl('https://api.weibo.com/2/users/show.json', appkey,
|
||||
accessToken, params))
|
||||
accessToken, params))
|
||||
.then((HttpClientRequest request) {
|
||||
return request.close();
|
||||
}).then((HttpClientResponse response) async {
|
||||
@ -129,21 +132,20 @@ class Weibo {
|
||||
.fromMap(json.decode(content) as Map<dynamic, dynamic>);
|
||||
}
|
||||
throw HttpException(
|
||||
'HttpResponse statusCode: ${response.statusCode}, reasonPhrase: ${response.reasonPhrase}.');
|
||||
'HttpResponse statusCode: ${response
|
||||
.statusCode}, reasonPhrase: ${response.reasonPhrase}.');
|
||||
});
|
||||
}
|
||||
|
||||
Uri _encodeUrl(
|
||||
String baseUrl,
|
||||
String appkey,
|
||||
String accessToken,
|
||||
Map<String, String> params,
|
||||
) {
|
||||
Uri _encodeUrl(String baseUrl,
|
||||
String appkey,
|
||||
String accessToken,
|
||||
Map<String, String> params,) {
|
||||
params.putIfAbsent('source', () => appkey);
|
||||
params.putIfAbsent('access_token', () => accessToken);
|
||||
Uri baseUri = Uri.parse(baseUrl);
|
||||
Map<String, List<String>> queryParametersAll =
|
||||
Map<String, List<String>>.of(baseUri.queryParametersAll);
|
||||
Map<String, List<String>>.of(baseUri.queryParametersAll);
|
||||
params.forEach((String key, String value) {
|
||||
queryParametersAll.remove(key);
|
||||
queryParametersAll.putIfAbsent(key, () => <String>[value]);
|
||||
@ -155,7 +157,7 @@ class Weibo {
|
||||
Future<void> shareText({
|
||||
@required String text,
|
||||
}) {
|
||||
assert(text != null && text.isNotEmpty && text.length <= 1024);
|
||||
assert(text != null && text.length <= 1024);
|
||||
return _channel.invokeMethod(
|
||||
_METHOD_SHARETEXT,
|
||||
<String, dynamic>{
|
||||
@ -166,15 +168,27 @@ class Weibo {
|
||||
|
||||
/// 分享 - 图片
|
||||
Future<void> shareImage({
|
||||
@required Uint8List imageData,
|
||||
String text,
|
||||
Uint8List imageData,
|
||||
Uri imageUri,
|
||||
}) {
|
||||
assert(imageData != null && imageData.lengthInBytes <= 2 * 1024 * 1024);
|
||||
return _channel.invokeMethod(
|
||||
_METHOD_SHAREIMAGE,
|
||||
<String, dynamic>{
|
||||
_ARGUMENT_KEY_IMAGEDATA: imageData,
|
||||
},
|
||||
);
|
||||
assert(text == null || text.length <= 1024);
|
||||
assert((imageData != null && imageData.lengthInBytes <= 2 * 1024 * 1024) ||
|
||||
(imageUri != null &&
|
||||
imageUri.isScheme(_SCHEME_FILE) &&
|
||||
imageUri.toFilePath().length <= 512 &&
|
||||
File.fromUri(imageUri).lengthSync() <= 10 * 1024 * 1024));
|
||||
Map<String, dynamic> map = <String, dynamic>{};
|
||||
if (text != null && text.isNotEmpty) {
|
||||
map.putIfAbsent(_ARGUMENT_KEY_TEXT, () => text);
|
||||
}
|
||||
if (imageData != null) {
|
||||
map.putIfAbsent(_ARGUMENT_KEY_IMAGEDATA, () => imageData);
|
||||
}
|
||||
if (imageUri != null) {
|
||||
map.putIfAbsent(_ARGUMENT_KEY_IMAGEURI, () => imageUri.toString());
|
||||
}
|
||||
return _channel.invokeMethod(_METHOD_SHAREIMAGE, map);
|
||||
}
|
||||
|
||||
/// 分享 - 网页
|
||||
|
Loading…
Reference in New Issue
Block a user