【问题标题】:Flutter Firebase Phone Authentication return success but don't send sms code verificationFlutter Firebase Phone Authentication 返回成功但不发送短信验证码
【发布时间】:2020-12-23 01:42:04
【问题描述】:

我开发了一个带有电话号码身份验证的安卓应用,当我将它发布到 Play 商店时,它不再工作了。

在调试版本中,我通过短信收到了一次代码,但它不再起作用了。

用这个电话号码可以,只是不能用我的真实号码作为测试

1 - 在仪表板上启用对手机的访问 2 - SHA-1 在项目中设置

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());
  }
}

【问题讨论】:

  • 我想我发现了这个问题,即使遵循所有指南并注册测试电话号码,由于某种原因,我的网络 IP 在 firebase 服务器上被阻止。当我尝试使用手机的 4G 网络时,它起作用了

标签: android firebase flutter authentication


【解决方案1】:

我找到了解决方案;它在 SHA-1 密钥上;在firebase中,我配置了我在Android Studio keytool上获得的SHA-1;但是当我在 Google Play Store 上发布应用程序时;他用另一个密钥替换了 SHA-1,以便在 Play Store 上交付应用程序;您可以在 Google Play Console>Release Management>App siging 中找到新的;在应用签名证书中。 在firebase projet中配置它并哇;它的工作。

1 - 您使用上传密钥对每个版本进行数字签名,然后再将其发布到 Play 管理中心上的轨道。 2 - Google Play 使用上传证书来验证您的身份,并使用应用的订阅密钥重新签署您的版本以进行分发。 3 - 每台 Android 设备在更新之前验证版本的应用签名证书是否与已安装应用的签名证书匹配。

我找到了解决方案here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 2020-05-11
    • 1970-01-01
    • 2020-07-20
    • 1970-01-01
    • 2018-03-17
    相关资源
    最近更新 更多