JKInfoBip2FAKit 0.1.2

JKInfoBip2FAKit 0.1.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布最后发布2017年4月

Jose Aponte 维护。



  • 作者:
  • Jose Aponte

示例

要运行示例项目,请克隆回购库,然后首先从示例目录中运行 pod install

在运行示例项目之前,您应配置一些参数

  • InfoBipAppToken 密钥 在 JKInfoBip2FAKit-Info.plist 文件中,您需要将 your-app-token 值替换为在 infobip 平台上生成的自己的 API 密钥

  • APPLICATION_ID 在 infobip 平台上生成的应用程序 ID

  • MESSAGE_ID 在 infobop 平台上生成的消息 ID

需求

您需要在 infobip 网站平台 上有一个账户并生成一个 API 键

安装和配置

JKInfoBip2FAKit 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile。

pod "JKInfoBip2FAKit"
  • NSAppTransportSecurity 中配置 infobip.com 域。
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
        <key>infobip.com</key>
    <dict>
        <key>NSIncludesSubdomains</key>
        <true/>
        <key>NSExceptionAllowsInsecureHTTPLoads</key>
        <true/>
        <key>NSExceptionRequiresForwardSecrecy</key>
        <true/>
        <key>NSExceptionMinimumTLSVersion</key>
        <string>TLSv1.2</string>
        <key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
        <false/>
        <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
        <true/>
        <key>NSThirdPartyExceptionMinimumTLSVersion</key>
        <string>TLSv1.2</string>
        <key>NSRequiresCertificateTransparency</key>
        <false/>
    </dict>
</dict>
  • 在应用程序 Plist 文件 AppName-Info.plist 中添加密钥 InfoBipAppToken,其值应该是您的 API 密钥,例如 App xxxxxxxxxxxxxxxxxxxxxx

  • infobip 平台上创建一个应用程序。

  • infobop 平台上创建一条消息。

然后在这个 ID 中使用您的应用程序向 infobip 发送请求。

使用

在控制器头文件中导入 JKIB2FARequest.h

#import <JKInfoBip2FAKit/JKIB2FARequest.h>

添加代理 JKIB2FARequestDelegate

函数

要使用每个函数,您需要创建一个 JKIB2FARequest 实例并将代理分配以获取结果。

JKIB2FARequest *request = [JKIB2FARequest new];
request.delegate = self;

发送 SMS

JKIB2FAPinBody *body = [JKIB2FAPinBody new];
#warning change for your test application ID configured in InfoBip
body.applicationId = APPLICATION_ID;//@"your-config-applicationID";

#warning change for your test message ID configured in InfoBip
body.messageId = MESSAGE_ID;//@"your-config-messageID";

// This parameter should contains the country calling code + phone number
// remember to NOT include the sign (+), this parameter only can contains numbers
#warning change for your test phone number
body.to = _textFieldPhoneNumber.text;

[request sendSmsWithPinBody:body];

实现以下代理方法以获取结果

-(void)sendSmsWithPinBodyDidFinishSuccessful:(JKIB2FAPinResult *)pinResult
{
    if (pinResult.smsStatus == SmsStatusMessageSent)
  {
    NSLog(@"message send successful");
    pinId = pinResult.pinId;
  }
  else
  {
    // You can use pinResult.ncStatus to know the reason why the message was not sent
    NSLog(@"message not send becouse ncStatus");
  }
}
-(void)sendSmsWithPinBodyDidFinishFailure:(JKIB2FAResponseError *)responseError statusCode:(NSInteger)statusCode
{
    // You can use the responseError.text to see message information about the problem
  // and use the statusCode to know the http status code
}

重发 SMS

// the parameter is the pinID generated when your send a sms code
// whith methods sendSmsWithPinBody:
[request resendSmsCodeWithPinId:pinId];

实现以下代理方法以获取结果

-(void)resendSmsCodeWithPinIdDidFinishSuccessful:(JKIB2FAPinResult *)pinResult
{
  if (pinResult.smsStatus == SmsStatusMessageSent)
  {
    NSLog(@"message resend successful");
    pinId = pinResult.pinId;
  }
  else
  {
    // You can use pinResult.ncStatus to know the reason why the message was not sent
    NSLog(@"message not resend becouse ncStatus");
  }
}
-(void)resendSmsCodeWithPinIdDidFinishFailure:(JKIB2FAResponseError *)responseError statusCode:(NSInteger)statusCode
{
  // You can use the responseError.text to see message information about the problem
  // and use the statusCode to know the http status code
}

验证 PIN 码

// this method need two parameters, the first is the PinID generated when your send a sms code
// whith methods sendSmsWithPinBody:
// The second parameter is the pin code that user receive in the sms message.
[request verifySmsCodeWithPinId:pinId andCode:_textFieldPinCode.text];
-(void)verifySmsCodeWithPinIdDidFinishSuccessful:(JKIB2FAPinVerifyResult *)pinVerifyResult
{
  if (pinVerifyResult.verified)
  {
    // The pin code is valid and the phone number was verified
  }
  else
  {
    // You can use pinVerifyResult.pinError to know the problem
  }
}
-(void)verifySmsCodeWithPinIdDidFinishFailure:(JKIB2FAResponseError *)responseError statusCode:(NSInteger)statusCode
{
  // You can use the responseError.text to see message information about the problem
  // and use the statusCode to know the http status code
}

作者

Jose Aponte

许可

JKInfoBip2FAKit可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。