1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
using System.Collections.Generic;
using System.Net;
using System.Web.Script.Serialization;
namespace SMS
{
class SmsSender
{
public SmsResponse SendSMS(string number, string from, string username, string pasword, string text)
{
string uri = string.Format("http://rest.nexmo.com/sms/json?username={0}&password={1}&from={2}&to={3}&text={4}", username, pasword, from, number, text);
var json = new WebClient().DownloadString(uri);
return ParseSmsResponseJson(json);
}
private SmsResponse ParseSmsResponseJson(string json)
{
// hyphens are not allowed in in .NET var names
json = json.Replace("message-count", "MessageCount");
json = json.Replace("message-price", "MessagePrice");
json = json.Replace("message-id", "MessageId");
json = json.Replace("remaining-balance", "RemainingBalance");
return new JavaScriptSerializer().Deserialize<SmsResponse>(json);
}
}
public class Message
{
public string To { get; set; }
public string Messageprice { get; set; }
public string Status { get; set; }
public string MessageId { get; set; }
public string RemainingBalance { get; set; }
}
public class SmsResponse
{
public string Messagecount { get; set; }
public List<Message> Messages { get; set; }
}
}
|