Пример #1
0
        public Msg91ApiResponse SendOtpOnEmail(Msg91EmailOtpRequest smsRequest)
        {
            Msg91ApiResponse msg91ApiResponse = new Msg91ApiResponse()
            {
                StatusCode = 200
            };
            string url = _msg91ServiceConfiguration.SendOtpApiUrl + Msg91Constant.SEND_OTP_ON_EMAIL_URL;

            Dictionary <string, string> requestHeader = new Dictionary <string, string>();

            requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");

            Dictionary <string, string> queryParameter = new Dictionary <string, string>();

            queryParameter.Add("authkey", _msg91ServiceConfiguration.AuthKey);
            queryParameter.Add("email", smsRequest.email);
            queryParameter.Add("otp", smsRequest.otp);

            BaseHttpWebResponse httpWebResponse = _httpWebRequestHandler.Post(url, null, requestHeader, queryParameter);

            if (httpWebResponse != null)
            {
                BaseResponse msg91response = StringUtility.ConvertJsonToObject <BaseResponse>(httpWebResponse.Response);
                msg91ApiResponse.StatusCode      = httpWebResponse.StatusCode;
                msg91ApiResponse.MessageResponse = msg91response;
            }
            return(msg91ApiResponse);
        }
Пример #2
0
        public Msg91ApiResponse SendBulkSms(Msg91BulkSmsRequest bulkSmsRequest)
        {
            Msg91ApiResponse msg91ApiResponse = new Msg91ApiResponse()
            {
                StatusCode = 200
            };
            string url = _msg91ServiceConfiguration.BaseApiUrl + Msg91Constant.SEND_BULK_SMS_URL;

            Dictionary <string, string> requestHeader = new Dictionary <string, string>();

            requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");
            requestHeader.Add("authkey", _msg91ServiceConfiguration.AuthKey);

            Dictionary <string, string> queryParameter = new Dictionary <string, string>();

            queryParameter.Add("country", bulkSmsRequest.country);

            bulkSmsRequest.sender = _msg91ServiceConfiguration.SenderId;

            string postData = StringUtility.ConvertObjectToJson(bulkSmsRequest);
            BaseHttpWebResponse httpWebResponse = _httpWebRequestHandler.Post(url, postData, requestHeader, queryParameter);

            if (httpWebResponse != null)
            {
                BaseResponse msg91response = StringUtility.ConvertJsonToObject <BaseResponse>(httpWebResponse.Response);
                msg91ApiResponse.StatusCode      = httpWebResponse.StatusCode;
                msg91ApiResponse.MessageResponse = msg91response;
            }
            return(msg91ApiResponse);
        }
Пример #3
0
        public Msg91ApiResponse ResendOtpSms(Msg91ResendSmsOtpRequest smsRequest)
        {
            Msg91ApiResponse msg91ApiResponse = new Msg91ApiResponse()
            {
                StatusCode = 200
            };
            string url = _msg91ServiceConfiguration.SendOtpApiUrl + Msg91Constant.RESEND_OTP_SMS_URL;

            Dictionary <string, string> requestHeader = new Dictionary <string, string>();

            requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");

            Dictionary <string, string> queryParameter = new Dictionary <string, string>();

            queryParameter.Add("authkey", _msg91ServiceConfiguration.AuthKey);
            queryParameter.Add("mobile", smsRequest.mobile.ToString());
            if (!string.IsNullOrWhiteSpace(smsRequest.retrytype))
            {
                queryParameter.Add("retrytype", smsRequest.retrytype);
            }

            BaseHttpWebResponse httpWebResponse = _httpWebRequestHandler.Post(url, null, requestHeader, queryParameter);

            if (httpWebResponse != null)
            {
                BaseResponse msg91response = StringUtility.ConvertJsonToObject <BaseResponse>(httpWebResponse.Response);
                msg91ApiResponse.StatusCode      = httpWebResponse.StatusCode;
                msg91ApiResponse.MessageResponse = msg91response;
            }
            return(msg91ApiResponse);
        }
Пример #4
0
        public Msg91ApiResponse VerifyOtpSms(Msg91VerifyOtpRequest smsRequest)
        {
            Msg91ApiResponse msg91ApiResponse = new Msg91ApiResponse()
            {
                StatusCode = 200
            };
            string url = _msg91ServiceConfiguration.SendOtpApiUrl + Msg91Constant.VERIFYREQUESTOTP_OTP_SMS_URL;

            Dictionary <string, string> requestHeader = new Dictionary <string, string>();

            requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");

            Dictionary <string, string> queryParameter = new Dictionary <string, string>();

            queryParameter.Add("authkey", _msg91ServiceConfiguration.AuthKey);
            queryParameter.Add("mobile", smsRequest.mobile);
            queryParameter.Add("otp", smsRequest.otp);

            BaseHttpWebResponse httpWebResponse = _httpWebRequestHandler.Post(url, null, requestHeader, queryParameter);

            if (httpWebResponse != null)
            {
                msg91ApiResponse.StatusCode      = httpWebResponse.StatusCode;
                msg91ApiResponse.MessageResponse = StringUtility.ConvertJsonToObject <BaseResponse>(httpWebResponse.Response);
            }
            else
            {
                msg91ApiResponse.StatusCode = 400;
            }
            return(msg91ApiResponse);
        }
