gpt4 book ai didi

Flutter Firebase 电话身份验证不发送短信代码。直接调用 PhoneCodeAutoRetrievalTimeout 方法。这是我的代码

转载 作者:行者123 更新时间:2023-12-04 14:11:19 27 4
gpt4 key购买 nike

我刚刚复制粘贴了示例代码以开始处理 Firebase 电话身份验证。但 firebase 不会向真实号码和测试号码发送短信代码。我测试了两者。你能帮忙找出问题所在吗?

这是 Flutter Doctor 的输出

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.20.4, on Microsoft Windows [Version 10.0.19041.508], locale en-IN)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
[√] Android Studio (version 4.0)
[√] VS Code (version 1.49.1)
[√] Connected device (1 available)

• 未发现问题!


import 'package:firebase_auth/firebase_auth.dart';

class AuthService {
String _phoneNumber;
String _verificationId;
String _smsCode;
String _message;

final FirebaseAuth _auth = FirebaseAuth.instance;

String get phoneNumber1 => _phoneNumber;
String get verificationId => _verificationId;
String get smsCode => _smsCode;
String get message => _message;

Future<void> verifyPhoneNumber(String phoneNumber) async {
print(phoneNumber);
PhoneVerificationCompleted verificationCompleted =
(PhoneAuthCredential phoneAuthCredential) async {
print('User Auto Logged In');
// UserCredential _userCredential =
// await _auth.signInWithCredential(phoneAuthCredential);
};

PhoneVerificationFailed verificationFailed =
(FirebaseAuthException authException) async {
print('Auth Exception Occured');
// throw Exception(authException.message);
// _message =
// 'Phone number verification failed. Code: ${authException.code}. Message: ${authException.message}';
};

PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
print('SMS Sent');
_verificationId = verificationId;
};

PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) async {
print('SMS Auto Retrieval Timeout');
_verificationId = verificationId;
};

await _auth.verifyPhoneNumber(
phoneNumber: phoneNumber,
timeout: const Duration(seconds: 5),
verificationCompleted: verificationCompleted,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout);
}

// Example code of how to sign in with phone.
void signInWithPhoneNumber(String smsCode) async {
final AuthCredential credential = PhoneAuthProvider.credential(
verificationId: _verificationId,
smsCode: smsCode,
);
final User user = (await _auth.signInWithCredential(credential)).user;
}
}

输出:


I/BiChannelGoogleApi( 2258): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzaq@57888fb
Reloaded 4 of 704 libraries in 1,013ms.
I/flutter ( 2258): SMS Auto Retrieval Timeout

请帮我解决这个问题。

最佳答案

问题出在 Firebase 本身。那天它没有发送任何短信。现在相同的代码可以正常工作。

关于Flutter Firebase 电话身份验证不发送短信代码。直接调用 PhoneCodeAutoRetrievalTimeout 方法。这是我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64011626/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com