Beispiel #1
0
        public Result <dynamic> VerifySmsCode(string mobilePhone, byte smsType, int smsCode)
        {
            var entity = SmsRepository.Get(mobilePhone, smsType, smsCode);

            if (entity == null)
            {
                return(new Result <dynamic>()
                {
                    Code = ResultCode.Error,
                    Message = "验证码不正确"
                });
            }
            if (DateTime.Now > entity.ExpireTime || entity.SmsStatus == 1)
            {
                return(new Result <dynamic>()
                {
                    Code = ResultCode.Error,
                    Message = "验证码已过期"
                });
            }
            try
            {
                entity.SmsStatus = 1;
                SmsRepository.Update(entity);
            }
            catch { }
            return(new Result <dynamic>()
            {
                Code = ResultCode.Success,
                Message = "验证码验证成功"
            });
        }
Beispiel #2
0
        public ActionResult <ApiResponse> Get(string mobile, int randomNumber)
        {
            var smsRepository = new SmsRepository();


            if (Regex.IsMatch(mobile, "^[0-9]*$") && Regex.IsMatch(randomNumber.ToString(), "^[0-9]*$"))
            {
                return new ApiResponse
                       {
                           ErrorId = mobile == null || mobile.Trim() == ""

                ? (int)Helper.ApiOutputError.NotExists
                : (int)Helper.ApiOutputError.NoError,

                           ErrorTitle = mobile == null || mobile.Trim() == ""
                ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                           Result = $"{mobile}-{smsRepository.SendRandomNumber(mobile, randomNumber.ToString(), _config)}"
                       }
            }
            ;
            else
            {
                return new ApiResponse
                       {
                           ErrorId = (int)Helper.ApiOutputError.BadRequest,

                           ErrorTitle = ((Helper.ApiOutputError)Helper.ApiOutputError.BadRequest).ToString(),
                       }
            };
        }
    }
Beispiel #3
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            var     requestBody  = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic sportMessage = JsonConvert.DeserializeObject <CoachTextDto>(requestBody);


            try
            {
                var                 accountSid         = System.Environment.GetEnvironmentVariable("AccountSid");
                var                 authToken          = System.Environment.GetEnvironmentVariable("AuthToken");
                var                 fromPhone          = System.Environment.GetEnvironmentVariable("FromPhone");
                ISmsRepository      smsRepository      = new SmsRepository(accountSid, authToken, fromPhone);
                var                 connectionString   = System.Environment.GetEnvironmentVariable("SQLAZURECONNSTR_TrainingModel");
                var                 options            = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString ?? throw new InvalidOperationException()).Options;
                var                 context            = new PwsodbContext(options);
                ITrainingRepository trainingRepository = new TrainingRepository(context);
                var                 worker             = new TextWorker(trainingRepository, smsRepository);
                var                 numOfSms           = await worker.SendSmsForSport(sportMessage);

                return((ActionResult) new OkObjectResult(numOfSms));
            }
            catch (Exception ex)
            {
                return((ActionResult) new BadRequestObjectResult(ex));
            }
        }
Beispiel #4
0
        public void SendEmailsForSport_WithoutMock(int sportId, int?locationId, int?categoryId, int?teamId, bool?selected, bool?volunteerOnly, int expected)

        {
            IConfiguration config           = new ConfigurationBuilder().AddJsonFile("appsettings.test.json").Build();
            var            connectionString = config["TrainingDatabase"];
            var            options          = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString).Options;

            PwsodbContext context = new PwsodbContext(options);

            const string plainTextContent = "testing PWSO sending text messages";
            CoachTextDto message          = new CoachTextDto
            {
                SportId     = sportId,
                Message     = plainTextContent,
                IsVolunteer = volunteerOnly,
                Selected    = selected,
                ProgramId   = locationId,
                SportTypeId = categoryId,
                TeamId      = teamId
            };
            ITrainingRepository trainingRepository = new TrainingRepository(context);
            var            accountSid      = config["AccountSid"];
            var            authToken       = config["AuthToken"];
            var            fromPhone       = config["FromPhone"];
            ISmsRepository emailRepository = new SmsRepository(accountSid, authToken, fromPhone);
            TextWorker     worker          = new TextWorker(trainingRepository, emailRepository);


            //var actual = worker.SendSmsForSport(message);
            //Assert.Equal(expected, actual.Result);
        }
