Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
65fc30a0
提交
65fc30a0
authored
8月 15, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:crashes on android when sharing image;wrong scene settings
上级
d3a07bfc
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
107 行增加
和
38 行删除
+107
-38
WechatPluginKeys.java
...in/kotlin/com/jarvan/fluwx/constant/WechatPluginKeys.java
+3
-4
WeChatPluginHandler.kt
...in/kotlin/com/jarvan/fluwx/handler/WeChatPluginHandler.kt
+53
-24
build.gradle
example/android/app/build.gradle
+1
-0
AndroidManifest.xml
example/android/app/src/main/AndroidManifest.xml
+1
-0
WXEntryActivity.java
...kotlin/com/jarvan/fluwxexample/wxapi/WXEntryActivity.java
+43
-0
main.dart
example/lib/main.dart
+6
-2
wechat_share_models.dart
lib/src/models/wechat_share_models.dart
+0
-8
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/constant/WechatPluginKeys.java
浏览文件 @
65fc30a0
...
...
@@ -8,10 +8,9 @@ package com.jarvan.fluwx.constant;
public
class
WechatPluginKeys
{
public
static
String
appId
=
""
;
public
static
final
String
SCENE
=
"scene"
;
public
static
final
String
TIMELINE
=
"timeline"
;
public
static
final
String
SESSION
=
"session"
;
public
static
final
String
FAVORITE
=
"favorite"
;
public
static
final
String
SCENE_TIMELINE
=
"WeChatScene.TIMELINE"
;
public
static
final
String
SCENE_SESSION
=
"WeChatScene.SESSION"
;
public
static
final
String
SCENE_FAVORITE
=
"WeChatScene.FAVORITE"
;
public
static
final
String
TRANSACTION
=
"transaction"
;
public
static
final
String
TEXT
=
"text"
;
...
...
android/src/main/kotlin/com/jarvan/fluwx/handler/WeChatPluginHandler.kt
浏览文件 @
65fc30a0
package
com.jarvan.fluwx.handler
import
android.util.Log
import
com.jarvan.fluwx.constant.CallResult
import
com.jarvan.fluwx.constant.WeChatPluginMethods
import
com.jarvan.fluwx.constant.WechatPluginKeys
...
...
@@ -15,6 +16,10 @@ import io.flutter.plugin.common.PluginRegistry
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import
com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import
com.tencent.mm.opensdk.modelmsg.WXMusicObject
import
kotlinx.coroutines.experimental.CommonPool
import
kotlinx.coroutines.experimental.android.UI
import
kotlinx.coroutines.experimental.async
import
kotlinx.coroutines.experimental.launch
/***
...
...
@@ -110,32 +115,56 @@ object WeChatPluginHandler {
}
private
suspend
fun
getImageByteArrayCommon
(
registrar
:
PluginRegistry
.
Registrar
?,
imagePath
:
String
):
ByteArray
{
return
async
(
CommonPool
){
ShareImageUtil
.
getImageData
(
registrar
,
imagePath
)
}.
await
()
}
private
suspend
fun
getThumbnailByteArrayCommon
(
registrar
:
PluginRegistry
.
Registrar
?,
thumbnail
:
String
):
ByteArray
{
return
async
(
CommonPool
){
WeChatThumbnailUtil
.
thumbnailForCommon
(
thumbnail
,
registrar
)
}.
await
()
}
private
fun
shareImage
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
val
imagePath
=
call
.
argument
<
String
>(
WechatPluginKeys
.
IMAGE
)
val
byteArray
=
ShareImageUtil
.
getImageData
(
registrar
,
imagePath
)
val
imgObj
=
if
(
byteArray
!=
null
)
{
WXImageObject
(
byteArray
)
}
else
{
null
}
if
(
imgObj
==
null
)
{
result
.
error
(
CallResult
.
RESULT_FILE_NOT_EXIST
,
CallResult
.
RESULT_FILE_NOT_EXIST
,
imagePath
)
return
}
val
msg
=
WXMediaMessage
()
msg
.
mediaObject
=
imgObj
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
call
.
argument
(
WechatPluginKeys
.
THUMBNAIL
),
registrar
)
launch
(
UI
){
val
byteArray
:
ByteArray
?
=
getImageByteArrayCommon
(
registrar
,
imagePath
)
val
imgObj
=
if
(
byteArray
!=
null
)
{
WXImageObject
(
byteArray
)
}
else
{
null
}
if
(
imgObj
==
null
)
{
result
.
error
(
CallResult
.
RESULT_FILE_NOT_EXIST
,
CallResult
.
RESULT_FILE_NOT_EXIST
,
imagePath
)
return
@launch
}
msg
.
title
=
call
.
argument
<
String
>(
WechatPluginKeys
.
TITLE
)
msg
.
description
=
call
.
argument
<
String
>(
WechatPluginKeys
.
DESCRIPTION
)
Log
.
e
(
"tag"
,
"${byteArray!!.size}"
)
val
msg
=
WXMediaMessage
()
msg
.
mediaObject
=
imgObj
var
thumbnail
:
String
?
=
call
.
argument
(
WechatPluginKeys
.
THUMBNAIL
)
if
(
thumbnail
.
isNullOrBlank
()){
thumbnail
=
imagePath
}
// msg.thumbData = getThumbnailByteArrayCommon(registrar,thumbnail!!)
msg
.
title
=
call
.
argument
<
String
>(
WechatPluginKeys
.
TITLE
)
msg
.
description
=
call
.
argument
<
String
>(
WechatPluginKeys
.
DESCRIPTION
)
//
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
shareMusic
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
...
...
@@ -156,6 +185,7 @@ object WeChatPluginHandler {
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
thumbnail
,
registrar
)
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
...
...
@@ -240,10 +270,10 @@ object WeChatPluginHandler {
}
private
fun
getScene
(
value
:
String
)
=
when
(
value
.
toLowerCase
()
)
{
WechatPluginKeys
.
TIMELINE
->
SendMessageToWX
.
Req
.
WXSceneTimeline
WechatPluginKeys
.
SESSION
->
SendMessageToWX
.
Req
.
WXSceneSession
WechatPluginKeys
.
FAVORITE
->
SendMessageToWX
.
Req
.
WXSceneFavorite
private
fun
getScene
(
value
:
String
)
=
when
(
value
)
{
WechatPluginKeys
.
SCENE_
TIMELINE
->
SendMessageToWX
.
Req
.
WXSceneTimeline
WechatPluginKeys
.
S
CENE_S
ESSION
->
SendMessageToWX
.
Req
.
WXSceneSession
WechatPluginKeys
.
SCENE_
FAVORITE
->
SendMessageToWX
.
Req
.
WXSceneFavorite
else
->
SendMessageToWX
.
Req
.
WXSceneTimeline
}
...
...
@@ -251,7 +281,6 @@ object WeChatPluginHandler {
msg
.
messageAction
=
call
.
argument
<
String
>(
WechatPluginKeys
.
MESSAGE_ACTION
)
msg
.
messageExt
=
call
.
argument
<
String
>(
WechatPluginKeys
.
MESSAGE_EXT
)
msg
.
mediaTagName
=
call
.
argument
<
String
>(
WechatPluginKeys
.
MEDIA_TAG_NAME
)
req
.
transaction
=
call
.
argument
(
WechatPluginKeys
.
TRANSACTION
)
req
.
scene
=
getScene
(
call
.
argument
(
WechatPluginKeys
.
SCENE
))
}
...
...
example/android/app/build.gradle
浏览文件 @
65fc30a0
...
...
@@ -59,4 +59,5 @@ dependencies {
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.1'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.1'
implementation
'com.tencent.mm.opensdk:wechat-sdk-android-with-mta:5.1.4'
}
example/android/app/src/main/AndroidManifest.xml
浏览文件 @
65fc30a0
...
...
@@ -35,5 +35,6 @@
<category
android:name=
"android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
<activity
android:name=
".wxapi.WXEntryActivity"
/>
</application>
</manifest>
example/android/app/src/main/kotlin/com/jarvan/fluwxexample/wxapi/WXEntryActivity.java
0 → 100644
浏览文件 @
65fc30a0
package
com
.
jarvan
.
fluwxexample
.
wxapi
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.widget.Button
;
import
com.jarvan.fluwx.handler.WeChatPluginHandler
;
import
com.tencent.mm.opensdk.modelbase.BaseReq
;
import
com.tencent.mm.opensdk.modelbase.BaseResp
;
import
com.tencent.mm.opensdk.openapi.IWXAPIEventHandler
;
public
class
WXEntryActivity
extends
Activity
implements
IWXAPIEventHandler
{
private
static
final
int
TIMELINE_SUPPORTED_VERSION
=
0x21020001
;
private
Button
gotoBtn
,
regBtn
,
launchBtn
,
checkBtn
,
scanBtn
;
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
}
@Override
protected
void
onNewIntent
(
Intent
intent
)
{
super
.
onNewIntent
(
intent
);
}
@Override
public
void
onReq
(
BaseReq
req
)
{
}
@Override
public
void
onResp
(
BaseResp
resp
)
{
WeChatPluginHandler
.
INSTANCE
.
onResp
(
resp
);
}
}
\ No newline at end of file
example/lib/main.dart
浏览文件 @
65fc30a0
...
...
@@ -56,8 +56,12 @@ class _MyAppState extends State<MyApp> {
child:
new
FlatButton
(
onPressed:
()
{
var
fluwx
=
Fluwx
();
fluwx
.
share
(
WeChatShareTextModel
(
text:
"share text from flutter"
,
transaction:
"hehe"
));
fluwx
.
share
(
WeChatShareImageModel
(
image:
"https://www.baidu.com/img/bd_logo1.png"
,
transaction:
"hehe"
,
title:
"from dart"
,
scene:
WeChatScene
.
SESSION
));
},
child:
new
Text
(
"share text to wechat"
)),
),
...
...
lib/src/models/wechat_share_models.dart
浏览文件 @
65fc30a0
...
...
@@ -116,7 +116,6 @@ class WeChatShareMiniProgramModel extends WeChatShareModel {
class
WeChatShareImageModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
image
;
final
String
thumbnail
;
final
String
title
;
...
...
@@ -133,7 +132,6 @@ class WeChatShareImageModel extends WeChatShareModel {
String
mediaTagName
,
this
.
title
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
image
!=
null
),
super
(
...
...
@@ -160,7 +158,6 @@ class WeChatShareImageModel extends WeChatShareModel {
class
WeChatShareMusicModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
musicUrl
;
final
String
musicLowBandUrl
;
final
String
thumbnail
;
...
...
@@ -179,7 +176,6 @@ class WeChatShareMusicModel extends WeChatShareModel {
String
messageAction
,
String
mediaTagName
,
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
musicUrl
!=
null
||
musicLowBandUrl
!=
null
),
assert
(
thumbnail
!=
null
),
...
...
@@ -208,7 +204,6 @@ class WeChatShareMusicModel extends WeChatShareModel {
class
WeChatShareVideoModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
videoUrl
;
final
String
videoLowBandUrl
;
final
String
thumbnail
;
...
...
@@ -231,7 +226,6 @@ class WeChatShareVideoModel extends WeChatShareModel {
this
.
messageAction
,
this
.
mediaTagName
,
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
videoUrl
!=
null
||
videoLowBandUrl
!=
null
),
assert
(
thumbnail
!=
null
),
...
...
@@ -260,7 +254,6 @@ class WeChatShareVideoModel extends WeChatShareModel {
class
WeChatShareWebPageModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
webPage
;
final
String
thumbnail
;
final
String
title
;
...
...
@@ -277,7 +270,6 @@ class WeChatShareWebPageModel extends WeChatShareModel {
String
messageAction
,
String
mediaTagName
,
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
webPage
!=
null
),
assert
(
thumbnail
!=
null
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论