Пример #5
0
        public Msg91ApiResponse SendSingleSms(Msg91SingleSmsRequest smsRequest)
        {
            Msg91ApiResponse msg91ApiResponse = new Msg91ApiResponse()
            {
                StatusCode = 200
            };
            string url = _msg91ServiceConfiguration.BaseApiUrl + Msg91Constant.SEND_SINGLE_SMS_URL;

            Dictionary <string, string> requestHeader = new Dictionary <string, string>();

            requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");

            Dictionary <string, string> queryParameter = new Dictionary <string, string>();

            queryParameter.Add("authkey", _msg91ServiceConfiguration.AuthKey);
            queryParameter.Add("sender", _msg91ServiceConfiguration.SenderId);
            queryParameter.Add("message", smsRequest.message);
            queryParameter.Add("mobiles", smsRequest.mobiles);
            queryParameter.Add("route", smsRequest.route);
            queryParameter.Add("country", smsRequest.country.ToString());
            queryParameter.Add("response", "json");

            if (smsRequest.afterminutes > 0)
            {
                queryParameter.Add("afterminutes", smsRequest.afterminutes.ToString());
            }
            if (!string.IsNullOrWhiteSpace(smsRequest.campaign))
            {
                queryParameter.Add("campaign", smsRequest.campaign);
            }
            if (smsRequest.schtime != null && smsRequest.schtime != DateTime.MinValue)
            {
                queryParameter.Add("schtime", Convert.ToString(smsRequest.schtime));
            }
            if (smsRequest.flash != null)
            {
                queryParameter.Add("flash", smsRequest.flash.Value ? "1" : "0");
            }
            if (smsRequest.unicode != null)
            {
                queryParameter.Add("unicode", smsRequest.unicode.Value ? "1" : "0");
            }

            BaseHttpWebResponse httpWebResponse = _httpWebRequestHandler.Post(url, null, requestHeader, queryParameter);

            if (httpWebResponse != null)
            {
                BaseResponse msg91response = StringUtility.ConvertJsonToObject <BaseResponse>(httpWebResponse.Response);
                msg91ApiResponse.StatusCode      = httpWebResponse.StatusCode;
                msg91ApiResponse.MessageResponse = msg91response;
            }
            return(msg91ApiResponse);
        }
Пример #6
0
        public Msg91ApiResponse SendOtpSms(Msg91SmsOtpRequest smsRequest)
        {
            Msg91ApiResponse msg91ApiResponse = new Msg91ApiResponse()
            {
                StatusCode = 200
            };
            string url = _msg91ServiceConfiguration.SendOtpApiUrl + Msg91Constant.SEND_OTP_SMS_URL;

            Dictionary <string, string> requestHeader = new Dictionary <string, string>();

            requestHeader.Add("Content-Type", "application/x-www-form-urlencoded");

            Dictionary <string, string> queryParameter = new Dictionary <string, string>();

            queryParameter.Add("authkey", _msg91ServiceConfiguration.AuthKey);
            queryParameter.Add("sender", _msg91ServiceConfiguration.SenderId);
            queryParameter.Add("mobile", smsRequest.mobile.ToString());
            queryParameter.Add("otp", smsRequest.otp.ToString());

            if (!string.IsNullOrWhiteSpace(smsRequest.email))
            {
                queryParameter.Add("email", smsRequest.email);
            }
            if (smsRequest.otp_expiry > 0)
            {
                queryParameter.Add("otp_expiry", smsRequest.otp_expiry.ToString());
            }
            if (smsRequest.otp_length > 0)
            {
                queryParameter.Add("otp_length", smsRequest.otp_length.ToString());
            }
            if (!string.IsNullOrWhiteSpace(smsRequest.template_id))
            {
                queryParameter.Add("template_id", smsRequest.template_id);
            }

            BaseHttpWebResponse httpWebResponse = _httpWebRequestHandler.Post(url, null, requestHeader, queryParameter);

            if (httpWebResponse != null)
            {
                msg91ApiResponse.StatusCode      = httpWebResponse.StatusCode;
                msg91ApiResponse.MessageResponse = StringUtility.ConvertJsonToObject <BaseResponse>(httpWebResponse.Response);
            }
            else
            {
                msg91ApiResponse.StatusCode = 400;
            }
            return(msg91ApiResponse);
        }
Пример #7
0
        public BaseHttpWebResponse GetResponse(HttpWebRequest httpWebRequest)
        {
            BaseHttpWebResponse webResponse = new BaseHttpWebResponse();

            try
            {
                HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
                webResponse.StatusCode  = (int)httpWebResponse.StatusCode;
                webResponse.WebResponse = httpWebResponse;
                webResponse.Response    = httpWebResponse.ResponseAsString();
            }
            catch (WebException webEx)
            {
                HttpWebResponse httpWebResponse = (HttpWebResponse)webEx.Response;
                if (httpWebResponse != null)
                {
                    webResponse.webException  = webEx;
                    webResponse.WebResponse   = httpWebResponse;
                    webResponse.StatusCode    = (int)httpWebResponse.StatusCode;
                    webResponse.ErrorResponse = httpWebResponse.ResponseAsString();
                }
            }
            return(webResponse);
        }