融360的爬虫 SDK
Swift 配置
****** 必须使用 1.1.8 及以后的 pod 库
1、创建一个头文件,例如:RDPCrawlerBridg.h
2、在头文件中引入 #import "<RDPCrawlerSDK/RDPCrawlerManager.h>"
3、点击工程配置yourTarget->build setting -> Objective-c Bridging Header -> xxxTarget/RDPCrawlerBridg.h(xxxTarget为您的工程的名)
接入步骤:
支持 iOS 最低版本 7.0, Xcode 8.0
需要先申请 appid,配置好相应的证书和回调 url
1. 在 Podfile 文件中添加 pod 'R360CrawlerSDK',然后执行 pod update(需要更新本地 pod 仓库,以防本地仓库不包含 SDK 的信息)
2. 权限配置
a. 如果支持了 ATS,需要对 uiwebview 放开限制
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
b. 如果使用支付宝抓取,需要在工程中的 info.plist 中添加 LSApplicationQueriesSchemes 数组,在数组中添加一个支持的 scheme: alipayqr
<key>LSApplicationQueriesSchemes</key>
<array>
<string>alipayqr</string>
</array>
c. 使用运营商时,如果支持了 ATS,需要对以下域名放开限制
10086.cn
10010.com
189.cn
chinamobile.com
telecomjs.com
ct10000.com
chinatelecom-ec.com
plist 配置:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>10086.cn</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>10010.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>189.cn</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>chinamobile.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>telecomjs.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>ct10000.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
<key>chinatelecom-ec.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.0</string>
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
<key>NSAllowsArbitraryLoadsInWebContent</key>
<true/>
<key>NSPhotoLibraryUsageDescription</key>
<string>访问相册</string>
</dict>
3. 初始化 SDK,调用接口传入 appid 和对应的 p12 格式的私钥
NSString *keyPath = [[NSBundle mainBundle] pathForResource:@"private" ofType:@"p12"];
NSData *keyData = [NSData dataWithContentsOfFile:keyPath];
如私钥文件没有设置密码,调用以下方法:
[RDPCrawlerManager configAppId:@"申请的appid" delegate:self privateKey:keyData];
如私钥文件设置了密码,调用另一个方法
[RDPCrawlerManager configAppId:@"申请的appid" delegate:self privateKey:keyData password:@"私钥密码"];
4. 调用所需类型的抓取服务
支付宝抓取
[RDPCrawlerManager startCrawlerByType:kRDPCrawlerTypeAlipay identifier:@"自定义的任务id"];
淘宝抓取
[RDPCrawlerManager startCrawlerByType:kRDPCrawlerTypeTaobao identifier:@"自定义的任务id"];
运营商抓取
RDPC_OperatorConfig *config = [RDPC_OperatorConfig new];
config.phone = @"xxxxxxxxxx";
config.canEditPhone = YES;
[RDPCrawlerManager startCrawlerOperatorByConfig:config identifier:@"自定义的任务id" addtionalParams:nil];
邮箱抓取
[RDPCrawlerManager startCrawlerByType:kRDPCrawlerTypeEmail identifier:@"自定义的任务id" addtionalParams:nil];
addtionalParams 传入用户需要在抓取成功后回调的参数。当前版本需要传入用户的三要素进行服务器端校验,即姓名 real_name、身份证号 id_card、手机号 cellphone,如下所示,可以在其后面添加自己所需要的参数
@{@"real_name":@"XXX",@"id_card":@"4222219820211062X",@"cellphone":@"13812345678"}
5. 抓取结果
在抓取结果类中实现 RDPCrawlerDelegate 协议,并实现协议的具体方法,其中 RDPCrawlerItem.addtionParams 是抓取任务开始时传入的 addtionalParams 参数。
- (void)crawlerChangeStatus:(RDPCrawlerItem *)statusItem {
switch (statusItem.status) {
case kRDPCrawlerStatusStart:
NSLog(@"分配到serverId,开始抓取");
break;
case kRDPCrawlerStatusLoginSuccess:
NSLog(@"登录成功");
break;
case kRDPCrawlerStatusFetchSuccess:
NSLog(@"获取数据成功, 抓取完成");
break;
case kRDPCrawlerStatusFailed:
NSLog(@"出现错误:%@", statusItem.error.domain);
break;
case kRDPCrawlerStatusCancel:
NSLog(@"用户手动取消任务");
break;
default:
break;
}
}
6. 界面自定义
当前 SDK 支持界面部分元素进行自定义,主要包括顶部导航栏背景色、导航栏文字字号以及颜色。运营商页面提交按钮颜色和按钮文字颜色,如果未设置,则使用默认颜色。具体如下
+ (void)setNavigationColor:(UIColor *)navigationColor;//设置导航栏背景色
+ (void)setNavigationTitleFont:(UIFont *)font;//设置导航栏字体
+ (void)setNavigationTitleColor:(UIColor *)titleColor;//导航栏字体颜色
+ (void)setSubmitButtonColor:(UIColor *)buttonColor;//运营商,邮箱底部提交按钮颜色
+ (void)setSubmitButtonHighLightColor:(UIColor *)buttonHighLightColor;//运营商,邮箱底部提交按钮高亮颜色,当未设置按钮颜色时,改属性不起作用
+ (void)setSubmitButtonTitleColor:(UIColor *)titleColor;//运营商,邮箱底部提交底部按钮文字颜色,当未设置按钮颜色时,改属性不起作用
ps
如需使用测试环境联调,需调用[RDPCrawlerManager setIsDebug:YES]
pem转p12的步骤,需在终端输入如下命令:
如pem文件为private.pem
(1) 生成一个csr文件
openssl req -new -key private.pem -out rsacert.csr
这时候要求输入以下一些证书配置信息
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:beijing
Locality Name (eg, city) []:beijing
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Rong360
Organizational Unit Name (eg, section) []:com
Common Name (e.g. server FQDN or YOUR name) []:R360
Email Address []:[email protected]
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
(2)生成证书并签名,有效期 10 年
openssl x509 -req -days 3650 -in rsacert.csr -signkey private.pem -out rsacert.crt
(3)生成 P12 文件
openssl pkcs12 -export -out private.p12 -inkey private.pem -in rsacert.crt