OTP 不来了,我正在获取验证 ID,测试编号也有效
OTP is not coming, I am getting the verification ID and the Testing number is also working
这是我用来生成 OTP 和提交 OTP 的功能。
OTP 来过一次,但之后 OTP 就不会来了。
我什至尝试了 2 个不同的国家代码和号码。
class AuthService with ChangeNotifier {
final FirebaseAuth _auth = FirebaseAuth.instance;
//Sign In
String userphone = "";
String verificationId;
String errorMessage = "";
Future verifyPhone(String phonenumber) async {
final PhoneVerificationFailed verificationFailed =
(FirebaseAuthException authException) {
print("Auth Exception is ${authException.message}");
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
print("verification id is $verificationId");
this.verificationId = verificationId;
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
this.verificationId = verificationId;
};
await _auth.verifyPhoneNumber(
phoneNumber: "+7" + phonenumber,
verificationCompleted: null,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
timeout: const Duration(seconds: 60),
);
}
Future signIn({@required String smsCode, context}) async {
AuthCredential authCredential = PhoneAuthProvider.credential(
verificationId: verificationId,
smsCode: smsCode,
);
UserCredential result = await _auth.signInWithCredential(authCredential);
User user = result.user;
await checkUser(result);
return _userFromFirebase(user);
}
}
}
我用来触发生成 otp 的自定义按钮。
我在模拟器和真机上都试过了。
CustomButton(
buttonName: "Generate OTP",
function: () async {
if (_formKeySignIn.currentState.validate() &&
phonenumber.length == 10) {
Provider.of<AuthService>(context, listen: false).userphone =
phonenumber;
Provider.of<AuthService>(context, listen: false)
.verifyPhone(phonenumber);
widget.changeView();
} else {
setState(() {
error = "Please enter a valid phone number";
});
}
},
),
密码正确!我犯的错误是,我还必须将来自 Play Publisher 的 App Signing 部分的 SHA 代码与您的应用程序 SHA 代码一起添加到 Firebase。然后再次下载 Google 服务 json 文件并替换您的应用程序 json 文件并再次生成应用程序包。
这是我用来生成 OTP 和提交 OTP 的功能。 OTP 来过一次,但之后 OTP 就不会来了。 我什至尝试了 2 个不同的国家代码和号码。
class AuthService with ChangeNotifier {
final FirebaseAuth _auth = FirebaseAuth.instance;
//Sign In
String userphone = "";
String verificationId;
String errorMessage = "";
Future verifyPhone(String phonenumber) async {
final PhoneVerificationFailed verificationFailed =
(FirebaseAuthException authException) {
print("Auth Exception is ${authException.message}");
};
final PhoneCodeSent codeSent =
(String verificationId, [int forceResendingToken]) async {
print("verification id is $verificationId");
this.verificationId = verificationId;
};
final PhoneCodeAutoRetrievalTimeout codeAutoRetrievalTimeout =
(String verificationId) {
this.verificationId = verificationId;
};
await _auth.verifyPhoneNumber(
phoneNumber: "+7" + phonenumber,
verificationCompleted: null,
verificationFailed: verificationFailed,
codeSent: codeSent,
codeAutoRetrievalTimeout: codeAutoRetrievalTimeout,
timeout: const Duration(seconds: 60),
);
}
Future signIn({@required String smsCode, context}) async {
AuthCredential authCredential = PhoneAuthProvider.credential(
verificationId: verificationId,
smsCode: smsCode,
);
UserCredential result = await _auth.signInWithCredential(authCredential);
User user = result.user;
await checkUser(result);
return _userFromFirebase(user);
}
}
}
我用来触发生成 otp 的自定义按钮。 我在模拟器和真机上都试过了。
CustomButton(
buttonName: "Generate OTP",
function: () async {
if (_formKeySignIn.currentState.validate() &&
phonenumber.length == 10) {
Provider.of<AuthService>(context, listen: false).userphone =
phonenumber;
Provider.of<AuthService>(context, listen: false)
.verifyPhone(phonenumber);
widget.changeView();
} else {
setState(() {
error = "Please enter a valid phone number";
});
}
},
),
密码正确!我犯的错误是,我还必须将来自 Play Publisher 的 App Signing 部分的 SHA 代码与您的应用程序 SHA 代码一起添加到 Firebase。然后再次下载 Google 服务 json 文件并替换您的应用程序 json 文件并再次生成应用程序包。