Flutter Firebase电话验证返回成功,但不发送短信验证码

时间:2020-09-03 18:59:42

标签: android firebase flutter authentication

我开发了一个具有电话号码验证功能的android应用程序,当我将其发布到Play商店时,它不再起作用了。

在调试版本中,我一次通过SMS收到了代码,现在不再起作用。

使用此电话号码可以正常工作,但不能与我的真实电话号码一起测试

1-在仪表板上启用了对电话的访问 2-SHA-1已设置为projet

buildscript {
    ext.kotlin_version = '1.3.50'
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}



dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    implementation 'com.google.firebase:firebase-analytics:17.2.2'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation 'androidx.multidex:multidex:2.0.0'
    implementation 'com.android.support:multidex:1.0.3'  //with support libraries
}

apply plugin: 'com.google.gms.google-services'



Future<void> verifyPhone() async {

    final PhoneCodeSent smsOTPSent = (String verId, [int forceCodeResend]) {
      print("smsOTPSent");
      print(forceCodeResend);
      print(verId);
      this.verificationId = verId;
      smsOTPDialog(context).then((value) {
        print('sign in');
      });
    };

    try {

    await _auth.verifyPhoneNumber(
        phoneNumber: "+55" + this.telController.text, // PHONE NUMBER TO SEND OTP
        codeAutoRetrievalTimeout: (String verId) {
          //Starts the phone number verification process for the given phone number.
          //Either sends an SMS with a 6 digit code to the phone number specified, or sign's the user in and [verificationCompleted] is called.
          this.verificationId = verId;
          print("verId " + verId);
        },
        codeSent: smsOTPSent, // WHEN CODE SENT THEN WE OPEN DIALOG TO ENTER OTP.
        timeout: const Duration(seconds: 20),
        verificationCompleted: (AuthCredential phoneAuthCredential) {
          print("verificationCompleted " + this.telController.text);
          print(phoneAuthCredential);
        },
        verificationFailed: (AuthException exceptio) {
          print("fail");
          print('${exceptio.message}');
        }).timeout(const Duration(seconds: 2));
  } catch (e) {
    handleError(e);
    print(e.printStackTrace());
  }
}



verificaLogado(){
  print("chamou: verificaLogado()");
  print(_auth.currentUser());
  _auth.currentUser().then((user) {
    if (user != null) {
      Navigator.of(context).pop();
      Navigator.of(context).pushReplacementNamed('/homepage');
    }else{
      print("não logado");
    }
  });
}


signIn() async {
  try {
    final AuthCredential credential = PhoneAuthProvider.getCredential(
      verificationId: verificationId,
      smsCode: smsOTP,
    );
    final FirebaseUser user = (await _auth.signInWithCredential(credential)).user;
    final FirebaseUser currentUser = await _auth.currentUser().timeout(Duration(seconds: 5));
    assert(user.uid == currentUser.uid);
    _showDialog('Sucesso', 'Autenticado com o número de telefone ' + user.phoneNumber);
    _setPhoneFCM(currentUser.uid, currentUser.phoneNumber);
    Navigator.of(context).pop();
    Navigator.of(context).pushReplacementNamed('/homepage');
  } catch (e) {
    handleError(e);
    print(e.printStackTrace());
  }
}

1 个答案:

答案 0 :(得分:0)

我找到了解决方案;它在SHA-1键上;在firebase中,我配置了在Android Studio键盘工具上获得的SHA-1;但是当我在Google Play商店上发布应用程序时;他将SHA-1替换为另一个密钥,以便在Play商店中交付该应用;您可以在Google Play控制台>版本管理>应用兄弟中找到新版本;在App siging证书中。 在firebase的projet和哇配置;它的工作。

1-在将每个版本发布到Play控制台上的曲目之前,请使用上传密钥对每个版本进行数字签名。 2-Google Play使用上传证书来验证您的身份,并使用该应用的订阅密钥对您的版本进行重新签名以进行分发。 3-每台Android设备在更新之前都要先验证该版本的应用签名证书是否与已安装的应用的证书签名相符。

我找到了解决方法here