【问题标题】:Firebase is not sending OTP to the Mobile NumberFirebase 未向手机号码发送 OTP
【发布时间】:2018-02-12 06:24:01
【问题描述】:

我面临着不同类型的问题。我在我的应用程序中使用 Firebase Mobile 号码身份验证。当我尝试将 OTP 发送到我正在使用的手机号码时,OTP 没有发送。但是,如果我从我的移动 OTP 发送 OTP 到其他手机正在发送。我还发现如果我从另一个手机发送 OTP 到我的号码 OTP 即将到来。因此不存在手机号码问题。在调试时我发现这个代码块不起作用

@Override
    public void onCodeSent(String verificationId, PhoneAuthProvider.ForceResendingToken forceResendingToken) {
        super.onCodeSent(verificationId, forceResendingToken);

        Log.e(TAG, "onCodeSent: s - " + verificationId + " : t - " + forceResendingToken);
        xVerificationId = verificationId;
    }

对于其他号码,它正在工作并且正在生成验证和 forceResendingToken。

【问题讨论】:

    标签: android firebase firebase-authentication


    【解决方案1】:

    如果您在 firebase 下的测试中添加了您的电话号码(登录方法->电话)。然后请从那里删除以获取 otp。

    【讨论】:

    • 并非总是如此。我在使用 OTP 时遇到了这些问题,有些用户没有收到,但有些用户收到了。
    【解决方案2】:

    您是否正在实施onVerificationCompleted?在以下 2 种情况下,不发送 OTP,如 https://firebase.google.com/docs/auth/android/phone-auth 中所述:

    • 即时验证:无需发送 OTP 即可即时验证电话号码。
    • 自动检索:Google Play 服务无需任何用户操作即可自动检测 OTP。

    在这种情况下,您将直接取回一个PhoneAuthCredential。

    【讨论】:

      【解决方案3】:

      如前所述,电话号码会自动验证

      1. 即时验证或
      2. 自动检索

      这就是onCodeSent() 不起作用的原因。

      现在,为了解决这个问题,你需要实现onVerificationCompleted(),你很可能已经实现了它,但你不知道里面放了什么。

      如果您在 onVerificationCompleted() 中,那么您可能没有 OTP,但您肯定有 phoneAuthCredential,您只需将此变量传递给 mAuth.signInWithCredential(),这应该会导致您获得所需的输出。

      示例代码:

              @Override
              public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential) {
      
                  Toast.makeText(getApplicationContext(),"Verifying code Automatically",LENGTH_LONG).show();
      
                  signInWithCredential(phoneAuthCredential);
      
              }
      

      示例代码:

      private void signInWithCredential(PhoneAuthCredential credential) {
          mAuth.signInWithCredential(credential)
                  .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                      @Override
                      public void onComplete(@NonNull Task<AuthResult> task) {
                          if (task.isSuccessful()) {
      
                              // Sign in success, update UI with the signed-in user's information
                              // Log.d(TAG, "signInWithCredential:success");
      
      
                          } else {
                              // Sign in failed, display a message and update the UI
                              // Log.w(TAG, "signInWithCredential:failure", task.getException());
      
                              }
                          }
                      }
                  });
      }
      

      【讨论】:

      • 这是给我的。你过分了!我有那个 onVerificationCompleted 方法。但我没有通过 PhoneAuthCredential 参数。谢谢兄弟
      【解决方案4】:

      更新 SHA1 指纹。它对我有用。

      【讨论】:

      • 太好了,你节省了我的时间。实际上,我忘了设置 SHA
      【解决方案5】:

      为我工作。

      有时 Google 无法验证来自您的应用的请求。 为了解决它。重新生成您应用的签名报告并获取您的 SHA-1 或 SHA-256 指纹。 转到您的 firebase 项目设置并添加这些指纹。

      How to generate fingerprints

      【讨论】:

        【解决方案6】:

        由于我更改了包名并生成了新的 google-services.json,因此应用程序 ID 未更新。

        更新“applicationid”解决了这个问题!

        【讨论】:

        • 您能详细说明更新应用程序ID是什么意思吗?
        【解决方案7】:

        在您的 build.gradle 文件中使用依赖项实现“androidx.browser:browser:1.2.0”。 Firebase 现在想通过图像检查验证,此依赖项将允许打开浏览器并验证 Captcha,您将获得 OTP。

        【讨论】:

          【解决方案8】:
          1. 更新您的 SHA 密钥。如果您的应用在 Playstore 中,那么您将从 Play 控制台获得新的 SHA 密钥:发布---> 应用程序完整性---> SHAH 密钥。 有时他们会更新他们的网站,因此最好搜索如何从游戏控制台获取 SHA 密钥

          【讨论】:

          • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
          【解决方案9】:

          就我而言,我意识到这个问题发生在从一个提供商转移到另一个提供商的所有号码上。使用从未移植过 Firebase 身份验证的电话号码就像一个魅力!

          【讨论】:

            猜你喜欢
            • 2020-05-26
            • 1970-01-01
            • 2020-02-09
            • 1970-01-01
            • 1970-01-01
            • 2016-01-17
            • 2021-12-10
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多