Beispiel #5
0
        public Result <dynamic> Send(string mobile, byte smsType)
        {
            int smsCode = GenerateSMSCode();
            var entity  = new SmsModel()
            {
                MobilePhone = mobile,
                SmsType     = smsType,
                SmsCode     = smsCode,
                SmsStatus   = 0,
                ExpireTime  = DateTime.Now.AddMinutes(10),
                CreateTime  = DateTime.Now
            };

            if (SmsRepository.Add(entity))
            {
                var account_id    = ConfigurationManager.AppSettings["SMS_Account_Sid"];
                var account_token = ConfigurationManager.AppSettings["SMS_Account_Token"];
                var app_Id        = ConfigurationManager.AppSettings["SMS_App_Id"];

                string result = string.Empty;

                CCPRestSDK.CCPRestSDK api = new CCPRestSDK.CCPRestSDK();
                bool init = api.init("sandboxapp.cloopen.com", "8883");
                api.setAccount(account_id, account_token);
                api.setAppId(app_Id);
                try
                {
                    if (init)
                    {
                        string[] param = { smsCode.ToString(), "10分钟" };
                        Dictionary <string, object> retApiData = api.SendTemplateSMS(mobile, "125246", param);
                        result = GetDictionaryData(retApiData);
                    }
                    else
                    {
                        return(new Result <dynamic>()
                        {
                            Code = ResultCode.Error,
                            Message = "初始化失败"
                        });
                    }
                }
                catch { }
                if (result.ToLower().Contains("statuscode=000000;statusmsg=成功"))
                {
                    /* 调用短信接口发送短信验证码 */
                    return(new Result <dynamic>()
                    {
                        Code = ResultCode.Success,
                        Message = "验证码发送成功"
                    });
                }
            }
            return(new Result <dynamic>()
            {
                Code = ResultCode.Error,
                Message = "验证码发送失败"
            });
        }
Beispiel #6
0
        public ApiModule(SmsRepository smsRepository, SessionRepository sessionRepository) : base("/api")
        {
            _sessionRepository = sessionRepository;
            _smsRepository = smsRepository;

            Post["/ReceiveSms"] = o => ReceiveSms();

            Get["/TestReceive"] = o => { return this.View["TestReceive"]; };
            Post["/TestReceive"] = o => { return TestReceive().Result; };
        }
Beispiel #7
0
 public ActionResult Grade(int id = 0)
 {
     if (id > 0)
     {
         var grade = SmsRepository.GetGradeById(id);
         ViewBag.Grade = grade;
     }
     GradeCommon();
     return(View());
 }
Beispiel #8
0
 public ActionResult Session(int id = 0)
 {
     if (id > 0)
     {
         var session = SmsRepository.GetSessionById(id);
         ViewBag.Session = session;
     }
     SessionCommon();
     return(View());
 }
Beispiel #9
0
 public PartialViewResult Subject(int id = 0)
 {
     if (id > 0)
     {
         var subject = SmsRepository.GetSubjectById(id);
         ViewBag.Subject = subject;
     }
     SubjectCommon();
     return(PartialView("Subject"));
 }
Beispiel #10
0
 public ActionResult TestGrade()
 {
     //if (id > 0)
     {
         var grade = SmsRepository.GetGradeById(1);
         ViewBag.Grade = grade;
     }
     GradeCommon();
     return(View());
 }
Beispiel #11
0
 public ActionResult City(int id = 0)
 {
     if (id > 0)
     {
         var city = SmsRepository.GetCityById(id);
         ViewBag.City = city;
     }
     CityCommon();
     return(View());
 }
Beispiel #12
0
 public SmsService(
     SmsRepository smsRepository,
     TemplateService templateService,
     ScenicService scenicService,
     OrderDetailService orderDetailService)
 {
     _smsRepository      = smsRepository;
     _templateService    = templateService;
     _scenicService      = scenicService;
     _orderDetailService = orderDetailService;
 }
        private async Task ClearAllSms()
        {
            var uow = _serviceProvider.GetScopedService <UnitOfWork>();

            using (uow.Begin())
            {
                var smsRepository = new SmsRepository(uow);
                await smsRepository.DeleteAllSmsAsync();

                await uow.CommitAsync();
            }
        }
Beispiel #14
0
        public ActionResult Section(int id = 0)
        {
            if (id > 0)
            {
                var section = SmsRepository.GetSectionById(id);
                ViewBag.Section = section;
            }
            var tempClassList = SmsRepository.GetAllClasses();

            ViewBag.ClassList = tempClassList;
            SectionCommon();
            return(View());
        }
