一键认证:一键认证方案,运营商利用其移动数据网络,采用“通信网关取号”及 SIM卡识别等技术,准确验证用户本机号码,实现一键认证,并可有效规避短信验证码泄露风险。 通过运营商网关认证能力,用户无需输入手机号码和短信验证码,即可使用手机号一键认证成功。
使用限制说明:一键认证功能的使用前提是用户打开蜂窝网络,目前支持的网络制式有移动 2G、3G、4G,联通 3G、4G、5G,电信 4G、5G。对于双卡手机支,以开启数据流量的 SIM 卡进行认证;对于Wifi环境,在数据网络开通的前提下,会强制使用数据网络触发网关请求,请求仅为几K,可正常校验。 另外,一键认证当前不支持分屏显示,建议此功能不要应用在分屏显示场景下。
调用接口前请先完成个验SDK的接入与初始化。
业务流程图:

注意
"绿色流程”由接入方实现对接。
“蓝色流程”由个推实现,接入方可进行了解。
成功对接效果图:

接入方可以根据自己产品需要接入自己产品的Logo,如果不接入自己产品的Logo,将使用默认的Logo。
接入方添加自己应用的Logo的步骤如下:
TYRZResource.bundle 引入到项目TYRZResource.bundle/logo.png 替换为自已应用的图标注意事项: Logo图标名称必须命名为logo_80x80_.png 或自行设置 appLogo 属性。

目前运营商个别接口为http请求,对于全局禁用http的项目,需要设置http白名单。以下为运营商http接口域名和ip名单:cmpassport.com、id6.me、mdn.open.wo.cn。配置ATS,在 info.plist 文件中添加 App Transport Security Settings 项,并在其中添加 Exception Domains 子项,设置如下:

