feat: iOS端新增Api的实现

master
wangtao 2021-12-22 17:32:18 +08:00
parent 48c8f1c708
commit 31b1c35a36
8 changed files with 205 additions and 24 deletions

View File

@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface MOP_finishRunningApplet : MOPBaseApi @interface MOP_finishRunningApplet : MOPBaseApi
@property (nonatomic, copy) NSString appletId; @property (nonatomic, copy) NSString *appletId;
@property (nonatomic, assign) BOOL animated; @property (nonatomic, assign) BOOL animated;
@end @end

View File

@ -11,14 +11,20 @@ NS_ASSUME_NONNULL_BEGIN
@interface MOP_initialize : MOPBaseApi @interface MOP_initialize : MOPBaseApi
@property (nonatomic, copy) NSString *appkey; @property (nonatomic, copy) NSString *sdkkey;
@property (nonatomic, copy) NSString *secret; @property (nonatomic, copy) NSString *secret;
@property (nonatomic, copy) NSString *apiServer; @property (nonatomic, copy) NSString *apiServer;
@property (nonatomic, copy) NSString *apiPrefix; @property (nonatomic, copy) NSString *apiPrefix;
@property (nonatomic, copy) NSString *cryptType; @property (nonatomic, copy) NSString *cryptType;
@property (nonatomic, copy) NSString *userId;
@property (nonatomic, assign) BOOL disablePermission;
@property (nonatomic, assign) BOOL encryptServerData; @property (nonatomic, assign) BOOL encryptServerData;
@property (nonatomic, copy) NSString *userId;
@property (nonatomic, strong) NSArray *finStoreConfigs;
@property (nonatomic, strong) NSDictionary *uiConfig;
@property (nonatomic, copy) NSString *customWebViewUserAgent;
@property (nonatomic, assign) BOOL disablePermission;
@property (nonatomic, assign) NSInteger appletIntervalUpdateLimit;
@property (nonatomic, assign) NSInteger maxRunningApplet;
@end @end

View File

