Firebase 未向设备中的 phone 号码发送 OTP
Firebase not sending OTP to the phone number in device
我已经在我的 flutter 应用程序中实现了 firebase otp
当我在我的设备上安装该应用程序并在该设备上请求相同的号码时,它没有向我发送消息。但是当我更改号码时,它会发送消息
所以我换了设备,尝试发送之前的号码,发短信成功了。然后我在第二台设备上使用了这个号码,它没有发送消息
* 当我在设备上使用相同的号码时,它不会发送 OTP
这是发送 otp 的代码
Future<void> verifyPhone() async {
final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verID) {
this.verificationId = verID;
};
final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]) {
this.verificationId = verId;
};
final PhoneVerificationCompleted verifiedSuccess =
(AuthCredential phoneAuthCredential) {
print('verified');
};
final PhoneVerificationFailed verifyFailed = (AuthException exception) {
print('${exception.message}');
};
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: widget.phone,
timeout: const Duration(seconds: 5),
verificationCompleted: verifiedSuccess,
verificationFailed: verifyFailed,
codeSent: smsCodeSent,
codeAutoRetrievalTimeout: autoRetrieve);
log("OTP sent");
}
这是验证OTP的代码
signIn() async{
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationId,
smsCode: enteredOtp,
);
await FirebaseAuth.instance.signInWithCredential(credential).then((user) {
//SOME CODE HERE
}).catchError((e) {
showAlert(
context: context,
title: "Empty or Invalid OTP",
);
log("Invalid OTP");
});
}
这里有什么问题吗?我该如何解决这个问题并在设备中获取相同号码的 otp。
事实上,我相信这确实是预期的,并且是预期的用途。 (或接近它)好像 Firebase 可以通过推送通知确认 phone 身份,它甚至不发送文本,因为它已经过验证。 (通常只有在验证 phone 一次时才会发生)。但是,如果您将其发送到设备连接的 phone 号码以外的 phone 号码,则它无法使用系统中之前的 verificationID。
所以我建议检查代码的哪些部分起作用,哪些不起作用。检查代码和授权是否失败,或者是否会继续到程序的下一部分完全授权。在那里添加一些打印语句只是为了确保。但我很确定它应该是这样工作的。
我已经在我的 flutter 应用程序中实现了 firebase otp
当我在我的设备上安装该应用程序并在该设备上请求相同的号码时,它没有向我发送消息。但是当我更改号码时,它会发送消息
所以我换了设备,尝试发送之前的号码,发短信成功了。然后我在第二台设备上使用了这个号码,它没有发送消息
* 当我在设备上使用相同的号码时,它不会发送 OTP
这是发送 otp 的代码
Future<void> verifyPhone() async {
final PhoneCodeAutoRetrievalTimeout autoRetrieve = (String verID) {
this.verificationId = verID;
};
final PhoneCodeSent smsCodeSent = (String verId, [int forceCodeResend]) {
this.verificationId = verId;
};
final PhoneVerificationCompleted verifiedSuccess =
(AuthCredential phoneAuthCredential) {
print('verified');
};
final PhoneVerificationFailed verifyFailed = (AuthException exception) {
print('${exception.message}');
};
await FirebaseAuth.instance.verifyPhoneNumber(
phoneNumber: widget.phone,
timeout: const Duration(seconds: 5),
verificationCompleted: verifiedSuccess,
verificationFailed: verifyFailed,
codeSent: smsCodeSent,
codeAutoRetrievalTimeout: autoRetrieve);
log("OTP sent");
}
这是验证OTP的代码
signIn() async{
final AuthCredential credential = PhoneAuthProvider.getCredential(
verificationId: verificationId,
smsCode: enteredOtp,
);
await FirebaseAuth.instance.signInWithCredential(credential).then((user) {
//SOME CODE HERE
}).catchError((e) {
showAlert(
context: context,
title: "Empty or Invalid OTP",
);
log("Invalid OTP");
});
}
这里有什么问题吗?我该如何解决这个问题并在设备中获取相同号码的 otp。
事实上,我相信这确实是预期的,并且是预期的用途。 (或接近它)好像 Firebase 可以通过推送通知确认 phone 身份,它甚至不发送文本,因为它已经过验证。 (通常只有在验证 phone 一次时才会发生)。但是,如果您将其发送到设备连接的 phone 号码以外的 phone 号码,则它无法使用系统中之前的 verificationID。
所以我建议检查代码的哪些部分起作用,哪些不起作用。检查代码和授权是否失败,或者是否会继续到程序的下一部分完全授权。在那里添加一些打印语句只是为了确保。但我很确定它应该是这样工作的。