mirror of
https://github.com/RxReader/wechat_kit.git
synced 2025-08-26 16:50:28 +08:00
整理
This commit is contained in:
@ -45,6 +45,7 @@ import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import io.flutter.embedding.engine.plugins.FlutterPlugin;
|
||||
import io.flutter.embedding.engine.plugins.activity.ActivityAware;
|
||||
@ -170,6 +171,7 @@ public final class WechatKitPlugin implements FlutterPlugin, ActivityAware, Plug
|
||||
private final IDiffDevOAuth qrauth = DiffDevOAuthFactory.getDiffDevOAuth();
|
||||
|
||||
private IWXAPI iwxapi;
|
||||
private AtomicBoolean handleInitialWXReqFlag = new AtomicBoolean(false);
|
||||
|
||||
// --- FlutterPlugin
|
||||
|
||||
@ -377,6 +379,7 @@ public final class WechatKitPlugin implements FlutterPlugin, ActivityAware, Plug
|
||||
}
|
||||
|
||||
private void handleInitialWXReq(@NonNull MethodCall call, @NonNull Result result) {
|
||||
if (handleInitialWXReqFlag.compareAndSet(false, true)) {
|
||||
final Activity activity = activityPluginBinding != null ? activityPluginBinding.getActivity() : null;
|
||||
if (activity != null) {
|
||||
final Intent resp = WechatCallbackActivity.extraCallback(activity.getIntent());
|
||||
@ -387,6 +390,9 @@ public final class WechatKitPlugin implements FlutterPlugin, ActivityAware, Plug
|
||||
}
|
||||
}
|
||||
result.success(null);
|
||||
} else {
|
||||
result.error("FAILED", null, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleAuthCall(@NonNull MethodCall call, @NonNull Result result) {
|
||||
|
@ -78,6 +78,12 @@ class _HomeState extends State<Home> {
|
||||
),
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
title: const Text('微信回调 - 冷启'),
|
||||
onTap: () async {
|
||||
await Wechat.instance.handleInitialWXReq();
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text('环境检查'),
|
||||
onTap: () async {
|
||||
|
@ -7,6 +7,8 @@
|
||||
#import <WechatAuthSDK.h>
|
||||
#endif
|
||||
|
||||
typedef void(^WechatKitWXReqRunnable)(void);
|
||||
|
||||
@interface WechatKitPlugin () <WXApiDelegate, WechatAuthAPIDelegate>
|
||||
|
||||
@end
|
||||
@ -14,6 +16,9 @@
|
||||
@implementation WechatKitPlugin {
|
||||
FlutterMethodChannel *_channel;
|
||||
WechatAuthSDK *_qrauth;
|
||||
BOOL _isRunning;
|
||||
BOOL _handleInitialWXReqFlag;
|
||||
WechatKitWXReqRunnable _initialWXReqRunnable;
|
||||
}
|
||||
|
||||
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar {
|
||||
@ -26,6 +31,7 @@
|
||||
}
|
||||
|
||||
static NSString *const METHOD_REGISTERAPP = @"registerApp";
|
||||
static NSString *const METHOD_HANDLEINITIALWXREQ = @"handleInitialWXReq";
|
||||
static NSString *const METHOD_ISINSTALLED = @"isInstalled";
|
||||
static NSString *const METHOD_ISSUPPORTAPI = @"isSupportApi";
|
||||
static NSString *const METHOD_ISSUPPORTSTATEAPI = @"isSupportStateAPI";
|
||||
@ -49,8 +55,9 @@ static NSString *const METHOD_OPENCUSTOMERSERVICECHAT = @"openCustomerServiceCha
|
||||
#ifndef NO_PAY
|
||||
static NSString *const METHOD_PAY = @"pay";
|
||||
#endif
|
||||
static NSString *const METHOD_LAUNCHFROMWX = @"launchFromWX";
|
||||
static NSString *const METHOD_SHOWMESSAGEFROMWX = @"showMessageFromWX";
|
||||
|
||||
static NSString *const METHOD_ONLAUNCHFROMWXREQ = @"onLaunchFromWXReq";
|
||||
static NSString *const METHOD_ONSHOWMESSAGEFROMWXREQ = @"onShowMessageFromWXReq";
|
||||
|
||||
static NSString *const METHOD_ONAUTHRESP = @"onAuthResp";
|
||||
static NSString *const METHOD_ONOPENURLRESP = @"onOpenUrlResp";
|
||||
@ -135,6 +142,8 @@ static NSString *const ARGUMENT_KEY_RESULT_AUTHCODE = @"authCode";
|
||||
_channel = channel;
|
||||
_qrauth = [[WechatAuthSDK alloc] init];
|
||||
_qrauth.delegate = self;
|
||||
_isRunning = NO;
|
||||
_handleInitialWXReqFlag = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -145,7 +154,19 @@ static NSString *const ARGUMENT_KEY_RESULT_AUTHCODE = @"authCode";
|
||||
NSString *appId = call.arguments[ARGUMENT_KEY_APPID];
|
||||
NSString *universalLink = call.arguments[ARGUMENT_KEY_UNIVERSALLINK];
|
||||
[WXApi registerApp:appId universalLink:universalLink];
|
||||
_isRunning = YES;
|
||||
result(nil);
|
||||
} else if ([METHOD_HANDLEINITIALWXREQ isEqualToString:call.method]) {
|
||||
if (!_handleInitialWXReqFlag) {
|
||||
_handleInitialWXReqFlag = YES;
|
||||
if (_initialWXReqRunnable != nil) {
|
||||
_initialWXReqRunnable();
|
||||
_initialWXReqRunnable = nil;
|
||||
}
|
||||
result(nil);
|
||||
} else {
|
||||
result([FlutterError errorWithCode:@"FAILED" message:nil details:nil]);
|
||||
}
|
||||
} else if ([METHOD_ISINSTALLED isEqualToString:call.method]) {
|
||||
result([NSNumber numberWithBool:[WXApi isWXAppInstalled]]);
|
||||
} else if ([METHOD_ISSUPPORTAPI isEqualToString:call.method]) {
|
||||
@ -447,14 +468,30 @@ static NSString *const ARGUMENT_KEY_RESULT_AUTHCODE = @"authCode";
|
||||
[dictionary setValue:launchFromWXReq.message.messageExt forKey:ARGUMENT_KEY_RESULT_MESSAGEEXT];
|
||||
[dictionary setValue:launchFromWXReq.lang forKey:ARGUMENT_KEY_RESULT_LANG];
|
||||
[dictionary setValue:launchFromWXReq.country forKey:ARGUMENT_KEY_RESULT_COUNTRY];
|
||||
//
|
||||
if (_isRunning) {
|
||||
[_channel invokeMethod:METHOD_ONLAUNCHFROMWXREQ arguments:dictionary];
|
||||
} else {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
_initialWXReqRunnable = ^() {
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
[strongSelf -> _channel invokeMethod:METHOD_ONLAUNCHFROMWXREQ arguments:dictionary];
|
||||
};
|
||||
}
|
||||
} else if ([req isKindOfClass:[ShowMessageFromWXReq class]]) {
|
||||
ShowMessageFromWXReq *showMessageFromWXReq = (ShowMessageFromWXReq *)req;
|
||||
[dictionary setValue:showMessageFromWXReq.message.messageAction forKey:ARGUMENT_KEY_RESULT_MESSAGEACTION];
|
||||
[dictionary setValue:showMessageFromWXReq.message.messageExt forKey:ARGUMENT_KEY_RESULT_MESSAGEEXT];
|
||||
[dictionary setValue:showMessageFromWXReq.lang forKey:ARGUMENT_KEY_RESULT_LANG];
|
||||
[dictionary setValue:showMessageFromWXReq.country forKey:ARGUMENT_KEY_RESULT_COUNTRY];
|
||||
//
|
||||
if (_isRunning) {
|
||||
[_channel invokeMethod:METHOD_ONSHOWMESSAGEFROMWXREQ arguments:dictionary];
|
||||
} else {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
_initialWXReqRunnable = ^() {
|
||||
__strong typeof(weakSelf) strongSelf = weakSelf;
|
||||
[strongSelf -> _channel invokeMethod:METHOD_ONSHOWMESSAGEFROMWXREQ arguments:dictionary];
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ class Wechat {
|
||||
);
|
||||
}
|
||||
|
||||
///
|
||||
/// 微信回调 - 冷启
|
||||
Future<void> handleInitialWXReq() {
|
||||
return _channel.invokeMethod<void>(_METHOD_HANDLEINITIALWXREQ);
|
||||
}
|
||||
|
Reference in New Issue
Block a user