private bool SendOtp(string phoneNumber, string templateName, string[] tokens)
        {
            try
            {
                if (phoneNumber == null)
                {
                    throw new ArgumentNullException("PhoneNumber cant be null");
                }

                if (templateName == null)
                {
                    throw new ArgumentNullException("TemplateName cant be null");
                }

                if (tokens == null)
                {
                    throw new ArgumentNullException("Tokens cant be null");
                }

                KavenegarApi Api    = new KavenegarApi(_apiKey);
                SendResult   Result = null;

                if (tokens.Length == 0)
                {
                    throw new ArgumentNullException("Tokens cant be null");
                }
                else if (tokens.Length == 1)
                {
                    Result = Api.VerifyLookup(phoneNumber, tokens[0], templateName);
                }
                else if (tokens.Length == 2)
                {
                    tokens.Append("");
                    Result = Api.VerifyLookup(phoneNumber, tokens[0], tokens[1], tokens[2], templateName);
                }
                else if (tokens.Length == 3)
                {
                    Result = Api.VerifyLookup(phoneNumber, tokens[0], tokens[1], tokens[2], templateName);
                }

                var IsSent = CheckStatus(Result);

                return(IsSent);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(false);
            }
        }
Ejemplo n.º 2
0
 static void VerifyLookup()
 {
     try
     {
         const string receptor = "";
         const string token    = "";
         const string token2   = "";
         const string token3   = "";
         const string template = "";
         var          result   = Api.VerifyLookup(receptor, token, token2, token3, template);
         if (result != null)
         {
             Console.WriteLine(result.Cost + "\n");
             Console.WriteLine(result.Date + "\n");
             Console.WriteLine(result.Message + "\n");
             Console.WriteLine(result.Receptor + "\n");
             Console.WriteLine(result.Sender + "\n");
             Console.WriteLine(result.Status + "\n");
             Console.WriteLine(result.StatusText + "\n");
         }
     }
     catch (ApiException ex)
     {
         // در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد.
         Console.Write("Message : " + ex.Message);
     }
     catch (HttpException ex)
     {
         // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد
         Console.Write("Message : " + ex.Message);
     }
 }
