1.增加微信第三方支付;2.优化微信登录代码;3.优化finclip初始化代码,使用plist文件维护(小程序列表也是)

master
jizelin 2021-08-19 19:47:47 +08:00
parent d3c2bd4fde
commit 65d10c5b42
12 changed files with 364 additions and 103 deletions

View File

@ -6,6 +6,7 @@ inhibit_all_warnings!
target "demo" do target "demo" do
pod 'FinApplet' pod 'FinApplet'
pod 'FinAppletExt' pod 'FinAppletExt'
pod 'WechatOpenSDK'
end end

View File

@ -12,6 +12,9 @@
9DD565C923EC450A0011FC4A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9DD565C823EC450A0011FC4A /* Assets.xcassets */; }; 9DD565C923EC450A0011FC4A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9DD565C823EC450A0011FC4A /* Assets.xcassets */; };
9DD565CC23EC450A0011FC4A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DD565CA23EC450A0011FC4A /* LaunchScreen.storyboard */; }; 9DD565CC23EC450A0011FC4A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9DD565CA23EC450A0011FC4A /* LaunchScreen.storyboard */; };
9DD565CF23EC450A0011FC4A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD565CE23EC450A0011FC4A /* main.m */; }; 9DD565CF23EC450A0011FC4A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 9DD565CE23EC450A0011FC4A /* main.m */; };
A0E041B926CE6DAD00D58D47 /* demo.plist in Resources */ = {isa = PBXBuildFile; fileRef = A0E041B826CE6DAD00D58D47 /* demo.plist */; };
A0E041BB26CE6E1F00D58D47 /* finosprite.plist in Resources */ = {isa = PBXBuildFile; fileRef = A0E041BA26CE6E1F00D58D47 /* finosprite.plist */; };
A0E041BD26CE720900D58D47 /* servers.plist in Resources */ = {isa = PBXBuildFile; fileRef = A0E041BC26CE720900D58D47 /* servers.plist */; };
A823321F258C3B7000C1B2D5 /* FINDemoClientHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = A823321D258C3B7000C1B2D5 /* FINDemoClientHelper.m */; }; A823321F258C3B7000C1B2D5 /* FINDemoClientHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = A823321D258C3B7000C1B2D5 /* FINDemoClientHelper.m */; };
A863B745257A09A300959AA1 /* FINExtensionHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = A863B744257A09A300959AA1 /* FINExtensionHelper.m */; }; A863B745257A09A300959AA1 /* FINExtensionHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = A863B744257A09A300959AA1 /* FINExtensionHelper.m */; };
A8BC097A258BA095001289A3 /* FINCustomMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A8BC0979258BA095001289A3 /* FINCustomMenuModel.m */; }; A8BC097A258BA095001289A3 /* FINCustomMenuModel.m in Sources */ = {isa = PBXBuildFile; fileRef = A8BC0979258BA095001289A3 /* FINCustomMenuModel.m */; };
@ -30,6 +33,9 @@
9DD565CB23EC450A0011FC4A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; }; 9DD565CB23EC450A0011FC4A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
9DD565CD23EC450A0011FC4A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 9DD565CD23EC450A0011FC4A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9DD565CE23EC450A0011FC4A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; 9DD565CE23EC450A0011FC4A /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
A0E041B826CE6DAD00D58D47 /* demo.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = demo.plist; sourceTree = "<group>"; };
A0E041BA26CE6E1F00D58D47 /* finosprite.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = finosprite.plist; sourceTree = "<group>"; };
A0E041BC26CE720900D58D47 /* servers.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = servers.plist; sourceTree = "<group>"; };
A823321D258C3B7000C1B2D5 /* FINDemoClientHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FINDemoClientHelper.m; sourceTree = "<group>"; }; A823321D258C3B7000C1B2D5 /* FINDemoClientHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FINDemoClientHelper.m; sourceTree = "<group>"; };
A823321E258C3B7000C1B2D5 /* FINDemoClientHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FINDemoClientHelper.h; sourceTree = "<group>"; }; A823321E258C3B7000C1B2D5 /* FINDemoClientHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FINDemoClientHelper.h; sourceTree = "<group>"; };
A863B743257A09A200959AA1 /* FINExtensionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FINExtensionHelper.h; sourceTree = "<group>"; }; A863B743257A09A200959AA1 /* FINExtensionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FINExtensionHelper.h; sourceTree = "<group>"; };
@ -86,6 +92,9 @@
9DD565CA23EC450A0011FC4A /* LaunchScreen.storyboard */, 9DD565CA23EC450A0011FC4A /* LaunchScreen.storyboard */,
9DD565CD23EC450A0011FC4A /* Info.plist */, 9DD565CD23EC450A0011FC4A /* Info.plist */,
9DD565CE23EC450A0011FC4A /* main.m */, 9DD565CE23EC450A0011FC4A /* main.m */,
A0E041B826CE6DAD00D58D47 /* demo.plist */,
A0E041BA26CE6E1F00D58D47 /* finosprite.plist */,
A0E041BC26CE720900D58D47 /* servers.plist */,
); );
path = demo; path = demo;
sourceTree = "<group>"; sourceTree = "<group>";
@ -167,7 +176,10 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
9DD565CC23EC450A0011FC4A /* LaunchScreen.storyboard in Resources */, 9DD565CC23EC450A0011FC4A /* LaunchScreen.storyboard in Resources */,
A0E041BB26CE6E1F00D58D47 /* finosprite.plist in Resources */,
A0E041B926CE6DAD00D58D47 /* demo.plist in Resources */,
9DD565C923EC450A0011FC4A /* Assets.xcassets in Resources */, 9DD565C923EC450A0011FC4A /* Assets.xcassets in Resources */,
A0E041BD26CE720900D58D47 /* servers.plist in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@ -356,26 +368,6 @@
9DD565D323EC450A0011FC4A /* Debug */ = { 9DD565D323EC450A0011FC4A /* Debug */ = {
isa = XCBuildConfiguration; isa = XCBuildConfiguration;
baseConfigurationReference = FBEBA7E73B95B66C846E76FF /* Pods-demo.debug.xcconfig */; baseConfigurationReference = FBEBA7E73B95B66C846E76FF /* Pods-demo.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 9QCKYFU5M4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.finogeeks.finclip.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
9DD565D423EC450A0011FC4A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 3F2BFD149B6F799A303A07B3 /* Pods-demo.release.xcconfig */;
buildSettings = { buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
@ -393,6 +385,28 @@
PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "";
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
name = Debug;
};
9DD565D423EC450A0011FC4A /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 3F2BFD149B6F799A303A07B3 /* Pods-demo.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Distribution";
CODE_SIGN_STYLE = Manual;
DEVELOPMENT_TEAM = 9QCKYFU5M4;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = demo/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
PRODUCT_BUNDLE_IDENTIFIER = com.finogeeks.finclip.demo;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = github_demo_adhoc;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release; name = Release;
}; };
/* End XCBuildConfiguration section */ /* End XCBuildConfiguration section */

View File

@ -12,6 +12,7 @@
#import "FINDemoClientHelper.h" #import "FINDemoClientHelper.h"
#import <FinApplet/FinApplet.h> #import <FinApplet/FinApplet.h>
#import <WechatOpenSDK/WXApi.h>
@interface AppDelegate () @interface AppDelegate ()
@ -23,17 +24,30 @@
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch. // Override point for customization after application launch.
NSString *appKey = @"22LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM="; // servers.plistfinclip
FATConfig *config = [FATConfig configWithAppSecret:@"bdfd76cae24d4313" appKey:appKey]; NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
config.apiServer = @"https://api.finclip.com"; NSString *path = [[NSBundle mainBundle] pathForResource:@"servers" ofType:@"plist"];
config.apiPrefix = @"/api/v1/mop"; NSDictionary *servers = [NSDictionary dictionaryWithContentsOfFile:path];
NSDictionary *data = servers[bundleId];
NSString *appKey = data[@"appKey"];
NSString *appSecret = data[@"appSecret"];
NSString *apiServer = data[@"apiServer"];
NSString *apiPrefix = data[@"apiPrefix"];
FATApiCryptType cryptType = [data[@"cryptType"] isEqualToString:@"MD5"] ? FATApiCryptTypeMD5 : FATApiCryptTypeSM;
FATConfig *config = [FATConfig configWithAppSecret:appSecret appKey:appKey];
config.apiServer = apiServer;
config.apiPrefix = apiPrefix;
config.cryptType = cryptType;
[[FATClient sharedClient] initWithConfig:config error:nil]; [[FATClient sharedClient] initWithConfig:config error:nil];
[[FATClient sharedClient] setEnableLog:YES]; [[FATClient sharedClient] setEnableLog:YES];
[FATClient sharedClient].delegate = [FINDemoClientHelper sharedHelper]; [FATClient sharedClient].delegate = [FINDemoClientHelper sharedHelper];
// api
[[FINExtensionHelper sharedHelper] registerCustomApis];
[FINExtensionHelper registerCustomApis]; // appIDwx85663af68a0cbbc8BundleIDcom.finogeeks.mop.finosprite
[WXApi registerApp:@"wx85663af68a0cbbc8" universalLink:apiServer];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor]; self.window.backgroundColor = [UIColor whiteColor];
@ -43,4 +57,11 @@
return YES; return YES;
} }
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
if ([url.scheme isEqualToString:@"wx85663af68a0cbbc8"]) {
return [WXApi handleOpenURL:url delegate:(id<WXApiDelegate> _Nullable)[FINExtensionHelper sharedHelper]];
}
return YES;
}
@end @end

