Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
53a1188e
提交
53a1188e
authored
8月 17, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
thumbnail on android
上级
f84f12bc
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
193 行增加
和
90 行删除
+193
-90
launch.json
.vscode/launch.json
+14
-0
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+2
-0
WeChatPluginHandler.kt
...in/kotlin/com/jarvan/fluwx/handler/WeChatPluginHandler.kt
+30
-22
Util.java
android/src/main/kotlin/com/jarvan/fluwx/utils/Util.java
+38
-1
WeChatThumbnailUtil.java
...in/kotlin/com/jarvan/fluwx/utils/WeChatThumbnailUtil.java
+79
-42
launch.json
example/.vscode/launch.json
+14
-0
main.dart
example/lib/main.dart
+13
-24
fluwx.dart
lib/src/fluwx.dart
+1
-0
wechat_share_models.dart
lib/src/models/wechat_share_models.dart
+2
-1
没有找到文件。
.vscode/launch.json
0 → 100644
浏览文件 @
53a1188e
{
//
使用
IntelliSense
了解相关属性。
//
悬停以查看现有属性的描述。
//
欲了解更多信息,请访问
:
https
:
//go.microsoft.com/fwlink/?linkid=
830387
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"name"
:
"Flutter"
,
"request"
:
"launch"
,
"type"
:
"dart"
}
]
}
\ No newline at end of file
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
53a1188e
package
com.jarvan.fluwx
import
android.util.Log
import
com.jarvan.fluwx.constant.CallResult
import
com.jarvan.fluwx.constant.WeChatPluginMethods
import
com.jarvan.fluwx.handler.WeChatPluginHandler
...
...
@@ -22,6 +23,7 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler {
}
override
fun
onMethodCall
(
call
:
MethodCall
,
result
:
Result
):
Unit
{
Log
.
e
(
"---"
,
call
.
method
)
if
(
call
.
method
==
WeChatPluginMethods
.
INIT
){
val
api
=
WXAPIFactory
.
createWXAPI
(
registrar
.
context
().
applicationContext
,
call
.
arguments
as
String
?)
api
.
registerApp
(
call
.
arguments
as
String
)
...
...
android/src/main/kotlin/com/jarvan/fluwx/handler/WeChatPluginHandler.kt
浏览文件 @
53a1188e
...
...
@@ -50,11 +50,12 @@ object WeChatPluginHandler {
fun
handle
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
Log
.
e
(
"---"
,
call
.
method
)
if
(!
wxApi
!!
.
isWXAppInstalled
)
{
result
.
error
(
CallResult
.
RESULT_WE_CHAT_NOT_INSTALLED
,
CallResult
.
RESULT_WE_CHAT_NOT_INSTALLED
,
null
)
return
}
when
(
call
.
method
)
{
WeChatPluginMethods
.
SHARE_TEXT
->
shareText
(
call
,
result
)
WeChatPluginMethods
.
SHARE_MINI_PROGRAM
->
shareMiniProgram
(
call
,
result
)
...
...
@@ -151,11 +152,9 @@ object WeChatPluginHandler {
if
(
thumbnail
.
isNullOrBlank
()){
thumbnail
=
imagePath
}
Log
.
e
(
"tag"
,
"$thumbnail"
)
val
thumbnailData
=
getThumbnailByteArrayCommon
(
registrar
,
thumbnail
!!
)
// val thumbnailData = Util.bmpToByteArray(bitmap,true)
handleShareImage
(
imgObj
,
call
,
thumbnailData
,
result
)
}
...
...
@@ -197,15 +196,19 @@ object WeChatPluginHandler {
msg
.
title
=
call
.
argument
(
"title"
)
msg
.
description
=
call
.
argument
(
"description"
)
val
thumbnail
:
String
?
=
call
.
argument
(
"thumbnail"
)
if
(
thumbnail
!=
null
&&
thumbnail
.
isNotBlank
())
{
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
thumbnail
,
registrar
)
launch
(
UI
){
if
(
thumbnail
!=
null
&&
thumbnail
.
isNotBlank
())
{
msg
.
thumbData
=
getThumbnailByteArrayCommon
(
registrar
,
thumbnail
)
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
result
.
success
(
wxApi
?.
sendReq
(
req
))
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
result
.
success
(
wxApi
?.
sendReq
(
req
))
}
private
fun
shareVideo
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
...
...
@@ -222,15 +225,18 @@ object WeChatPluginHandler {
msg
.
title
=
call
.
argument
(
WechatPluginKeys
.
TITLE
)
msg
.
description
=
call
.
argument
(
WechatPluginKeys
.
DESCRIPTION
)
val
thumbnail
:
String
?
=
call
.
argument
(
WechatPluginKeys
.
THUMBNAIL
)
if
(
thumbnail
!=
null
&&
thumbnail
.
isNotBlank
())
{
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
thumbnail
,
registrar
)
launch
(
UI
){
if
(
thumbnail
!=
null
&&
thumbnail
.
isNotBlank
())
{
msg
.
thumbData
=
getThumbnailByteArrayCommon
(
registrar
,
thumbnail
)
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
result
.
success
(
wxApi
?.
sendReq
(
req
))
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
result
.
success
(
wxApi
?.
sendReq
(
req
))
}
...
...
@@ -239,18 +245,20 @@ object WeChatPluginHandler {
webPage
.
webpageUrl
=
call
.
argument
(
"webPage"
)
val
msg
=
WXMediaMessage
()
Log
.
e
(
"tag"
,
"share web"
)
msg
.
mediaObject
=
webPage
msg
.
title
=
call
.
argument
(
WechatPluginKeys
.
TITLE
)
msg
.
description
=
call
.
argument
(
WechatPluginKeys
.
DESCRIPTION
)
val
thumbnail
:
String
?
=
call
.
argument
(
WechatPluginKeys
.
THUMBNAIL
)
if
(
thumbnail
!=
null
&&
thumbnail
.
isNotBlank
())
{
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
thumbnail
,
registrar
)
launch
(
UI
)
{
if
(
thumbnail
!=
null
&&
thumbnail
.
isNotBlank
())
{
msg
.
thumbData
=
getThumbnailByteArrayCommon
(
registrar
,
thumbnail
)
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
result
.
success
(
wxApi
?.
sendReq
(
req
))
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
result
.
success
(
wxApi
?.
sendReq
(
req
))
}
// private fun createWxImageObject(imagePath:String):WXImageObject?{
...
...
android/src/main/kotlin/com/jarvan/fluwx/utils/Util.java
浏览文件 @
53a1188e
...
...
@@ -16,6 +16,8 @@ import junit.framework.Assert;
import
android.graphics.Bitmap
;
import
android.graphics.BitmapFactory
;
import
android.graphics.Bitmap.CompressFormat
;
import
android.graphics.Canvas
;
import
android.graphics.Rect
;
import
android.util.Log
;
class
Util
{
...
...
@@ -44,7 +46,42 @@ class Util {
}
public
static
byte
[]
getHtmlByteArray
(
final
String
url
)
{
public
static
byte
[]
bmpToByteArray2
(
final
Bitmap
bmp
,
final
boolean
needRecycle
)
{
int
i
;
int
j
;
if
(
bmp
.
getHeight
()
>
bmp
.
getWidth
())
{
i
=
bmp
.
getWidth
();
j
=
bmp
.
getWidth
();
}
else
{
i
=
bmp
.
getHeight
();
j
=
bmp
.
getHeight
();
}
Bitmap
localBitmap
=
Bitmap
.
createBitmap
(
i
,
j
,
Bitmap
.
Config
.
ARGB_4444
);
Canvas
localCanvas
=
new
Canvas
(
localBitmap
);
while
(
true
)
{
localCanvas
.
drawBitmap
(
bmp
,
new
Rect
(
0
,
0
,
i
,
j
),
new
Rect
(
0
,
0
,
i
,
j
),
null
);
if
(
needRecycle
)
bmp
.
recycle
();
ByteArrayOutputStream
localByteArrayOutputStream
=
new
ByteArrayOutputStream
();
localBitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
localByteArrayOutputStream
);
localBitmap
.
recycle
();
byte
[]
arrayOfByte
=
localByteArrayOutputStream
.
toByteArray
();
try
{
localByteArrayOutputStream
.
close
();
return
arrayOfByte
;
}
catch
(
Exception
e
)
{
// F.out(e);
}
i
=
bmp
.
getHeight
();
j
=
bmp
.
getHeight
();
}
}
public
static
byte
[]
getHtmlByteArray
(
final
String
url
)
{
URL
htmlUrl
=
null
;
InputStream
inStream
=
null
;
try
{
...
...
android/src/main/kotlin/com/jarvan/fluwx/utils/WeChatThumbnailUtil.java
浏览文件 @
53a1188e
...
...
@@ -9,6 +9,8 @@ import android.util.Log;
import
com.jarvan.fluwx.constant.WeChatPluginImageSchema
;
import
com.jarvan.fluwx.constant.WechatPluginKeys
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
...
...
@@ -24,13 +26,14 @@ import okhttp3.Request;
import
okhttp3.Response
;
import
okhttp3.ResponseBody
;
import
okio.BufferedSink
;
import
okio.BufferedSource
;
import
okio.Okio
;
import
okio.Source
;
import
top.zibin.luban.Luban
;
public
class
WeChatThumbnailUtil
{
public
static
final
int
SHARE_IMAGE_THUMB_LENGTH
=
32
;
private
static
final
int
COMMON_THUMB_WIDTH
=
1
5
0
;
private
static
final
int
COMMON_THUMB_WIDTH
=
10
;
private
WeChatThumbnailUtil
()
{
}
...
...
@@ -102,58 +105,78 @@ public class WeChatThumbnailUtil {
int
size
=
SHARE_IMAGE_THUMB_LENGTH
*
1024
;
try
{
File
file1
=
Luban
File
compressedFile
=
Luban
.
with
(
registrar
.
context
())
.
ignoreBy
(
SHARE_IMAGE_THUMB_LENGTH
)
.
setTargetDir
(
registrar
.
context
().
getCacheDir
().
getAbsolutePath
())
.
ignoreBy
(
32
)
.
get
(
file
.
getAbsolutePath
());
if
(
file
.
length
()
<=
32
*
1024
){
return
Util
.
bmpToByteArray
(
BitmapFactory
.
decodeFile
(
file1
.
getAbsolutePath
()),
true
);
}
else
{
return
continueCompress
(
file1
);
if
(
compressedFile
.
length
()
<
SHARE_IMAGE_THUMB_LENGTH
*
1024
)
{
Source
source
=
Okio
.
source
(
compressedFile
);
BufferedSource
bufferedSource
=
Okio
.
buffer
(
source
);
byte
[]
bytes
=
bufferedSource
.
readByteArray
();
source
.
close
();
bufferedSource
.
close
();
return
bytes
;
}
byte
[]
result
=
createScaledBitmapWithRatio
(
compressedFile
);
if
(
result
.
length
<
SHARE_IMAGE_THUMB_LENGTH
*
1024
)
{
return
result
;
}
return
createScaledBitmap
(
compressedFile
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
new
byte
[]{};
return
new
byte
[]{};
}
private
static
byte
[]
continueCompress
(
File
file
){
// Bitmap bitmap = ThumbnailCompressUtil.makeNormalBitmap(file.getAbsolutePath(), -1, 32 * 1024);
// if (bitmap.getByteCount() <= size) {
// return bmpToByteArray(bitmap,true);
// }
//
//
// byte[] result = Util.bmpToByteArray(bitmap, true);
// if (result.length <= size) {
// return result;
// }
//
Bitmap
bitmap
=
BitmapFactory
.
decodeFile
(
file
.
getAbsolutePath
());
Bitmap
bitmap2
=
ThumbnailCompressUtil
.
createScaledBitmapWithRatio
(
bitmap
,
COMMON_THUMB_WIDTH
,
false
);
Util
.
getHtmlByteArray
()
if
(
bitmap2
.
getByteCount
()
<=
32
*
1024
){
return
bmpToByteArray
(
bitmap2
,
true
);
}
private
static
byte
[]
createScaledBitmapWithRatio
(
File
file
)
{
Bitmap
originBitmap
=
BitmapFactory
.
decodeFile
(
file
.
getAbsolutePath
());
Bitmap
result
=
ThumbnailCompressUtil
.
createScaledBitmapWithRatio
(
originBitmap
,
COMMON_THUMB_WIDTH
,
true
);
String
path
=
file
.
getAbsolutePath
();
String
suffix
=
path
.
substring
(
path
.
lastIndexOf
(
"."
),
path
.
length
());
return
bmpToByteArray
(
result
,
suffix
,
true
);
}
bitmap
=
ThumbnailCompressUtil
.
createScaledBitmap
(
bitmap
,
COMMON_THUMB_WIDTH
,
true
);
private
static
byte
[]
createScaledBitmap
(
File
file
)
{
Bitmap
originBitmap
=
BitmapFactory
.
decodeFile
(
file
.
getAbsolutePath
());
Bitmap
result
=
ThumbnailCompressUtil
.
createScaledBitmap
(
originBitmap
,
COMMON_THUMB_WIDTH
,
true
);
return
bmpToByteArray
(
bitmap
,
true
);
return
bmpToByteArray
(
result
,
".png"
,
true
);
}
private
static
byte
[]
bmpToByteArray
(
Bitmap
bitmap
,
boolean
recycle
)
{
int
bytes
=
bitmap
.
getByteCount
();
ByteBuffer
buf
=
ByteBuffer
.
allocate
(
bytes
);
bitmap
.
copyPixelsToBuffer
(
buf
);
private
static
byte
[]
bmpToByteArray
(
Bitmap
bitmap
,
String
suffix
,
boolean
recycle
)
{
// int bytes = bitmap.getByteCount();
// ByteBuffer buf = ByteBuffer.allocate(bytes);
// bitmap.copyPixelsToBuffer(buf);
ByteArrayOutputStream
byteArrayOutputStream
=
new
ByteArrayOutputStream
();
Bitmap
.
CompressFormat
format
=
Bitmap
.
CompressFormat
.
PNG
;
if
(
suffix
.
toLowerCase
().
equals
(
".jpg"
)
||
suffix
.
toLowerCase
().
equals
(
".jpeg"
))
{
format
=
Bitmap
.
CompressFormat
.
JPEG
;
}
bitmap
.
compress
(
format
,
100
,
byteArrayOutputStream
);
InputStream
inputStream
=
new
ByteArrayInputStream
(
byteArrayOutputStream
.
toByteArray
());
byte
[]
result
=
null
;
if
(
recycle
)
{
bitmap
.
recycle
();
}
return
buf
.
array
();
Source
source
=
Okio
.
source
(
inputStream
);
BufferedSource
bufferedSource
=
Okio
.
buffer
(
source
);
try
{
result
=
bufferedSource
.
readByteArray
();
source
.
close
();
bufferedSource
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
private
static
File
fromAssetForCommon
(
String
thumbnail
,
PluginRegistry
.
Registrar
registrar
)
{
...
...
@@ -168,8 +191,6 @@ public class WeChatThumbnailUtil {
BufferedSink
sink
=
Okio
.
buffer
(
Okio
.
sink
(
outputStream
));
Source
source
=
Okio
.
source
(
fileDescriptor
.
createInputStream
());
sink
.
writeAll
(
source
);
sink
.
flush
();
source
.
close
();
sink
.
close
();
}
catch
(
IOException
e
)
{
...
...
@@ -199,11 +220,8 @@ public class WeChatThumbnailUtil {
result
=
File
.
createTempFile
(
UUID
.
randomUUID
().
toString
(),
getSuffix
(
url
));
OutputStream
outputStream
=
new
FileOutputStream
(
result
);
BufferedSink
sink
=
Okio
.
buffer
(
Okio
.
sink
(
outputStream
));
Source
source
=
Okio
.
source
(
responseBody
.
byteStream
());
sink
.
writeAll
(
source
);
sink
.
writeAll
(
responseBody
.
source
());
sink
.
flush
();
source
.
close
();
sink
.
close
();
}
...
...
@@ -214,6 +232,25 @@ public class WeChatThumbnailUtil {
return
result
;
}
private
static
File
inputStreamToFile
(
InputStream
inputStream
,
String
suffix
)
{
File
result
=
null
;
try
{
result
=
File
.
createTempFile
(
UUID
.
randomUUID
().
toString
(),
suffix
);
OutputStream
outputStream
=
new
FileOutputStream
(
result
);
BufferedSink
sink
=
Okio
.
buffer
(
Okio
.
sink
(
outputStream
));
Source
source
=
Okio
.
source
(
inputStream
);
sink
.
writeAll
(
source
);
sink
.
flush
();
sink
.
close
();
source
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
private
static
String
getSuffix
(
String
path
)
{
String
suffix
=
".jpg"
;
int
index
=
path
.
lastIndexOf
(
"."
);
...
...
example/.vscode/launch.json
0 → 100644
浏览文件 @
53a1188e
{
//
使用
IntelliSense
了解相关属性。
//
悬停以查看现有属性的描述。
//
欲了解更多信息,请访问
:
https
:
//go.microsoft.com/fwlink/?linkid=
830387
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"name"
:
"Flutter"
,
"request"
:
"launch"
,
"type"
:
"dart"
}
]
}
\ No newline at end of file
example/lib/main.dart
浏览文件 @
53a1188e
...
...
@@ -12,7 +12,7 @@ class MyApp extends StatefulWidget {
}
class
_MyAppState
extends
State
<
MyApp
>
{
String
_platformVersion
=
'Unknown'
;
@override
void
initState
()
{
...
...
@@ -27,22 +27,7 @@ class _MyAppState extends State<MyApp> {
// Platform messages are asynchronous, so we initialize in an async method.
Future
<
void
>
initPlatformState
()
async
{
String
platformVersion
;
// Platform messages may fail, so we use a try/catch PlatformException.
try
{
// platformVersion = await Fluwx.platformVersion;
}
on
PlatformException
{
platformVersion
=
'Failed to get platform version.'
;
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if
(!
mounted
)
return
;
setState
(()
{
_platformVersion
=
platformVersion
;
});
}
@override
...
...
@@ -58,14 +43,18 @@ class _MyAppState extends State<MyApp> {
var
fluwx
=
Fluwx
();
// thumbnail: 'http://b.hiphotos.baidu.com/image/h%3D300/sign=4bfc640817d5ad6eb5f962eab1c939a3/8718367adab44aedb794e128bf1c8701a08bfb20.jpg',
fluwx
.
share
(
WeChatShareImageModel
(
image:
'http://a.hiphotos.baidu.com/image/h%3D300/sign=91a426229082d158a4825fb1b00819d5/0824ab18972bd4077557733177899e510eb3096d.jpg'
,
thumbnail:
'http://a.hiphotos.baidu.com/image/h%3D300/sign=91a426229082d158a4825fb1b00819d5/0824ab18972bd4077557733177899e510eb3096d.jpg'
,
transaction:
'http://b.hiphotos.baidu.com/image/h%3D300/sign=4bfc640817d5ad6eb5f962eab1c939a3/8718367adab44aedb794e128bf1c8701a08bfb20.jpg'
,
scene:
WeChatScene
.
SESSION
));
WeChatShareWebPageModel
(
webPage:
"https://www.jianshu.com/"
,
title:
"简书"
,
)
).
then
((
result
){
print
(
"--
$result
"
);
},
onError:
(
msg
){
print
(
msg
);
});
},
child:
new
Text
(
"share
text to wechat
"
)),
child:
new
Text
(
"share "
)),
),
),
);
...
...
lib/src/fluwx.dart
浏览文件 @
53a1188e
...
...
@@ -33,6 +33,7 @@ class Fluwx {
}
Future
share
(
WeChatShareModel
model
)
async
{
var
s
=
_shareModelMethodMapper
[
model
.
runtimeType
];
if
(
_shareModelMethodMapper
.
containsKey
(
model
.
runtimeType
))
{
return
await
_channel
.
invokeMethod
(
_shareModelMethodMapper
[
model
.
runtimeType
],
model
.
toMap
());
...
...
lib/src/models/wechat_share_models.dart
浏览文件 @
53a1188e
...
...
@@ -176,6 +176,7 @@ class WeChatShareMusicModel extends WeChatShareModel {
this
.
title
:
""
,
this
.
description
:
""
,
this
.
musicDataUrl
,
this
.
musicLowBandDataUrl
,
String
thumbnail
,
WeChatScene
scene
,
String
messageExt
,
...
...
@@ -269,7 +270,7 @@ class WeChatShareWebPageModel extends WeChatShareModel {
WeChatShareWebPageModel
({
String
transaction
,
this
.
webPage
,
@required
this
.
webPage
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论