public bool SendSms(string PhoneNumber, string Code) { var api = new Kavenegar.KavenegarApi("71625976436F417872583968335938637870516D4F3131304B7634746D796743"); api.VerifyLookup(PhoneNumber, Code, "VerifySabzBash"); return(true); }
bool SendActivationCodeViaSMS(string TellNumber, string RndNumber) { try { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("6A6B364F786E554E3353725364357359306F4C796362394337355149386F793475756E702B3465386737513D"); var result = api.VerifyLookup(TellNumber, RndNumber, "ActivationCode"); return(true); } catch (Kavenegar.Exceptions.ApiException) { // در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد. new System.Threading.Thread(delegate() { BLL.Log.DoLog(COM.Action.SendSMS, TellNumber, 0, "Return Not 200"); }).Start(); return(false); } catch (Kavenegar.Exceptions.HttpException) { // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد new System.Threading.Thread(delegate() { BLL.Log.DoLog(COM.Action.SendSMS, TellNumber, 0, "Not Connected"); }).Start(); return(false); } catch (Exception e) { new System.Threading.Thread(delegate() { BLL.Log.DoLog(COM.Action.SendSMS, TellNumber, 0, e.Message); }).Start(); return(false); } }
public static bool sendMessage(string mobile, string message) { decimal mor; bool testmobile = decimal.TryParse(mobile.Replace("+", ""), out mor); if (mobile.Length == 13 && testmobile) { var sender = "10001002000222"; var receptor = mobile; var template = "emdad"; var token = "797872306F7348482F7642707164346A346E5646724F7158324E70754576702B"; var api = new Kavenegar.KavenegarApi(token); try { // var result = api.Send(sender, receptor, message); var result = api.VerifyLookup(receptor, "1111", template); return(true); } catch (ApiException ex) { } catch (Kavenegar.Exceptions.HttpException ex) { } } return(false); }
bool SendActivationCodeViaSMS(string TellNumber, string RndNumber) { try { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("6E41717A4D532F556962626E7149466679445A6D4B413D3D"); var result = api.VerifyLookup(TellNumber, RndNumber, "GoftemanActivationCode"); return(true); } catch (Kavenegar.Exceptions.ApiException) { // در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد. new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.SendSMS, TellNumber, 0, "Return Not 200"); }).Start(); return(false); } catch (Kavenegar.Exceptions.HttpException) { // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.SendSMS, TellNumber, 0, "Not Connected"); }).Start(); return(false); } catch (Exception e) { new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.SendSMS, TellNumber, 0, e.Message); }).Start(); return(false); } }
public NotificationResponse VerifySms(string token, string receiver) { string apikey = ConfigurationManager.AppSettings[Constants.Kavenegar.ApiKey]; var api = new Kavenegar.KavenegarApi(apikey); var result = api.VerifyLookup(receiver, token, Constants.Kavenegar.svipVerifyPhone); return(new NotificationResponse() { Message = result.Message, Result = NotificationResultType.Success }); }
public void smssenderror(string mobile, string id, string dess, string err, string temp) { try { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("624E79452F76702B306F3757764A54505038346A743258556831444D67363158525650386E5451756967553D"); var result = api.VerifyLookup(mobile, id, dess, err, temp); // foreach (var r in result) // { // Console.Write("r.Messageid.ToString()"); // } } catch (Kavenegar.Exceptions.ApiException ex) { // در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد. Console.Write("Message : " + ex.Message); } catch (Kavenegar.Exceptions.HttpException ex) { // در زمانی که مشکلی در برقرای ارتباط با وب سرویس وجود داشته باشد این خطا رخ می دهد Console.Write("Message : " + ex.Message); } }
public async Task <IActionResult> Index(RegisterViewModel model) { if (ModelState.IsValid) { var random = new Random(); var code = random.Next(1000, 9999); var user = new User { UserName = model.Username, Email = model.Username + "@mousigha.com", FirstName = model.FirstName, LastName = model.FirstName, PhoneNumber = model.PhoneNumber, PhoneNumberConfirmed = false, IsActive = false, EmailConfirmed = false, ActivationCode = code.ToString() }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { await _userManager.AddToRoleAsync(user, "site-user"); _logger.LogInformation(3, $"{user.UserName} created a new account with password."); if (_siteOptions.Value.EnableEmailConfirmation) { var code1 = await _userManager.GenerateEmailConfirmationTokenAsync(user); //ControllerExtensions.ShortControllerName<RegisterController>(), //todo: use everywhere ................. await _emailSender.SendEmailAsync( email : user.Email, subject : "لطفا اکانت خود را تائید کنید", viewNameOrPath : "~/Areas/Identity/Views/EmailTemplates/_RegisterEmailConfirmation.cshtml", model : new RegisterEmailConfirmationViewModel { User = user, EmailConfirmationToken = code1, EmailSignature = _siteOptions.Value.Smtp.FromName, MessageDateTime = DateTime.UtcNow.ToLongPersianDateTimeString() }); return(RedirectToAction(nameof(ConfirmYourEmail))); } if (_siteOptions.Value.EnableMobileConfirmation) { var api = new Kavenegar.KavenegarApi("7768417353496E56316A5A6464754E516149704C753251465473515177587458"); var res = api.VerifyLookup(model.PhoneNumber, code.ToString(), "activation"); return(Json(new { id = user.Id, result = true, phone = user.PhoneNumber, username = user.UserName })); // return RedirectToAction(nameof(ConfirmYourMobile), new { id = user.Id }); } return(RedirectToAction(nameof(ConfirmedRegisteration))); } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } return(Content("Captcha")); }
public async Task <IActionResult> SuccessfulPayment(string authority = null, string status = null, int shoppingId = -1) { if (shoppingId == -1) { return(RedirectToAction(actionName: "ShoppingBasket")); } var shopping = await _db.Shoppings.AsNoTracking() .Where(c => c.Id.Equals(shoppingId)) .FirstOrDefaultAsync(); if (shopping.IsLocalPayment && shopping.Status.Equals(Status.WaitForRegister)) { return(RedirectToAction(actionName: "ShoppingBasket")); } if (shopping.IsLocalPayment) { return(View(model: shopping)); } var user = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name); int amount = (int)shopping.TotalPrice; if (status.Equals("OK")) { var zp = new ZarinPalGateWay.PaymentGatewayImplementationServicePortTypeClient(); var result = await zp.PaymentVerificationAsync(MerchantID : "1e608052-d5c6-11e8-bfd3-005056a205be" , Authority : authority, Amount : amount); if (result.Body.Status.Equals(100) || result.Body.Status.Equals(101)) { //update shopping await UpdateShoppingAsync(shopping, result.Body.RefID.ToString(), Status.OnlinePaid); //update user: total buy value and buy number of this user user.BuyNumber++; user.TotalBuyValue += shopping.TotalPrice; await _userManager.UpdateAsync(user); //decrease discount await DecreaseDiscountNumberAsync(shopping); //change status of orders and change product sell number and product stock var orders = await _db.Orders .Where(c => c.UserId.Equals(user.Id) && c.Status.Equals(Status.WaitForRegister)) .ToListAsync(); var products = new List <Product>(); var specialDiscounts = new List <SpecialDiscount>(); foreach (var item in orders) { item.Status = Status.Registered; item.ShoppingId = shopping.Id; var product = await _db.Products.Where(c => c.Id.Equals(item.ProductId)) .Include(c => c.SpecialDiscount).FirstOrDefaultAsync(); product.SellNumber++; product.Stock--; products.Add(product); var specialDiscount = product.SpecialDiscount.Where(c => c.ProductId.Equals(product.Id) && c.ExpirationDate > System.DateTime.Now && c.ActivationDate <= System.DateTime.Now).FirstOrDefault(); if (specialDiscount != null) { specialDiscount.SellNumber++; specialDiscounts.Add(specialDiscount); } } await UpdateOrdersAsync(orders); await UpdateProductsAsync(products); await UpdateSpeicalDiscountsAsync(specialDiscounts); //Send SMS to customer try { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("677045782B79456B7242656C377A372B514A667157487031756D2B536E687954"); var verifysms = api.VerifyLookup(user.Mobile, user.FullName, shopping.TracingCode, shopping.TotalPrice.ToString(), "success"); } catch (Kavenegar.Exceptions.ApiException ex) { // در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد. } //Send SMS to Admin and Manager try { var webmasters = await _userManager.Users.Where(c => c.ClientRole.Equals(ClientRole.Admin) || c.ClientRole.Equals(ClientRole.Manager)).ToListAsync(); foreach (var item in webmasters) { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("677045782B79456B7242656C377A372B514A667157487031756D2B536E687954"); var verifysms = api.VerifyLookup(item.Mobile, shopping.TracingCode, shopping.TotalPrice.ToString(), shopping.ReceiverName, "order"); } } catch (Exception) { } return(View(model: shopping)); } } return(RedirectToAction(actionName: "ShoppingBasket")); }
public async Task <IActionResult> PaymentGateway(int shoppingId = -1) { var shopping = await _db.Shoppings.FindAsync(shoppingId); if (shopping == null) { return(RedirectToAction(actionName: "ShoppingBasket")); } var user = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name); //if local payment is selected if (shopping.IsLocalPayment) { //update shopping await UpdateShoppingAsync(shopping, System.DateTime.Now.ToString("yyyyMMddmmss"), Status.Registered); //update user: update buy number and total buy value of this user user.BuyNumber++; user.TotalBuyValue += shopping.TotalPrice; await _userManager.UpdateAsync(user); //update discount remaining number and discount used number await DecreaseDiscountNumberAsync(shopping); var orders = await _db.Orders .Where(c => c.UserId.Equals(user.Id) && c.Status.Equals(Status.WaitForRegister)) .ToListAsync(); var products = new List <Product>(); var specialDiscounts = new List <SpecialDiscount>(); foreach (var item in orders) { item.Status = Status.Registered; item.ShoppingId = shopping.Id; var product = await _db.Products.Where(c => c.Id.Equals(item.ProductId)) .Include(c => c.SpecialDiscount).FirstOrDefaultAsync(); product.SellNumber++; product.Stock--; products.Add(product); var specialDiscount = product.SpecialDiscount.Where(c => c.ProductId.Equals(product.Id) && c.ExpirationDate > System.DateTime.Now && c.ActivationDate <= System.DateTime.Now).FirstOrDefault(); if (specialDiscount != null) { specialDiscount.SellNumber++; specialDiscounts.Add(specialDiscount); } } await UpdateOrdersAsync(orders); await UpdateProductsAsync(products); await UpdateSpeicalDiscountsAsync(specialDiscounts); //Send SMS to customer try { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("677045782B79456B7242656C377A372B514A667157487031756D2B536E687954"); var verifysms = api.VerifyLookup(user.Mobile, user.FullName, shopping.TracingCode, shopping.TotalPrice.ToString(), "success"); } catch (Kavenegar.Exceptions.ApiException ex) { // در صورتی که خروجی وب سرویس 200 نباشد این خطارخ می دهد. } //Send SMS to Admin and Manager try { var webmasters = await _userManager.Users.Where(c => c.ClientRole.Equals(ClientRole.Admin) || c.ClientRole.Equals(ClientRole.Manager)).ToListAsync(); foreach (var item in webmasters) { Kavenegar.KavenegarApi api = new Kavenegar.KavenegarApi("677045782B79456B7242656C377A372B514A667157487031756D2B536E687954"); var verifysms = api.VerifyLookup(item.Mobile, shopping.TracingCode, shopping.TotalPrice.ToString(), shopping.ReceiverName, "order"); } } catch (Exception) { } return(RedirectToAction(actionName: "SuccessfulPayment", routeValues: new { shoppingId = shopping.Id })); } else { //if online payment is selected send user to zarin pal gateway int amount = (int)shopping.TotalPrice; ZarinPalGateWay.PaymentGatewayImplementationServicePortTypeClient zp = new ZarinPalGateWay.PaymentGatewayImplementationServicePortTypeClient(); var paymentRequest = await zp.PaymentRequestAsync(MerchantID : "1e608052-d5c6-11e8-bfd3-005056a205be", Amount : amount, Description : "خرید محصول", Email : "", CallbackURL : "http://www.shopikardemo.ir/Shopping/SuccessfulPayment?shoppingId=" + shopping.Id , Mobile : user.Mobile); int status = paymentRequest.Body.Status; string authority = paymentRequest.Body.Authority; if (status.Equals(100) && authority.Length.Equals(36)) { return(Redirect("https://www.zarinpal.com/pg/StartPay/" + authority + "/ZarinGate ")); } } return(RedirectToAction("ConfirmAndPayment")); }