public RadioWaveSmsResponse SendSms(RadioWaveSmsRequest radioWaveRequest) { RadioWaveSmsResponse radioWaveResponse = new RadioWaveSmsResponse(); string streamResponse; try { var smsSettings = Settings.DeliverSmsSettings(); using (WebClient client = new WebClient()) { client.QueryString.Add("api_id", smsSettings.ApiId); client.QueryString.Add("user", smsSettings.Username); client.QueryString.Add("password", smsSettings.Password); client.QueryString.Add("to", radioWaveRequest.MobileNumber); client.QueryString.Add("text", radioWaveRequest.Message); using (var data = client.OpenRead("http://api.clickatell.com/http/sendmsg")) { using (var reader = new StreamReader(data)) { streamResponse = reader.ReadToEnd(); if (streamResponse.Contains("ID")) { radioWaveResponse.Success = true; radioWaveResponse.Message = "Sms submitted to Clickatell successfully. " + streamResponse; radioWaveResponse.ApiMessageId = streamResponse.Split(':')[1].Trim(); radioWaveResponse.SubmittedDateTime = DateTime.Now; radioWaveResponse.MobileNumber = radioWaveRequest.MobileNumber; radioWaveResponse.TextMessage = radioWaveRequest.Message; } else if (streamResponse.Contains("ERR")) { radioWaveResponse.Success = false; radioWaveResponse.Message = "An error has occurred: " + streamResponse; radioWaveResponse.ApiMessageId = null; radioWaveResponse.SubmittedDateTime = null; } } } } } catch (Exception ex) { radioWaveResponse.Success = false; radioWaveResponse.Message = "An error has occurred: " + ex.Message; radioWaveResponse.ApiMessageId = null; radioWaveResponse.SubmittedDateTime = null; } return(radioWaveResponse); }
public void TestSendSMSusingClickatellApi() { smsProvider = new ClickatellRadioWave(); RadioWaveSmsRequest request = new RadioWaveSmsRequest(); request.ClientId = "SmsClient002"; request.DateCreated = DateTime.Now; request.Message = "Please deposit 1.25 million into my account. ThanksKBye"; request.MobileNumber = "27837644406"; var response = smsProvider.SendSms(request); Assert.IsTrue(response.Success, "Test to send a sms message using the Clickatell Api"); }
public RadioWaveSmsResponse SendSms(RadioWaveSmsRequest request) { return(smsProvider.SendSms(request)); }