Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-fluwx
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
openSourceLibrary
clx-fluwx
Commits
e9c2bc6d
提交
e9c2bc6d
authored
8月 27, 2018
作者:
JarvanMo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: response api changed
上级
1a3a8678
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
43 行增加
和
54 行删除
+43
-54
send_auth.dart
example/lib/send_auth.dart
+1
-1
fluwx_class.dart
lib/src/fluwx_class.dart
+29
-53
wechat_response.dart
lib/src/models/wechat_response.dart
+13
-0
没有找到文件。
example/lib/send_auth.dart
浏览文件 @
e9c2bc6d
...
...
@@ -14,7 +14,7 @@ class _SendAuthPageState extends State<SendAuthPage> {
void
initState
()
{
super
.
initState
();
_fluwx
=
new
Fluwx
();
_fluwx
.
response
FromAuth
.
listen
((
data
){
_fluwx
.
response
.
listen
((
data
){
setState
(()
{
_result
=
data
.
toString
();
});
...
...
lib/src/fluwx_class.dart
浏览文件 @
e9c2bc6d
...
...
@@ -6,6 +6,26 @@ import 'models/flutter_register_model.dart';
import
'models/wechat_share_models.dart'
;
import
'models/wechat_send_auth_model.dart'
;
import
'models/wechat_pay_model.dart'
;
import
'models/wechat_response.dart'
;
StreamController
<
WeChatResponse
>
_responseController
=
new
StreamController
.
broadcast
();
final
MethodChannel
_channel
=
const
MethodChannel
(
'com.jarvanmo/fluwx'
)
..
setMethodCallHandler
(
_handler
);
Future
<
dynamic
>
_handler
(
MethodCall
methodCall
)
{
if
(
"onShareResponse"
==
methodCall
.
method
)
{
_responseController
.
add
(
WeChatResponse
(
methodCall
.
arguments
,
ResponseType
.
SHARE
));
}
else
if
(
"onAuthResponse"
==
methodCall
.
method
)
{
_responseController
.
add
(
WeChatResponse
(
methodCall
.
arguments
,
ResponseType
.
AUTH
));
}
else
if
(
"onPayResponse"
==
methodCall
.
method
)
{
_responseController
.
add
(
WeChatResponse
(
methodCall
.
arguments
,
ResponseType
.
PAYMENT
));
}
return
Future
.
value
(
true
);
}
class
Fluwx
{
static
const
Map
<
Type
,
String
>
_shareModelMethodMapper
=
{
WeChatShareTextModel:
"shareText"
,
...
...
@@ -16,54 +36,22 @@ class Fluwx {
WeChatShareMiniProgramModel:
"shareMiniProgram"
};
static
const
MethodChannel
_channel
=
const
MethodChannel
(
'com.jarvanmo/fluwx'
)
;
Stream
<
WeChatResponse
>
get
response
=>
_responseController
.
stream
;
StreamController
<
Map
>
_responseFromShareController
=
new
StreamController
.
broadcast
();
StreamController
<
Map
>
_responseFromAuthController
=
new
StreamController
.
broadcast
();
StreamController
<
Map
>
_responseFromPayController
=
new
StreamController
.
broadcast
();
Stream
<
Map
>
get
responseFromShare
=>
_responseFromShareController
.
stream
;
Stream
<
Map
>
get
responseFromAuth
=>
_responseFromAuthController
.
stream
;
Stream
<
Map
>
get
responseFromPay
=>
_responseFromPayController
.
stream
;
///the [model] should not be null
static
Future
registerApp
(
RegisterModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"registerApp"
,
model
.
toMap
());
}
///we don't need the response any longer.
static
void
dispose
(){
_responseController
.
close
();
}
// static Future unregisterApp(RegisterModel model) async {
// return await _channel.invokeMethod("unregisterApp", model.toMap());
// }
Fluwx
(){
_channel
.
setMethodCallHandler
(
_handler
);
}
void
listen
()
{
}
void
disposeAll
()
{
_responseFromShareController
.
close
();
_responseFromAuthController
.
close
();
_responseFromPayController
.
close
();
}
void
disposeResponseFromShare
(){
_responseFromShareController
.
close
();
}
void
disposeResponseFromAuth
(){
_responseFromAuthController
.
close
();
}
void
disposeResponseFromPay
(){
_responseFromPayController
.
close
();
}
///the [model] can not be null
///see [WeChatShareWebPageModel]
...
...
@@ -80,27 +68,15 @@ class Fluwx {
}
}
Future
sendAuth
(
WeChatSendAuthModel
model
)
async
{
Future
sendAuth
(
WeChatSendAuthModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"sendAuth"
,
model
.
toMap
());
}
Future
isWeChatInstalled
()
async
{
Future
isWeChatInstalled
()
async
{
return
await
_channel
.
invokeMethod
(
"isWeChatInstalled"
);
}
Future
<
dynamic
>
_handler
(
MethodCall
methodCall
)
{
if
(
"onShareResponse"
==
methodCall
.
method
)
{
_responseFromShareController
.
add
(
methodCall
.
arguments
);
}
else
if
(
"onAuthResponse"
==
methodCall
.
method
){
_responseFromAuthController
.
add
(
methodCall
.
arguments
);
}
else
if
(
"onPayResponse"
==
methodCall
.
method
){
_responseFromPayController
.
add
(
methodCall
.
arguments
);
}
return
Future
.
value
(
true
);
}
Future
pay
(
WeChatPayModel
model
)
async
{
return
await
_channel
.
invokeMethod
(
"pay"
,
model
.
toMap
());
return
await
_channel
.
invokeMethod
(
"pay"
,
model
.
toMap
());
}
}
lib/src/models/wechat_response.dart
0 → 100644
浏览文件 @
e9c2bc6d
enum
ResponseType
{
SHARE
,
AUTH
,
PAYMENT
}
class
WeChatResponse
{
final
Map
result
;
final
ResponseType
type
;
WeChatResponse
(
this
.
result
,
this
.
type
);
@override
String
toString
()
{
return
{
"type"
:
type
,
"result"
:
result
}.
toString
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论