Ejemplo n.º 3
0
        public async Task <bool> SendAsync(string token, string token2, string token3, string phoneNumber, string templateName)
        {
            try
            {
                var api             = new KavenegarApi(ApiKey);
                var smsTemplateName = _configuration["Sms:Kavenegar:Templates:" + templateName];
                await api.VerifyLookup(phoneNumber, token.Trim(), token2.Trim(), token3.Trim(), smsTemplateName);

                return(true);
            }
            catch (global::Kavenegar.Core.Exceptions.ApiException ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
            catch (global::Kavenegar.Core.Exceptions.HttpException ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 4
0
        public async Task <bool> SendAsync(string templateName, string phoneNumber, params string[] values)
        {
            try
            {
                var api             = new KavenegarApi(ApiKey);
                var smsTemplateName = _configuration["FazelMan:Modulus:Sms.Kavenegar:Templates:" + templateName];

                await api.VerifyLookup(phoneNumber, values[0].Trim(), values[1].Trim(), values[2].Trim(), values[3].Trim(), smsTemplateName);

                return(true);
            }
            catch (global::Kavenegar.Core.Exceptions.ApiException ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
            catch (global::Kavenegar.Core.Exceptions.HttpException ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> SendAsync(string templateName, string phoneNumber, string value)
        {
            try
            {
                var api             = new KavenegarApi(ApiKey);
                var smsTemplateName = _configuration["FazelMan:Modulus:Sms.Kavenegar:Templates:" + templateName];
                await api.VerifyLookup(phoneNumber, value.Trim(), smsTemplateName);

                return(true);
            }
            catch (global::Kavenegar.Core.Exceptions.ApiException ex)
            {
                //if it doesn't return 200
                Console.Write("Message : " + ex.Message);
                return(false);
            }
            catch (global::Kavenegar.Core.Exceptions.HttpException ex)
            {
                //if connect to service error occured
                Console.Write("Message : " + ex.Message);
                return(false);
            }
            catch (Exception ex)
            {
                Console.Write("Message : " + ex.Message);
                return(false);
            }
        }
        //Kavenegar
        public static Exception SendSMS_K(string token, string reciever, SMSMode mode)
        {
            try
            {
                var api = new KavenegarApi(KavenegarApiKey);
                switch (mode)
                {
                case SMSMode.VERIFICATION:
                    api.VerifyLookup(reciever, token, "TeelehVerification");
                    break;

                case SMSMode.PASSWORD_RECOVERY:
                    api.VerifyLookup(reciever, token, "TeelehForgetPassword");
                    break;
                }
                return(null);
            }
            catch (Exception e)
            {
                return(e);
            }
        }
Ejemplo n.º 7
0
        public static async Task <bool> Lookup(Configs.SmsConfig config, string template, string receiver, string token)
        {
            if (!config.ShouldSend)
            {
                return(true);
            }

            try {
                var api = new KavenegarApi(config.ApiKey);
                api.VerifyLookup(receiver, token, template);
                return(true);
            }
            catch (Exception) {
                return(false);
            }
        }
Ejemplo n.º 8
0
        public IActionResult sendtoken(Vm_User us)
        {
            Random rnd    = new Random();
            string number = rnd.Next(1000, 9999).ToString();

            mobile = us.phone;
            var qcheck = _db.tbl_Users.Where(a => a.phone == us.phone).SingleOrDefault();

            if (qcheck == null)
            {
                Tbl_User user = new Tbl_User()
                {
                    phone      = us.phone,
                    token      = number,
                    NameFamily = "نام شما",
                    Adress     = "آدرس شما ",
                    photo      = "9.jpg"
                };
                _db.tbl_Users.Add(user);
                _db.SaveChanges();

                var api = new KavenegarApi("3871353043697339486A70384F544A4A574C74612B51432F4C7A4B305076645457396F5267456F7A5A34383D");
                api.VerifyLookup(us.phone, number, "taxijo");
                return(RedirectToAction("otpconfig"));
            }
            else
            {
                qcheck.token = number;
                _db.tbl_Users.Update(qcheck);
                _db.SaveChanges();

                var api = new KavenegarApi("3871353043697339486A70384F544A4A574C74612B51432F4C7A4B305076645457396F5267456F7A5A34383D");
                api.VerifyLookup(us.phone, number, "taxijo");
                return(RedirectToAction("otpconfig"));
            }



            return(RedirectToAction("otpconfig"));
        }
Ejemplo n.º 9
0
        public bool Register(string Mobile)
        {
            if (Mobile != null)
            {
                Random rnd  = new Random();
                string code = rnd.Next(1000, 9999).ToString();

                var query = db.Rep_Phone.FindSingleAsync(a => a.Phone_Mobile == Mobile).Result;
                if (query == null)
                {
                    Tbl_Phone t = new Tbl_Phone
                    {
                        Phone_Mobile = Mobile,
                        Phone_Code   = code, //code
                    };
                    db.Rep_Phone.CreateAsync(t);
                    db.Save();
                }
                else
                {
                    query.Phone_Code = code;
                    db.Rep_Phone.Update(query);
                    db.Save();
                }

                // Kavenegar

                var api = new KavenegarApi("3871353043697339486A70384F544A4A574C74612B51432F4C7A4B305076645457396F5267456F7A5A34383D");
                api.VerifyLookup(Mobile, code, "tezalmarket");
                return(true);

                // Kavenegar
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 10
0
        public string SendServiceable(string receptor, string token, string token2, string token3, string token20, SMSTemplate template)
        {
            try
            {
                var        api    = new KavenegarApi(apikey);
                SendResult result = api.VerifyLookup(receptor, token, token2, token3, "", token20, GetTemplate(template), Kavenegar.Models.Enums.VerifyLookupType.Sms);

                InsertIntoDB(result, token, token2, token3);

                return(result.StatusText);
            }
            catch (ApiException ex)
            {
                return(ex.Message);
            }
            catch (HttpException ex)
            {
                return(ex.Message);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 11
0
        //private bool InsertIntoDB(SendResult result, string token, string token1, string token2)
        //{
        //    if (result != null)
        //    {
        //        Tbl_SMSResponse _SMSResponse = new Tbl_SMSResponse()
        //        {
        //            SMS_Guid = Guid.NewGuid(),
        //            SMS_Status = result.Status,
        //            SMS_StatusText = result.StatusText,
        //            SMS_MessageID = result.Messageid.ToString(),
        //            SMS_Message = result.Message,
        //            SMS_Token = token,
        //            SMS_Token1 = token1,
        //            SMS_Token2 = token2,
        //            SMS_Sender = result.Sender,
        //            SMS_Receptor = result.Receptor,
        //            SMS_Date = DateConverter.UnixTimeStampToDateTime(result.Date),
        //            SMS_Cost = result.Cost,
        //            SMS_CreationDate = DateTime.Now,
        //            SMS_ModifiedDate = DateTime.Now
        //        };

        //        db.Tbl_SMSResponse.Add(_SMSResponse);

        //        if (Convert.ToBoolean(db.SaveChanges() > 0))
        //        {
        //            return true;
        //        }
        //    }

        //    return false;
        //}

        //private bool InsertIntoDB(SendResult result)
        //{
        //    if (result != null)
        //    {
        //        Tbl_SMSResponse _SMSResponse = new Tbl_SMSResponse()
        //        {
        //            SMS_Guid = Guid.NewGuid(),
        //            SMS_Status = result.Status,
        //            SMS_StatusText = result.StatusText,
        //            SMS_MessageID = result.Messageid.ToString(),
        //            SMS_Message = result.Message,
        //            SMS_Sender = result.Sender,
        //            SMS_Receptor = result.Receptor,
        //            SMS_Date = DateConverter.UnixTimeStampToDateTime(result.Date),
        //            SMS_Cost = result.Cost,
        //            SMS_CreationDate = DateTime.Now,
        //            SMS_ModifiedDate = DateTime.Now
        //        };

        //        db.Tbl_SMSResponse.Add(_SMSResponse);

        //        if (Convert.ToBoolean(db.SaveChanges() > 0))
        //        {
        //            return true;
        //        }
        //    }

        //    return false;
        //}

        public async Task <object> SendServiceable(SmsTemplate template, string receptor, string token = "", string token2 = "", string token3 = "", string token10 = "", string token20 = "")
        {
            try
            {
                var        api    = new KavenegarApi(apikey);
                SendResult result = await api.VerifyLookup(receptor, token, token2, token3, token10, token20, GetSmsTemplateName(template), VerifyLookupType.Sms);

                //InsertIntoDB(result, token, token2, token3);

                return(result);
            }
            catch (ApiException ex)
            {
                return(ex.Message);
            }
            catch (HttpException ex)
            {
                return(ex.Message);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> Index()
        {
            //senders number
            string[] sender = { "10008663", "10008663", "10008663", "10008663", "10008663" };

            //receptors numbers
            string[] receptor = { "09112345678", "09112345678", "", "09112345678", "09012345678" };

            //list of messages
            string[] message = { "تست وب سرویس کاوه نگار", "تست وب سرویس کاوه نگار", "تست وب سرویس کاوه نگار", "تست وب سرویس کاوه نگار", "تست وب سرویس کاوه نگار" };

            //localids that exist in local database
            string[] localIDs = { new Random().Next(0,      2454).ToString(), new Random().Next(0,   12544).ToString(),
                                  new Random().Next(0,     45645).ToString(), new Random().Next(0, 2000000).ToString(),
                                  new Random().Next(0, 123123456).ToString(), };

            //Your Api Key in kavenegar
            KavenegarApi kavenegar = new KavenegarApi("Your Api Key");

            SendResult        result     = null;
            List <SendResult> resultList = null;

            StatusResult        statusResult     = null;
            List <StatusResult> statusResultList = null;

            StatusLocalMessageIdResult        StatusLocalMessageIdResultResult     = null;
            List <StatusLocalMessageIdResult> StatusLocalMessageIdResultResultList = null;

            CountInboxResult CountInboxResult = null;


            #region SelectAsync
            result     = kavenegar.Select("274037533");
            resultList = kavenegar.Select(new List <string>()
            {
                "1775698101", "1775696560"
            });
            #endregion

            #region SelectOutboxAsync
            resultList = kavenegar.SelectOutbox(DateTime.Now.AddDays(-1), DateTime.Now);
            resultList = kavenegar.SelectOutbox(DateTime.Now.AddDays(-2));
            #endregion

            #region SendByPostalCodeAsync
            resultList = kavenegar.SendByPostalCode(4451865169, sender[0], "slama", 0, 10, 0, 16);
            resultList = kavenegar.SendByPostalCode(4451865169, sender[0], "slama", 0, 10, 0, 16, DateTime.Now);
            #endregion

            #region StatusAsync
            statusResult     = kavenegar.Status("1775698101");
            statusResultList = kavenegar.Status(new List <string>()
            {
                "1775698101", "1775696560"
            });
            #endregion

            #region StatusLocalMessageIdAsync
            StatusLocalMessageIdResultResult     = kavenegar.StatusLocalMessageId(localIDs[0]);
            StatusLocalMessageIdResultResultList = kavenegar.StatusLocalMessageId(localIDs.ToList());
            #endregion

            #region CancelAsync
            statusResult     = kavenegar.Cancel("1775698101");
            statusResultList = kavenegar.Cancel(new List <string>()
            {
                "1775698101", "1775696560"
            });
            #endregion

            #region CountInboxAsync
            CountInboxResult = kavenegar.CountInbox(DateTime.Now.AddDays(-1), sender[0]);
            CountInboxResult = kavenegar.CountInbox(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1), sender[0]);
            #endregion

            #region CountOutboxAsync
            CountInboxResult = kavenegar.CountOutbox(DateTime.Now.AddDays(-1));
            CountInboxResult = kavenegar.CountOutbox(DateTime.Now.AddDays(-1), DateTime.Now.AddDays(-1));
            #endregion

            #region CountPostalCodeAsync
            List <CountPostalCodeResult> countPostalCodeResult = kavenegar.CountPostalCode(4451865169);
            #endregion

            #region LatestOutboxAsync
            resultList = kavenegar.LatestOutbox(1);
            resultList = kavenegar.LatestOutbox(1, sender[0]);
            #endregion

            #region LatestOutboxAsync
            List <ReceiveResult> receiveResult = kavenegar.Receive(sender[0], 0);
            List <ReceiveResult> ReceiveResult = kavenegar.Receive(sender[0], 1);
            #endregion

            #region sendAsync
            result = kavenegar.Send(sender[0], receptor[0], message[0]);
            result = kavenegar.Send(sender[0], receptor[0], message[0], localIDs[0].ToString());
            #endregion

            #region sendArrayAsync
            resultList = kavenegar.SendArray(sender.ToList(), receptor.ToList(), message.ToList(), localIDs[0]);
            resultList = kavenegar.SendArray(sender[0], receptor.ToList(), message.ToList(), localIDs[0]);
            #endregion

            #region VerifyLookupAsync

            //verify is template neme, you can create template from here https://panel.kavenegar.com/Client/Verification/Create
            result = kavenegar.VerifyLookup(receptor[0], "123", "verify");

            //rate is template neme, you can create template from here https://panel.kavenegar.com/Client/Verification/Create
            result = kavenegar.VerifyLookup(receptor[0], "123", null, null, null, "token20", "rate", VerifyLookupType.Sms);
            #endregion

            return(View());
        }