Beispiel #15
0
        public ActionResult PreviousSchool(int id = 0)
        {
            if (id > 0)
            {
                var previousSchool = SmsRepository.GetPreviousSchoolByStudentId(id);
                ViewBag.PreviousSchool = previousSchool;
            }
            var tempStudent = SmsRepository.GetAllStudents();

            ViewBag.StudentList = tempStudent;
            PreviousSchoolCommon();
            return(View());
        }
Beispiel #16
0
        public UnitOfWork()
        {
            _context = new TContext();

            Customer = new CustomerRepository(_context);
            Line     = new LineRepository(_context);
            Sms      = new SmsRepository(_context);
            Call     = new CallRepository(_context);
            Payment  = new PaymentRepository(_context);
            Package  = new PackageRepository(_context);
            Friends  = new FriendsRepository(_context);
            Employee = new EmployeeRepository(_context);
        }
Beispiel #17
0
        public ActionResult Module(int id = 0)
        {
            if (id > 0)
            {
                var module = SmsRepository.GetModuleById(id);
                ViewBag.Module = module;
            }
            var subjectList = SmsRepository.GetAllSubject();

            ViewBag.SubjectList = subjectList;
            ModuleCommon();
            return(View());
        }
Beispiel #18
0
 public ActionResult Class(Class cClass)
 {
     if (cClass.Id > 0)
     {
         SmsRepository.UpdateClass(cClass);
     }
     else
     {
         SmsRepository.InsertClass(cClass);
     }
     ClassCommon();
     return(RedirectToAction("index", "sms", new { p = "Class" }));
 }
Beispiel #19
0
        public ActionResult Class(int id = 0)
        {
            if (id > 0)
            {
                var cClass = SmsRepository.GetClassById(id);
                ViewBag.Class = cClass;
            }
            var tempAllgrade = SmsRepository.GetAllGrades();

            ViewBag.GradeList = tempAllgrade;
            ClassCommon();
            return(View());
        }
Beispiel #20
0
 public ActionResult Grade(Grade grade)
 {
     if (grade.Id > 0)
     {
         SmsRepository.UpdateGrade(grade);
     }
     else
     {
         SmsRepository.InsertGrade(grade);
     }
     GradeCommon();
     return(RedirectToAction("index", "sms", new { p = "Grade" }));
 }
Beispiel #21
0
 public ActionResult Session(Session session)
 {
     if (session.Id > 0)
     {
         SmsRepository.UpdateSession(session);
     }
     else
     {
         SmsRepository.InsertSessions(session);
     }
     SessionCommon();
     return(View());
 }
Beispiel #22
0
 public ActionResult Module(Module module)
 {
     if (module.Id > 0)
     {
         SmsRepository.UpdateModule(module);
     }
     else
     {
         SmsRepository.InsertModule(module);
     }
     ModuleCommon();
     return(View());
 }
Beispiel #23
0
 public PartialViewResult Subject(Subject subject)
 {
     if (subject.Id > 0)
     {
         SmsRepository.UpdateSubject(subject);
     }
     else
     {
         SmsRepository.InsertSubjects(subject);
     }
     SubjectCommon();
     return(PartialView("Subject"));
 }
Beispiel #24
0
 public ActionResult PreviousSchool(PreviousSchool previousSchool)
 {
     if (previousSchool.Id > 0)
     {
         SmsRepository.UpdatePreviousSchool(previousSchool);
     }
     else
     {
         SmsRepository.InsertPreviousSchool(previousSchool);
     }
     PreviousSchoolCommon();
     return(View());
 }
Beispiel #25
0
 public ActionResult City(City city)
 {
     if (city.Id > 0)
     {
         SmsRepository.UpdateCity(city);
     }
     else
     {
         SmsRepository.InsertCity(city);
     }
     CityCommon();
     return(RedirectToAction("index", "sms", new { p = "City" }));
 }
Beispiel #26
0
        public ActionResult Branch(int id = 0)
        {
            if (id > 0)
            {
                var branch = SmsRepository.GetBranchById(id);
                ViewBag.Branch = branch;
            }
            var tempAllcity = SmsRepository.GetListCities();

            ViewBag.CityList = tempAllcity;
            BranchCommon();

            return(View());
        }
Beispiel #27
0
        public ActionResult Branch(Branch branch)
        {
            if (branch.Id > 0)
            {
                SmsRepository.UpdateBranch(branch);
            }
            else
            {
                SmsRepository.InsertBranch(branch);
            }

            BranchCommon();

            return(RedirectToAction("index", "sms", new { p = "Branch" }));
        }
