예제 #1
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);
        }
예제 #2
0
        public SmsApiResponse VerifyOtpSms(VerifyOtpRequest smsRequest)
        {
            SmsApiResponse smsApiResponse = new SmsApiResponse()
            {
                StatusCode = 200
            };

            if (smsRequest != null)
            {
                if (string.IsNullOrWhiteSpace(smsRequest.Mobile))
                {
                    smsApiResponse.StatusCode = 400;
                    smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, nameof(smsRequest.Mobile) + " is required.", nameof(smsRequest.Mobile));
                    return(smsApiResponse);
                }

                if (!Regex.IsMatch(smsRequest.Mobile, RegexPattern.mobile_number_validation_Patterns.GetCombinedPattern()))
                {
                    smsApiResponse.StatusCode = 400;
                    smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, nameof(smsRequest.Mobile) + " should be valid. Format -: xxxxxxxxxx ", nameof(smsRequest.Mobile));
                    return(smsApiResponse);
                }

                if (smsRequest.CountryCode <= 0)
                {
                    smsApiResponse.StatusCode = 400;
                    smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, nameof(smsRequest.CountryCode) + " is required.", nameof(smsRequest.CountryCode));
                    return(smsApiResponse);
                }

                if (string.IsNullOrWhiteSpace(smsRequest.Otp))
                {
                    smsApiResponse.StatusCode = 400;
                    smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, nameof(smsRequest.Otp) + " is required.", nameof(smsRequest.Otp));
                    return(smsApiResponse);
                }

                Msg91VerifyOtpRequest msg91VerifyOtpRequest = new Msg91VerifyOtpRequest()
                {
                    mobile = string.Format("{0}{1}", smsRequest.CountryCode, smsRequest.Mobile),
                    otp    = smsRequest.Otp
                };

                Msg91ApiResponse msg91ApiResponse = _msg91.VerifyOtpSms(msg91VerifyOtpRequest);
                if (msg91ApiResponse.StatusCode == 200)
                {
                    BaseResponse baseResponse = msg91ApiResponse.MessageResponse;
                    if (string.Equals(baseResponse.Type, "error", StringComparison.OrdinalIgnoreCase))
                    {
                        smsApiResponse.StatusCode = 400;
                        smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, baseResponse.Message);
                    }
                    else
                    {
                        smsApiResponse.StatusCode = 200;
                        smsApiResponse.Response   = new SmsResponse()
                        {
                            Message = baseResponse.Message, RequestId = baseResponse.RequestId, Type = baseResponse.Type
                        };
                    }
                }
                else
                {
                    smsApiResponse.StatusCode = 400;
                    smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, "otp not verified");
                }
            }
            else
            {
                smsApiResponse.StatusCode = 400;
                smsApiResponse.ErrorList  = GetSmsApiValidationResponses(1001, nameof(smsRequest) + " is required.", nameof(smsRequest));
            }
            return(smsApiResponse);
        }