提交 f73fb952 authored 作者: JarvanMo's avatar JarvanMo

*…

* 使用了多端统一API,详情请点击[这里](https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Share_and_Favorites/Android.html) * 分享时所有的缩略图请使用`thumbData`字段 * Fluwx不会再对任何图片进行压缩处理
上级 31327261
......@@ -6,7 +6,6 @@ import com.jarvan.fluwx.handlers.FluwxAuthHandler
import com.jarvan.fluwx.handlers.FluwxRequestHandler
import com.jarvan.fluwx.handlers.FluwxShareHandler
import com.jarvan.fluwx.handlers.FluwxShareHandlerEmbedding
import com.jarvan.fluwx.handlers.PermissionHandler
import com.jarvan.fluwx.handlers.WXAPiHandler
import com.jarvan.fluwx.utils.WXApiUtils
import com.jarvan.fluwx.utils.readWeChatCallbackIntent
......
package com.jarvan.fluwx.handlers
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.content.res.AssetFileDescriptor
import android.net.Uri
import androidx.core.content.ContextCompat
import androidx.core.content.FileProvider
import com.jarvan.fluwx.io.*
import com.tencent.mm.opensdk.modelbase.BaseReq
......@@ -93,8 +90,6 @@ internal interface FluwxShareHandler : CoroutineScope {
msg.description = call.argument(keyDescription) // 小程序消息desc
launch {
msg.thumbData = readThumbnailByteArray(call, length = SHARE_MINI_PROGRAM_THUMB_LENGTH)
val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
......@@ -105,27 +100,24 @@ internal interface FluwxShareHandler : CoroutineScope {
private fun shareImage(call: MethodCall, result: MethodChannel.Result) {
launch {
val map: Map<String, Any> = call.argument("source") ?: mapOf()
val sourceImage = WeChatFile.createWeChatFile(map, assetFileDescriptor)
val thumbData = readThumbnailByteArray(call)
val sourceByteArray = sourceImage.readByteArray()
val imageObject = when {
sourceByteArray.isEmpty() -> {
WXImageObject()
}
else -> {
val imgHash = call.argument<String?>("imgDataHash")
val uint8List = map["uint8List"] as? ByteArray
val imageObject = uint8List?.let {
WXImageObject().apply {
if (supportFileProvider && targetHigherThanN) {
setImagePath(getFileContentUri(sourceByteArray.toCacheFile(context, sourceImage.suffix)))
} else {
setImagePath(sourceByteArray.toExternalCacheFile(context, sourceImage.suffix)?.absolutePath)
}
imageData = it
imgDataHash = imgHash
}
}?:run {
WXImageObject().apply {
imagePath = call.argument<String?>("localImagePath")
imgDataHash = imgHash
}
}
val msg = WXMediaMessage()
msg.mediaObject = imageObject
msg.thumbData = thumbData
msg.description = call.argument(keyDescription)
......@@ -154,8 +146,6 @@ internal interface FluwxShareHandler : CoroutineScope {
msg.description = call.argument(keyDescription)
launch {
msg.thumbData = readThumbnailByteArray(call)
val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
......@@ -177,7 +167,6 @@ internal interface FluwxShareHandler : CoroutineScope {
msg.description = call.argument(keyDescription)
launch {
msg.thumbData = readThumbnailByteArray(call)
val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
......@@ -195,7 +184,6 @@ internal interface FluwxShareHandler : CoroutineScope {
msg.description = call.argument(keyDescription)
launch {
msg.thumbData = readThumbnailByteArray(call)
val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
......@@ -227,7 +215,6 @@ internal interface FluwxShareHandler : CoroutineScope {
}
}
msg.thumbData = readThumbnailByteArray(call)
val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
......@@ -239,20 +226,6 @@ internal interface FluwxShareHandler : CoroutineScope {
result.success(WXAPiHandler.wxApi?.sendReq(request))
}
private suspend fun readThumbnailByteArray(call: MethodCall, length: Int = SHARE_IMAGE_THUMB_LENGTH): ByteArray? {
val thumbnailMap: Map<String, Any>? = call.argument(keyThumbnail)
val compress:Boolean = call.argument("compressThumbnail")?:true
return thumbnailMap?.run {
val thumbnailImage = WeChatFile.createWeChatFile(thumbnailMap, assetFileDescriptor)
val thumbnailImageIO = ImagesIOIml(thumbnailImage)
if(compress){
compressThumbnail(thumbnailImageIO, length)
}else{
thumbnailImageIO.readByteArray()
}
}
}
private suspend fun compressThumbnail(ioIml: ImagesIO, length: Int) = ioIml.compressedByteArray(context, length)
// SESSION, TIMELINE, FAVORITE
......
......@@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'
# platform :ios, '12.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
......
......@@ -29,10 +29,10 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
fluwx: c37e78d6ad04b852e39f785e660c65d4906e3f4f
fluwx: c18fd6c16b03a2187cd07d6e48e32a7801962849
integration_test: 13825b8a9334a850581300559b8839134b124670
WechatOpenSDK-XCFramework: 36fb2bea0754266c17184adf4963d7e6ff98b69f
PODFILE CHECKSUM: 02caaa843f6501172c0d470d80e72f61175c8b93
PODFILE CHECKSUM: 6e700dec67e6deac9b1c69bb14c49a2217a12d15
COCOAPODS: 1.12.1
COCOAPODS: 1.15.2
......@@ -230,7 +230,7 @@
KnownAssetTags = (
New,
);
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
331C80F0294D02FB00263BE5 = {
......@@ -467,7 +467,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
......@@ -585,7 +585,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
......@@ -634,7 +634,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
......
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
......
......@@ -12,8 +12,6 @@ class _ShareImagePageState extends State<ShareImagePage> {
WeChatScene scene = WeChatScene.session;
String _response = '';
WeChatImage? source;
WeChatImage? thumbnail;
Fluwx fluwx = Fluwx();
@override
......@@ -57,7 +55,6 @@ class _ShareImagePageState extends State<ShareImagePage> {
'&src=http%3A%2F%2Fimg.mp.sohu.com%2Fupload%2F20170516%2F51296b2673704ae2992d0a28c244274c_th.png',
),
onChanged: (value) {
source = WeChatImage.network(value);
},
keyboardType: TextInputType.multiline,
),
......@@ -65,7 +62,6 @@ class _ShareImagePageState extends State<ShareImagePage> {
decoration: InputDecoration(labelText: '缩略地址'),
controller: TextEditingController(text: '//images/logo.png'),
onChanged: (value) {
thumbnail = WeChatImage.asset(value);
},
),
Row(
......@@ -117,7 +113,6 @@ class _ShareImagePageState extends State<ShareImagePage> {
}
void _shareImage() {
fluwx.share(WeChatShareImageModel(source!, thumbnail: thumbnail));
}
void handleRadioValueChanged(WeChatScene scene) {
......
......@@ -97,7 +97,6 @@ class _ShareMiniProgramPageState extends State<ShareMiniProgramPage> {
title: _title,
path: _path,
description: _description,
thumbnail: WeChatImage.network(_thumbnail),
);
fluwx.share(model);
}
......
......@@ -129,7 +129,6 @@ class _ShareMusicPageState extends State<ShareMusicPage> {
musicUrl: _musicUrl,
scene: scene,
musicLowBandUrl: _musicLowBandUrl,
thumbnail: WeChatImage.network(_thumnail),
);
_fluwx.share(model);
......
......@@ -125,7 +125,6 @@ class _ShareVideoPageState extends State<ShareVideoPage> {
var model = WeChatShareVideoModel(
videoUrl: _videoUrl,
videoLowBandUrl: _videoLowBandUrl,
thumbnail: WeChatImage.network(_thumnail),
description: _description,
scene: scene,
title: _title,
......
......@@ -106,7 +106,6 @@ class ShareWebPagePageState extends State<ShareWebPagePage> {
var model = WeChatShareWebPageModel(
_url,
title: _title,
thumbnail: WeChatImage.network(_thumnail),
scene: scene,
);
fluwx.share(model);
......
差异被折叠。
......@@ -17,6 +17,7 @@
* the License.
*/
import 'dart:io';
import 'dart:typed_data';
import '../wechat_enums.dart';
......
......@@ -21,13 +21,11 @@ part of 'arguments.dart';
const String _scene = "scene";
const String _source = "source";
const String _thumbnail = "thumbnail";
const String _title = "title";
const String _description = "description";
const String _messageExt = "messageExt";
const String _mediaTagName = "mediaTagName";
const String _messageAction = "messageAction";
const String _compressThumbnail = "compressThumbnail";
const String _msgSignature = "msgSignature";
const String _thumbData = "thumbData";
const String _thumbDataHash = "thumbDataHash";
......@@ -88,8 +86,6 @@ class WeChatShareTextModel extends WeChatShareModel {
}
/// the default value is [MINI_PROGRAM_TYPE_RELEASE]
/// [hdImagePath] only works on iOS, not sure the relationship
/// between [thumbnail] and [hdImagePath].
class WeChatShareMiniProgramModel extends WeChatShareModel {
WeChatShareMiniProgramModel({
required this.webPageUrl,
......@@ -99,12 +95,9 @@ class WeChatShareMiniProgramModel extends WeChatShareModel {
super.title,
super.description,
this.withShareTicket = false,
required this.thumbnail,
this.hdImagePath,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
super.msgSignature,
super.thumbData,
super.thumbDataHash,
......@@ -116,13 +109,10 @@ class WeChatShareMiniProgramModel extends WeChatShareModel {
final WXMiniProgramType miniProgramType;
final String userName;
final String path;
final WeChatImage? hdImagePath;
final WeChatImage thumbnail;
final bool withShareTicket;
final String? messageExt;
final String? messageAction;
final String? mediaTagName;
final bool compressThumbnail;
@override
Map<String, dynamic> get arguments => {
......@@ -133,11 +123,8 @@ class WeChatShareMiniProgramModel extends WeChatShareModel {
"title": title,
_description: description,
"withShareTicket": withShareTicket,
_thumbnail: thumbnail.toMap(),
"hdImagePath": hdImagePath?.toMap(),
_messageAction: messageAction,
_mediaTagName: mediaTagName,
_compressThumbnail: compressThumbnail,
_msgSignature: msgSignature,
_thumbData: thumbData,
_thumbDataHash: thumbDataHash,
......@@ -146,44 +133,43 @@ class WeChatShareMiniProgramModel extends WeChatShareModel {
/// [source] the image you want to send to WeChat
/// [scene] the target you want to send
/// [thumbnail] the preview of your image, will be created from [scene] if null.
class WeChatShareImageModel extends WeChatShareModel {
WeChatShareImageModel(
this.source, {
WeChatImage? thumbnail,
this.entranceMiniProgramPath,
this.entranceMiniProgramUsername,
super.title,
this.scene = WeChatScene.session,
super.description,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
super.msgSignature,
super.thumbData,
super.thumbDataHash,
}) : thumbnail = thumbnail ?? source;
});
final WeChatImage source;
final WeChatImage thumbnail;
final WeChatImageToShare source;
final WeChatScene scene;
final String? messageExt;
final String? messageAction;
final String? mediaTagName;
final bool compressThumbnail;
final String? entranceMiniProgramUsername;
final String? entranceMiniProgramPath;
@override
Map<String, dynamic> get arguments => {
_scene: scene.index,
_source: source.toMap(),
_thumbnail: thumbnail.toMap(),
_source: source.arguments,
_title: title,
_description: description,
_messageAction: messageAction,
_mediaTagName: mediaTagName,
_compressThumbnail: compressThumbnail,
_msgSignature: msgSignature,
_thumbData: thumbData,
_thumbDataHash: thumbDataHash,
"entranceMiniProgramUsername": entranceMiniProgramUsername,
"entranceMiniProgramPath": entranceMiniProgramPath,
};
}
......@@ -197,12 +183,10 @@ class WeChatShareMusicModel extends WeChatShareModel {
super.description = "",
this.musicDataUrl,
this.musicLowBandDataUrl,
this.thumbnail,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.scene = WeChatScene.session,
this.compressThumbnail = true,
super.msgSignature,
super.thumbData,
super.thumbDataHash})
......@@ -212,12 +196,10 @@ class WeChatShareMusicModel extends WeChatShareModel {
final String? musicDataUrl;
final String? musicLowBandUrl;
final String? musicLowBandDataUrl;
final WeChatImage? thumbnail;
final WeChatScene scene;
final String? messageExt;
final String? messageAction;
final String? mediaTagName;
final bool compressThumbnail;
@override
Map<String, dynamic> get arguments => {
......@@ -226,12 +208,10 @@ class WeChatShareMusicModel extends WeChatShareModel {
"musicDataUrl": musicDataUrl,
"musicLowBandUrl": musicLowBandUrl,
"musicLowBandDataUrl": musicLowBandDataUrl,
_thumbnail: thumbnail?.toMap(),
_title: title,
_description: description,
_messageAction: messageAction,
_mediaTagName: mediaTagName,
_compressThumbnail: compressThumbnail,
_msgSignature: msgSignature,
_thumbData: thumbData,
_thumbDataHash: thumbDataHash,
......@@ -247,37 +227,30 @@ class WeChatShareVideoModel extends WeChatShareModel {
this.videoLowBandUrl,
super.title = "",
super.description = "",
this.thumbnail,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
super.msgSignature,
super.thumbData,
super.thumbDataHash,
}) : assert(videoUrl != null || videoLowBandUrl != null),
assert(thumbnail != null);
}) : assert(videoUrl != null || videoLowBandUrl != null);
final String? videoUrl;
final String? videoLowBandUrl;
final WeChatImage? thumbnail;
final WeChatScene scene;
final String? messageExt;
final String? messageAction;
final String? mediaTagName;
final bool compressThumbnail;
@override
Map<String, dynamic> get arguments => {
_scene: scene.index,
"videoUrl": videoUrl,
"videoLowBandUrl": videoLowBandUrl,
_thumbnail: thumbnail?.toMap(),
_title: title,
_description: description,
_messageAction: messageAction,
_mediaTagName: mediaTagName,
_compressThumbnail: compressThumbnail,
_msgSignature: msgSignature,
_thumbData: thumbData,
_thumbDataHash: thumbDataHash,
......@@ -291,35 +264,29 @@ class WeChatShareWebPageModel extends WeChatShareModel {
this.webPage, {
super.title = "",
super.description,
this.thumbnail,
this.scene = WeChatScene.session,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
super.msgSignature,
super.thumbData,
super.thumbDataHash,
}) : assert(webPage.isNotEmpty);
final String webPage;
final WeChatImage? thumbnail;
final WeChatScene scene;
final String? messageExt;
final String? messageAction;
final String? mediaTagName;
final bool compressThumbnail;
@override
Map<String, dynamic> get arguments => {
_scene: scene.index,
"webPage": webPage,
_thumbnail: thumbnail?.toMap(),
_title: title,
_messageAction: messageAction,
_mediaTagName: mediaTagName,
_description: description,
_compressThumbnail: compressThumbnail,
_msgSignature: msgSignature,
_thumbData: thumbData,
_thumbDataHash: thumbDataHash,
......@@ -334,37 +301,52 @@ class WeChatShareFileModel extends WeChatShareModel {
this.source, {
super.title = "",
super.description = "",
this.thumbnail,
this.scene = WeChatScene.session,
this.mediaTagName,
this.messageAction,
this.messageExt,
this.compressThumbnail = true,
super.msgSignature,
super.thumbData,
super.thumbDataHash,
});
final WeChatFile source;
final WeChatImage? thumbnail;
final WeChatScene scene;
final String? messageExt;
final String? messageAction;
final String? mediaTagName;
final bool compressThumbnail;
@override
Map<String, dynamic> get arguments => {
_scene: scene.index,
_source: source.toMap(),
_thumbnail: thumbnail?.toMap(),
_title: title,
_description: description,
_messageAction: messageAction,
_mediaTagName: mediaTagName,
_compressThumbnail: compressThumbnail,
_msgSignature: msgSignature,
_thumbData: thumbData,
_thumbDataHash: thumbDataHash,
};
}
class WeChatImageToShare with _Argument {
final Uint8List? uint8List;
final String? localImagePath;
final String? imgDataHash;
/// [uint8List] is available on both iOS and Android
/// [localImagePath] only available on Android, if [uint8List] is null, [localImagePath] must not be null;
/// if [uint8List] and [localImagePath] are both provided on android, [uint8List] will be used.
WeChatImageToShare(this.uint8List, this.localImagePath, this.imgDataHash)
: assert(Platform.isIOS && uint8List != null),
assert(Platform.isAndroid &&
(uint8List != null || localImagePath != null));
@override
Map<String, dynamic> get arguments => {
'uint8List': uint8List,
'localImagePath': localImagePath,
'imgDataHash': imgDataHash,
};
}
......@@ -22,28 +22,6 @@ import 'dart:typed_data';
const String defaultSuffixJpeg = '.jpeg';
const String defaultSuffixTxt = '.txt';
class WeChatImage extends WeChatFile {
WeChatImage.network(
String source, {
String suffix = defaultSuffixJpeg,
}) : super.network(source, suffix: suffix);
WeChatImage.asset(
String source, {
String suffix = defaultSuffixJpeg,
}) : super.asset(source, suffix: suffix);
WeChatImage.file(
File source, {
String suffix = defaultSuffixJpeg,
}) : super.file(source, suffix: suffix);
WeChatImage.binary(
Uint8List source, {
String suffix = defaultSuffixJpeg,
}) : super.binary(source, suffix: suffix);
}
class WeChatFile {
/// [source] must begin with http or https
WeChatFile.network(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论