View File

@ -10,7 +10,7 @@
@implementation FINCustomMenuModel @implementation FINCustomMenuModel
@synthesize menuId, menuIconImage, menuTitle; @synthesize menuId, menuIconImage, menuTitle, menuType;
- (id)copyWithZone:(NSZone *)zone - (id)copyWithZone:(NSZone *)zone
{ {

View File

@ -13,8 +13,7 @@ static FINDemoClientHelper *instance = nil;
@implementation FINDemoClientHelper @implementation FINDemoClientHelper
+ (instancetype)sharedHelper + (instancetype)sharedHelper {
{
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
instance = [[[self class] alloc] init]; instance = [[[self class] alloc] init];
@ -22,6 +21,18 @@ static FINDemoClientHelper *instance = nil;
return instance; return instance;
} }
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [super allocWithZone:zone];
});
return instance;
}
- (id)copy {
return instance;
}
#pragma mark - FATAppletDelegate #pragma mark - FATAppletDelegate
- (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion - (void)forwardAppletWithInfo:(NSDictionary *)contentInfo completion:(void (^)(FATExtensionCode, NSDictionary *))completion
{ {
@ -92,12 +103,12 @@ static FINDemoClientHelper *instance = nil;
- (void)customMenu:(id<FATAppletMenuProtocol>)customMenu inApplet:(FATAppletInfo *)appletInfo didClickAtPath:(NSString *)path - (void)customMenu:(id<FATAppletMenuProtocol>)customMenu inApplet:(FATAppletInfo *)appletInfo didClickAtPath:(NSString *)path
{ {
NSLog(@"自定义按钮被点击"); NSLog(@"自定义按钮被点击");
if (customMenu.menuId == 1001) { if ([customMenu.menuId isEqual:@"1001"]) {
NSLog(@"客服按钮被点击"); NSLog(@"客服按钮被点击");
return; return;
} }
if (customMenu.menuId == 1002) { if ([customMenu.menuId isEqual:@"1002"]) {
NSLog(@"收藏按钮被点击"); NSLog(@"收藏按钮被点击");
// 1.id // 1.id
// NSString *userId = @""; // NSString *userId = @"";

View File

@ -9,7 +9,9 @@
@interface FINExtensionHelper : NSObject @interface FINExtensionHelper : NSObject
+ (void)registerCustomApis; + (instancetype)sharedHelper;
- (void)registerCustomApis;
@end @end

View File

@ -7,22 +7,154 @@
#import "FINExtensionHelper.h" #import "FINExtensionHelper.h"
#import <FinApplet/FinApplet.h> #import <FinApplet/FinApplet.h>
#import <WechatOpenSDK/WXApi.h>
#import <CommonCrypto/CommonDigest.h>
#import <CommonCrypto/CommonHMAC.h>
@interface FINExtensionHelper () <WXApiDelegate>
//
@property (nonatomic, copy) FATExtensionApiCallback callback;
@end
static FINExtensionHelper *instance = nil;
@implementation FINExtensionHelper @implementation FINExtensionHelper
+ (void)registerCustomApis + (instancetype)sharedHelper {
{ static dispatch_once_t onceToken;
[[FATClient sharedClient] registerExtensionApi:@"onNative" handle:^(id param, FATExtensionApiCallback callback) { dispatch_once(&onceToken, ^{
instance = [[FINExtensionHelper alloc] init];
});
return instance;
}
+ (instancetype)allocWithZone:(struct _NSZone *)zone {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [super allocWithZone:zone];
});
return instance;
}
- (id)copy {
return instance;
}
// api
- (void)registerCustomApis {
[[FATClient sharedClient] registerExtensionApi:@"onNative" handle:^(id param, FATExtensionApiCallback callback) {
NSString *inputText = @"床前明月光,疑是地上霜。举头望明月,低头思故乡。"; NSString *inputText = @"床前明月光,疑是地上霜。举头望明月,低头思故乡。";
callback(FATExtensionCodeSuccess, @{@"text":inputText}); callback(FATExtensionCodeSuccess, @{@"text":inputText});
}]; }];
[[FATClient sharedClient] fat_registerWebApi:@"user_define_native" handle:^(id param, FATExtensionApiCallback callback) { [[FATClient sharedClient] fat_registerWebApi:@"user_define_native" handle:^(id param, FATExtensionApiCallback callback) {
NSString *inputText = @"鹅鹅鹅,曲项向天歌,白毛浮绿水,红掌拨清波。"; NSString *inputText = @"鹅鹅鹅,曲项向天歌,白毛浮绿水,红掌拨清波。";
callback(FATExtensionCodeSuccess, @{@"text":inputText}); callback(FATExtensionCodeSuccess, @{@"text":inputText});
}]; }];
//
[[FATClient sharedClient] registerExtensionApi:@"getUserProfile" handle:^(id param, FATExtensionApiCallback callback) {
NSDictionary *userInfo = @{@"nickName":@"张三",@"avatarUrl":@"",@"gender":@1,@"country":@"中国",@"province":@"广东省",@"city":@"深圳",@"language":@"zh_CN"};
NSDictionary *resDic = @{@"userInfo":userInfo};
callback(FATExtensionCodeSuccess,resDic);
}];
//
[[FATClient sharedClient] registerExtensionApi:@"login" handle:^(id param, FATExtensionApiCallback callback) {
//
//
callback(FATExtensionCodeSuccess,@{@"desc":@"登录成功"});
}];
//
__weak typeof(self) weakSelf = self;
[[FATClient sharedClient] registerExtensionApi:@"requestPayment" handle:^(id param, FATExtensionApiCallback callback) {
//
[weakSelf getTestPayment:callback];
}];
} }
#pragma mark - WXPay
//
- (void)getTestPayment:(FATExtensionApiCallback)callback {
NSString *urlString = @"https://finclip-testing.finogeeks.club/mop/wechat-auth/api/order";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *requset = [NSMutableURLRequest requestWithURL:url];
requset.HTTPMethod = @"POST";
__weak typeof(self) weakSelf = self;
NSURLSessionTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:requset completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode == 200) {
NSString *appId = @"wx85663af68a0cbbc8";
NSString *partnerId = @"1600932850";
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSString *prepayId = dict[@"data"][@"prepay_id"];
NSString *nonceStr = @"5K8264ILTKCH16CQ2502SI8ZNMTM67VS"; //
UInt32 timeStamp = [[NSDate date] timeIntervalSince1970];
NSString *text = [NSString stringWithFormat:@"%@\n%ld\n%@\n%@\n", appId, (long)timeStamp, nonceStr, prepayId];
NSString *sign = [weakSelf sha256:text];
PayReq *request = [[PayReq alloc] init];
request.partnerId = partnerId;
request.prepayId = prepayId;
request.package = @"Sign=WXPay";
request.nonceStr = nonceStr;
request.timeStamp = timeStamp;
request.sign= sign;
dispatch_async(dispatch_get_main_queue(), ^{
[WXApi sendReq:request completion:^(BOOL success) {
if (success) {
weakSelf.callback = callback;
} else {
callback(FATExtensionCodeFailure, nil);
}
}];
});
return;
}
callback(FATExtensionCodeFailure, nil);
}];
[task resume];
}
//
- (NSString *)sha256:(NSString *)shaStr {
NSData *data = [shaStr dataUsingEncoding:NSUTF8StringEncoding];
uint8_t digest[CC_SHA256_DIGEST_LENGTH];
CC_SHA256(data.bytes, (CC_LONG)data.length, digest);
NSData *adata = [[NSData alloc] initWithBytes:digest length:CC_SHA256_DIGEST_LENGTH];
adata = [adata base64EncodedDataWithOptions:0];
NSString *ret = [[NSString alloc] initWithData:adata encoding:NSUTF8StringEncoding];
return ret;
}
#pragma mark - WXApiDelegate
//
- (void)onReq:(BaseReq *)req {
}
//
- (void)onResp:(BaseResp *)resp {
if ([resp isKindOfClass:[PayResp class]]) {
PayResp *response = (PayResp*)resp;
//response.errCode
// WXSuccess = 0, /**< 成功 */
// WXErrCodeCommon = -1, /**< 普通错误类型 */
// WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */
// WXErrCodeSentFail = -3, /**< 发送失败 */
// WXErrCodeAuthDeny = -4, /**< 授权失败 */
// WXErrCodeUnsupport = -5, /**< 微信不支持 */
switch (response.errCode) {
case WXSuccess:
self.callback(FATExtensionCodeSuccess, nil);
break;
default:
self.callback(FATExtensionCodeFailure, nil);
break;
}
}
}
@end @end

View File

@ -16,8 +16,26 @@
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string> <string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>1.0</string> <string>1.0</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>weixin</string>
<key>CFBundleURLSchemes</key>
<array>
<string>wx85663af68a0cbbc8</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>
<string>1</string> <string>1</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>weixinULAPI</string>
</array>
<key>LSRequiresIPhoneOS</key> <key>LSRequiresIPhoneOS</key>
<true/> <true/>
<key>NSAppTransportSecurity</key> <key>NSAppTransportSecurity</key>

View File

@ -8,6 +8,7 @@
#import "ViewController.h" #import "ViewController.h"
#import <FinApplet/FinApplet.h> #import <FinApplet/FinApplet.h>
#import <WechatOpenSDK/WXApi.h>
@interface ViewController ()<UITableViewDelegate, UITableViewDataSource> @interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
@ -28,8 +29,7 @@
[self p_initSubViews]; [self p_initSubViews];
} }
- (void)p_initSubViews - (void)p_initSubViews {
{
CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width; CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
@ -44,32 +44,25 @@
[self.view addSubview:self.tableView]; [self.view addSubview:self.tableView];
} }
- (void)p_loadData - (void)p_loadData {
{ //
NSDictionary *startParams = nil;
self.appletList = [[NSMutableArray alloc] init]; self.appletList = [[NSMutableArray alloc] init];
NSString *bundleId = [NSBundle mainBundle].bundleIdentifier;
[self.appletList addObject:@{@"appId":@"5facb3a52dcbff00017469bd",@"title":@"绘图小程序"}]; NSString *appName = [bundleId componentsSeparatedByString:@"."].lastObject;
[self.appletList addObject:@{@"appId":@"5fa214a29a6a7900019b5cc1",@"title":@"官方示例小程序"}]; if (![appName isEqualToString:@""]) {
[self.appletList addObject:@{@"appId":@"5fa215459a6a7900019b5cc3",@"title":@"对账单"}]; NSString *path = [[NSBundle mainBundle] pathForResource:appName ofType:@"plist"];
// FAT NSArray *array = [NSArray arrayWithContentsOfFile:path];
[self.appletList addObject:@{@"appId":@"5fc8934aefb8c600019e9747",@"title":@"自定义小程序API示例"}]; for (NSDictionary *dict in array) {
[self.appletList addObject:dict];
startParams = @{ }
@"path" : @"/pages/webview/webview" }
};
[self.appletList addObject:@{@"appId":@"5fc8934aefb8c600019e9747",@"title":@"自定义H5 API示例", @"startParams":startParams}];
[self.appletList addObject:@{@"appId":@"60c5bbf99e094f00015079ee",@"title":@"原生向小程序发送事件"}];
//App
[self registAppletLoginApi];
[self.appletList addObject:@{@"appId":@"60f051ea525ea10001c0bd22",@"title":@"小程序登录授权示例"}];
[self.tableView reloadData]; [self.tableView reloadData];
} }
- (void)sendCustomEvent //
{ - (void)sendCustomEvent {
if (@available(iOS 10.0, *)) { if (@available(iOS 10.0, *)) {
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:3 repeats:YES block:^(NSTimer * _Nonnull timer) { [NSTimer scheduledTimerWithTimeInterval:3 repeats:YES block:^(NSTimer * _Nonnull timer) {
NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970]; NSTimeInterval timestamp = [[NSDate date] timeIntervalSince1970];
[[FATClient sharedClient].nativeViewManager sendCustomEventWithDetail:@{@"timestamp":@(timestamp)} completion:^(id result, NSError *error) { [[FATClient sharedClient].nativeViewManager sendCustomEventWithDetail:@{@"timestamp":@(timestamp)} completion:^(id result, NSError *error) {
NSLog(@"sendCustomEventW:%@", error); NSLog(@"sendCustomEventW:%@", error);
@ -78,52 +71,12 @@
} }
} }
- (void)registAppletLoginApi {
//
[[FATClient sharedClient]registerExtensionApi:@"getUserProfile" handle:^(id param, FATExtensionApiCallback callback) {
NSDictionary *userInfo = @{@"nickName":@"张三",@"avatarUrl":@"",@"gender":@1,@"country":@"中国",@"province":@"广东省",@"city":@"深圳",@"language":@"zh_CN"};
NSDictionary *resDic = @{@"userInfo":userInfo};
callback(FATExtensionCodeSuccess,resDic);
}];
//
[[FATClient sharedClient]registerExtensionApi:@"login" handle:^(id param, FATExtensionApiCallback callback) {
//
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:@"是否同意授权登录?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *agreeAction = [UIAlertAction actionWithTitle:@"允许" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
callback(FATExtensionCodeSuccess,@{@"desc":@"登录成功"});
}];
[alertVC addAction:agreeAction];
UIAlertAction *refuseAction = [UIAlertAction actionWithTitle:@"拒绝" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
callback(FATExtensionCodeSuccess,@{@"desc":@"登录失败"});
}];
[alertVC addAction:refuseAction];
if (self.presentedViewController) {
[self.presentedViewController presentViewController:alertVC animated:YES completion:^{
}];
} else {
[self presentViewController:alertVC animated:YES completion:^{
}];
}
}];
}
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
{
return self.appletList.count; return self.appletList.count;
} }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
{
static NSString *identifer = @"identifer"; static NSString *identifer = @"identifer";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer]; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifer];
if (cell == nil) { if (cell == nil) {
@ -132,12 +85,10 @@
NSDictionary *dict = self.appletList[indexPath.row]; NSDictionary *dict = self.appletList[indexPath.row];
cell.textLabel.text = dict[@"title"]; cell.textLabel.text = dict[@"title"];
return cell; return cell;
} }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
{
[tableView deselectRowAtIndexPath:indexPath animated:YES]; [tableView deselectRowAtIndexPath:indexPath animated:YES];
NSDictionary *dict = self.appletList[indexPath.row]; NSDictionary *dict = self.appletList[indexPath.row];

65
demo/demo.plist 100644
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>appId</key>
<string>5facb3a52dcbff00017469bd</string>
<key>title</key>
<string></string>
<key>startParams</key>
<dict/>
</dict>
<dict>
<key>appId</key>
<string>5fa214a29a6a7900019b5cc1</string>
<key>title</key>
<string></string>
<key>startParams</key>
<dict/>
</dict>
<dict>
<key>appId</key>
<string>5fa215459a6a7900019b5cc3</string>
<key>title</key>
<string></string>
<key>startParams</key>
<dict/>
</dict>
<dict>
<key>appId</key>
<string>5fc8934aefb8c600019e9747</string>
<key>title</key>
<string>API</string>
<key>startParams</key>
<dict/>
</dict>
<dict>
<key>appId</key>
<string>5fc8934aefb8c600019e9747</string>
<key>title</key>
<string>H5 API</string>
<key>startParams</key>
<dict>
<key>path</key>
<string>/pages/webview/webview</string>
</dict>
</dict>
<dict>
<key>appId</key>
<string>60c5bbf99e094f00015079ee</string>
<key>title</key>
<string></string>
<key>startParams</key>
<dict/>
</dict>
<dict>
<key>appId</key>
<string>60f051ea525ea10001c0bd22</string>
<key>title</key>
<string></string>
<key>startParams</key>
<dict/>
</dict>
</array>
</plist>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>appId</key>
<string>611cf17739245f000182fa40</string>
<key>title</key>
<string>&amp;</string>
<key>startParams</key>
<dict/>
</dict>
</array>
</plist>

32
demo/servers.plist 100644
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.finogeeks.finclip.demo</key>
<dict>
<key>appKey</key>
<string>22LyZEib0gLTQdU3MUauATBwgfnTCJjdr7FCnywmAEM=</string>
<key>appSecret</key>
<string>bdfd76cae24d4313</string>
<key>apiServer</key>
<string>https://api.finclip.com</string>
<key>apiPrefix</key>
<string>/api/v1/mop/</string>
<key>cryptType</key>
<string>MD5</string>
</dict>
<key>com.finogeeks.mop.finosprite</key>
<dict>
<key>appKey</key>
<string>22LyZEib0gLTQdU3MUauAQVLIkNNhTSGIN42gXzlAsk=</string>
<key>appSecret</key>
<string>ae55433be2f62915</string>
<key>apiServer</key>
<string>https://finchat-mop-b.finogeeks.club</string>
<key>apiPrefix</key>
<string>/api/v1/mop/</string>
<key>cryptType</key>
<string>SM</string>
</dict>
</dict>
</plist>