public void SaveSMSLog(SMS_LoggerDTO objSMS_LoggerDTO) { CH_SMSLogger objSMSLogger = new CH_SMSLogger(); objSMSLogger.Number = objSMS_LoggerDTO.Number; objSMSLogger.SendBy = objSMS_LoggerDTO.SendBy; objSMSLogger.SendDate = objSMS_LoggerDTO.SendDate; objSMSLogger.Category = objSMS_LoggerDTO.Category; objSMSLogger.SMSStatus = objSMS_LoggerDTO.SMSStatus; repCH_SMSLogger.Add(objSMSLogger); GeneralManagerUtility.Commit(); }
private void SendSMS(string mobile, string code, long UserId, string Category) { Stream Answer = null; StreamReader _Answer = null; SMS_LoggerDTO objSMS_LoggerDTO = new SMS_LoggerDTO(); try { objSMS_LoggerDTO.Number = mobile; objSMS_LoggerDTO.SendBy = UserId; objSMS_LoggerDTO.SendDate = DateTime.Now; objSMS_LoggerDTO.Category = Category; string OTPURL = ConfigurationManager.AppSettings["OTPURL"]; string FEEDID = ConfigurationManager.AppSettings["FEEDID"]; string USERNAME = ConfigurationManager.AppSettings["USERNAME"]; string PASSWORD = ConfigurationManager.AppSettings["PASSWORD"]; if (string.IsNullOrEmpty(OTPURL) || string.IsNullOrEmpty(FEEDID) || string.IsNullOrEmpty(USERNAME) || string.IsNullOrEmpty(PASSWORD)) { objSMS_LoggerDTO.SMSStatus = "Due to some reason unable to send OTP"; return; } string message = string.Format(ConfigurationManager.AppSettings["MESSAGE"].Decrypt(), code); string url = string.Format("{0}?feedid={1}&username={2}&password={3}&To={4}&Text={5}&time={6}", OTPURL.Decrypt(), FEEDID.Decrypt(), USERNAME.Decrypt(), PASSWORD.Decrypt(), mobile, message, DateTime.Now.ToString("yyyyMMddHHmm")); ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return(true); }); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Uri.EscapeUriString(url)); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; request.AllowAutoRedirect = true; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response != null) { Answer = response.GetResponseStream(); _Answer = new StreamReader(Answer); string str_response = _Answer.ReadToEnd(); if (response.StatusCode == HttpStatusCode.OK) { objSMS_LoggerDTO.SMSStatus = "Delivered"; } else { objSMS_LoggerDTO.SMSStatus = "SMS Fail ERROR:" + Convert.ToString(response.StatusCode); } } else { objSMS_LoggerDTO.SMSStatus = "Due to some technical issue unable to send OTP"; //return "Due to some reason unable to send OTP"; } //SaveSMSLog(objSMS_LoggerDTO); } catch (Exception exp) { common.logger.Debug("SMS Fail ERROR:" + exp.Message.ToString()); // return "SMS Fail ERROR:" + exp.Message; objSMS_LoggerDTO.SMSStatus = "SMS Fail ERROR:" + exp.Message; throw; } finally { SaveSMSLog(objSMS_LoggerDTO); Answer.Close(); _Answer.Close(); } }