Unverified 提交 8f61a2f3 authored 作者: JarvanMo's avatar JarvanMo 提交者: GitHub

Merge pull request #33 from CaiJingLong/SubscribeMsg-patch-1

一次性订阅消息的api
...@@ -39,6 +39,7 @@ class FluwxPlugin(private val registrar: Registrar, private val channel: MethodC ...@@ -39,6 +39,7 @@ class FluwxPlugin(private val registrar: Registrar, private val channel: MethodC
private val fluwxAuthHandler = FluwxAuthHandler() private val fluwxAuthHandler = FluwxAuthHandler()
private val fluwxPayHandler = FluwxPayHandler() private val fluwxPayHandler = FluwxPayHandler()
private val fluwxLaunchMiniProgramHandler = FluwxLaunchMiniProgramHandler() private val fluwxLaunchMiniProgramHandler = FluwxLaunchMiniProgramHandler()
private val fluwxSubscribeMsgHandler = FluwxSubscribeMsgHandler()
init { init {
fluwxShareHandler.setRegistrar(registrar) fluwxShareHandler.setRegistrar(registrar)
...@@ -73,8 +74,13 @@ class FluwxPlugin(private val registrar: Registrar, private val channel: MethodC ...@@ -73,8 +74,13 @@ class FluwxPlugin(private val registrar: Registrar, private val channel: MethodC
return return
} }
if (call.method == WeChatPluginMethods.LAUNCH_MINI_PROGRAM){ if (call.method == WeChatPluginMethods.LAUNCH_MINI_PROGRAM) {
fluwxLaunchMiniProgramHandler.launchMiniProgram(call,result) fluwxLaunchMiniProgramHandler.launchMiniProgram(call, result)
return
}
if (WeChatPluginMethods.SUBSCRIBE_MSG == call.method) {
fluwxSubscribeMsgHandler.subScribeMsg(call, result)
return return
} }
......
...@@ -9,7 +9,8 @@ public class WeChatPluginMethods { ...@@ -9,7 +9,8 @@ public class WeChatPluginMethods {
public static final String REGISTER_APP = "registerApp"; public static final String REGISTER_APP = "registerApp";
public static final String UNREGISTER_APP = "unregisterApp"; public static final String UNREGISTER_APP = "unregisterApp";
public static final String WE_CHAT_SHARE_RESPONSE = "onShareResponse"; 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"; public static final String IS_WE_CHAT_INSTALLED = "isWeChatInstalled";
...@@ -24,4 +25,5 @@ public class WeChatPluginMethods { ...@@ -24,4 +25,5 @@ public class WeChatPluginMethods {
public static final String PAY = "payWithFluwx"; public static final String PAY = "payWithFluwx";
public static final String WE_CHAT_PAY_RESPONSE = "onPayResponse"; public static final String WE_CHAT_PAY_RESPONSE = "onPayResponse";
public static final String SUBSCRIBE_MSG = "subscribeMsg";
} }
...@@ -19,6 +19,7 @@ import android.util.Log ...@@ -19,6 +19,7 @@ import android.util.Log
import com.jarvan.fluwx.constant.WeChatPluginMethods import com.jarvan.fluwx.constant.WeChatPluginMethods
import com.jarvan.fluwx.constant.WechatPluginKeys import com.jarvan.fluwx.constant.WechatPluginKeys
import com.tencent.mm.opensdk.modelbase.BaseResp 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.modelbiz.WXLaunchMiniProgram
import com.tencent.mm.opensdk.modelmsg.SendAuth import com.tencent.mm.opensdk.modelmsg.SendAuth
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX import com.tencent.mm.opensdk.modelmsg.SendMessageToWX
...@@ -40,16 +41,29 @@ object FluwxResponseHandler { ...@@ -40,16 +41,29 @@ object FluwxResponseHandler {
fun handleResponse(response: BaseResp) { fun handleResponse(response: BaseResp) {
Log.e("tag","heeeeee") Log.e("tag", "heeeeee")
when (response) { when (response) {
is SendAuth.Resp -> handleAuthResponse(response) is SendAuth.Resp -> handleAuthResponse(response)
is SendMessageToWX.Resp -> handleSendMessageResp(response) is SendMessageToWX.Resp -> handleSendMessageResp(response)
is PayResp -> handlePayResp(response) is PayResp -> handlePayResp(response)
is WXLaunchMiniProgram.Resp -> handleLaunchMiniProgramResponse(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) { private fun handleLaunchMiniProgramResponse(response: WXLaunchMiniProgram.Resp) {
val result = mutableMapOf( val result = mutableMapOf(
errStr to response.errStr, errStr to response.errStr,
......
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
...@@ -2,6 +2,7 @@ import 'dart:async'; ...@@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:fluwx/fluwx.dart' as fluwx; import 'package:fluwx/fluwx.dart' as fluwx;
import 'package:fluwx_example/subscribe_message_page.dart';
import 'pay_page.dart'; import 'pay_page.dart';
import 'send_auth.dart'; import 'send_auth.dart';
...@@ -12,6 +13,7 @@ import 'share_text_image.dart'; ...@@ -12,6 +13,7 @@ import 'share_text_image.dart';
import 'share_video_page.dart'; import 'share_video_page.dart';
import 'share_web_page.dart'; import 'share_web_page.dart';
import 'package:fluwx_example/launch_mini_program_page.dart'; import 'package:fluwx_example/launch_mini_program_page.dart';
void main() => runApp(new MyApp()); void main() => runApp(new MyApp());
class MyApp extends StatefulWidget { class MyApp extends StatefulWidget {
...@@ -23,13 +25,11 @@ class _MyAppState extends State<MyApp> { ...@@ -23,13 +25,11 @@ class _MyAppState extends State<MyApp> {
@override @override
void initState() { void initState() {
super.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. // Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async { Future<void> initPlatformState() async {}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -43,15 +43,15 @@ class _MyAppState extends State<MyApp> { ...@@ -43,15 +43,15 @@ class _MyAppState extends State<MyApp> {
"sendAuth": (context) => SendAuthPage(), "sendAuth": (context) => SendAuthPage(),
"shareMiniProgram": (context) => ShareMiniProgramPage(), "shareMiniProgram": (context) => ShareMiniProgramPage(),
"pay": (context) => PayPage(), "pay": (context) => PayPage(),
"launchMiniProgram": (context) => LaunchMiniProgramPage() "launchMiniProgram": (context) => LaunchMiniProgramPage(),
"subscribeMessage": (ctx) => SubscribeMessagePage(),
}, },
home: new Scaffold( home: new Scaffold(
appBar: new AppBar( appBar: new AppBar(
title: const Text('Plugin example app'), title: const Text('Plugin example app'),
), ),
body: ShareSelectorPage()), body: ShareSelectorPage()),
) );
;
} }
} }
...@@ -133,6 +133,14 @@ class ShareSelectorPage extends StatelessWidget { ...@@ -133,6 +133,14 @@ class ShareSelectorPage extends StatelessWidget {
}, },
child: const Text("Launch MiniProgram")), 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")),
),
], ],
), ),
); );
......
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,
);
}
}
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#import "FluwxWXApiHandler.h" #import "FluwxWXApiHandler.h"
#import "FluwxShareHandler.h" #import "FluwxShareHandler.h"
#import "FluwxLaunchMiniProgramHandler.h" #import "FluwxLaunchMiniProgramHandler.h"
#import "FluwxSubscribeMsgHandler.h"
@implementation FluwxPlugin @implementation FluwxPlugin
...@@ -22,6 +22,7 @@ FluwxAuthHandler *_fluwxAuthHandler; ...@@ -22,6 +22,7 @@ FluwxAuthHandler *_fluwxAuthHandler;
FluwxWXApiHandler *_fluwxWXApiHandler; FluwxWXApiHandler *_fluwxWXApiHandler;
FluwxPaymentHandler *_fluwxPaymentHandler; FluwxPaymentHandler *_fluwxPaymentHandler;
FluwxLaunchMiniProgramHandler *_fluwxLaunchMiniProgramHandler; FluwxLaunchMiniProgramHandler *_fluwxLaunchMiniProgramHandler;
FluwxSubscribeMsgHandler *_fluwxSubscribeMsgHandler;
- (void)dealloc - (void)dealloc
{ {
...@@ -52,7 +53,7 @@ FluwxLaunchMiniProgramHandler *_fluwxLaunchMiniProgramHandler; ...@@ -52,7 +53,7 @@ FluwxLaunchMiniProgramHandler *_fluwxLaunchMiniProgramHandler;
_fluwxWXApiHandler = [[FluwxWXApiHandler alloc] init]; _fluwxWXApiHandler = [[FluwxWXApiHandler alloc] init];
_fluwxPaymentHandler = [[FluwxPaymentHandler alloc] initWithRegistrar:registrar]; _fluwxPaymentHandler = [[FluwxPaymentHandler alloc] initWithRegistrar:registrar];
_fluwxLaunchMiniProgramHandler = [[FluwxLaunchMiniProgramHandler alloc] initWithRegistrar:registrar]; _fluwxLaunchMiniProgramHandler = [[FluwxLaunchMiniProgramHandler alloc] initWithRegistrar:registrar];
_fluwxSubscribeMsgHandler = [[FluwxSubscribeMsgHandler alloc] initWithRegistrar:registrar];
} }
return self; return self;
...@@ -90,6 +91,11 @@ FluwxLaunchMiniProgramHandler *_fluwxLaunchMiniProgramHandler; ...@@ -90,6 +91,11 @@ FluwxLaunchMiniProgramHandler *_fluwxLaunchMiniProgramHandler;
return; return;
} }
if([@"subscribeMsg" isEqualToString: call.method]){
[_fluwxSubscribeMsgHandler handleSubscribeWithCall:call result:result];
return;
}
if ([call.method hasPrefix:@"share"]) { if ([call.method hasPrefix:@"share"]) {
[_fluwxShareHandler handleShare:call result:result]; [_fluwxShareHandler handleShare:call result:result];
return; return;
......
//
// FluwxSubscribeMsgHandler.m
// fluwx
//
// Created by cjl on 2018/12/19.
//
#import "FluwxSubscribeMsgHandler.h"
#import <WXApiRequestHandler.h>
@implementation FluwxSubscribeMsgHandler {
NSObject <FlutterPluginRegistrar> *_registrar;
}
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
self = [super init];
if (self) {
_registrar = registrar;
}
return self;
}
- (void)handleSubscribeWithCall:(FlutterMethodCall *)call result:(FlutterResult)result {
NSDictionary *params = call.arguments;
NSString *appId = [params valueForKey:@"appId"];
int scene = [[params valueForKey:@"scene"] intValue];
NSString *templateId = [params valueForKey:@"templateId"];
NSString *reserved = [params valueForKey:@"reserved"];
WXSubscribeMsgReq *req = [WXSubscribeMsgReq new];
req.scene = (UInt32) scene;
req.templateId = templateId;
req.reserved = reserved;
req.openID = appId;
BOOL b = [WXApi sendReq:req];
result(@(b));
}
@end
//
// FluwxSubscribeMsgHandler.h
// fluwx
//
// Created by cjl on 2018/12/19.
//
#import <Foundation/Foundation.h>
#import <Flutter/Flutter.h>
NS_ASSUME_NONNULL_BEGIN
@interface FluwxSubscribeMsgHandler : NSObject
-(instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar;
-(void)handleSubscribeWithCall:(FlutterMethodCall *)call result:(FlutterResult)result;
@end
NS_ASSUME_NONNULL_END
...@@ -38,6 +38,7 @@ FlutterMethodChannel *fluwxMethodChannel = nil; ...@@ -38,6 +38,7 @@ FlutterMethodChannel *fluwxMethodChannel = nil;
} }
#pragma mark - WXApiDelegate #pragma mark - WXApiDelegate
- (void)onResp:(BaseResp *)resp { - (void)onResp:(BaseResp *)resp {
if ([resp isKindOfClass:[SendMessageToWXResp class]]) { if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
if (_delegate if (_delegate
...@@ -51,15 +52,13 @@ FlutterMethodChannel *fluwxMethodChannel = nil; ...@@ -51,15 +52,13 @@ FlutterMethodChannel *fluwxMethodChannel = nil;
SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp; SendMessageToWXResp *messageResp = (SendMessageToWXResp *) resp;
NSDictionary *result = @{ NSDictionary *result = @{
description: messageResp.description == nil ?@"":messageResp.description, description: messageResp.description == nil ? @"" : messageResp.description,
errStr: messageResp.errStr == nil ? @"":messageResp.errStr, errStr: messageResp.errStr == nil ? @"" : messageResp.errStr,
errCode: @(messageResp.errCode), errCode: @(messageResp.errCode),
type: messageResp.type == nil ? @2 :@(messageResp.type), type: messageResp.type == nil ? @2 : @(messageResp.type),
country: messageResp.country== nil ? @"":messageResp.country, country: messageResp.country == nil ? @"" : messageResp.country,
lang: messageResp.lang == nil ? @"":messageResp.lang, lang: messageResp.lang == nil ? @"" : messageResp.lang,
fluwxKeyPlatform: fluwxKeyIOS fluwxKeyPlatform: fluwxKeyIOS
}; };
[fluwxMethodChannel invokeMethod:@"onShareResponse" arguments:result]; [fluwxMethodChannel invokeMethod:@"onShareResponse" arguments:result];
...@@ -76,14 +75,14 @@ FlutterMethodChannel *fluwxMethodChannel = nil; ...@@ -76,14 +75,14 @@ FlutterMethodChannel *fluwxMethodChannel = nil;
SendAuthResp *authResp = (SendAuthResp *) resp; SendAuthResp *authResp = (SendAuthResp *) resp;
NSDictionary *result = @{ NSDictionary *result = @{
description: authResp.description == nil ?@"":authResp.description, description: authResp.description == nil ? @"" : authResp.description,
errStr: authResp.errStr == nil ?@"":authResp.errStr, errStr: authResp.errStr == nil ? @"" : authResp.errStr,
errCode: @(authResp.errCode), errCode: @(authResp.errCode),
type: authResp.type == nil ?@1:@(authResp.type), type: authResp.type == nil ? @1 : @(authResp.type),
country: authResp.country == nil? @"":authResp.country, country: authResp.country == nil ? @"" : authResp.country,
lang: authResp.lang == nil?@"":authResp.lang, lang: authResp.lang == nil ? @"" : authResp.lang,
fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyPlatform: fluwxKeyIOS,
@"code":[StringUtil nilToEmpty:authResp.code], @"code": [StringUtil nilToEmpty:authResp.code],
@"state": [StringUtil nilToEmpty:authResp.state] @"state": [StringUtil nilToEmpty:authResp.state]
}; };
...@@ -111,27 +110,37 @@ FlutterMethodChannel *fluwxMethodChannel = nil; ...@@ -111,27 +110,37 @@ FlutterMethodChannel *fluwxMethodChannel = nil;
if ([_delegate respondsToSelector:@selector(managerDidRecvSubscribeMsgResponse:)]) { if ([_delegate respondsToSelector:@selector(managerDidRecvSubscribeMsgResponse:)]) {
[_delegate managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *) resp]; [_delegate managerDidRecvSubscribeMsgResponse:(WXSubscribeMsgResp *) resp];
} }
WXSubscribeMsgResp *subscribeMsgResp = (WXSubscribeMsgResp *) resp;
NSDictionary *subMsgResult = @{
@"openid": subscribeMsgResp.openId,
@"templateId": subscribeMsgResp.templateId,
@"action": subscribeMsgResp.action,
@"reserved": subscribeMsgResp.reserved,
@"scene": @(subscribeMsgResp.scene),
};
[fluwxMethodChannel invokeMethod:@"onSubscribeMsgResp" arguments:subMsgResult];
} else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) { } else if ([resp isKindOfClass:[WXLaunchMiniProgramResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvLaunchMiniProgram:)]) { if ([_delegate respondsToSelector:@selector(managerDidRecvLaunchMiniProgram:)]) {
[_delegate managerDidRecvLaunchMiniProgram:(WXLaunchMiniProgramResp *) resp]; [_delegate managerDidRecvLaunchMiniProgram:(WXLaunchMiniProgramResp *) resp];
} }
WXLaunchMiniProgramResp *miniProgramResp = (WXLaunchMiniProgramResp *) resp; WXLaunchMiniProgramResp *miniProgramResp = (WXLaunchMiniProgramResp *) resp;
NSDictionary *commonResult = @{ NSDictionary *commonResult = @{
description: miniProgramResp.description == nil ?@"":miniProgramResp.description, description: miniProgramResp.description == nil ? @"" : miniProgramResp.description,
errStr: miniProgramResp.errStr == nil ?@"":miniProgramResp.errStr, errStr: miniProgramResp.errStr == nil ? @"" : miniProgramResp.errStr,
errCode: @(miniProgramResp.errCode), errCode: @(miniProgramResp.errCode),
type: miniProgramResp.type == nil ?@1:@(miniProgramResp.type), type: miniProgramResp.type == nil ? @1 : @(miniProgramResp.type),
fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyPlatform: fluwxKeyIOS,
}; };
NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:commonResult]; NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:commonResult];
if(miniProgramResp.extMsg != nil){ if (miniProgramResp.extMsg != nil) {
result[@"extMsg"] = miniProgramResp.extMsg; result[@"extMsg"] = miniProgramResp.extMsg;
} }
...@@ -153,21 +162,20 @@ FlutterMethodChannel *fluwxMethodChannel = nil; ...@@ -153,21 +162,20 @@ FlutterMethodChannel *fluwxMethodChannel = nil;
if ([_delegate respondsToSelector:@selector(managerDidRecvPayInsuranceResponse:)]) { if ([_delegate respondsToSelector:@selector(managerDidRecvPayInsuranceResponse:)]) {
[_delegate managerDidRecvPayInsuranceResponse:(WXPayInsuranceResp *) resp]; [_delegate managerDidRecvPayInsuranceResponse:(WXPayInsuranceResp *) resp];
} }
}else if ([resp isKindOfClass:[PayResp class]]) { } else if ([resp isKindOfClass:[PayResp class]]) {
if ([_delegate respondsToSelector:@selector(managerDidRecvPaymentResponse)]) { if ([_delegate respondsToSelector:@selector(managerDidRecvPaymentResponse)]) {
[_delegate managerDidRecvPaymentResponse:(PayResp *) resp]; [_delegate managerDidRecvPaymentResponse:(PayResp *) resp];
} }
PayResp *payResp = (PayResp *) resp; PayResp *payResp = (PayResp *) resp;
NSDictionary *result = @{ NSDictionary *result = @{
description:[StringUtil nilToEmpty:payResp.description] , description: [StringUtil nilToEmpty:payResp.description],
errStr: [StringUtil nilToEmpty:resp.errStr], errStr: [StringUtil nilToEmpty:resp.errStr],
errCode: @(payResp.errCode), errCode: @(payResp.errCode),
type: payResp.type == nil ?@5:@(payResp.type), type: payResp.type == nil ? @5 : @(payResp.type),
@"returnKey":payResp.returnKey== nil?@"":payResp.returnKey, @"returnKey": payResp.returnKey == nil ? @"" : payResp.returnKey,
fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyPlatform: fluwxKeyIOS,
}; };
[fluwxMethodChannel invokeMethod:@"onPayResponse" arguments:result]; [fluwxMethodChannel invokeMethod:@"onPayResponse" arguments:result];
......
...@@ -47,6 +47,12 @@ Stream<WeChatLaunchMiniProgramResponse> get responseFromLaunchMiniProgram => ...@@ -47,6 +47,12 @@ Stream<WeChatLaunchMiniProgramResponse> get responseFromLaunchMiniProgram =>
StreamController<WeChatLaunchMiniProgramResponse> StreamController<WeChatLaunchMiniProgramResponse>
_responseLaunchMiniProgramController = new StreamController.broadcast(); _responseLaunchMiniProgramController = new StreamController.broadcast();
StreamController<WeChatSubscribeMsgResp> _responseFromSubscribeMsg =
new StreamController.broadcast();
Stream<WeChatSubscribeMsgResp> get responseFromSubscribeMsg =>
_responseFromSubscribeMsg.stream;
final MethodChannel _channel = const MethodChannel('com.jarvanmo/fluwx') final MethodChannel _channel = const MethodChannel('com.jarvanmo/fluwx')
..setMethodCallHandler(_handler); ..setMethodCallHandler(_handler);
...@@ -63,6 +69,9 @@ Future<dynamic> _handler(MethodCall methodCall) { ...@@ -63,6 +69,9 @@ Future<dynamic> _handler(MethodCall methodCall) {
} else if ("onPayResponse" == methodCall.method) { } else if ("onPayResponse" == methodCall.method) {
_responsePaymentController _responsePaymentController
.add(WeChatPaymentResponse.fromMap(methodCall.arguments)); .add(WeChatPaymentResponse.fromMap(methodCall.arguments));
} else if ("onSubscribeMsgResp" == methodCall.method) {
_responseFromSubscribeMsg
.add(WeChatSubscribeMsgResp.fromMap(methodCall.arguments));
} }
return Future.value(true); return Future.value(true);
...@@ -180,3 +189,20 @@ Future pay( ...@@ -180,3 +189,20 @@ Future pay(
"extData": extData, "extData": extData,
}); });
} }
Future subscribeMsg({
@required String appId,
@required int scene,
@required String templateId,
String reserved,
}) async {
return await _channel.invokeMethod(
"subscribeMsg",
{
"appId": appId,
"scene": scene,
"templateId": templateId,
"reserved": reserved,
},
);
}
...@@ -115,3 +115,18 @@ class WeChatPaymentResponse { ...@@ -115,3 +115,18 @@ class WeChatPaymentResponse {
extData = map["extData"], extData = map["extData"],
androidTransaction = map["transaction"]; androidTransaction = map["transaction"];
} }
class WeChatSubscribeMsgResp {
final String openid;
final String templateId;
final String action;
final String reserved;
final int scene;
WeChatSubscribeMsgResp.fromMap(Map map)
: openid = map["openid"],
templateId = map["templateId"],
action = map["action"],
reserved = map["reserved"],
scene = map["scene"];
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论