Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
57549978
提交
57549978
authored
12月 20, 2018
作者:
Caijinglong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
android example 一次性订阅的原生代码
上级
0b1311ec
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
146 行增加
和
12 行删除
+146
-12
FluwxPlugin.kt
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
+8
-2
WeChatPluginMethods.java
...kotlin/com/jarvan/fluwx/constant/WeChatPluginMethods.java
+4
-2
FluwxResponseHandler.kt
...n/kotlin/com/jarvan/fluwx/handler/FluwxResponseHandler.kt
+15
-1
FluwxSubscribeMsgHandler.kt
...tlin/com/jarvan/fluwx/handler/FluwxSubscribeMsgHandler.kt
+28
-0
main.dart
example/lib/main.dart
+15
-7
subscribe_message_page.dart
example/lib/subscribe_message_page.dart
+76
-0
没有找到文件。
android/src/main/kotlin/com/jarvan/fluwx/FluwxPlugin.kt
浏览文件 @
57549978
...
...
@@ -39,6 +39,7 @@ class FluwxPlugin(private val registrar: Registrar, private val channel: MethodC
private
val
fluwxAuthHandler
=
FluwxAuthHandler
()
private
val
fluwxPayHandler
=
FluwxPayHandler
()
private
val
fluwxLaunchMiniProgramHandler
=
FluwxLaunchMiniProgramHandler
()
private
val
fluwxSubscribeMsgHandler
=
FluwxSubscribeMsgHandler
()
init
{
fluwxShareHandler
.
setRegistrar
(
registrar
)
...
...
@@ -73,8 +74,13 @@ class FluwxPlugin(private val registrar: Registrar, private val channel: MethodC
return
}
if
(
call
.
method
==
WeChatPluginMethods
.
LAUNCH_MINI_PROGRAM
){
fluwxLaunchMiniProgramHandler
.
launchMiniProgram
(
call
,
result
)
if
(
call
.
method
==
WeChatPluginMethods
.
LAUNCH_MINI_PROGRAM
)
{
fluwxLaunchMiniProgramHandler
.
launchMiniProgram
(
call
,
result
)
return
}
if
(
WeChatPluginMethods
.
SUBSCRIBE_MSG
==
call
.
method
)
{
fluwxSubscribeMsgHandler
.
subScribeMsg
(
call
,
result
)
return
}
...
...
android/src/main/kotlin/com/jarvan/fluwx/constant/WeChatPluginMethods.java
浏览文件 @
57549978
...
...
@@ -9,7 +9,8 @@ public class WeChatPluginMethods {
public
static
final
String
REGISTER_APP
=
"registerApp"
;
public
static
final
String
UNREGISTER_APP
=
"unregisterApp"
;
public
static
final
String
WE_CHAT_SHARE_RESPONSE
=
"onShareResponse"
;
public
static
final
String
WE_CHAT_LAUNCHMINIPROGRAM_RESPONSE
=
"onLaunchMiniProgramResponse"
;
public
static
final
String
WE_CHAT_LAUNCHMINIPROGRAM_RESPONSE
=
"onLaunchMiniProgramResponse"
;
public
static
final
String
ON_SUBSCRIBE_MSG_RESP
=
"onSubscribeMsgResp"
;
public
static
final
String
IS_WE_CHAT_INSTALLED
=
"isWeChatInstalled"
;
...
...
@@ -20,8 +21,9 @@ public class WeChatPluginMethods {
public
static
final
String
SHARE_WEB_PAGE
=
"shareWebPage"
;
public
static
final
String
SHARE_MINI_PROGRAM
=
"shareMiniProgram"
;
public
static
final
String
LAUNCH_MINI_PROGRAM
=
"launchMiniProgram"
;
public
static
final
String
LAUNCH_MINI_PROGRAM
=
"launchMiniProgram"
;
public
static
final
String
PAY
=
"payWithFluwx"
;
public
static
final
String
WE_CHAT_PAY_RESPONSE
=
"onPayResponse"
;
public
static
final
String
SUBSCRIBE_MSG
=
"subscribeMsg"
;
}
android/src/main/kotlin/com/jarvan/fluwx/handler/FluwxResponseHandler.kt
浏览文件 @
57549978
...
...
@@ -19,6 +19,7 @@ import android.util.Log
import
com.jarvan.fluwx.constant.WeChatPluginMethods
import
com.jarvan.fluwx.constant.WechatPluginKeys
import
com.tencent.mm.opensdk.modelbase.BaseResp
import
com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import
com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
import
com.tencent.mm.opensdk.modelmsg.SendAuth
import
com.tencent.mm.opensdk.modelmsg.SendMessageToWX
...
...
@@ -40,16 +41,29 @@ object FluwxResponseHandler {
fun
handleResponse
(
response
:
BaseResp
)
{
Log
.
e
(
"tag"
,
"heeeeee"
)
Log
.
e
(
"tag"
,
"heeeeee"
)
when
(
response
)
{
is
SendAuth
.
Resp
->
handleAuthResponse
(
response
)
is
SendMessageToWX
.
Resp
->
handleSendMessageResp
(
response
)
is
PayResp
->
handlePayResp
(
response
)
is
WXLaunchMiniProgram
.
Resp
->
handleLaunchMiniProgramResponse
(
response
)
is
SubscribeMessage
.
Resp
->
handleSubscribeMessage
(
response
)
}
}
private
fun
handleSubscribeMessage
(
response
:
SubscribeMessage
.
Resp
)
{
val
result
=
mapOf
(
"openid"
to
response
.
openId
,
"templateId"
to
response
.
templateID
,
"action"
to
response
.
action
,
"reserved"
to
response
.
reserved
,
"scene"
to
response
.
scene
)
channel
?.
invokeMethod
(
WeChatPluginMethods
.
ON_SUBSCRIBE_MSG_RESP
,
result
)
}
private
fun
handleLaunchMiniProgramResponse
(
response
:
WXLaunchMiniProgram
.
Resp
)
{
val
result
=
mutableMapOf
(
errStr
to
response
.
errStr
,
...
...
android/src/main/kotlin/com/jarvan/fluwx/handler/FluwxSubscribeMsgHandler.kt
0 → 100644
浏览文件 @
57549978
package
com.jarvan.fluwx.handler
import
com.tencent.mm.opensdk.modelbiz.SubscribeMessage
import
io.flutter.plugin.common.MethodCall
import
io.flutter.plugin.common.MethodChannel
/// create 2018/12/20 by cai
class
FluwxSubscribeMsgHandler
{
fun
subScribeMsg
(
call
:
MethodCall
,
result
:
MethodChannel
.
Result
)
{
val
appId
=
call
.
argument
<
String
>(
"appId"
)
val
scene
=
call
.
argument
<
Int
>(
"scene"
)
val
templateId
=
call
.
argument
<
String
>(
"templateId"
)
val
reserved
=
call
.
argument
<
String
>(
"reserved"
)
val
req
=
SubscribeMessage
.
Req
()
req
.
openId
=
appId
req
.
scene
=
scene
!!
req
.
reserved
=
reserved
req
.
templateID
=
templateId
val
b
=
WXAPiHandler
.
wxApi
?.
sendReq
(
req
)
result
.
success
(
b
)
}
}
\ No newline at end of file
example/lib/main.dart
浏览文件 @
57549978
...
...
@@ -2,6 +2,7 @@ import 'dart:async';
import
'package:flutter/material.dart'
;
import
'package:fluwx/fluwx.dart'
as
fluwx
;
import
'package:fluwx_example/subscribe_message_page.dart'
;
import
'pay_page.dart'
;
import
'send_auth.dart'
;
...
...
@@ -12,6 +13,7 @@ import 'share_text_image.dart';
import
'share_video_page.dart'
;
import
'share_web_page.dart'
;
import
'package:fluwx_example/launch_mini_program_page.dart'
;
void
main
(
)
=>
runApp
(
new
MyApp
());
class
MyApp
extends
StatefulWidget
{
...
...
@@ -23,13 +25,11 @@ class _MyAppState extends State<MyApp> {
@override
void
initState
()
{
super
.
initState
();
fluwx
.
register
(
appId:
"wxd930ea5d5a258f4f"
,
doOnAndroid:
true
,
doOnIOS:
true
,
enableMTA:
false
);
fluwx
.
register
(
appId:
"wxd930ea5d5a258f4f"
,
doOnAndroid:
true
,
doOnIOS:
true
,
enableMTA:
false
);
}
// Platform messages are asynchronous, so we initialize in an async method.
Future
<
void
>
initPlatformState
()
async
{
}
Future
<
void
>
initPlatformState
()
async
{}
@override
Widget
build
(
BuildContext
context
)
{
...
...
@@ -43,15 +43,15 @@ class _MyAppState extends State<MyApp> {
"sendAuth"
:
(
context
)
=>
SendAuthPage
(),
"shareMiniProgram"
:
(
context
)
=>
ShareMiniProgramPage
(),
"pay"
:
(
context
)
=>
PayPage
(),
"launchMiniProgram"
:
(
context
)
=>
LaunchMiniProgramPage
()
"launchMiniProgram"
:
(
context
)
=>
LaunchMiniProgramPage
(),
"subscribeMessage"
:
(
ctx
)
=>
SubscribeMessagePage
(),
},
home:
new
Scaffold
(
appBar:
new
AppBar
(
title:
const
Text
(
'Plugin example app'
),
),
body:
ShareSelectorPage
()),
)
;
);
}
}
...
...
@@ -133,6 +133,14 @@ class ShareSelectorPage extends StatelessWidget {
},
child:
const
Text
(
"Launch MiniProgram"
)),
),
Padding
(
padding:
const
EdgeInsets
.
all
(
8.0
),
child:
new
OutlineButton
(
onPressed:
()
{
Navigator
.
of
(
context
).
pushNamed
(
"subscribeMessage"
);
},
child:
const
Text
(
"SubscribeMessage"
)),
),
],
),
);
...
...
example/lib/subscribe_message_page.dart
0 → 100644
浏览文件 @
57549978
import
'package:flutter/material.dart'
;
import
'package:fluwx/fluwx.dart'
as
fluwx
;
class
SubscribeMessagePage
extends
StatefulWidget
{
@override
_SubscribeMessagePageState
createState
()
=>
_SubscribeMessagePageState
();
}
/// see wechat [document](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list&t=resource/res_list&verify=1&id=open1500434436_aWfqW&token=&lang=zh_CN)
class
_SubscribeMessagePageState
extends
State
<
SubscribeMessagePage
>
{
TextEditingController
appId
=
TextEditingController
(
text:
"wx316f9c82e99ac105"
);
TextEditingController
scene
=
TextEditingController
(
text:
"1"
);
TextEditingController
templateId
=
TextEditingController
(
text:
"cm_vM2k3IjHcYbkGUeAfL6Fja_7Pgv4Hx_q4tA253Ss"
);
TextEditingController
reserved
=
TextEditingController
(
text:
"123"
);
@override
void
initState
()
{
super
.
initState
();
fluwx
.
responseFromSubscribeMsg
.
listen
((
resp
)
{
print
(
"resp =
$resp
"
);
});
}
@override
void
dispose
()
{
appId
.
dispose
();
scene
.
dispose
();
templateId
.
dispose
();
reserved
.
dispose
();
super
.
dispose
();
}
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
appBar:
AppBar
(
title:
Text
(
'SubscribeMessagePage'
),
),
body:
Container
(
child:
Column
(
children:
<
Widget
>[
_buildTextField
(
title:
"appId"
,
textEditController:
appId
),
_buildTextField
(
title:
"scene"
,
textEditController:
scene
),
_buildTextField
(
title:
"templateId"
,
textEditController:
templateId
),
_buildTextField
(
title:
"reserved"
,
textEditController:
reserved
),
FlatButton
(
child:
Text
(
'request once subscribe message'
),
onPressed:
_requestSubMsg
,
),
],
),
),
);
}
Widget
_buildTextField
({
String
title
,
TextEditingController
textEditController
,
})
{
return
TextField
(
decoration:
InputDecoration
(
labelText:
title
,
),
controller:
textEditController
,
);
}
void
_requestSubMsg
()
{
fluwx
.
subscribeMsg
(
appId:
appId
.
text
,
scene:
int
.
tryParse
(
scene
.
text
)
??
1
,
templateId:
templateId
.
text
,
reserved:
reserved
.
text
,
);
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论