当前位置: 首页 > 知识库问答 >
问题:

在android中使用Sinch SMS验证来验证接收到的OTP时触发了错误的回调

邴修远
2023-03-14

我正在整合Sinch短信验证API在我的应用程序和一半的部分已经完成。到目前为止,我能够发送和生成给定移动号码的OTP请求/响应,并在该移动号码上接收。但是,当我试图验证接收到的OTP错误时,回调会被激发。

public class MainActivity extends AppCompatActivity implements OnClickListener, VerificationListener {

    private EditText editTextVerify;
    private Button buttonVerify;

    private Config config;
    private Verification verification;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        editTextVerify = (EditText) findViewById(R.id.editTextVerify);
        buttonVerify = (Button) findViewById(R.id.buttonVerify);
        buttonVerify.setOnClickListener(this);

        config = SinchVerification.config().applicationKey("5xxxxx9c-xxc-4***-a***-76xxxxxb1xx1").context(getApplicationContext()).build();
        verification = SinchVerification.createSmsVerification(config, "91xx**xx**", this);
        verification.initiate();
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        System.out.println("...button clicked...");
        verification.verify(editTextVerify.getText().toString().trim());
    }

    @Override
    public void onInitiated() {
        // TODO Auto-generated method stub
        System.out.println("...calls onInitiated...");
    }

    @Override
    public void onInitiationFailed(Exception e) {
        // TODO Auto-generated method stub
        if (e instanceof InvalidInputException) {
            // Incorrect number provided
            System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof ServiceErrorException) {
            // Sinch service error
            System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
        } else {
            // Other system error, such as UnknownHostException in case of network error
            System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
        }
    }

    @Override
    public void onVerified() {
        // TODO Auto-generated method stub
        System.out.println("...callls onVerified this....");
    }

    @Override
    public void onVerificationFailed(Exception e) {
        // TODO Auto-generated method stub
        if (e instanceof InvalidInputException) {
            // Incorrect number or code provided
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof CodeInterceptionException) {
            // Intercepting the verification code automatically failed, input the code manually with verify()
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof IncorrectCodeException) {
            // The verification code provided was incorrect
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else if (e instanceof ServiceErrorException) {
            // Sinch service error
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        } else {
            // Other system error, such as UnknownHostException in case of network error
            System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
        }
    }

}
@Override
public void onInitiationFailed(Exception e) {
    // TODO Auto-generated method stub
    if (e instanceof InvalidInputException) {
        // Incorrect number provided
        System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof ServiceErrorException) {
        // Sinch service error
        System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
    } else {
        // Other system error, such as UnknownHostException in case of network error
        System.out.println("....onInitiationFailed exception... " + e.getLocalizedMessage());
    }
}
@Override
public void onVerificationFailed(Exception e) {
    // TODO Auto-generated method stub
    if (e instanceof InvalidInputException) {
        // Incorrect number or code provided
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof CodeInterceptionException) {
        // Intercepting the verification code automatically failed, input the code manually with verify()
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof IncorrectCodeException) {
        // The verification code provided was incorrect
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else if (e instanceof ServiceErrorException) {
        // Sinch service error
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    } else {
        // Other system error, such as UnknownHostException in case of network error
        System.out.println("....onVerificationFailed exception... " + e.getLocalizedMessage());
    }
}

共有1个答案

谷梁建中
2023-03-14

我会尝试将onVerificed回调放在onInitiationFailed方法之后。然后,这应该允许OTP响应通过onVerificationFailed回调。

下面是验证侦听器的文档:http://download.sinch.com/docs/Verification/android/latest/reference/index.html

 类似资料:
  • 我正在开发执行用户登录检查的Android应用程序。 我的代码如下, 其中url是有效的magento主机路径。此代码仅适用于管理员帐户,意味着如果我以管理员用户身份登录。但是它给了我错误 XMLRPC错误:访问被拒绝。[代码2] 对于输入电子邮件地址和密码的其他用户。我也尝试过使用客户。登录API,但它提供 无效的api路径错误 . 这个代码有什么问题?谁能告诉我用户登录的正确方法吗?

  • 问题内容: 我的意图是读取原始资源,然后使用JSON将其转换为Java代码。执行此操作的类和外部库存储在另一个项目中。当我运行我的应用程序时,在日志猫中出现此错误: 我可以说该错误是由JSONArray的创建引起的。我已经在stackoverflow上遇到过此错误,但是没有明确的方法来解决此问题。任何人都可以向我推荐解决此问题的方法。帮助将不胜感激。 问题答案: 您正在添加似乎具有未解决依赖性的n

  • 问题内容: 非常奇怪的错误。我使用的是http://developers.facebook.com/docs/authentication/。所以我创建了对fb的请求并传递redirect_uri。我在本地主机上使用测试站点。所以如果我通过 redirect_uri = http://localhost/test_blog/index.php 它工作正常,但如果我通过 redirect_uri =

  • 我计划使用API中的 波姆。xml 位置检查。JAVA 位置验证器。JAVA 位置JAVA 机器人。JAVA 一个pp.java 这里的问题是,上的