【问题标题】:Send SMS Message with Twilio purchased number使用 Twilio 购买的号码发送 SMS 消息
【发布时间】:2017-02-21 12:22:46
【问题描述】:

我已经购买了号码,但我无法发送 SMS 消息 给出错误的请求 400。通过使用试用号,我可以在下面发送短信 我正在为 API 使用 AFNewtorking 或者是否有任何其他方法可以调用 购买有效号码的api

NSString *kTwilioSID = @" ";
    NSString *kTwilioSecret = @" ";
    NSString *kFromNumber = @"+ ";

    NSString* nospacestring =[phno stringByReplacingOccurrencesOfString:@" " withString:@""];
    NSString *kToNumber = nospacestring;
    NSString *kSMSMessage = @"Smart Child Info is a precautionary app designed to fight child abduction, exploitation, and maltreatment.";

    // Build request
    NSString *urlString = [NSString stringWithFormat:@"https://%@:%@@api.twilio.com/2010-04-01/Accounts/%@/SMS/Messages/", kTwilioSID, kTwilioSecret, kTwilioSID];

    NSString *Loginurl = urlString;


    NSDictionary*
    dic=@{@"From":kFromNumber,@"To":kToNumber,@"Body":kSMSMessage};

    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];

    manager.responseSerializer = [AFHTTPResponseSerializer serializer];

    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/plain",@"application/xml",nil];

    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];

    [manager POST:Loginurl parameters:dic progress:nil success:^(NSURLSessionTask *task, id responseObject) {


        NSLog(@"Response from server  :  %@", [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]);

        NSData * data = (NSData *)responseObject;
        NSString* xmlData = [NSString stringWithCString:[data bytes] encoding:NSISOLatin1StringEncoding];
        NSLog(@"%@",xmlData);

        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Success" message:@"Message has been sent" preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
        [alertController addAction:ok];

        [self presentViewController:alertController animated:YES completion:nil];

    }
          failure:^(NSURLSessionTask *operation, NSError *error)

     {

         NSLog(@"Error: %@", error);

         UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Failed" message:@"Message not sent" preferredStyle:UIAlertControllerStyleAlert];

         UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
         [alertController addAction:ok];

         [self presentViewController:alertController animated:YES completion:nil];

     }];

【问题讨论】:

    标签: ios objective-c twilio sms-gateway


    【解决方案1】:

    这里是 Twilio 开发者宣传员。

    首先,我们不建议您从 iOS 应用程序直接对 Twilio API 进行 API 调用。如果有人要解压您的应用程序,他们可以访问您的 Account SID 和 Auth Token,然后将您的帐户用于他们想要的任何事情。

    其次,您正在使用已弃用的 SMS/Messages 端点。相反,您应该使用最新的Messages endpoint

    我建议您查看sending SMS messages with Twilio on iOS 上的这篇博文。它涵盖了如何设置服务器来发送您的消息,然后与该服务器进行交互。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多