Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
e0c8f572
提交
e0c8f572
authored
8月 15, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.better api 2.add some params support in android
上级
ad4db98a
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
225 行增加
和
116 行删除
+225
-116
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+1
-2
WechatPluginKeys.java
...in/kotlin/com/jarvan/fluwx/constant/WechatPluginKeys.java
+4
-0
WeChatPluginHandler.kt
...in/kotlin/com/jarvan/fluwx/handler/WeChatPluginHandler.kt
+23
-8
main.dart
example/lib/main.dart
+8
-9
fluwx.dart
lib/fluwx.dart
+1
-1
wechat_plugin.dart
lib/src/wechat_plugin.dart
+26
-34
wechat_share_models.dart
lib/src/wechat_share_models.dart
+162
-62
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
e0c8f572
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
import
com.tencent.mm.opensdk.openapi.WXAPIFactory
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
import
io.flutter.plugin.common.MethodChannel.MethodCallHandler
import
io.flutter.plugin.common.MethodChannel.Result
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.PluginRegistry.Registrar
class
FluwxPlugin
(
private
var
registrar
:
Registrar
)
:
MethodCallHandler
{
...
...
android/src/main/kotlin/com/jarvan/fluwx/constant/WechatPluginKeys.java
浏览文件 @
e0c8f572
...
...
@@ -22,4 +22,8 @@ public class WechatPluginKeys {
public
static
final
String
DESCRIPTION
=
"description"
;
public
static
final
String
PACKAGE
=
"?package="
;
public
static
final
String
MESSAGE_EXT
=
"messageExt"
;
public
static
final
String
MEDIA_TAG_NAME
=
"mediaTagName "
;
public
static
final
String
MESSAGE_ACTION
=
"messageAction"
;
}
android/src/main/kotlin/com/jarvan/fluwx/handler/WeChatPluginHandler.kt
浏览文件 @
e0c8f572
...
...
@@ -72,7 +72,13 @@ object WeChatPluginHandler {
msg
.
description
=
call
.
argument
(
WechatPluginKeys
.
TEXT
)
val
req
=
SendMessageToWX
.
Req
()
req
.
message
=
msg
setCommonArguments
(
call
,
req
)
msg
.
description
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
)
setCommonArguments
(
call
,
req
,
msg
)
wxApi
?.
sendReq
(
req
)
result
.
success
(
true
)
...
...
@@ -99,7 +105,7 @@ object WeChatPluginHandler {
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
)
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
wxApi
?.
sendReq
(
req
)
result
.
success
(
true
)
...
...
@@ -123,10 +129,14 @@ object WeChatPluginHandler {
val
msg
=
WXMediaMessage
()
msg
.
mediaObject
=
imgObj
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
call
.
argument
(
WechatPluginKeys
.
THUMBNAIL
),
registrar
)
msg
.
title
=
call
.
argument
<
String
>(
WechatPluginKeys
.
TITLE
)
msg
.
description
=
call
.
argument
<
String
>(
WechatPluginKeys
.
DESCRIPTION
)
//
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
)
//
req.message = msg
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
wxApi
?.
sendReq
(
req
)
result
.
success
(
true
)
...
...
@@ -151,7 +161,7 @@ object WeChatPluginHandler {
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
)
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
wxApi
?.
sendReq
(
req
)
result
.
success
(
true
)
...
...
@@ -175,8 +185,9 @@ object WeChatPluginHandler {
msg
.
thumbData
=
WeChatThumbnailUtil
.
thumbnailForCommon
(
thumbnail
,
registrar
)
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
)
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
wxApi
?.
sendReq
(
req
)
result
.
success
(
true
)
...
...
@@ -197,7 +208,7 @@ object WeChatPluginHandler {
}
val
req
=
SendMessageToWX
.
Req
()
setCommonArguments
(
call
,
req
)
setCommonArguments
(
call
,
req
,
msg
)
req
.
message
=
msg
wxApi
?.
sendReq
(
req
)
result
.
success
(
true
)
...
...
@@ -242,7 +253,11 @@ object WeChatPluginHandler {
else
->
SendMessageToWX
.
Req
.
WXSceneTimeline
}
private
fun
setCommonArguments
(
call
:
MethodCall
,
req
:
SendMessageToWX
.
Req
)
{
private
fun
setCommonArguments
(
call
:
MethodCall
,
req
:
SendMessageToWX
.
Req
,
msg
:
WXMediaMessage
)
{
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/lib/main.dart
浏览文件 @
e0c8f572
...
...
@@ -18,12 +18,11 @@ class _MyAppState extends State<MyApp> {
void
initState
()
{
super
.
initState
();
// initPlatformState();
Fluwx
.
init
(
"wxd930ea5d5a258f4f"
).
then
((
_
){
Fluwx
.
init
(
"wxd930ea5d5a258f4f"
).
then
((
_
)
{
print
(
"succes"
);
},
onError:
(
value
)
{
},
onError:
(
value
)
{
print
(
"--->
$value
"
);
});
}
// Platform messages are asynchronous, so we initialize in an async method.
...
...
@@ -54,15 +53,15 @@ class _MyAppState extends State<MyApp> {
title:
const
Text
(
'Plugin example app'
),
),
body:
new
Center
(
child:
new
FlatButton
(
onPressed:
()
{
child:
new
FlatButton
(
onPressed:
()
{
var
fluwx
=
Fluwx
();
fluwx
.
shareText
(
WeChatShareTextModel
(
text:
"share text from flutter"
,
transaction:
"hehe"
));
},
child:
new
Text
(
"share text to wechat"
)),
fluwx
.
share
(
WeChatShareTextModel
(
text:
"share text from flutter"
,
transaction:
"hehe"
));
},
child:
new
Text
(
"share text to wechat"
)),
),
),
);
}
}
lib/fluwx.dart
浏览文件 @
e0c8f572
library
fluw
e
;
library
fluw
x
;
export
'src/wechat_plugin.dart'
;
export
'src/wechat_share_models.dart'
;
export
'src/wechat_scene.dart'
;
...
...
lib/src/wechat_plugin.dart
浏览文件 @
e0c8f572
...
...
@@ -4,56 +4,48 @@ import 'package:flutter/services.dart';
import
'package:fluwx/src/wechat_share_models.dart'
;
class
Fluwx
{
static
const
Map
<
Type
,
String
>
_shareModelMethodMapper
=
{
WeChatShareTextModel:
"shareText"
,
WeChatShareImageModel:
"shareImage"
,
WeChatShareMusicModel:
"shareMusic"
,
WeChatShareVideoModel:
"shareVideo"
,
WeChatShareWebPageModel:
"shareWebPage"
,
WeChatShareMiniProgramModel:
"shareMiniProgram"
};
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'fluwx'
);
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'fluwx'
);
StreamController
<
Map
>
_responseStreamController
=
new
StreamController
.
broadcast
();
StreamController
<
Map
>
_responseStreamController
=
new
StreamController
.
broadcast
();
Stream
<
Map
>
get
weChatResponseUpdate
=>
_responseStreamController
.
stream
;
Stream
<
Map
>
get
weChatResponseUpdate
=>
_responseStreamController
.
stream
;
static
Future
init
(
String
appId
)
async
{
return
await
_channel
.
invokeMethod
(
"initWeChat"
,
appId
);
static
Future
init
(
String
appId
)
async
{
return
await
_channel
.
invokeMethod
(
"initWeChat"
,
appId
);
}
void
listen
()
{
void
listen
()
{
_channel
.
setMethodCallHandler
(
_handler
);
}
void
dispose
()
{
void
dispose
()
{
_responseStreamController
.
close
();
}
Future
shareText
(
WeChatShareTextModel
model
)
async
{
await
_channel
.
invokeMethod
(
"shareText"
,
model
.
toMap
());
}
Future
shareMiniProgram
(
WeChatShareMiniProgramModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"shareMiniProgram"
,
model
.
toMap
());
}
Future
shareMusic
(
WeChatShareMusicModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"shareMusic"
,
model
.
toMap
());
}
Future
shareVideo
(
WeChatShareVideoModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"shareVideo"
,
model
.
toMap
());
}
Future
shareWebPage
(
WeChatShareWebPageModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"shareWebPage"
,
model
.
toMap
());
Future
share
(
WeChatShareModel
model
)
async
{
if
(
_shareModelMethodMapper
.
containsKey
(
model
.
runtimeType
))
{
return
await
_channel
.
invokeMethod
(
_shareModelMethodMapper
[
model
.
runtimeType
],
model
.
toMap
());
}
else
{
return
Future
.
error
(
"no method mapper found[
${model.runtimeType}
]"
);
}
}
Future
<
dynamic
>
_handler
(
MethodCall
methodCall
){
if
(
"onWeChatResponse"
==
methodCall
.
method
){
Future
<
dynamic
>
_handler
(
MethodCall
methodCall
)
{
if
(
"onWeChatResponse"
==
methodCall
.
method
)
{
_responseStreamController
.
add
(
methodCall
.
arguments
);
}
return
Future
.
value
(
true
);
return
Future
.
value
(
true
);
}
}
lib/src/wechat_share_models.dart
浏览文件 @
e0c8f572
...
...
@@ -4,31 +4,63 @@ const String _scene = "scene";
const
String
_transaction
=
"transaction"
;
const
String
_thumbnail
=
"thumbnail"
;
const
String
_title
=
"title"
;
const
String
_description
=
"description"
;
const
String
_description
=
"description"
;
const
String
_messageExt
=
"messageExt"
;
const
String
_mediaTagName
=
"mediaTagName "
;
const
String
_messageAction
=
"messageAction"
;
abstract
class
WeChatShareModel
{
final
String
messageExt
;
final
String
messageAction
;
final
String
mediaTagName
;
final
WeChatScene
scene
;
WeChatShareModel
(
{
this
.
messageExt
,
this
.
messageAction
,
this
.
mediaTagName
,
this
.
scene
:
WeChatScene
.
SESSION
});
Map
toMap
();
}
class
WeChatShareTextModel
{
class
WeChatShareTextModel
extends
WeChatShareModel
{
final
String
text
;
final
String
transaction
;
final
WeChatScene
scene
;
WeChatShareTextModel
({
String
text
,
String
transaction
,
WeChatScene
scene
})
WeChatShareTextModel
(
{
String
text
,
String
transaction
,
WeChatScene
scene
,
String
messageExt
,
String
messageAction
,
String
mediaTagName
})
:
this
.
text
=
text
??
""
,
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
;
super
(
mediaTagName:
mediaTagName
,
messageAction:
messageAction
,
messageExt:
messageExt
,
scene:
scene
);
@override
Map
toMap
()
{
return
{
"text"
:
text
,
_transaction:
transaction
,
_scene:
scene
.
toString
()};
return
{
"text"
:
text
,
_transaction:
transaction
,
_scene:
scene
.
toString
(),
_messageExt:
messageExt
,
_messageAction:
messageAction
,
_mediaTagName:
mediaTagName
};
}
}
class
WeChatShareMiniProgramModel
{
class
WeChatShareMiniProgramModel
extends
WeChatShareModel
{
static
const
int
MINI_PROGRAM_TYPE_RELEASE
=
0
;
static
const
int
MINI_PROGRAM_TYPE_TEST
=
1
;
static
const
int
MINI_PROGRAM_TYPE_PREVIEW
=
2
;
final
WeChatScene
scene
=
WeChatScene
.
SESSION
;
final
String
webPageUrl
;
final
int
miniProgramType
;
final
String
userName
;
...
...
@@ -50,13 +82,23 @@ class WeChatShareMiniProgramModel {
this
.
title
,
this
.
description
,
this
.
thumbnail
,
String
transaction
})
String
transaction
,
WeChatScene
scene
,
String
messageExt
,
String
messageAction
,
String
mediaTagName
})
:
this
.
transaction
=
transaction
??
"miniProgram"
,
this
.
miniProgramType
=
miniProgramType
??
MINI_PROGRAM_TYPE_RELEASE
,
assert
(
webPageUrl
!=
null
&&
webPageUrl
.
isNotEmpty
),
assert
(
userName
!=
null
&&
userName
.
isNotEmpty
),
assert
(
path
!=
null
&&
path
.
isNotEmpty
);
assert
(
path
!=
null
&&
path
.
isNotEmpty
),
super
(
mediaTagName:
mediaTagName
,
messageAction:
messageAction
,
messageExt:
messageExt
,
scene:
scene
);
@override
Map
toMap
()
{
return
{
'webPageUrl'
:
webPageUrl
,
...
...
@@ -72,31 +114,51 @@ class WeChatShareMiniProgramModel {
}
}
class
WeChatShareImageModel
{
class
WeChatShareImageModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
image
;
final
String
thumbnail
;
final
String
title
;
final
String
description
;
WeChatShareImageModel
(
{
String
transaction
,
WeChatScene
scene
,
this
.
image
,
String
thumbnail
})
{
String
transaction
,
this
.
image
,
this
.
description
,
String
thumbnail
,
WeChatScene
scene
,
String
messageExt
,
String
messageAction
,
String
mediaTagName
,
this
.
title
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
image
!=
null
);
assert
(
image
!=
null
),
super
(
mediaTagName:
mediaTagName
,
messageAction:
messageAction
,
messageExt:
messageExt
,
scene:
scene
);
@override
Map
toMap
()
{
return
{
_transaction:
transaction
,
_scene:
scene
.
toString
(),
"image"
:
image
,
_thumbnail:
thumbnail
_thumbnail:
thumbnail
,
_mediaTagName:
mediaTagName
,
_messageAction:
messageAction
,
_messageExt:
messageExt
,
_title:
title
,
_description:
description
};
}
}
class
WeChatShareMusicModel
{
class
WeChatShareMusicModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
musicUrl
;
...
...
@@ -105,35 +167,46 @@ class WeChatShareMusicModel {
final
String
title
;
final
String
description
;
WeChatShareMusicModel
(
{
String
transaction
,
WeChatScene
scene
,
this
.
musicUrl
,
this
.
musicLowBandUrl
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
})
:
this
.
transaction
=
transaction
??
"text"
,
WeChatShareMusicModel
({
String
transaction
,
this
.
musicUrl
,
this
.
musicLowBandUrl
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
,
WeChatScene
scene
,
String
messageExt
,
String
messageAction
,
String
mediaTagName
,
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
musicUrl
!=
null
||
musicLowBandUrl
!=
null
),
assert
(
thumbnail
!=
null
);
assert
(
musicUrl
!=
null
||
musicLowBandUrl
!=
null
),
assert
(
thumbnail
!=
null
),
super
(
mediaTagName:
mediaTagName
,
messageAction:
messageAction
,
messageExt:
messageExt
,
scene:
scene
);
@override
Map
toMap
()
{
return
{
_transaction:
transaction
,
_scene:
scene
.
toString
(),
"musicUrl"
:
musicUrl
,
"musicLowBandUrl"
:
musicLowBandUrl
,
"musicLowBandUrl"
:
musicLowBandUrl
,
_thumbnail:
thumbnail
,
_title:
title
,
_description:
description
,
_title:
title
,
_description:
description
,
_mediaTagName:
mediaTagName
,
_messageAction:
messageAction
,
_messageExt:
messageExt
,
};
}
}
class
WeChatShareVideoModel
{
class
WeChatShareVideoModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
videoUrl
;
...
...
@@ -142,34 +215,50 @@ class WeChatShareVideoModel {
final
String
title
;
final
String
description
;
WeChatShareVideoModel
(
{
String
transaction
,
WeChatScene
scene
,
this
.
videoUrl
,
this
.
videoLowBandUrl
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
})
:
this
.
transaction
=
transaction
??
"text"
,
final
String
messageExt
;
final
String
messageAction
;
final
String
mediaTagName
;
WeChatShareVideoModel
({
String
transaction
,
WeChatScene
scene
,
this
.
videoUrl
,
this
.
videoLowBandUrl
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
,
this
.
messageExt
,
this
.
messageAction
,
this
.
mediaTagName
,
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
videoUrl
!=
null
||
videoLowBandUrl
!=
null
),
assert
(
thumbnail
!=
null
);
assert
(
videoUrl
!=
null
||
videoLowBandUrl
!=
null
),
assert
(
thumbnail
!=
null
),
super
(
mediaTagName:
mediaTagName
,
messageAction:
messageAction
,
messageExt:
messageExt
,
scene:
scene
);
@override
Map
toMap
()
{
return
{
_transaction:
transaction
,
_scene:
scene
.
toString
(),
"videoUrl"
:
videoUrl
,
"videoLowBandUrl"
:
videoLowBandUrl
,
"videoLowBandUrl"
:
videoLowBandUrl
,
_thumbnail:
thumbnail
,
_title:
title
,
_description:
description
_title:
title
,
_description:
description
,
_mediaTagName:
mediaTagName
,
_messageAction:
messageAction
,
_messageExt:
messageExt
,
};
}
}
class
WeChatShareWebPageModel
{
class
WeChatShareWebPageModel
extends
WeChatShareModel
{
final
String
transaction
;
final
WeChatScene
scene
;
final
String
webPage
;
...
...
@@ -177,27 +266,39 @@ class WeChatShareWebPageModel {
final
String
title
;
final
String
description
;
WeChatShareWebPageModel
(
{
String
transaction
,
WeChatScene
scene
,
this
.
webPage
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
})
:
this
.
transaction
=
transaction
??
"text"
,
WeChatShareWebPageModel
({
String
transaction
,
this
.
webPage
,
this
.
title
:
""
,
this
.
description
:
""
,
String
thumbnail
,
WeChatScene
scene
,
String
messageExt
,
String
messageAction
,
String
mediaTagName
,
})
:
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
,
this
.
thumbnail
=
thumbnail
??
""
,
assert
(
webPage
!=
null
),
assert
(
thumbnail
!=
null
);
assert
(
webPage
!=
null
),
assert
(
thumbnail
!=
null
),
super
(
mediaTagName:
mediaTagName
,
messageAction:
messageAction
,
messageExt:
messageExt
,
scene:
scene
);
@override
Map
toMap
()
{
return
{
_transaction:
transaction
,
_scene:
scene
.
toString
(),
"webPage"
:
webPage
,
_thumbnail:
thumbnail
,
_title:
title
,
_description:
description
_title:
title
,
_description:
description
,
_mediaTagName:
mediaTagName
,
_messageAction:
messageAction
,
_messageExt:
messageExt
,
};
}
}
\ No newline at end of file
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论