Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
3cd11b5f
提交
3cd11b5f
authored
8月 10, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
share mini program
上级
4a9ff87c
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
95 行增加
和
46 行删除
+95
-46
WeChatPluginMethods.java
...com/jarvanmo/wechatplugin/config/WeChatPluginMethods.java
+1
-0
WeChatPluginHandler.kt
.../com/jarvanmo/wechatplugin/handler/WeChatPluginHandler.kt
+25
-33
wechat_share_models.dart
lib/src/wechat_share_models.dart
+63
-13
wechat_plugin.dart
lib/wechat_plugin.dart
+6
-0
没有找到文件。
android/src/main/kotlin/com/jarvanmo/wechatplugin/config/WeChatPluginMethods.java
浏览文件 @
3cd11b5f
...
...
@@ -14,5 +14,6 @@ public class WeChatPluginMethods {
public
static
final
String
SHARE_MUSIC
=
"shareMusic"
;
public
static
final
String
SHARE_VIDEO
=
"shareVideo"
;
public
static
final
String
SHARE_WEBSITE
=
"shareWebsite"
;
public
static
final
String
SHARE_MINI_PROGRAM
=
"shareMiniProgram"
;
}
android/src/main/kotlin/com/jarvanmo/wechatplugin/handler/WeChatPluginHandler.kt
浏览文件 @
3cd11b5f
package
com.jarvanmo.wechatplugin.handler
import
com.jarvanmo.wechatplugin.config.WeChatPluginMethods
import
com.
tencent.mm.opensdk.openapi.IWXAPI
import
com.
jarvanmo.wechatplugin.config.WechatPluginConfig
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
io.flutter.plugin.common.MethodCall
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
import
com.jarvanmo.wechatplugin.config.WechatPluginConfig
import
com.tencent.mm.opensdk.modelmsg.WXMediaMessage
import
com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject
import
com.tencent.mm.opensdk.modelmsg.WXTextObject
import
com.tencent.mm.opensdk.openapi.IWXAPI
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
...
...
@@ -34,9 +35,8 @@ object WeChatPluginHandler {
fun
handle
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
when
(
call
.
method
)
{
WeChatPluginMethods
.
SHARE_TEXT
->
{
shareText
(
call
)
}
WeChatPluginMethods
.
SHARE_TEXT
->
shareText
(
call
)
WeChatPluginMethods
.
SHARE_MINI_PROGRAM
->
shareMiniProgram
(
call
)
else
->
{
result
.
notImplemented
()
}
...
...
@@ -58,45 +58,37 @@ object WeChatPluginHandler {
}
fun
onResp
(
resp
:
BaseResp
)
{
var
code
=-
99
when
(
resp
.
errCode
)
{
BaseResp
.
ErrCode
.
ERR_OK
->
{
code
=
0
}
BaseResp
.
ErrCode
.
ERR_COMM
->
{
code
=
1
}
BaseResp
.
ErrCode
.
ERR_USER_CANCEL
->
{
code
=
2
}
BaseResp
.
ErrCode
.
ERR_SENT_FAILED
->
{
code
=
-
3
}
BaseResp
.
ErrCode
.
ERR_AUTH_DENIED
->
{
code
=
-
4
}
BaseResp
.
ErrCode
.
ERR_UNSUPPORT
->
{
code
=
-
5
}
private
fun
shareMiniProgram
(
call
:
MethodCall
){
val
miniProgramObj
=
WXMiniProgramObject
()
miniProgramObj
.
webpageUrl
=
call
.
argument
(
"webPageUrl"
)
// 兼容低版本的网页链接
miniProgramObj
.
miniprogramType
=
call
.
argument
(
"miniProgramType"
)
// 正式版:0,测试版:1,体验版:2
miniProgramObj
.
userName
=
call
.
argument
(
"userName"
)
// 小程序原始id
miniProgramObj
.
path
=
call
.
argument
(
"path"
)
//小程序页面路径
val
msg
=
WXMediaMessage
(
miniProgramObj
)
msg
.
title
=
call
.
argument
(
"title"
)
// 小程序消息title
msg
.
description
=
call
.
argument
(
"description"
)
// 小程序消息desc
// msg.thumbData = getThumb() // 小程序消息封面图片,小于128k
else
->
{
}
}
val
req
=
SendMessageToWX
.
Req
()
req
.
transaction
=
call
.
argument
(
"transaction"
)
req
.
message
=
msg
req
.
scene
=
call
.
argument
(
"scene"
)
// 目前支持会话
wxApi
.
sendReq
(
req
)
}
fun
onResp
(
resp
:
BaseResp
)
{
val
result
=
mapOf
(
"errStr"
to
resp
.
errStr
,
"transaction"
to
resp
.
transaction
,
"type"
to
resp
.
type
,
"errCode"
to
c
ode
,
"errCode"
to
resp
.
errC
ode
,
"openId"
to
resp
.
openId
)
channel
?.
invokeMethod
(
WeChatPluginMethods
.
WE_CHAT_RESPONSE
,
result
)
}
...
...
lib/src/wechat_share_models.dart
浏览文件 @
3cd11b5f
import
'package:wechat_plugin/src/wechat_scene.dart'
;
class
WeChatShareTextModel
{
class
WeChatShareTextModel
{
final
String
text
;
final
String
transaction
;
final
WeChatScene
scene
;
final
WeChatScene
scene
;
WeChatShareTextModel
({
String
text
,
String
transaction
,
WeChatScene
scene
}):
this
.
text
=
text
??
""
,
this
.
transaction
=
transaction
??
"text"
,
WeChatShareTextModel
({
String
text
,
String
transaction
,
WeChatScene
scene
})
:
this
.
text
=
text
??
""
,
this
.
transaction
=
transaction
??
"text"
,
this
.
scene
=
scene
??
WeChatScene
.
TIMELINE
;
Map
toMap
()
{
return
{
"text"
:
text
,
"transaction"
:
transaction
,
"scene"
:
scene
.
toString
()
};
}
}
class
WeChatMiniProgramModel
{
static
const
int
MINI_PTOGRAM_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
;
final
String
path
;
final
String
title
;
final
String
description
;
final
String
transaction
;
final
String
thumbnail
;
WeChatMiniProgramModel
(
{
this
.
webPageUrl
,
int
miniProgramType
,
this
.
userName
,
this
.
path
,
this
.
title
,
this
.
description
,
this
.
thumbnail
,
String
transaction
})
:
this
.
transaction
=
transaction
??
"miniProgram"
,
this
.
miniProgramType
=
miniProgramType
??
MINI_PTOGRAM_TYPE_RELEASE
,
assert
(
webPageUrl
!=
null
&&
webPageUrl
.
isNotEmpty
),
assert
(
userName
!=
null
&&
userName
.
isNotEmpty
)
,
assert
(
path
!=
null
&&
path
.
isNotEmpty
);
Map
toMap
(){
return
{
"text"
:
text
,
"transaction"
:
transaction
,
"scene"
:
scene
.
toString
()};
return
{
'webPageUrl'
:
webPageUrl
,
"miniProgramType"
:
miniProgramType
,
"userName"
:
userName
,
"path"
:
path
,
"title"
:
title
,
"description"
:
description
,
"transaction"
:
transaction
,
"scene"
:
scene
,
"thumbnail"
:
thumbnail
};
}
}
\ No newline at end of file
}
lib/wechat_plugin.dart
浏览文件 @
3cd11b5f
...
...
@@ -31,6 +31,12 @@ class WechatPlugin {
return
await
_channel
.
invokeMethod
(
"shareText"
,
model
.
toMap
());
}
static
Future
shareMiniProgram
(
WeChatMiniProgramModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"shareMiniProgram"
,
model
.
toMap
());
}
static
Future
<
dynamic
>
_handler
(
MethodCall
methodCall
){
if
(
"onWeChatResponse"
==
methodCall
.
method
){
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论