我正在使用twilio rest-api从我的控制器类发送SMS,然后返回:id = 166,status = watchforactivation,method =" {null}",result =" {不但计算}"
public Task SendSmsAsync(string number, string message)
{
var accountSid = Options.SMSAccountIdentification;
var authToken = Options.SMSAccountPassword;
TwilioClient.Init(accountSid, authToken);
return MessageResource.CreateAsync(
to: new PhoneNumber(number),
from: new PhoneNumber(Options.SMSAccountFrom),
body: message);
}
我正在从控制器类中调用此方法:
var result = _smsSender.SendSmsAsync("+92331234566", "Hi its my first msg to ya. Twilio")
它是返回状态:watchforactivation。
如果我将整个过程异步解决?虽然我已经尝试过,但是我没有达到解决方案。
twilio开发人员在这里。
您正在使用异步方法,因此结果将是尚未解决的任务。我不是C#开发人员,但我相信您需要正确的位置async
和await
关键字。类似:
public async Task SendSmsAsync(string number, string message)
{
var accountSid = Options.SMSAccountIdentification;
var authToken = Options.SMSAccountPassword;
TwilioClient.Init(accountSid, authToken);
return await MessageResource.CreateAsync(
to: new PhoneNumber(number),
from: new PhoneNumber(Options.SMSAccountFrom),
body: message);
}
也请查看此博客文章以获取一个很好的例子。