当我尝试向手机发送短信时,我的控制台正在记录此错误:
[Error]: Uh oh, something went wrong (Code: 141, Version: 1.7.1)
有什么问题?它的错误141来自我理解的response.success包含附属错误,但老实说,我包括response.success所以我不清楚这里的问题是什么。任何帮助非常感谢。
Xcode中的代码
NSDictionary *params = [NSDictionary dictionaryWithObject:number forKey:@"number"];
[PFCloud callFunctionInBackground:@"sendSMSVerification" withParameters:params block:^(id object, NSError *error) {
NSString *message = @"";
if (!error) {
message = @"Your SMS invitation has been sent!";
} else {
message = @"Uh oh, something went wrong :(";
}
[[[UIAlertView alloc] initWithTitle:@"Verification Code sent!"
message:message
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil] show];
}];
云功能:
// Include the Twilio Cloud Module and initialize it
var twilio = require("twilio");
twilio.initialize("****","*****"); //these are for testing; todo insert real ones when deploying
// Create the Cloud Function
Parse.Cloud.define("sendSMSVerification", function(request, response) {
// Use the Twilio Cloud Module to send an SMS
twilio.sendSMS({
From: "1##########",
To: request.params.number,
Body: "test" //request.params.message// SMS Verification: 1234 or whatever the specific number is...
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
});
答案 0 :(得分:0)
这是我的云代码,对我有用。
var client = require('twilio')('<Your Twilio Account Sid>', '<Your Twilio Auth Token>');
// Send an SMS message
client.sendSms(
{
to:'number',
from: 'number',
body: "Your verification code is " + verificationCode + "."
}, function(err,responseData) {
if (err) {
} else {
response.error(verificationCode);
}
}
);
response.success(verificationCode);
});
如果您使用免费的Twilio帐户,请确保您的号码已经过twilio验证。
我按照this tutorial发送短信,这对我有用。试着遵循这个。
希望这会对你有所帮助。