本文档仅适用于个验3.0.0.0及以上版本。
3.0.0.0以下版请查看《版本更新说明》
+ (void)startWithAppId:(NSString *_Nonnull)appId withCallback:(GyCallback _Nonnull)callback;
[GeYanSdk startWithAppId:APPID
withCallback:^(BOOL isSuccess, NSError *error, NSString *gtcid) {
NSLog(@"GeYanSdk startWithAppId gtcid:%@", error);
// GeYanSdk startWithAppId gtcid:gtc_dbf8471ad1ef4681bf9928a446784aa535
}];
// 通过 appId 启动SDK,注:该方法需要在主线程中调用
+ (void)setDebug:(BOOL)debug;
[GeYanSdk setDebug:YES];
+ (void)setPreLoginTimeout:(NSTimeInterval)timeout;
[GeYanSdk setPreLoginTimeout:10];
+ (void)setEloginTimeout:(NSTimeInterval)timeout;
[GeYanSdk setEloginTimeout:10];
+ (void)preGetToken:(GyVerifyCallback _Nonnull)callback;
[GeYanSdk isPreGettedTokenValidate]
查看当前预登陆结果是否有效。[GeYanSdk preGetToken:^(NSDictionary *preDic)
NSLog(@"preGetToken: %@", preDic);
/*
成功示例:
preGetToken: {
code = 30000; //30000:操作成功, 其他错误码需参考《状态码汇总》
expiredTime = 120; //结果有效时长,秒
number = "152****0533"; //当前设备的手机号,带掩码
operatorType = 1; //0:未知 1:移动 2:联通 3:电信
msg = "操作成功";
gyuid = "gtc_dbf8471ad1ef4681bf9928a446784aa535";
processID = d3729d0402e358bfaabdb59670ee9143;
}
失败实例:
preGetToken: {
code = 30005;
errorCode = "-20201";
gyuid = "gtc_dbf8471ad1ef4681bf9928a446784aa535";
msg = "无SIM卡";
operatorType = 0;
processID = d674db1383288b8b005a823ffef15dad;
}
失败实例:
preGetToken: {
code = 30005;
errorCode = "-40001";
metadata = { //运营商错误信息
desc = "无网络";
resultCode = 200022;
traceId = c542db408fe3438028b644d451d479d3;
};
operatorType = 1;
msg = "运营商返回失败";
gyuid = gtc_dbf8471ad1ef4681bf9928a446784aa535;
processID = f676bc541499282fda1f795d390c5f5c;
}
*/
}];
@interface GyContentModel : NSObject
@property (nonatomic, copy) NSString *pn;
@property (nonatomic, copy) NSString *slogan;
@property (nonatomic, copy) NSString *term;
@property (nonatomic, copy) NSString *link;
+ (GyContentModel*)currentModel;
@end
- (void)renderView { //将预登陆信息渲染到UI界面
GyContentModel *model = [GyContentModel currentModel];
self.pnLabel.text = model.pn; //当前手机号,带掩码
self.sloganLabel.text = model.slogan; //运营商slogan
self.termLabel.text = model.term; //运营商隐私协议名称
[self updateCheckBoxState];
// 隐私条款字符串拼接
NSString *termText = [NSString stringWithFormat:@"登录即同意%@并使用本机号码登录", model.term];
self.termLabel.text = termText;
NSRange range = [termText rangeOfString:model.term];
if (range.location != NSNotFound) {
[self.termLabel addLinkToURL:[[NSURL alloc] initWithString:[NSString stringWithFormat:@"%@", model.link]] withRange:range];
}
[self.termLabel sizeToFit];
}
+ (BOOL)isPreGettedTokenValidate;
/// YES - 还在有效期,可直接调用一键登录
/// NO - 已失效,需重新预取号
[GeYanSdk isPreGettedTokenValidate];
+ (void)oneTapLogin:(UIViewController *_Nonnull)controller
viewModel:(GyAuthViewModel *_Nonnull)model
contentView:(UIView *_Nonnull)contentView
subViewList:(NSArray *_Nonnull)subViewList
loginBlock:(GyVerifyCallback __nullable)loginBlock;
授权页的必要组件不符合授权页规范,会无法一键登录
,返回错误UI校验失败
。不合规行为比如:不可见、遮挡、修改内容等;sdk将对登录按钮设置点击监听。
状态码参考状态码汇总
__weak LoginListController *weakSelf = self;
NSArray *list = @[self.customView.pnLabel,
self.customView.sloganLabel,
self.customView.loginBtn,
self.customView.checkboxBtn,
self.customView.termLabel];
// 一键登录
/*
由SDK控制Controller生命周期,开发者控制Controller中View的显示。
但View的显示需要遵循一定规则:
1 pnLabel 手机号码
2 sloganLabel 运营商slogan
3 loginBtn 登录按钮
4 checkboxBtn 协议勾选框
5 termLabel 协议内容
以上控件必须保持页面内可见,不可遮挡、隐藏、曲解意义等操作。
以上控件的内容值,在预取号成功后可以通过接口[GyContentModel currentModel]获取。
*/
if ([GeYanSdk isPreGettedTokenValidate]) {
// 渲染页面信息
[weakSelf.customView render];
// 一键登录
[GeYanSdk oneTapLogin:self
viewModel:viewModel
contentView:self.contentView
subViewList:list
loginBlock:^(NSDictionary * _Nullable dic) {
NSLog(@"%@", dic);
/*
成功示例:
oneTapLogin:{
code = 30000;
expiredTime = 120;
gyuid = gtc_dbf8471ad1ef4681bf9928a446784aa535;
msg = "操作成功";
number = "152****0533";
operatorType = 1;
processID = a6811893890c73765e02eeb77634164f;
token = "U1RzaWQwMDAwMDAxNjYzNzQzNTM2MTI5TGtJM3dtdVd1VzB6MDB3d1BYbXk5cXVVcWFyN3pmYjR8KG51bGwpfDF8djJ8MXxhNjgxMTg5Mzg5MGM3Mzc2NWUwMmVlYjc3NjM0MTY0Zg==";
}
失败示例:
oneTapLogin:{
code = 30006;
errorCode = "-40001";
gyuid = gtc_dbf8471ad1ef4681bf9928a446784aa535;
metadata = { //运营商错误信息
desc = "无网络";
resultCode = 200022;
traceId = 447980b7d866b0cf79dcd65a30dfa831;
};
msg = "运营商返回失败";
operatorType = 1;
processID = 6398a0fc97c4393afa7916929c28b493;
}
必要组件不符合授权页规范的失败示例:
oneTapLogin:{
code = 30006;
errorCode = "-20304";
gyuid = gtc_dbf8471ad1ef4681bf9928a446784aa535;
msg = "手机号码控件<UILabel: 0x104605e70; frame = (0 330; 414 30); text = 'test'; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; tintColor = UIExtendedGrayColorSpace 0.666667 1; layer = <_UILabelLayer: 0x281d63d90>>需要显示正确内容(152****0533)";
operatorType = 1;
processID = 2e934ac69eb457768eda7529e38410aa;
}
*/
}];
return;
}
[GeYanSdk preGetToken:^(NSDictionary *preDic) {
NSLog(@"preGetToken: %@ %@", preDic, preDic[@"msg"]);
if (![GeYanSdk isPreGettedTokenValidate]) {
[CommonToastHUD hideAllAndTip:[Utils dic2Str:preDic]];
return;
}
[Utils switchNewOrientation:viewModel.supportedInterfaceOrientations];
//渲染页面信息
[weakSelf.customView render];
[GeYanSdk oneTapLogin:self
viewModel:viewModel
contentView:self.contentView
subViewList:list
loginBlock:^(NSDictionary * _Nullable dic) {
//登录完成
NSLog(@"%@", dic);
}];
}];
让开发者通过设置GyAuthModel的属性来控制授权页ViewController的行为。
@interface GyAuthViewModel : NSObject
//MARK: - StatusBar
/// 状态栏样式。 默认 `UIStatusBarStyleDefault`。
@property(nonatomic, assign) UIStatusBarStyle statusBarStyle;
/**
* 授权页面 UIUserInterfaceStyle,默认为 UIUserInterfaceStyleLight,即 @(UIUserInterfaceStyleLight)
*
* UIUserInterfaceStyle
* UIUserInterfaceStyleUnspecified - 不指定样式,跟随系统设置进行展示
* UIUserInterfaceStyleLight - 明亮
* UIUserInterfaceStyleDark - 暗黑 仅对 iOS 13+ 系统有效
*/
@property(nonatomic, strong) NSNumber *userInterfaceStyle;
//MARK: - LifeCycle
/// 授权页面视图生命周期回调。
@property(nullable, nonatomic, copy) OLAuthViewLifeCycleBlock viewLifeCycleBlock;
//MARK: - VCStyle
/// 进入授权页面的方式,默认为 modal 方式,即 present 到授权页面,从授权页面进入服务条款页面的方式与此保持一致。 也可以设置为OLPullAuthVCStylePush。
@property(nonatomic, assign) OLPullAuthVCStyle pullAuthVCStyle;
/// presentViewController 或者 pushViewController 授权页时, 是否设置动画animated。 默认YES
@property(nonatomic, assign) BOOL pullAnimate;
/**
* 点击授权页面授权按钮的回调
* 返回YES,继续登录操作
* 返回NO,中断登录
* at 3.0.0.0
*/
@property(nullable, nonatomic, copy) GyBoolBlock clickAuthButtonBlock;
@end
GyAuthViewModel *viewModel = [GyAuthViewModel new];
viewModel.pullAuthVCStyle = OLPullAuthVCStylePush; //push方式打开授权页
viewModel.statusBarStyle = UIStatusBarStyleDefault;
viewModel.clickAuthButtonBlock = ^() {
NSLog(@"点击登录按钮的回调");
return YES;//返回YES:继续登录流程, 返回NO:停止登录
};
viewModel.viewLifeCycleBlock = ^(NSString *viewLifeCycle, BOOL animated) {
NSLog(@"页面生命周期 回调: %@, %@", viewLifeCycle, @(animated));
}
+ (void)deletePreResultCache;
删除预登录缓存;
[GeYanSdk deletePreResultCache];
+ (void)closeAuthVC:(BOOL)animated completion:(void (^ __nullable)(void))completion;
[GeYanSdk closeAuthVC:YES completion:^{
NSLog(@"关闭授权页面");
}];
+ (void)getPhoneVerifyTokenCallback:(GyVerifyCallback _Nonnull)callback;
[GeYanSdk getPhoneVerifyTokenCallback:^(NSDictionary *result) {
NSLog(@"getPhoneVerifyToken: %@", result);
/// {
/// code = 30000;
/// msg = "操作成功";
/// operatorType = 3;
/// processID = 0af5e43c1b06d1ca97f932725ae364ef;
/// token = nm62ee17653a214872904a42671bf25ac3;
/// }
}];
+ (void)checkPhoneNumber:(NSString *_Nonnull)pn withToken:(NSString *_Nonnull)token withProcessId:(NSString *_Nonnull)processId withOperatorType:(NSString *_Nonnull)opType andCallback:(GyVerifyCallback _Nonnull)callback;
[CommonToastHUD showLoading];
[GeYanSdk getPhoneVerifyTokenCallback:^(NSDictionary *result) {
NSLog(@"getPhoneVerifyToken: %@", result);
NSString *token = result[@"token"];
if (token.length > 0) {
[GeYanSdk checkPhoneNumber:pn andCallback:^(NSDictionary * _Nullable verifyDictionary) {
NSLog(@"checkPhoneNumber: %@", verifyDictionary);
/*
code: 30000, //NSNumber, 非30000为失败
msg: "success" // NSString, 返回信息
*/
if ([verifyDictionary[@"code"] isEqualToNumber:@30000]) {
[CommonToastHUD hideAllHUD];
SuccessController *ctrl = [[SuccessController alloc] init];
ctrl.tipTitle = @"认证一致";
ctrl.pn = pn;
[self.navigationController pushViewController:ctrl animated:YES];
} else {
[CommonToastHUD hideAllAndTip:[Utils dic2Str:verifyDictionary]];
}
}];
} else {
[CommonToastHUD hideAllAndTip:[Utils dic2Str:result]];
}
}];
+ (NSString *_Nonnull)getVersion;
+ (NSString *_Nullable)gyuid;
获取当前的设备的gyuid。
GeYanSdk.h
[GeYanSdk gyuid];//gtc_dbf8471ad1ef4681bf9928a446784aa535
+ (UIViewController *_Nullable)currentAuthViewController;
[GeYanSdk currentAuthViewController];
/// 设置联通参数, 优化首次取号速度
/// - Parameters:
/// - appId: appId
/// - appKey: appKey
+ (void)setUnicomWithAppId:(NSString* _Nonnull)appId appKey:(NSString* _Nonnull)appKey;
/// 设置移动参数, 优化首次取号速度
/// - Parameters:
/// - appId: appId
/// - appKey: appKey
+ (void)setMobileWithAppId:(NSString* _Nonnull)appId appKey:(NSString* _Nonnull)appKey;
/// 设置电信参数, 优化首次取号速度
/// - Parameters:
/// - appId: appId
/// - appKey: appKey
+ (void)setTelecomWithAppId:(NSString* _Nonnull)appId appKey:(NSString* _Nonnull)appKey;
//电信
[GeYanSdk setTelecomWithAppId:@"对应运营商appid" appKey:@"对应运营商appkey"];
//联通
[GeYanSdk setUnicomWithAppId:@"对应运营商appid" appKey:@"对应运营商appkey"];
//移动
[GeYanSdk setMobileWithAppId:@"对应运营商appid" appKey:@"对应运营商appkey"];
+ (void)destroy;
[GeYanSdk destroy];
以上文档对您是否有帮助?