Flutter Firebase手机号认证非测试号码报错17499(错误码39)求助
Flutter集成Firebase手机号认证时非测试号码报错17499的问题
我在使用Flutter和Dart为应用集成Firebase手机号认证功能时,遇到以下问题:输入非测试号码时,Recaptcha界面弹出后会出现错误:
[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 17499 Error code:39
使用测试号码时一切正常。
AuthController代码
class AuthController extends GetxController{ final _auth = FirebaseAuth.instance; var verificationId = ''.obs; TextEditingController phoneController = TextEditingController(); var otp = ''; var _resendToken; Future<void> phoneAuthentication(String phone) async{ await _auth.verifyPhoneNumber( phoneNumber: phone, verificationCompleted: (credential) {}, codeSent: (verificationId, resendToken){ this.verificationId.value = verificationId; this._resendToken = resendToken; debugPrint('code is sent'); Get.toNamed(Verification.routeName); }, timeout: const Duration(seconds: 120), codeAutoRetrievalTimeout: (verificationId){ this.verificationId.value = verificationId; }, verificationFailed: (FirebaseAuthException e){ debugPrint('error message: ${e.message}'); debugPrint('error code: ${e.code}'); debugPrint('error stackTrace: ${e.stackTrace}'); showCustomToast(msg: 'sending failed error code: ${e.code}'); }, forceResendingToken: this._resendToken, ); } Future<void> verifyOTP(String otp) async{ try { PhoneAuthCredential credential = PhoneAuthProvider.credential( verificationId: verificationId.value, smsCode: otp); UserCredential user = await _auth.signInWithCredential(credential); debugPrint('${credential.smsCode}: credential.smsCode'); if (user.user != null) { Get.offAndToNamed(Home.routeName); } } catch (e){ showCustomToast(msg: 'wrong code'); } } }
app/build.gradle配置
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" apply plugin: 'com.google.gms.google-services' android { compileSdkVersion 33 ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.phone_store" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion 20 targetSdkVersion 33 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation platform('com.google.firebase:firebase-bom:32.1.0') implementation 'com.google.firebase:firebase-auth-ktx' implementation 'androidx.browser:browser:1.5.0' } configurations.all { exclude group: 'com.google.android.gms', module: 'play-services-safetynet' }
android/build.gradle配置
buildscript { ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.15' } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
pubspec.yaml依赖配置
dev_dependencies: flutter_test: sdk: flutter # The "flutter_lints" package below contains a set of recommended lints to # encourage good coding practices. The lint set provided by the package is # activated in the `analysis_options.yaml` file located at the root of your # package. See that file for information about deactivating specific lint # rules and activating additional ones. flutter_lints: ^2.0.0 otp_text_field: ^1.1.1 flutter_carousel_slider: ^1.0.8 intl_phone_number_input: ^0.7.0+2 cached_network_image: ^3.2.0 shimmer: ^2.0.0 flutter_screenutil: ^5.0.1 firebase_core: firebase_auth: cloud_firestore: flutter_smart_dialog: get:
已完成的配置
- 将应用的SHA-1和SHA-256与Firebase关联
- 在Firebase控制台启用手机号认证
- 在Google Cloud启用Google Play Integrity API
- 完成App Check注册并下载最新的google-services.json
- 尝试升级所有依赖至最新版本
以上操作后问题仍未解决,寻求帮助。
内容的提问来源于stack exchange,提问作者Mutasim Al-Mualimi
相关产品推荐
相关产品推荐

