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

response uses classes now;rm Fluwx.class

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