@ -8,14 +8,15 @@
#import "MOP_initialize.h" #import "MOP_initialize.h"
#import <FinApplet/FinApplet.h> #import <FinApplet/FinApplet.h>
#import <FinAppletExt/FinAppletExt.h> #import <FinAppletExt/FinAppletExt.h>
#import "MOPTools.h"
// #import <FinAppletWebRTC/FinAppletWebRTC.h> // #import <FinAppletWebRTC/FinAppletWebRTC.h>
@implementation MOP_initialize @implementation MOP_initialize
- (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel - (void)setupApiWithSuccess:(void (^)(NSDictionary<NSString *,id> * _Nonnull))success failure:(void (^)(id _Nullable))failure cancel:(void (^)(void))cancel
{ {
if (!self.appkey || !self.secret) { if (!self.sdkkey || !self.secret) {
failure(@"appkey 或 secret不能为空"); failure(@"sdkkey 或 secret不能为空");
return; return;
} }
if (!self.apiServer || [self.apiServer isEqualToString:@""]) { if (!self.apiServer || [self.apiServer isEqualToString:@""]) {
@ -24,27 +25,102 @@
if (!self.apiPrefix|| [self.apiPrefix isEqualToString:@""]) { if (!self.apiPrefix|| [self.apiPrefix isEqualToString:@""]) {
self.apiPrefix = @"/api/v1/mop"; self.apiPrefix = @"/api/v1/mop";
} }
FATConfig *config = [FATConfig configWithAppSecret:self.secret appKey:self.appkey]; FATConfig *config;
config.apiServer = [self.apiServer copy]; if (_finStoreConfigs && _finStoreConfigs.count > 0) {
config.apiPrefix = [self.apiPrefix copy]; NSMutableArray *storeArrayM = [NSMutableArray array];
if([self.cryptType isEqualToString: @"SM"]) for (NSDictionary *dict in _finStoreConfigs) {
{ FATStoreConfig *storeConfig = [[FATStoreConfig alloc] init];
config.cryptType = FATApiCryptTypeSM; storeConfig.sdkKey = dict[@"sdkKey"];
// storeConfig.sdkKey = @"22LyZEib0gLTQdU3MUauAb4V4W8Uxd/gMgmH8Hg1bGQ=";
storeConfig.sdkSecret = @"703b9026be3d6bc5";
storeConfig.apiServer = dict[@"apiServer"];
storeConfig.apmServer = dict[@"apmServer"];
storeConfig.fingerprint = dict[@"fingerprint"];
if ([@"SM" isEqualToString:dict[@"cryptType"]]) {
storeConfig.cryptType = FATApiCryptTypeSM;
} else {
storeConfig.cryptType = FATApiCryptTypeMD5;
}
storeConfig.encryptServerData = [dict[@"encryptServerData"] boolValue];
[storeArrayM addObject:storeConfig];
}
config = [FATConfig configWithStoreConfigs:storeArrayM];
} else {
config = [FATConfig configWithAppSecret:self.secret appKey:self.sdkkey];
config.apiServer = [self.apiServer copy];
config.apiPrefix = [self.apiPrefix copy];
if([self.cryptType isEqualToString: @"SM"])
{
config.cryptType = FATApiCryptTypeSM;
}
else
{
config.cryptType = FATApiCryptTypeMD5;
}
// encryptServerData
NSLog(@"encryptServerData:%d",self.encryptServerData);
config.encryptServerData = self.encryptServerData;
} }
else
{
config.cryptType = FATApiCryptTypeMD5;
}
config.currentUserId = [self.userId copy];
// encryptServerData
NSLog(@"encryptServerData:%d",self.encryptServerData);
config.encryptServerData = self.encryptServerData;
NSLog(@"disablePermission:%d",self.disablePermission); NSLog(@"disablePermission:%d",self.disablePermission);
config.disableAuthorize = self.disablePermission; config.disableAuthorize = self.disablePermission;
config.currentUserId = [self.userId copy];
config.appletIntervalUpdateLimit = self.appletIntervalUpdateLimit;
// bool debug = false,
// bool bindAppletWithMainProcess = false,
// List<FinStoreConfig>? finStoreConfigs,
// UIConfig? uiConfig,
// String? customWebViewUserAgent,
// int appletIntervalUpdateLimit = 0,
// int maxRunningApplet = 5,
NSError* error = nil; NSError* error = nil;
FATUIConfig *uiconfig = [[FATUIConfig alloc]init]; FATUIConfig *uiconfig = [[FATUIConfig alloc]init];
uiconfig.autoAdaptDarkMode = YES; uiconfig.autoAdaptDarkMode = YES;
if (_uiConfig) {
if (_uiConfig[@"navigationTitleTextAttributes"]) {
uiconfig.navigationTitleTextAttributes = _uiConfig[@"navigationTitleTextAttributes"];
}
if (_uiConfig[@"progressBarColor"]) {
uiconfig.progressBarColor = [MOPTools colorWithRGBHex:[_uiConfig[@"progressBarColor"] intValue]];
}
uiconfig.hideBackToHome = [_uiConfig[@"isHideBackHome"] boolValue];
uiconfig.hideFeedbackMenu = [_uiConfig[@"isHideFeedbackAndComplaints"] boolValue];
uiconfig.hideForwardMenu = [_uiConfig[@"isHideForwardMenu"] boolValue];
uiconfig.autoAdaptDarkMode = [_uiConfig[@"autoAdaptDarkMode"] boolValue];
uiconfig.appletText = _uiConfig[@"appletText"];
uiconfig.hideTransitionCloseButton = [_uiConfig[@"hideTransitionCloseButton"] boolValue];
uiconfig.disableSlideCloseAppletGesture = _uiConfig[@"disableSlideCloseAppletGesture"];
if (_uiConfig[@"capsuleConfig"]) {
NSDictionary *capsuleConfigDic = _uiConfig[@"capsuleConfig"];
FATCapsuleConfig *capsuleConfig = [[FATCapsuleConfig alloc]init];
capsuleConfig.capsuleWidth = [capsuleConfigDic[@"capsuleWidth"] floatValue];
capsuleConfig.capsuleHeight = [capsuleConfigDic[@"capsuleHeight"] floatValue];
capsuleConfig.capsuleRightMargin = [capsuleConfigDic[@"capsuleRightMargin"] floatValue];
capsuleConfig.capsuleCornerRadius = [capsuleConfigDic[@"capsuleCornerRadius"] floatValue];
capsuleConfig.capsuleBorderWidth = [capsuleConfigDic[@"capsuleBorderWidth"] floatValue];
capsuleConfig.moreBtnWidth = [capsuleConfigDic[@"moreBtnWidth"] floatValue];
capsuleConfig.moreBtnLeftMargin = [capsuleConfigDic[@"moreBtnLeftMargin"] floatValue];
capsuleConfig.closeBtnWidth = [capsuleConfigDic[@"closeBtnWidth"] floatValue];
capsuleConfig.closeBtnLeftMargin = [capsuleConfigDic[@"closeBtnLeftMargin"] floatValue];
capsuleConfig.capsuleBorderLightColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBorderLightColor"] intValue]];
capsuleConfig.capsuleBorderDarkColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBorderDarkColor"] intValue]];
capsuleConfig.capsuleBgLightColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBgLightColor"] intValue]];
capsuleConfig.capsuleBgDarkColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleBgDarkColor"] intValue]];
capsuleConfig.capsuleDividerLightColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleDividerLightColor"] intValue]];
capsuleConfig.capsuleDividerDarkColor = [MOPTools colorWithRGBHex:[capsuleConfigDic[@"capsuleDividerDarkColor"] intValue]];
uiconfig.capsuleConfig = capsuleConfig;
}
}
uiconfig.appendingCustomUserAgent = self.customWebViewUserAgent;
// uiconfig.moreMenuStyle = FATMoreViewStyleNormal; // uiconfig.moreMenuStyle = FATMoreViewStyleNormal;
[[FATClient sharedClient] initWithConfig:config uiConfig:uiconfig error:&error]; [[FATClient sharedClient] initWithConfig:config uiConfig:uiconfig error:&error];
if (error) { if (error) {

View File

@ -10,7 +10,7 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface MOP_sendCustomEvent : MOPBaseApi @interface MOP_sendCustomEvent : MOPBaseApi
@property (nonatomic, strong) NSDictonary *eventData; @property (nonatomic, strong) NSDictionary *eventData;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -13,6 +13,9 @@ NS_ASSUME_NONNULL_BEGIN
+ (UIViewController *)topViewController; + (UIViewController *)topViewController;
+ (UIViewController *)topViewController:(UIViewController *)rootViewController; + (UIViewController *)topViewController:(UIViewController *)rootViewController;
+ (UIColor *)colorWithRGBHex:(UInt32)hex;
+ (UIColor *)fat_colorWithHexString:(NSString *)hexColor;
@end @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

View File

@ -28,4 +28,89 @@
return [self topViewController:presentedViewController]; return [self topViewController:presentedViewController];
} }
+ (UIColor *)colorWithRGBHex:(UInt32)hex
{
int a = (hex >> 24) & 0xFF;
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r / 255.0f
green:g / 255.0f
blue:b / 255.0f
alpha:a / 255.0f];
}
+ (UIColor *)fat_colorWithHexString:(NSString *)hexColor {
if (!hexColor) return nil;
// blackwhite
if ([hexColor compare:@"black" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
return UIColor.blackColor;
} else if ([hexColor compare:@"white" options:NSCaseInsensitiveSearch] == NSOrderedSame) {
return UIColor.whiteColor;
}
NSString *cString = [[hexColor stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
if (cString.length == 0) return nil;
if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
if ([cString containsString:@"0X"]) cString = [cString stringByReplacingOccurrencesOfString:@"0X" withString:@""];
if (cString.length == 3) { // 36
cString = [NSString stringWithFormat:@"%c%c%c%c%c%c",
[cString characterAtIndex:0],
[cString characterAtIndex:0],
[cString characterAtIndex:1],
[cString characterAtIndex:1],
[cString characterAtIndex:2],
[cString characterAtIndex:2]];
}
if (cString.length == 4) { // 48
cString = [NSString stringWithFormat:@"%c%c%c%c%c%c%c%c",
[cString characterAtIndex:0],
[cString characterAtIndex:0],
[cString characterAtIndex:1],
[cString characterAtIndex:1],
[cString characterAtIndex:2],
[cString characterAtIndex:2],
[cString characterAtIndex:3],
[cString characterAtIndex:3]];
}
NSScanner *scanner = [NSScanner scannerWithString:cString];
unsigned hexNum;
if (![scanner scanHexInt:&hexNum]) return [UIColor blackColor];
if (cString.length == 6) {
return [self fat_colorWithRGBHex:hexNum];
} else if (cString.length == 8) {
return [self fat_colorWithARGBHex:hexNum];
}
return nil;
}
+ (UIColor *)fat_colorWithRGBHex:(UInt32)hex {
int red = (hex >> 16) & 0xFF;
int green = (hex >> 8) & 0xFF;
int blue = (hex)&0xFF;
return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:1.0f];
}
+ (UIColor *)fat_colorWithRGBAlphaHex:(UInt32)hex {
int red = (hex >> 24) & 0xFF;
int green = (hex >> 16) & 0xFF;
int blue = (hex >> 8) & 0xFF;
int alpha = hex & 0xFF;
return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:alpha / 255.0f];
}
+ (UIColor *)fat_colorWithARGBHex:(UInt32)hex {
int alpha = (hex >> 24) & 0xFF;
int red = (hex >> 16) & 0xFF;
int green = (hex >> 8) & 0xFF;
int blue = hex & 0xFF;
return [UIColor colorWithRed:red / 255.0f green:green / 255.0f blue:blue / 255.0f alpha:alpha / 255.0f];
}
@end @end

View File

@ -17,7 +17,7 @@ A finclip miniprogram flutter sdk.
s.dependency 'Flutter' s.dependency 'Flutter'
s.ios.deployment_target = '9.0' s.ios.deployment_target = '9.0'
s.dependency 'FinApplet' , '2.34.12' s.dependency 'FinApplet' , '2.34.11'
s.dependency 'FinAppletExt' , '2.34.12' s.dependency 'FinAppletExt' , '2.34.11'
end end

View File

@ -67,6 +67,14 @@ class UIConfig {
FloatWindowConfig? floatWindowConfig; FloatWindowConfig? floatWindowConfig;
//iOS
//H5 0xFFFFAA00
int? progressBarColor;
//true
bool autoAdaptDarkMode = true;
//appletText
String? appletText;
Map<String, dynamic> toMap() { Map<String, dynamic> toMap() {
return { return {
"navigationTitleTextAttributes": navigationTitleTextAttributes, "navigationTitleTextAttributes": navigationTitleTextAttributes,
@ -81,6 +89,9 @@ class UIConfig {
"disableSlideCloseAppletGesture": disableSlideCloseAppletGesture, "disableSlideCloseAppletGesture": disableSlideCloseAppletGesture,
"capsuleConfig": capsuleConfig?.toMap(), "capsuleConfig": capsuleConfig?.toMap(),
"floatWindowConfig": floatWindowConfig?.toMap(), "floatWindowConfig": floatWindowConfig?.toMap(),
"progressBarColor": progressBarColor,
"autoAdaptDarkMode": autoAdaptDarkMode,
"appletText": appletText
}; };
} }
} }