Beispiel #28
0
        public ActionResult <ApiResponse> Get(Helper.ObjectType objectType, string code, int randomNumber)
        {
            var    smsRepository = new SmsRepository();
            string mobile;

            switch (objectType)
            {
            case Helper.ObjectType.Student:
                var studentRepository = new StudentRepository();
                mobile = studentRepository.Select(code).Mobile;

                return(new ApiResponse
                {
                    ErrorId = mobile == null || mobile.Trim() == ""
                        ? (int)Helper.ApiOutputError.NotExists
                        : (int)Helper.ApiOutputError.NoError,

                    ErrorTitle = mobile == null || mobile.Trim() == ""
                        ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                        : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                    Result = $"{mobile}-{smsRepository.SendRandomNumber(mobile, randomNumber.ToString(), _config)}"
                });

            case Helper.ObjectType.Professor:

                var professorRepository = new ProfessorRepository();
                mobile = professorRepository.Select(code).Mobile;

                return(new ApiResponse
                {
                    ErrorId = mobile == null || mobile.Trim() == ""
                            ? (int)Helper.ApiOutputError.NotExists
                            : (int)Helper.ApiOutputError.NoError,

                    ErrorTitle = mobile == null || mobile.Trim() == ""
                            ? ((Helper.ApiOutputError)Helper.ApiOutputError.NotExists).ToString()
                            : ((Helper.ApiOutputError)Helper.ApiOutputError.NoError).ToString(),

                    Result = $"{mobile}-{smsRepository.SendRandomNumber(mobile, randomNumber.ToString(), _config)}"
                });

            default:
                return(new ApiResponse());
            }
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic teams       = JsonConvert.DeserializeObject <TournamentDto>(requestBody);


            try
            {
                var apiKey = System.Environment.GetEnvironmentVariable("ApiKey");
                IEmailRepository emailRepository         = new EmailRepository(apiKey);
                var                  connectionString    = System.Environment.GetEnvironmentVariable("SQLAZURECONNSTR_TrainingModel");
                var                  options             = new DbContextOptionsBuilder <PwsodbContext>().UseSqlServer(connectionString).Options;
                PwsodbContext        context             = new PwsodbContext(options);
                ITrainingRepository  trainingRepository  = new TrainingRepository(context);
                IReferenceRepository referenceRepository = new ReferenceRepository(context);
                ReferenceWorker      refWorker           = new ReferenceWorker(referenceRepository);
                EmailWorker          emailWorker         = new EmailWorker(trainingRepository, emailRepository);
                var                  accountSid          = System.Environment.GetEnvironmentVariable("AccountSid");
                var                  authToken           = System.Environment.GetEnvironmentVariable("AuthToken");
                var                  fromPhone           = System.Environment.GetEnvironmentVariable("FromPhone");
                ISmsRepository       smsRepository       = new SmsRepository(accountSid, authToken, fromPhone);
                var                  textWorker          = new TextWorker(trainingRepository, smsRepository);

                foreach (var team in teams.Teams)
                {
                    var emailMessage = refWorker.ChampionshipEmailPreparation(team);
                    var textMessage  = refWorker.ChampionshipTextPreparation(team);
                    var numOfEmails  = await emailWorker.SendEmailsForSport(emailMessage);

                    var numOfSms = await textWorker.SendSmsForSport(textMessage);
                }

                return((ActionResult) new OkObjectResult(1));
            }
            catch (Exception ex)
            {
                return((ActionResult) new BadRequestObjectResult(ex));
            }
        }
        public string SendSms(SmsModel entity)
        {
            var credentials = Credentials.FromApiKeyAndSecret(SmsSettings.NEXMO_API_KEY, SmsSettings.NEXMO_API_SECRET);
            var client      = new SmsClient(credentials);
            var request     = new SendSmsRequest {
                To = entity.To, From = SmsSettings.BROJ_MOBITELA, Text = entity.Text
            };
            var response = client.SendAnSms(request);

            // if we sent the sms succesfully save the details to database.
            if (response != null)
            {
                SmsLog log = new SmsLog {
                    Broj = entity.To, Poruka = entity.Text, Dodatnisadrzaj = response.Messages[0].MessageId
                };
                SmsRepository.Insert(log);
                return(response.Messages[0].MessageId);
            }

            return(null);
        }
Beispiel #31
0
        public void CityCommon()
        {
            var cityList = SmsRepository.GetListCities();

            ViewBag.CityList = cityList;
        }