From 06fc8af9c0b0b5fd631baf220d0b9d2aa8b6f9d1 Mon Sep 17 00:00:00 2001 From: shakun Date: Sat, 9 Sep 2023 23:33:53 +0545 Subject: [PATCH] #18143 SMS --- .../BusinessLogic/SMSApiService/SMSService.cs | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/Business/BusinessLogic/SMSApiService/SMSService.cs b/Business/BusinessLogic/SMSApiService/SMSService.cs index 024926a..a067b11 100644 --- a/Business/BusinessLogic/SMSApiService/SMSService.cs +++ b/Business/BusinessLogic/SMSApiService/SMSService.cs @@ -3,8 +3,12 @@ using Common.Models.SendSMS; using Common.Utility; using log4net; using System; +using System.IO; +using System.Net; using System.Net.Http; using System.Net.Http.Headers; +using System.Text; +using System.Web; namespace Business.BusinessLogic.SMSApiService { @@ -34,18 +38,44 @@ namespace Business.BusinessLogic.SMSApiService string _qs = ""; if (model.method.ToLower() == "send") { - if (model.MobileNumber.Replace("+", "").Equals("817044652959")) + StringBuilder sb = new StringBuilder(); + byte[] buf = new byte[1024]; + string url = _baseUrl + + "?username=" + _userName + "&password=" + _password + "&option=xml" + + "&number=" + model.MobileNumber + "&message=" + HttpUtility.UrlEncode(model.SMSBody) + + "&orig=" + HttpUtility.UrlEncode(_senderId); + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); + HttpWebResponse response = (HttpWebResponse)request.GetResponse(); + Stream resStream = response.GetResponseStream(); + string tempString = null; + int count = 0; + do { - _qs = "?apiusername=" + _userName + "&apipassword=" + _password + "&mobileno=" + model.MobileNumber; - _qs += "&senderid=" + _senderId + "&languagetype=" + _langType + "&message=" + model.SMSBody + " dt: " + DateTime.Now.ToString("yyyyMMddhmmss"); ; + count = resStream.Read(buf, 0, buf.Length); + if (count != 0) + { + tempString = Encoding.ASCII.GetString(buf, 0, count); + sb.Append(tempString); + } + } + while (count > 0); + + var result = sb.ToString(); + + if (result.Contains("SUCCESS 722")) + { + _tPResponse.ResponseCode = "0"; + _tPResponse.Msg = "SMS Sent Successfully!"; + _tPResponse.Extra = result; } else { - _qs = "?apiusername=" + _userName + "&apipassword=" + _password + "&mobileno=" + model.MobileNumber; - _qs += "&senderid=" + _senderId + "&languagetype=" + _langType + "&message=" + model.SMSBody; + _tPResponse.ResponseCode = "1"; + _tPResponse.Msg = "SMS Sent Failed!"; + _tPResponse.Extra = result; } - _tPResponse = CallTPApi(_qs, "get", model.method, _baseUrl); + return _tPResponse; } else if (model.method.ToLower() == "status") {