| 类 | 描述 |
|---|---|
| GeYanSdk | 一键登录基础api,包括预取号、拉起授权页、修改授权页元素状态等 |
| GyAuthViewModel | 一键登录界面UI配置类,包括弹窗/全屏、界面元素设置、添加自定义元素等 |
| GyAuthPrivacyItem | 一键登录中隐私协议配置类,包括字体颜色、字体大小、行间距等 |
| GyOneLoginPro | 一键登录进阶使用类 预取号逻辑封装在 SDK 内部,开发者只需控制授权页拉起时机 |
| 方法 | 功能说明 |
|---|---|
| setEloginTimeout | 【GeYanSdk】设置一键认证和号码校验预登录阶段的超时时间 |
| preGetToken | 【GeYanSdk】预登录获取token等信息 |
| oneTapLogin | 【GeYanSdk】一键认证接口 |
| getCurrentCarrierCount | 【GeYanSdk】获取sim卡数量 |
| renewPreGetToken: | 【GyOneLoginPro】重新预取号 |
| requestTokenWithViewController:viewModel:completion | 【GyOneLoginPro】一键认证接口 |
| isPreGetTokenResultValidate | 【GyOneLoginPro】判断预取号是否有效 |
| dismissAuthViewController | 【GyOneLoginPro】关闭当前的授权页面 |
| updateAuthButtonTitle: | 【GyOneLoginPro】更新授权页面一键登录按钮的文案 |
| deletePreResultCache | 【GyOneLoginPro】删除预取号的缓存 |
TYRZResource.bundle必须添加到工程,否则可能会引起crash
若对自定义界面有需求,请参考GYAuthViewModel介绍进行开发,若无自定义界面需求,替换TYRZResource.bundle中的图片资源文件即可
/**
* 设置一键认证和号码校验预登录阶段的超时时间
* @param timeout 单位秒
*/
+ (void)setEloginTimeout:(NSTimeInterval)timeout;
GeyanSdk
/**
* 预登陆,若成功,则可以调用一键认证接口,打开登录页面
* @param callback 结果回调
*/
+ (void)preGetToken:(GyVerifyCallback)callback;
GyOneLoginPro
/**
* @abstract 重新预取号
*
* @discussion 在通过requestTokenWithViewController方法成功登录之后,为保证用户在退出登录之后,能快速拉起授权页面,请在用户退出登录时,调用此方法
*/
+ (void)renewPreGetToken;
注意1:预登录操作用于提前判定当前网络环境是否适合使用一键登录,建议在登录操作前调用,不影响登录流程,降低对用户体验的影响。例如:初次打开APP、进入个人中心页(“我的”),等。预登录结果的有效期是10分钟,且只能使用一次。也就是第二次调用一键认证接口时,需要再次先调用预登录。
预登录成功表示当前设备可以使用一键认证,失败则表示不可用,开发者在失败的时候可以换成其他登录方式。
注意2:在 SDK 初始化之后,调用requestTokenWithViewController获取 token 之前,SDK 内部会一直维护预取号的结果,但是在调用requestTokenWithViewController获取 token 之后,就不再维护预取号结果了,调用该接口,就会重新开始预取号,并维持预取号结果有效,以保证在用户退出登录之后再次登录时能快速进入授权页面
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
| callBack | 是 | GyVerifyCallback | 结果回调 |
[GeYanSdk preGetToken:^(NSDictionary *tokenDic) {
NSLog(@"获取token返回结果:%@", tokenDic);
}];
校验token会通过 GyVerifyCallback 返回结果.
GyVerifyCallback:
typedef void (^GyVerifyCallback)(NSDictionary *verifyDictionary);
verifyDictionary返回示例和说明:
{
code = 30000; // NSNumber, 非30000为失败的状态码
processID = 47dab9b7c26629cd9bc117f88e2f9233; // NSString, 流水号
operatorType = 4; // NSString, 操作类型
errorCode = "-30003", // NSString, 运营商返回的错误码
msg = "\U83b7\U53d6accessCode\U6210\U529f"; // NSString, 运营商返回的描述消息
metadata = {}; // NSDictionary, 失败时, 运营商的响应内容。
}
GeyanSdk
/**
* 一键认证
* @param controller 当前viewController
* @param model GYAuthViewModel 自定义view参数
* @param callback 通用接口回调
*/
+ (void)oneTapLogin:(UIViewController *)controller withViewModel:(GyAuthViewModel *)model andCallback:(GyVerifyCallback)callback;
GyOneLoginPro
/**
进行用户认证授权, 获取网关 token 。
@discussion 调用限制说明
为避免授权页面多次弹出, 在调用该方法后, 授权页面弹出, 再次调用该方法时,
该方法会直接跳出, 不执行授权逻辑。
@discussion 需要用户在弹出的页面上同意服务意条款后, 才会进行免密认证。
@param viewController present认证页面控制器的vc
@param viewModel 自定义授权页面的视图模型
@param completion 结果处理回调
@seealso GyAuthViewModel
*/
+ (void)requestTokenWithViewController:(nullable UIViewController *)viewController
viewModel:(nullable GyAuthViewModel *)viewModel
completion:(void (^)(NSDictionary *_Nullable result))completion;
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
| controller | 是 | UIViewController | 视图控制器 |
| model | 是 | GyAuthViewModel | 自定义界面所需参数 |
| callback | 是 | GyVerifyCallback | 一键登陆结果回调 |
model 详细参数 参考头文件GyAuthViewModel.h,每个参数都有使用注解
部分用到了TYRZResource.bundle资源文件的参数解释:
| 参数 | 解释 | 备注 |
|---|---|---|
| naviBackImage | 授权页导航左边的返回按钮的图片 | back_13x21_.png |
| closePopupImage | 弹窗关闭按钮图片 | close_icon_11x10_.png |
| appLogo | 授权页面上展示的图标 | logo_80x80_.png |
| checkedImage | 授权页面上勾选框勾选的图标 | check_12x12_.png |
| uncheckedImage | 授权页面上勾选框未勾选的图标 | uncheck_12x12_.png |
//调用此接口接口前请调用 preGetToken 并成功获取到 accessCode
GyAuthViewModel *authViewModel = [[GyAuthViewModel alloc] init];
GyAuthPrivacyItem *item1 = [[GyAuthPrivacyItem alloc] initWithTitle:@"隐私条款一"
linkURL:[NSURL URLWithString:@"https://getui.com"]];
GyAuthPrivacyItem *item2 = [[GyAuthPrivacyItem alloc] initWithTitle:@"隐私条款二"
linkURL:[NSURL URLWithString:@"https://getui.com"]];
authViewModel.additionalPrivacyTerms = [@[item1, item2] mutableCopy];
[GeYanSdk oneTapLogin:self withViewModel:authViewModel andCallback:^(NSDictionary *verifyDictionary) {
NSLog(@"一键认证返回结果:%@", verifyDictionary);
[GeYanSdk closeAuthVC];
}];
一键认证会通过 GyVerifyCallback 返回结果.
GyVerifyCallback:
typedef void (^GyVerifyCallback)(NSDictionary *verifyDictionary);
一键认证verifyDictionary返回示例和说明:
{
code = 30000; // NSNumber, 非30000为失败的状态码
processID = 47dab9b7c26629cd9bc117f88e2f9233; // NSString, 流水号
operatorType = 4; // NSString, 操作类型
errorCode = "-30003", // NSString, 失败时,运营商返回的错误码
msg = "\U83b7\U53d6accessCode\U6210\U529f"; // NSString, 描述消息
metadata = {}; // NSDictionary, 失败时, 运营商的响应内容。
token = "xxx", //NSString, 登陆成功返回的用户授权凭证信息,可以用于在服务端获取登录信息
expiredTime: 600, //NSInteger,成功时, token失效时间间隔,单位秒
pn: "133****3333", //NSString,成功时, 脱敏7位手机号码
}
/**
* 关闭登录界面
* 请不要使用其他方式关闭授权页面, 否则可能导致 OneLogin 无法再次调起
*/
+ (void)closeAuthVC:(BOOL)animated completion:(void (^ __nullable)(void))completion;
| 参数名称 | 是否必填 | 类型 | 描述 |
|---|---|---|---|
| animated | 是 | BOOL | 是否使用动画 |
| completion | 否 | (void (^ __nullable)(void)) | 自定义界面所需参数 |
[GeYanSdk closeAuthVC:NO completion:^{
NSLog(@"关闭页面成功");
}];
/**
* @abstract 判断预取号结果是否有效
*
* @return YES: 预取号结果有效,可直接拉起授权页面
* NO: 预取号结果无效,需手动加载进度条,等待预取号完成之后拉起授权页面
*/
+ (BOOL)isPreGetTokenResultValidate;
/**
* @abstract 删除预取号的缓存
*/
+ (void)deletePreResultCache;
开发者不得通过任何技术手段将授权页面的隐私协议栏、slogan隐藏或者覆盖,对于接入个验SDK并上线的应用,我方会对上线的应用授权页面做审查,如果发现未按要求设计授权页面,将关闭应用的一键登录服务。
设置控件的 OLRect 属性,通过设置控件距离屏幕顶部和屏幕左边的偏移量来控制控件的位置,通过设置控件的宽高来控制控件的大小
/**
* @abstract 1、若授权页面只支持竖屏,只设置竖屏方向偏移;
2、若授权页面只支持横屏,只设置横屏方向偏移;
3、若授权页面支持旋转自动切换横竖屏,则同时设置竖屏方向和横屏方向偏移
4、弹窗模式,同以上1、2、3
5、size默认都可以不用设置,会根据字体大小自适应
6、x轴方向偏移量有两个值可以设置,portraitCenterXOffset为控件的x轴中点到弹窗x轴中点的距离,portraitLeftXOffset为控件的左边缘到屏幕左边缘的距离,两者选其一即可
*/
typedef struct OLRect {
/**
竖屏时
导航栏隐藏时,为控件顶部到状态栏的距离;导航栏显示时,为控件顶部到导航栏底部的距离
弹窗时
为控件顶部到弹窗顶部的距离
*/
CGFloat portraitTopYOffset;
/**
竖屏时
控件的x轴中点到屏幕x轴中点的距离,默认为0
弹窗时
控件的x轴中点到弹窗x轴中点的距离,默认为0
*/
CGFloat portraitCenterXOffset;
/**
竖屏时
控件的左边缘到屏幕左边缘的距离,默认为0
弹窗时
控件的左边缘到屏幕左边缘的距离,默认为0
portraitLeftXOffset与portraitCenterXOffset设置一个即可
portraitLeftXOffset优先级大于portraitCenterXOffset,
设置此属性时,portraitCenterXOffset属性失效
*/
CGFloat portraitLeftXOffset;
/**
横屏时
导航栏隐藏时,为控件顶部到屏幕顶部的距离;导航栏显示时,为控件顶部到导航栏底部的距离
弹窗时
为控件顶部到弹窗顶部的距离
*/
CGFloat landscapeTopYOffset;
/**
横屏时
控件的x轴中点到屏幕x轴中点的距离,默认为0
弹窗时
控件的x轴中点到弹窗x轴中点的距离,默认为0
*/
CGFloat landscapeCenterXOffset;
/**
横屏时
控件的左边缘到屏幕左边缘的距离,默认为0
弹窗时
控件的左边缘到屏幕左边缘的距离,默认为0
landscapeLeftXOffset与landscapeCenterXOffset设置一个即可
landscapeLeftXOffset优先级大于landscapeCenterXOffset
设置此属性时,landscapeCenterXOffset属性失效
*/
CGFloat landscapeLeftXOffset;
/**
控件大小,只有宽度、高度同时大于0,设置的size才会生效,否则为控件默认的size
*/
CGSize size;
} OLRect;
/**
返回按钮位置及大小,返回按钮最大size为CGSizeMake(40, 40)。
*/
@property (nonatomic, assign) OLRect backButtonRect;
/**
Logo 位置及大小。
*/
@property (nonatomic, assign) OLRect logoRect;
/**
号码预览 位置及大小
*/
@property (nonatomic, assign) OLRect phoneNumRect;
/**
授权页切换账号按钮 位置及大小。
*/
@property (nonatomic, assign) OLRect switchButtonRect;
/**
授权按钮 位置及大小。
*/
@property (nonatomic, assign) OLRect authButtonRect;
/**
Slogan 位置及大小。
*/
@property (nonatomic, assign) OLRect sloganRect;
/**
隐私条款 位置及大小,隐私条款,宽需大于50,高需大于20,才会生效。
*/
@property (nonatomic, assign) OLRect termsRect;
/**
弹窗 位置及大小。弹窗模式时,x轴偏移只支持portraitLeftXOffset和landscapeLeftXOffset。
*/
@property (nonatomic, assign) OLRect popupRect;
OLRect backButtonRect = {0, 0, 0, 0, 0, 0, {0, 0}}; // 返回按钮偏移、大小设置,偏移量和大小设置值需大于0,否则取默认值,默认可不设置
viewModel.backButtonRect = backButtonRect;
OLRect logoRect = {0, 0, 0, 20, 0, 0, {0, 0}}; // logo偏移、大小设置,偏移量和大小设置值需大于0,否则取默认值,默认可不设置,logo大小默认为图片大小
viewModel.logoRect = logoRect;
OLRect phoneNumRect = {0, 0, 0, 0, 0, 0, {0, 0}}; // 手机号偏移设置
viewModel.phoneNumRect = phoneNumRect;
OLRect switchButtonRect = {0, 0, 0, 0, 0, 0, {0, 0}}; // 切换按钮偏移、大小设置,偏移量和大小设置值需大于0,否则取默认值,默认可不设置
viewModel.switchButtonRect = switchButtonRect;
OLRect authButtonRect = {0, 0, 0, 0, 0, 0, {300, 40}}; // 授权按钮偏移、大小设置,偏移量和大小设置值需大于0,否则取默认值,默认可不设置
viewModel.authButtonRect = authButtonRect;
OLRect sloganRect = {0, 0, 0, 0, 0, 0, {0, 0}}; // slogan偏移、大小设置,偏移量和大小设置值需大于0,否则取默认值,默认可不设置
viewModel.sloganRect = sloganRect;
OLRect termsRect = {0, 0, 0, 0, 0, 0, {0, 0}}; // 服务条款偏移、大小设置,偏移量和大小设置值需大于0,否则取默认值,默认可不设置
viewModel.termsRect = termsRect;
#pragma mark - Status Bar/状态栏
/**
状态栏样式。 默认 `UIStatusBarStyleDefault`。
*/
@property (nonatomic, assign) UIStatusBarStyle statusBarStyle;
#pragma mark - Navigation/导航
/**
授权页导航的标题。默认为空字符串。
*/
@property (nullable, nonatomic, strong) NSAttributedString *naviTitle;
/**
授权页导航的背景颜色。默认白色。
*/
@property (nullable, nonatomic, strong) UIColor *naviBgColor;
/**
授权页导航左边的返回按钮的图片。默认黑色系统样式返回图片。
*/
@property (nullable, nonatomic, strong) UIImage *naviBackImage;
/**
授权页导航右边的自定义控件。
*/
@property (nullable, nonatomic, strong) UIView *naviRightControl;
/**
导航栏隐藏。默认不隐藏。
*/
@property (nonatomic, assign) BOOL naviHidden;
/**
返回按钮隐藏。默认不隐藏。
*/
@property (nonatomic, assign) BOOL backButtonHidden;
#pragma mark - Logo/图标
/**
授权页面上展示的图标。默认为 "AppLogo" 图标。
*/
@property (nullable, nonatomic, strong) UIImage *appLogo;
/**
Logo 图片隐藏。默认不隐藏。
*/
@property (nonatomic, assign) BOOL logoHidden;
/**
logo圆角,默认为0。
*/
@property (nonatomic, assign) CGFloat logoCornerRadius;
#pragma mark - Phone Number Preview/手机号预览
/**
号码预览文字的颜色。默认黑色。
*/
@property (nullable, nonatomic, strong) UIColor *phoneNumColor;
/**
号码预览文字的字体。默认粗体,24pt。
*/
@property (nullable, nonatomic, strong) UIFont *phoneNumFont;
#pragma mark - Switch Button/切换按钮
/**
授权页切换账号按钮的文案。默认为“切换账号”。
*/
@property (nullable, nonatomic, copy) NSString *switchButtonText;
/**
授权页切换账号按钮的颜色。默认蓝色。
*/
@property (nullable, nonatomic, strong) UIColor *switchButtonColor;
/**
授权页切换账号按钮背景颜色。默认为 nil。
*/
@property (nullable, nonatomic, strong) UIColor *switchButtonBackgroundColor;
/**
授权页切换账号的字体。默认字体,15pt。
*/
@property (nullable, nonatomic, strong) UIFont *switchButtonFont;
/**
隐藏切换账号按钮。默认不隐藏。
*/
@property (nonatomic, assign) BOOL switchButtonHidden;
#pragma mark - Authorization Button/认证按钮
/**
授权页认证按钮的背景图片, @[正常状态的背景图片, 不可用状态的背景图片, 高亮状态的背景图片]。默认正常状态为蓝色纯色, 不可用状态的背景图片时为灰色, 高亮状态为灰蓝色。
*/
@property (nullable, nonatomic, strong) NSArray<UIImage *> *authButtonImages;
/**
授权按钮文案。默认白色的"一键登录"。
*/
@property (nullable, nonatomic, strong) NSAttributedString *authButtonTitle;
/**
授权按钮圆角,默认为0。
*/
@property (nonatomic, assign) CGFloat authButtonCornerRadius;
#pragma mark - Slogan/口号标语
/**
Slogan 文字颜色。默认灰色。
*/
@property (nonatomic, strong) UIColor *sloganTextColor;
/**
Slogan字体。默认字体, 12pt。
*/
@property (nonatomic, strong) UIFont *sloganTextFont;
#pragma mark - CheckBox & Privacy Terms/隐私条款勾选框及隐私条款
/**
授权页面上条款勾选框初始状态。默认 YES。
*/
@property (nonatomic, assign) BOOL defaultCheckBoxState;
/**
授权页面上勾选框勾选的图标。默认为蓝色图标。推荐尺寸为12x12。
*/
@property (nullable, nonatomic, strong) UIImage *checkedImage;
/**
授权页面上勾选框未勾选的图标。默认为白色图标。推荐尺寸为12x12。
*/
@property (nullable, nonatomic, strong) UIImage *uncheckedImage;
/**
隐私条款文字属性。默认基础文字灰色, 条款蓝色高亮, 12pt。
*/
@property (nullable, nonatomic, strong) NSDictionary<NSAttributedStringKey, id> *privacyTermsAttributes;
/**
额外的条款。默认为空。
*/
@property (nullable, nonatomic, strong) NSArray<OLPrivacyTermItem *> *additionalPrivacyTerms;
/**
服务条款普通文字的颜色。默认灰色。
*/
@property (nullable, nonatomic, strong) UIColor *termTextColor;
/**
除隐私条款外的其他文案,数组大小必须为4,元素依次为:条款前的文案、条款一和条款二连接符、条款二和条款三连接符,条款后的文案。
默认为@[@"登录即同意", @"和", @"、", @"并使用本机号码登录"]
*/
@property (nullable, nonatomic, copy) NSArray<NSString *> *auxiliaryPrivacyWords;
/**
* 点击授权页面隐私协议前勾选框的回调
*/
@property (nullable, nonatomic, copy) OLClickCheckboxBlock clickCheckboxBlock;
/**
* 服务条款文案对齐方式,默认为NSTextAlignmentLeft
*/
@property (nonatomic, assign) NSTextAlignment termsAlignment;
#pragma mark - Background Image/授权页面背景图片
/**
授权页背景颜色。默认白色。
*/
@property (nullable, nonatomic, strong) UIColor *backgroundColor;
/**
授权页面背景图片
*/
@property (nullable, nonatomic, strong) UIImage *backgroundImage;
/**
横屏模式授权页面背景图片
*/
@property (nullable, nonatomic, strong) UIImage *landscapeBackgroundImage;
/**
* 授权页面背景gif.
*/
@property(nullable, nonatomic, strong) NSString *backgroundGifPath;
/**
* 授权页面背景video.
*/
@property(nullable, nonatomic, strong) NSString *backgroundVideoPath;
/**
* 是否允许背景GIF 或者 video 循环播放
* 默认循环播放 YES
*/
@property (nonatomic, assign) BOOL allowGifOrVideoPlayRepeat;
/**
* 授权页面支持的横竖屏方向
*/
@property (nonatomic, assign) UIInterfaceOrientationMask supportedInterfaceOrientations;
通过设置 isPopup 属性为 YES,即可以弹窗模式弹出授权页面,可自定义弹窗的大小、弹窗弹出动画形式及弹窗圆角,弹窗中各控件大小、位置、属性的设置同上
#pragma mark - Popup
/**
* 是否为弹窗模式
*/
@property(nonatomic, assign) BOOL isPopup;
/**
弹窗 位置及大小。弹窗模式时,x轴偏移只支持portraitLeftXOffset和landscapeLeftXOffset。
*/
@property(nonatomic, assign) OLRect popupRect;
/**
弹窗圆角,默认为6。
*/
@property(nonatomic, assign) CGFloat popupCornerRadius;
/**
当只需要设置弹窗的部分圆角时,通过popupCornerRadius设置圆角大小,通过popupRectCorners设置需要设置圆角的位置。
popupRectCorners数组元素不超过四个,超过四个时,只取前四个。比如,要设置左上和右上为圆角,则传值:@[@(UIRectCornerTopLeft), @(UIRectCornerTopRight)]
*/
@property (nonatomic, strong) NSArray<NSNumber *> *popupRectCorners;
/**
* 弹窗动画类型,当popupAnimationStyle为OLAuthPopupAnimationStyleStyleCustom时,动画为用户自定义,用户需要传一个CATransition对象来设置动画
*/
@property(nonatomic, assign) OLAuthPopupAnimationStyle popupAnimationStyle;
/**
* 弹窗自定义动画
*/
@property(nonatomic, strong, nullable) CAAnimation *popupTransitionAnimation;
/**
弹窗关闭按钮图片,弹窗关闭按钮的尺寸跟图片尺寸保持一致。
弹窗关闭按钮位于弹窗右上角,目前只支持设置其距顶部偏移和距右边偏移。
*/
@property(nullable, nonatomic, strong) UIImage *closePopupImage;
/**
弹窗关闭按钮距弹窗顶部偏移。
*/
@property(nonatomic, strong) NSNumber *closePopupTopOffset;
/**
弹窗关闭按钮距弹窗右边偏移。
*/
@property(nonatomic, strong) NSNumber *closePopupRightOffset;
/**
弹窗关闭按钮大小。默认11x22
*/
@property(nonatomic, assign) CGSize closePopupSize;
/**
是否需要通过点击弹窗的背景区域以关闭授权页面。
*/
@property (nonatomic, assign) BOOL canClosePopupFromTapGesture;
/**
* 点击授权页面弹窗背景的回调
*/
@property (nonatomic, copy, nullable) OLTapAuthBackgroundBlock tapAuthBackgroundBlock;
/**
* 弹窗页遮罩背景
* 默认半透明遮罩
*/
@property(nonatomic, strong, nullable) UIView *popupMaskView;
/**
* @abstract 授权登录页面自定义视图,customAreaView为授权页面的view,如,可将三方登录添加到授权登录页面
*/
typedef void(^OLCustomUIHandler)(UIView *customAreaView);
/**
自定义区域视图的处理block
@discussion
提供的视图容器使用NSLayoutConstraint与相关的视图进行布局约束。
如果导航栏没有隐藏, 顶部与导航栏底部对齐, 左边与屏幕左边对齐, 右边与屏幕右边对齐, 底部与屏幕底部对齐。
如果导航栏隐藏, 顶部与状态栏底部对齐, 左边与屏幕左边对齐, 右边与屏幕右边对齐, 底部与屏幕底部对齐。
*/
@property (nullable, nonatomic, copy) OLCustomUIHandler customUIHandler;
/**
* 授权页面旋转时的回调,可在该回调中修改自定义视图的frame,以适应新的布局
*/
@property (nullable, nonatomic, copy) OLAuthVCTransitionBlock authVCTransitionBlock;
// -------------- 自定义UI设置,如,可以在授权页面添加三方登录入口 -------------------
[authViewModel setCustomUIHandler:^(UIView *customAreaView) {
UIButton *otherLoginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
otherLoginBtn.frame = CGRectMake(0, customAreaView.bounds.size.height / 2 - 80, customAreaView.bounds.size.width, 40);
[otherLoginBtn setTitle:@"其他登录方式" forState:UIControlStateNormal];
[otherLoginBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[otherLoginBtn setBackgroundColor:[UIColor redColor]];
[[otherLoginBtn titleLabel] setFont:[UIFont systemFontOfSize:16]];
[otherLoginBtn addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside];
[customAreaView addSubview:otherLoginBtn];
}];
/**
* 授权页自定义Loading,会在点击登录按钮之后触发
* containerView为loading的全屏蒙版view
* 请自行在containerView添加自定义loading
* 设置block后,默认loading将无效
*/
typedef void(^OLLoadingViewBlock)(UIView *containerView);
/**
* 停止授权页自定义Loading,会在调用[OneLogin stopLoading]时触发
* containerView为loading的全屏蒙版view
*/
typedef void(^OLStopLoadingViewBlock)(UIView *containerView);
/**
* 授权页面,自定义加载进度条,点击登录按钮之后的回调
*/
@property (nonatomic, copy, nullable) OLLoadingViewBlock loadingViewBlock;
/**
* 授权页面,停止自定义加载进度条,调用[OneLogin stopLoading]之后的回调
*/
@property (nonatomic, copy, nullable) OLStopLoadingViewBlock stopLoadingViewBlock;
#pragma mark - CheckBox & Privacy Terms/隐私条款勾选框及隐私条款
/**
授权页面上条款勾选框初始状态。默认 YES。
*/
@property(nonatomic, assign) BOOL defaultCheckBoxState;
/**
授权页面上勾选框勾选的图标。默认为蓝色图标。推荐尺寸为12x12。
*/
@property(nullable, nonatomic, strong) UIImage *checkedImage;
/**
授权页面上勾选框未勾选的图标。默认为白色图标。推荐尺寸为12x12。
*/
@property(nullable, nonatomic, strong) UIImage *uncheckedImage;
/**
授权页面上条款勾选框大小。
*/
@property(nonatomic, assign) CGSize checkBoxSize;
/**
隐私条款文字属性。默认条款蓝色高亮, 12pt。
*/
@property(nullable, nonatomic, strong) NSDictionary<NSAttributedStringKey, id> *privacyTermsAttributes;
/**
额外的条款。默认为空。其中默认的隐私条款index为0.
*/
@property(nullable, nonatomic, strong) NSArray<GyAuthPrivacyItem *> *additionalPrivacyTerms;
/**
服务条款普通文字的颜色。默认灰色。
*/
@property(nullable, nonatomic, strong) UIColor *termTextColor;
/**
隐私条款 位置及大小,隐私条款,宽需大于50,高需大于20,才会生效。
*/
@property(nonatomic, assign) OLRect termsRect;
/**
除隐私条款外的其他文案,数组大小必须为4,元素依次为:条款前的文案、条款一和条款二连接符、条款二和条款三连接符,条款后的文案。
默认为@[@"登录即同意", @"和", @"、", @"并使用本机号码登录"]
*/
@property(nullable, nonatomic, copy) NSArray<NSString *> *auxiliaryPrivacyWords;
/**
* 点击授权页面隐私协议前勾选框的回调
*/
@property(nullable, nonatomic, copy) OLClickCheckboxBlock clickCheckboxBlock;
/**
* 服务条款文案对齐方式,默认为NSTextAlignmentLeft
*/
@property (nonatomic, assign) NSTextAlignment termsAlignment;
/**
* 点击授权页面隐私协议的回调,设置后所有的点击回调都默认走这里
* 如果PrivacyItem设置了回调将不会走这里
*/
@property (nullable, nonatomic, copy) OLPrivacyTermItemBlock carrierTermItemBlock;
/**
* 是否在运营商协议名称上加书名号《》
* 默认NO
*/
@property (nonatomic, assign) BOOL hasQuotationMarkOnCarrierProtocol;
/**
* 隐私协议的点击响应属性
* 默认值:@{
* NSUnderlineStyleAttributeName: @NO,
* NSForegroundColorAttributeName: UIColor.redColor
* }
*/
@property(nonatomic, nullable, copy) NSDictionary *activeLinkAttributes;
/**
* 授权页面上勾选框 未勾选状态时点击登录按钮是否显示 提示弹窗
* 默认 YES
*/
@property(nonatomic, assign) BOOL showNotCheckProtocolHint;
/*
* 授权页面上勾选框 未勾选状态时点击登录按钮的提示弹窗 y轴偏移量
* 默认 0
*/
@property(nonatomic, assign) CGFloat protocolHintOffsetY;
/**
* 未勾选状态时点击登录按钮的回调
* 返回YES,提示sdk内置toast
* 返回NO,用户自定义toast
*/
@property(nullable, nonatomic, copy) OLProtocolHintBlock protocolHintBlock;
/**
* 隐私页面返回按钮隐藏。默认不隐藏。
*/
@property(nonatomic, assign) BOOL webBackBtnHidden;
/**
* 隐私页面返回按钮。默认黑色系统样式返回图片。
*/
@property(nonatomic, assign) UIImage *webBackBtnImg;
/**
返回按钮位置及大小,返回按钮最大size为CGSizeMake(40, 40)。
*/
@property(nonatomic, assign) OLRect webBackBtnRect;
/**
服务条款页面导航栏隐藏。默认不隐藏。
*/
@property(nonatomic, assign) BOOL webNaviHidden;
/**
服务条款页面导航的标题。默认为"服务条款",粗体、17pt。
*/
@property(nullable, nonatomic, strong) NSAttributedString *webNaviTitle;
/**
服务条款页面导航的背景颜色。默认白色。
*/
@property(nullable, nonatomic, strong) UIColor *webNaviBgColor;
#pragma mark - Hint
/**
未勾选服务条款复选框时,点击登录按钮的提示。默认为"请同意服务条款"。
*/
@property(nullable, nonatomic, copy) NSString *notCheckProtocolHint;
/**
* @abstract 进入授权页面的方式,默认为 modal 方式,即 present 到授权页面,从授权页面进入服务条款页面的方式与此保持一致
*
* @discussion push 模式时,不支持弹窗模式,进入授权页面时,会隐藏导航栏,退出授权页面时,会显示导航栏,如果您进入授权页面的当前页面导航栏为隐藏状态,在授权页面消失时,请注意将导航栏隐藏
*/
typedef NS_ENUM(NSInteger, OLPullAuthVCStyle) {
OLPullAuthVCStyleModal,
OLPullAuthVCStylePush
};
#pragma mark - OLPullAuthVCStyle
/**
* @abstract 进入授权页面的方式,默认为 modal 方式,即 present 到授权页面,从授权页面进入服务条款页面的方式与此保持一致
*/
@property (nonatomic, assign) OLPullAuthVCStyle pullAuthVCStyle;
授权页面状态栏已默认适配黑夜模式,若您使用 SDK 默认的授权页面,可以无需设置状态栏,若您需要改变授权页面的背景,请您根据实际情况设置状态栏
/**
状态栏样式。 默认 `UIStatusBarStyleDefault`。
*/
@property (nonatomic, assign) UIStatusBarStyle statusBarStyle;
/**
* 点击授权页面授权按钮的回调
*/
@property(nullable, nonatomic, copy) OLClickAuthButtonBlock clickAuthButtonBlock;
/**
* 点击授权页面隐私协议前勾选框的回调
*/
@property(nullable, nonatomic, copy) OLClickCheckboxBlock clickCheckboxBlock;
/**
* 点击授权页面隐私协议的回调,设置后所有的点击回调都默认走这里
* 如果PrivacyItem设置了回调将不会走这里
*/
@property (nullable, nonatomic, copy) OLPrivacyTermItemBlock carrierTermItemBlock;
/**
* 授权页面旋转时的回调,可在该回调中修改自定义视图的frame,以适应新的布局
*/
@property (nullable, nonatomic, copy) OLAuthVCTransitionBlock authVCTransitionBlock;
/**
* 点击授权页面弹窗背景的回调
*/
@property (nonatomic, copy, nullable) OLTapAuthBackgroundBlock tapAuthBackgroundBlock;
/**
* 授权页面,自定义加载进度条,点击登录按钮之后的回调
*/
@property(nonatomic, copy, nullable) OLLoadingViewBlock loadingViewBlock;
/**
* 授权页面,停止自定义加载进度条,调用[GetanSDK stopLoading]之后的回调
*/
@property(nonatomic, copy, nullable) OLStopLoadingViewBlock stopLoadingViewBlock;
/**
* 授权页面视图生命周期回调。
*/
@property(nullable, nonatomic, copy) OLAuthViewLifeCycleBlock viewLifeCycleBlock;
| 错误码 | 含义 |
|---|---|
| 30000 | 登录成功 |
| 30001 | 当前环境不适合免密登录 |
| 30002 | 用户点击了其他登录方式 |
| 30003 | 用户关闭验证界面 |
| 30004 | 其他错误,具体见返回 |
| 30005 | 预登陆错误 |
| 30006 | 一键认证错误 |
| 40047 | 一键认证取号失败 |
| 错误码 | 含义 |
|---|---|
| -20101 | 未配置 AppID, 请先配置 AppID |
| -20102 | 重复调用预登录接口 |
| -20103 | 重复调用取号接口 |
| -20202 | 当前没有开启蜂窝网络, 请检查是否开启蜂窝网络。 |
| -20203 | 不支持的运营商。OneLogin 仅支持在大陆地区支持三大运营商。 |
| -20204 | 无效的 accessCode 。确保每次调用 OneTapLogin 之前,都成功调用 preGetToken |
| -20302 | 用户点击返回键并退出取号页面。授权页面会自动关闭。 |
| -20303 | 用户点击了切换账号按钮。授权页面不会自动关闭。 |
| -40101 | 移动运营商预登录失败。请检查数据网络可用性。 |
| -40102 | 移动运营商取号失败。请检查数据网络可用性。 |
| -40198 | 移动运营商预登录异常。请检查数据网络可用性。 |
| -40199 | 移动运营商取号异常。请检查数据网络可用性。 |
| -40201 | 联通运营商预登录失败。请检查数据网络可用性。 |
| -40204 | 联通运营商取号失败。请检查数据网络可用性。 |
| -40298 | 联通运营商预登录异常。请检查数据网络可用性。 |
| -40299 | 联通运营商取号异常。请检查数据网络可用性。 |
| -40301 | 电信运营商预登录失败。请检查数据网络可用性。 |
| -40302 | 电信运营商取号失败。请检查数据网络可用性。 |
| -40398 | 电信运营商预登录异常。请检查数据网络可用性。 |
| -40399 | 电信运营商取号异常。请检查数据网络可用性。 |
| -50100 | 一键登录服务接口返回异常 |
| -50101 | 一键登录服务返回业务失败 |
| -50102 | 一键登录服务接口网络异常。请检查网络可用性。 |
运营商接口返回失败常见的错误代码,位于错误回调JSON中meta_data内的运营商错误码
| 错误码 | 含义 |
|---|---|
| 102102 | 网络异常 |
| 102507 | 登录超时(授权页点登录按钮时) |
| 103101 | appkey错误 |
| 103102 | 包签名错误 |
| 103108 | 短信验证码错误 |
| 103109 | 短信验证码校验超时 |
| 103111 | 网关IP错误(运营商误判) |
| 103119 | appid不存在 |
| 103125 | 号码格式错误 |
| 103203 | 缓存失效 |
| 103211 | 其他错误 |
| 103901 | 短验下发次数已达上限(5次/min,10次/day) |
| 103902 | scrip失效 |
| 103911 | token请求过于频繁,10分钟内获取token且未使用的数量不超过30个 |
| 105001 | 联通取号失败 |
| 105002 | 移动取号失败 |
| 105003 | 电信取号失败 |
| 105021 | 已达当天取号限额 |
| 105302 | appid不在白名单 |
| 200005 | 用户未授权(READ_PHONE_STATE) |
| 200010 | 取号请求时获取imsi失败 |
| 200014 | 号码不存在 |
| 200020 | 用户取消登录 |
| 200021 | 数据解析异常 |
| 200022 | 无网络 |
| 200023 | 请求超时 |
| 200024 | 数据网络切换失败 |
| 200025 | 其他错误(socket、系统未授权数据蜂窝权限等) |
| 200026 | 输入参数错误 |
| 200027 | 未开启数据网络 |
| 200028 | 网络请求出错 |
| 200030 | 没有初始化参数 |
| 200038 | 电信重定向失败 |
| 200039 | 电信取号接口返回失败 |
| 200040 | UI资源加载异常 |
| 200048 | 未安装sim卡 |
| 200050 | EOF异常 |
| 200060 | 切换账号(未使用SDK短验时返回) |
| 200061 | 授权页面异常 |
| 200062 | 预登录不支持联通 |
| 200063 | 预登录不支持电信 |
| 错误码 | 含义 |
|---|---|
| -64 | permission-denied(无权限访问) |
| -65 | API-request-rates-Exceed-Limitations(调用接口超限) |
| -10001 | 取号失败 |
| -10002 | 参数错误 |
| -10003 | 解密失败 |
| -10004 | ip受限 |
| -10005 | 异网取号回调参数异常 |
| -10006 | Mdn取号失败,且属于电信网络 |
| -10007 | 重定向到异网取号 |
| -10008 | 超过预设取号阈值 |
| -10009 | 时间戳过期 |
| -20005 | sign-invalid(签名错误) |
| -20006 | 应用不存在 |
| -20007 | 公钥数据不存在 |
| -20100 | 内部解析错误 |
| -20102 | 加密参数解析失败 |
| -30001 | 时间戳非法 |
| -30003 | topClass失效,请查看5.3常见问题。 |
| 51002 | 参数为空 |
| 51114 | 取号失败 |
| -8001 | 请求网络异常 |
| -8002 | 请求参数异常 |
| -8003 | 请求超时 |
| -8004 | 移动网络未开启 |
| -8005 | 请先初始化SDK |
| -8100 | 网络无连接 |
| -8101 | 响应码错误 |
| -8102 | Socket超时异常(读取超时、连接超时) |
| -8103 | 域名解析异常 |
| -8104 | IO异常 |
| -8201 | 响应码错误 |
| -720001 | 切换异常 |
| -720002 | 切换异常超时 |
| 错误码 | 含义 |
|---|---|
| 100 | 应用未授权 |
| 101 | 应用秘钥错误 |
| 102 | 应用无效 |
| 103 | 应用未授权该IP访问 |
| 104 | 应用访问次数不足 |
| 105 | 应用包名不正确 |
| 200 | tokenId无效 |
| 201 | token已失效 |
| 202 | token未授权该应用访问 |
| 203 | 登录鉴权级别不满足接口鉴权要求 |
| 300 | 接口未开放 |
| 301 | 应用未授权码访问该接口 |
| 302 | IP未授权码访问该接口 |
| 303 | 应用访问接口次数超日限额 |
| 400 | 请求参数为空 |
| 401 | 请求参数不完整 |
| 402 | 请求参数非法 |
| 600 | 请求非法 |
| 1000 | 请求解析错误 |
| 1001 | 请求已失效 |
| 1002 | 验签失败 |
| 1003 | 授权码已过期 |
| 1004 | 加密方式不支持 |
| 1005 | RSA加密错误 |
| 1010 | 服务间访问失败 |
| 1011 | 服务间访问错误 |
| 2004 | 用户不存在 |
| 3001 | unikey无效 |
| 3002 | 跳转异网取号 |
| 3003 | 本网执行取号失败,不需要重定向 |
| 3004 | NET取号失败 |
| 3005 | 上网方式为WIFI,无法取号 |
| 3006 | urlencode编码失败 |
| 3007 | 请求认证接口异常 |
| 3008 | imsi取号失败 |
| 3009 | 非联通号码 |
| 3010 | 网关取号错误 |
| 3011 | 源IP鉴权失败 |
| 3012 | 网关取号失败 |
| 3013 | 电信网关取号失败 |
| 3014 | 电信网关取号错误 |
| 3015 | 获取accessCode请求参数失败 |
| 3016 | 移动网关取号失败 |
| 3017 | 移动网关取号错误 |
建议开发者在开发期间开启debug模式,通过查看debug日志,可以更好的排查问题。
[GeYanSdk setDebug:YES];
目前支持移动 2G、3G、4G、5G,联通 3G、4G、5G,电信 4G、5G
支持,双卡手机以开启数据流量的 SIM 卡进行认证。
在数据网络开通的前提下,WiFi 环境中会强制使用数据网络触发网关请求,请求仅为几K,可正常校验。
SDK 不提供接口判断用户是否为携号转网用户,但可以判断用户流量卡当前的运营商。即携号转网用户可正常使用。
仅支持三大运营商(移动、联通、电信)的手机号进行一键登录。
三大运营商(移动、联通、电信)的卡,能够正常使用数据网络,运营商通过网关能够正常取号,均会被作为正常的卡来判断。
三大运营商(移动、联通、电信)一键登录服务均不可使用代理或者加速服务,运营商会根据出口IP做判断,出口IP被改变将无法使用一键登录
以上文档对您是否有帮助?