gpt4 book ai didi

ios - 验证码总是无效 Swift Parse

转载 作者:行者123 更新时间:2023-11-28 06:53:41 26 4
gpt4 key购买 nike

我使用短信验证来验证用户。我的问题是,当我输入代码进行验证时,我得到了无效代码。我这辈子都想不通为什么。

调用云码函数:

@IBAction func verifyCodeButtonTapped(sender: AnyObject) {
var verificationCode: String = verificationCodeTextField.text!
let textFieldText = verificationCodeTextField.text ?? ""

if verificationCode.utf16.count < 4 || verificationCode.utf16.count > 4 {
displayAlert("Error", message: "You must entert the 4 digit verification code sent yo your phone")
} else {
let params = ["verificationCode" : textFieldText]
PFCloud.callFunctionInBackground("verifyPhoneNumber", withParameters: params, block: { (object: AnyObject?, error) -> Void in
if error == nil {
self.performSegueWithIdentifier("showVerifyCodeView", sender: self)
} else {
self.displayAlert("Sorry", message: "We couldnt verify you. Please check that you enterd the correct 4 digit code sent to your phone")
}
})
}
}

云码验证码:

Parse.Cloud.define("verifyPhoneNumber", function(request, response) {
var user = Parse.User.current();
var verificationCode = user.get("phoneVerificationCode");
if (verificationCode == request.params.phoneVerificationCode) {
user.set("phoneNumber", request.params.phoneNumber);
user.save();
response.success("Success");
} else {
response.error("Invalid verification code.");
}
});

最佳答案

您的参数名称在 iOS 和 JS 代码之间不匹配。

verificationCodephoneVerificationCode

改变

let params = ["verificationCode" : textFieldText]

要使用相同的参数名称:

let params = ["phoneVerificationCode" : textFieldText]

编辑

我在代码中看到的其他问题:

iOS 代码的前两行根据 textField 的文本值创建了一个变量和一个常量。去掉 verificationCode 变量,只使用 textFieldText 常量。

在您检查代码是否等效之前,我会向 Cloud Code 添加更多错误状态。首先检查参数是否存在以及预期的类型和长度:

var requestCode = request.params.phoneVerificationCode;
if ((typeof requestCode !== "string") || (requestCode.length !== 4)) {
// The verification code did not come through from the client
}

然后对来自用户对象的值执行相同的检查:

else if ((typeof verificationCode !== "string) || (verificationCode.length !== 4)) {
// There is not a verification code on the Parse User
}

然后可以继续检查requestCodeverificationCode是否等价。

关于ios - 验证码总是无效 Swift Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34278202/

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