提交 ffa730d5 authored 作者: JarvanMo's avatar JarvanMo

response uses classes now;rm Fluwx.class

上级 d6b840e5
## 0.2.2
* 回调方式发生变化,由Map变更为实体类。
* iOS的SDK更换为'OpenWeChatSDK',并升级到了1.8.3。
* 修复iOS支付返回结果缺少*returnKey*的问题。
## 0.2.1
* 修复在Android处理网络图片后缀不对的问题。
......
......@@ -49,6 +49,7 @@ object FluwxResponseHandler {
}
private fun handlePayResp(response: PayResp) {
val result = mapOf(
"prepayId" to response.prepayId,
"returnKey" to response.returnKey,
......
......@@ -139,9 +139,10 @@ FlutterMethodChannel *methodChannel = nil;
errStr: [StringUtil nilToEmpty:resp.errStr],
errCode: @(payResp.errCode),
type: payResp.type == nil ?@5:@(payResp.type),
@"returnKey":payResp.returnKey== nil?@"":payResp.returnKey,
fluwxKeyPlatform: fluwxKeyIOS,
};
[methodChannel invokeMethod:@"onAuthResponse" arguments:result];
[methodChannel invokeMethod:@"onPayResponse" arguments:result];
}
}
......
......@@ -22,88 +22,109 @@ import 'models/wechat_response.dart';
import 'models/wechat_send_auth_model.dart';
import 'models/wechat_share_models.dart';
StreamController<WeChatResponse> _responseController =
StreamController<WeChatShareResponse> _responseShareController =
new StreamController.broadcast();
Stream<WeChatShareResponse> get responseFromShare =>
_responseShareController.stream;
StreamController<WeChatAuthResponse> _responseAuthController =
new StreamController.broadcast();
Stream<WeChatAuthResponse> get responseFromAuth =>
_responseAuthController.stream;
StreamController<WeChatPaymentResponse> _responsePaymentController =
new StreamController.broadcast();
Stream<WeChatPaymentResponse> get responseFromPayment =>
_responsePaymentController.stream;
final MethodChannel _channel = const MethodChannel('com.jarvanmo/fluwx')
..setMethodCallHandler(_handler);
Future<dynamic> _handler(MethodCall methodCall) {
if ("onShareResponse" == methodCall.method) {
_responseController
.add(WeChatResponse(methodCall.arguments, WeChatResponseType.SHARE));
_responseShareController
.add(WeChatShareResponse.fromMap(methodCall.arguments));
} else if ("onAuthResponse" == methodCall.method) {
_responseController
.add(WeChatResponse(methodCall.arguments, WeChatResponseType.AUTH));
_responseAuthController
.add(WeChatAuthResponse.fromMap(methodCall.arguments));
} else if ("onPayResponse" == methodCall.method) {
_responseController
.add(WeChatResponse(methodCall.arguments, WeChatResponseType.PAYMENT));
_responsePaymentController
.add(WeChatPaymentResponse.fromMap(methodCall.arguments));
}
return Future.value(true);
}
class Fluwx {
static const Map<Type, String> _shareModelMethodMapper = {
WeChatShareTextModel: "shareText",
WeChatShareImageModel: "shareImage",
WeChatShareMusicModel: "shareMusic",
WeChatShareVideoModel: "shareVideo",
WeChatShareWebPageModel: "shareWebPage",
WeChatShareMiniProgramModel: "shareMiniProgram"
};
Stream<WeChatResponse> get response => _responseController.stream;
///[appId] is not necessary.
///if [doOnIOS] is true ,fluwx will register WXApi on iOS.
///if [doOnAndroid] is true, fluwx will register WXApi on Android.
static Future register(
{String appId,
bool doOnIOS: true,
doOnAndroid: true,
enableMTA: false}) async {
return await _channel.invokeMethod("registerApp", {
"appId": appId,
"iOS": doOnIOS,
"android": doOnAndroid,
"enableMTA": enableMTA
});
const Map<Type, String> _shareModelMethodMapper = {
WeChatShareTextModel: "shareText",
WeChatShareImageModel: "shareImage",
WeChatShareMusicModel: "shareMusic",
WeChatShareVideoModel: "shareVideo",
WeChatShareWebPageModel: "shareWebPage",
WeChatShareMiniProgramModel: "shareMiniProgram"
};
///[appId] is not necessary.
///if [doOnIOS] is true ,fluwx will register WXApi on iOS.
///if [doOnAndroid] is true, fluwx will register WXApi on Android.
Future register(
{String appId,
bool doOnIOS: true,
doOnAndroid: true,
enableMTA: false}) async {
return await _channel.invokeMethod("registerApp", {
"appId": appId,
"iOS": doOnIOS,
"android": doOnAndroid,
"enableMTA": enableMTA
});
}
///we don't need the response any longer if params are true.
void dispose({shareResponse: true, authResponse: true, paymentResponse: true}) {
if (shareResponse) {
_responseShareController.close();
}
///we don't need the response any longer.
static void dispose() {
_responseController.close();
if (authResponse) {
_responseAuthController.close();
}
if (paymentResponse) {
_responseAuthController.close();
}
}
// static Future unregisterApp(RegisterModel model) async {
// return await _channel.invokeMethod("unregisterApp", model.toMap());
// }
///the [WeChatShareModel] can not be null
///see [WeChatShareWebPageModel]
/// [WeChatShareTextModel]
///[WeChatShareVideoModel]
///[WeChatShareMusicModel]
///[WeChatShareImageModel]
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}]");
}
///the [WeChatShareModel] can not be null
///see [WeChatShareWebPageModel]
/// [WeChatShareTextModel]
///[WeChatShareVideoModel]
///[WeChatShareMusicModel]
///[WeChatShareImageModel]
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 sendAuth(WeChatSendAuthModel model) async {
return await _channel.invokeMethod("sendAuth", model.toMap());
}
Future sendAuth(WeChatSendAuthModel model) async {
return await _channel.invokeMethod("sendAuth", model.toMap());
}
Future isWeChatInstalled() async {
return await _channel.invokeMethod("isWeChatInstalled");
}
Future isWeChatInstalled() async {
return await _channel.invokeMethod("isWeChatInstalled");
}
Future pay(WeChatPayModel model) async {
return await _channel.invokeMethod("pay", model.toMap());
}
Future pay(WeChatPayModel model) async {
return await _channel.invokeMethod("pay", model.toMap());
}
......@@ -27,3 +27,78 @@ class WeChatResponse {
return {"type": type, "result": result}.toString();
}
}
class WeChatShareResponse {
final String errStr;
final String androidTransaction;
final int type;
final int errCode;
final String androidOpenId;
final String iOSDescription;
final String iOSCountry;
final String iOSLang;
WeChatShareResponse.fromMap(Map map)
: errStr = map["errStr"],
androidTransaction = map["transaction"],
type = map["type"],
errCode = map["errCode"],
androidOpenId = map["openId"],
iOSDescription = map["description"],
iOSCountry = map["country"],
iOSLang = map["lang"];
}
class WeChatAuthResponse{
final String errStr;
final int type;
final int errCode;
final String androidOpenId;
final String iOSDescription;
final String country;
final String lang;
final String code;
final String androidUrl;
final String state;
final String androidTransaction;
WeChatAuthResponse.fromMap(Map map)
: errStr = map["errStr"],
type = map["type"],
errCode = map["errCode"],
androidOpenId = map["openId"],
iOSDescription = map["description"],
country = map["country"],
lang = map["lang"],
code = map["code"],
androidUrl = map["url"],
state =map["state"],
androidTransaction = map["transaction"];
}
class WeChatPaymentResponse{
final String errStr;
final int type;
final int errCode;
final String androidOpenId;
final String iOSDescription;
final String androidPrepayId;
final String extData;
final String androidTransaction;
WeChatPaymentResponse.fromMap(Map map):
errStr = map["errStr"],
type = map["type"],
errCode = map["errCode"],
androidOpenId = map["openId"],
iOSDescription = map["description"],
androidPrepayId = map["prepayId"],
extData = map["extData"],
androidTransaction = map["transaction"]
;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论