我正在尝试使用 Flutter 和 Dart 在此应用程序上启用 Firebase 电话身份验证 但每次我输入任何不是测试号码的数字时,都会出现验证码屏幕,然后出现此错误:
[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');
}
}
}
这是我的应用程序/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:
我已将我的应用程序与 Firebase SHA-1 以及 SHA-256 连接,我确保在 Firebase 控制台中启用电话身份验证,我还在 Google Cloud 中启用了 Google Play Integrity API 并进行了确保我的应用程序检查已注册并下载了最新版本的Google.service.json,并且我没有忘记尝试将我的依赖项升级到最新版本
请帮助我。
旧的解决方案不再有效。上面给出的链接不再有效。
造成这种情况的主要原因是Google Console中的某些API不再可用。例如 Android 设备验证。
因此,我提出了新的解决方案。
如果尚未添加,请添加。它将帮助您解决开发阶段的一些问题。
Android -> 应用程序 -> src -> 调试 -> AndroidManifest.xml
Android -> 应用程序 -> src -> main -> AndroidManifest.xml
添加到第15行。使用ClearTextTraffic;“true”
打开云控制台 (cloud.google.com/apis/),然后单击左侧面板上的 Credentials 菜单。
单击 IOS 和 Android 编辑 API 密钥
您可以看到SHA-1密钥: 打开终端并为 mac os 编写此内容
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
对 Android 密钥重复相同的过程。
就这样,您应该不再看到 17499 错误。
今天收到 FireBase 对我的请求的反馈。但这对我们没有帮助......
Hello Daniil,
My name is Taras and I'll be glad to assist you today.
We have investigated it and have confirmed the following key points:
Services are available in neighboring regions, indicating that the issue is not related to Google data centers.
Firebase services are healthy and stable.
The problem appears to be localized within a specific region and is affecting only certain carriers.
To ensure the safety and reliability of our services, carriers or entire regions with consistently low SMS success rates may become temporarily unavailable. To continue using Firebase Authentication in this region, I recommend considering using a different authentication method such as email and password or TOTP multi-factor. Alternatively, we also offer the ability to integrate a custom auth system.
I hope that helped clear things up, if you have any questions let me know.
Cheers,
Taras