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

send auth

上级 69a62e0d
...@@ -2,7 +2,7 @@ package com.jarvan.fluwx ...@@ -2,7 +2,7 @@ package com.jarvan.fluwx
import com.jarvan.fluwx.constant.WeChatPluginMethods import com.jarvan.fluwx.constant.WeChatPluginMethods
import com.jarvan.fluwx.constant.WeChatPluginMethods.IS_WE_CHAT_INSTALLED import com.jarvan.fluwx.constant.WeChatPluginMethods.IS_WE_CHAT_INSTALLED
import com.jarvan.fluwx.handler.FluwxLoginHandler import com.jarvan.fluwx.handler.FluwxAuthHandler
import com.jarvan.fluwx.handler.FluwxResponseHandler import com.jarvan.fluwx.handler.FluwxResponseHandler
import com.jarvan.fluwx.handler.FluwxShareHandler import com.jarvan.fluwx.handler.FluwxShareHandler
import com.jarvan.fluwx.handler.WXAPiHandler import com.jarvan.fluwx.handler.WXAPiHandler
...@@ -44,7 +44,7 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler { ...@@ -44,7 +44,7 @@ class FluwxPlugin(private var registrar: Registrar) : MethodCallHandler {
} }
if ("sendAuth" == call.method) { if ("sendAuth" == call.method) {
FluwxLoginHandler.sendAuth(call, result) FluwxAuthHandler.sendAuth(call, result)
return return
} }
......
package com.jarvan.fluwx.handler package com.jarvan.fluwx.handler
import com.jarvan.fluwx.constant.WechatPluginKeys
import com.tencent.mm.opensdk.modelmsg.SendAuth import com.tencent.mm.opensdk.modelmsg.SendAuth
import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodCall
import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel
internal object FluwxLoginHandler { internal object FluwxAuthHandler {
fun sendAuth(call: MethodCall, result: MethodChannel.Result) { fun sendAuth(call: MethodCall, result: MethodChannel.Result) {
val req = SendAuth.Req() val req = SendAuth.Req()
req.scope = call.argument("scope") req.scope = call.argument("scope")
req.state = call.argument("state") req.state = call.argument("state")
req.openId = call.argument("openId")
result.success(WXAPiHandler.wxApi?.sendReq(req)) result.success(WXAPiHandler.wxApi?.sendReq(req))
} }
fun hehe(){
}
} }
\ No newline at end of file
...@@ -5,7 +5,6 @@ import android.content.Intent; ...@@ -5,7 +5,6 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
import com.jarvan.fluwx.handler.FluwxLoginHandler;
import com.tencent.mm.opensdk.modelbase.BaseReq; import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp; import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler; import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
......
#import <Flutter/Flutter.h> #import <Flutter/Flutter.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "FluwxShareHandler.h"
@interface AppDelegate : FlutterAppDelegate @interface AppDelegate : FlutterAppDelegate
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self]; [GeneratedPluginRegistrant registerWithRegistry:self];
// Override point for customization after application launch. // Override point for customization after application launch.
return [super application:application didFinishLaunchingWithOptions:launchOptions]; return [super application:application didFinishLaunchingWithOptions:launchOptions];
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#import "FluwxKeys.h" #import "FluwxKeys.h"
@class FluwxShareHandler; @class FluwxShareHandler;
@class FluwxResponseHandler; @class FluwxResponseHandler;
@class FluwxAuthHandler;
extern BOOL isWeChatRegistered; extern BOOL isWeChatRegistered;
...@@ -12,6 +12,8 @@ extern BOOL isWeChatRegistered; ...@@ -12,6 +12,8 @@ extern BOOL isWeChatRegistered;
@private @private
FluwxShareHandler *_fluwxShareHandler; FluwxShareHandler *_fluwxShareHandler;
@private
FluwxAuthHandler *_fluwxAuthHandler;
} }
@end @end
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "../../../../../../ios/Classes/handler/FluwxShareHandler.h" #import "../../../../../../ios/Classes/handler/FluwxShareHandler.h"
#import "ImageSchema.h" #import "ImageSchema.h"
#import "FluwxResponseHandler.h" #import "FluwxResponseHandler.h"
#import "FluwxAuthHandler.h"
@implementation FluwxPlugin @implementation FluwxPlugin
...@@ -24,10 +25,11 @@ BOOL isWeChatRegistered = NO; ...@@ -24,10 +25,11 @@ BOOL isWeChatRegistered = NO;
} }
-(instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar { - (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
self = [super init]; self = [super init];
if (self) { if (self) {
_fluwxShareHandler = [[FluwxShareHandler alloc] initWithRegistrar:registrar]; _fluwxShareHandler = [[FluwxShareHandler alloc] initWithRegistrar:registrar];
_fluwxAuthHandler = [[FluwxAuthHandler alloc] initWithRegistrar:registrar];
} }
return self; return self;
...@@ -41,12 +43,18 @@ BOOL isWeChatRegistered = NO; ...@@ -41,12 +43,18 @@ BOOL isWeChatRegistered = NO;
return; return;
} }
if ([unregisterApp isEqualToString:call.method]) { if ([unregisterApp isEqualToString:call.method]) {
[self initWeChatIfNeeded:call result:result]; [self initWeChatIfNeeded:call result:result];
return; return;
} }
if ([call.method hasPrefix:@"share"]) {
if([@"sendAuth" isEqualToString :call.method]){
[_fluwxAuthHandler handleAuth:call result:result];
return;
}
if ([call.method hasPrefix:@"share"]) {
[_fluwxShareHandler handleShare:call result:result]; [_fluwxShareHandler handleShare:call result:result];
return; return;
} else { } else {
...@@ -54,21 +62,18 @@ BOOL isWeChatRegistered = NO; ...@@ -54,21 +62,18 @@ BOOL isWeChatRegistered = NO;
} }
} }
- (void)initWeChatIfNeeded:(FlutterMethodCall *)call result:(FlutterResult)result { - (void)initWeChatIfNeeded:(FlutterMethodCall *)call result:(FlutterResult)result {
if(!call.arguments[fluwxKeyIOS]){ if (!call.arguments[fluwxKeyIOS]) {
result(@{fluwxKeyPlatform:fluwxKeyIOS,fluwxKeyResult:@NO}); result(@{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @NO});
return; return;
} }
if (isWeChatRegistered) { if (isWeChatRegistered) {
result(@{fluwxKeyPlatform:fluwxKeyIOS,fluwxKeyResult:@YES}); result(@{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @YES});
return; return;
} }
...@@ -80,15 +85,14 @@ BOOL isWeChatRegistered = NO; ...@@ -80,15 +85,14 @@ BOOL isWeChatRegistered = NO;
isWeChatRegistered = [WXApi registerApp:appId]; isWeChatRegistered = [WXApi registerApp:appId];
result(@{fluwxKeyPlatform:fluwxKeyIOS,fluwxKeyResult: @(isWeChatRegistered)}); result(@{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @(isWeChatRegistered)});
} }
- (void)unregisterApp:(FlutterMethodCall *)call result:(FlutterResult)result { - (void)unregisterApp:(FlutterMethodCall *)call result:(FlutterResult)result {
isWeChatRegistered = false; isWeChatRegistered = false;
result(@YES); result(@YES);
} }
@end @end
//
// Created by mo on 2018/8/23.
//
#import <Foundation/Foundation.h>
#import "CallResults.h"
#import "WXApiRequestHandler.h"
#import "FluwxKeys.h"
#import "StringToWeChatScene.h"
#import "WXApi.h"
#import "FluwxMethods.h"
#import <Flutter/Flutter.h>
#import "FluwxPlugin.h"
#import "ThumbnailHelper.h"
#import "NSStringWrapper.h"
@class StringUtil;
@interface FluwxAuthHandler : NSObject
-(instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar;
- (void)handleAuth:(FlutterMethodCall *)call result:(FlutterResult)result;
@end
\ No newline at end of file
//
// Created by mo on 2018/8/23.
//
#import "FluwxAuthHandler.h"
@implementation FluwxAuthHandler
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
self = [super init];
// if (self) {
//
// }
return self;
}
- (void)handleAuth:(FlutterMethodCall *)call result:(FlutterResult)result {
[WXApiRequestHandler sendAuthRequestScope:call.arguments[@"scope"]
State:call.arguments[@"state"]
OpenID:call.arguments[@"openId"]
InViewController:nil];
}
@end
\ No newline at end of file
...@@ -18,4 +18,4 @@ ...@@ -18,4 +18,4 @@
@interface FluwxShareHandler : NSObject @interface FluwxShareHandler : NSObject
-(instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar; -(instancetype) initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar;
- (void)handleShare:(FlutterMethodCall *)call result:(FlutterResult)result; - (void)handleShare:(FlutterMethodCall *)call result:(FlutterResult)result;
@end @end
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "WXApiObject.h" #import "WXApiObject.h"
#import "StringUtil.h" #import "StringUtil.h"
#import "FluwxResponseHandler.h"
@interface WXApiRequestHandler : NSObject @interface WXApiRequestHandler : NSObject
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "WXApi.h" #import "WXApi.h"
#import "WXApiRequestHandler.h" #import "WXApiRequestHandler.h"
#import "WXApiManager.h"
#import "SendMessageToWXReq+requestWithTextOrMediaMessage.h" #import "SendMessageToWXReq+requestWithTextOrMediaMessage.h"
#import "WXMediaMessage+messageConstruct.h" #import "WXMediaMessage+messageConstruct.h"
...@@ -319,7 +318,7 @@ ...@@ -319,7 +318,7 @@
return [WXApi sendAuthReq:req return [WXApi sendAuthReq:req
viewController:viewController viewController:viewController
delegate:[WXApiManager sharedManager]]; delegate:[FluwxResponseHandler responseHandler]];
} }
+ (BOOL)openProfileWithAppID:(NSString *)appID + (BOOL)openProfileWithAppID:(NSString *)appID
......
class WeChatSendAuthModel { class WeChatSendAuthModel {
final String scope; final String scope;
final String state; final String state;
final String openId;
WeChatSendAuthModel(this.scope, this.state) : WeChatSendAuthModel(this.scope, this.state,this.openId) :
assert(scope != null && scope assert(scope != null && scope
.trim() .trim()
.isNotEmpty); .isNotEmpty);
...@@ -10,7 +11,8 @@ class WeChatSendAuthModel { ...@@ -10,7 +11,8 @@ class WeChatSendAuthModel {
Map toMap() { Map toMap() {
return { return {
"scope":scope, "scope":scope,
"state":state "state":state,
"openId":openId
}; };
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论