public void Login(string userId, string pwd, string messageServiceType)
        {
            IMessageService msgService = null;

            // 用字串比對的方式來決定該建立哪一種訊息服務物件。
            switch (messageServiceType)
            {
            case "EmailService":
                msgService = new EmailService();
                break;

            case "ShortMessageService":
                msgService = new ShortMessageService();
                break;

            default:
                throw new ArgumentException(" 無效的訊息服務型別!");
            }
            var authService = new AuthenticationService(msgService); // 注入相依物件。

            if (authService.TwoFactorLogin(userId, pwd))
            {
                // 與主題無關,故省略。
            }
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        public bool UpdateSMS(ShortMessageService sms)
        {
            _context.ShortMessageService.Update(sms);
            var affected = _context.SaveChanges();

            return(affected > 0);
        }
Ejemplo n.º 3
0
        private RecordDeleteViewModel DeleteModel(string id)
        {
            RecordDeleteViewModel deleteModel = new RecordDeleteViewModel();
            ShortMessageService   record      = null;

            deleteModel.ActionName     = "Delete";
            deleteModel.ControllerName = "ShortMessageService";
            deleteModel.Id             = id;
            deleteModel.Title          = "Delete SMS";
            if (id == null)
            {
                ModelState.AddModelError(string.Empty, "Invalid Action");
                return(deleteModel);
            }
            record = _context.ShortMessageService.SingleOrDefault(m => m.Id == id);
            if (record == null)
            {
                ModelState.AddModelError(string.Empty, "Record not found.");
            }
            else
            {
                deleteModel.RecordDetail.Add(new RecordDetail {
                    Label = "Mobile Number", Value = record.MobileNumber
                });
                deleteModel.RecordDetail.Add(new RecordDetail {
                    Label = "Message Body", Value = record.MessageBody
                });
            }
            return(deleteModel);
        }
Ejemplo n.º 4
0
        public ActionResult ServiceAdd(int spId)
        {
            var model = new ShortMessageService();

            model.SpId = spId;
            ViewData["ServiceType"] = EnumHelper.GetSelectListFromEnumType(typeof(ServiceType));

            return(View(model));
        }
Ejemplo n.º 5
0
 protected ApiControllerBase()
 {
     //MongoDBRepository<Entity> mongo = new MongoDBRepository<Entity>("volunteer");//开发:volunteer,测试:volunteerTest
     //MongoDBRepository<TokenModel> tok = new MongoDBRepository<TokenModel>("token");//开发:token,测试:tokenTest
     myService           = VolunteerService.Instance;
     tokenService        = TokenService.Instance;
     mailService         = MailService.Instance;
     shortMessageService = ShortMessageService.Instance;
     //Entity.SetServiceContext(myService);
 }
Ejemplo n.º 6
0
        protected void Application_Start()
        {
            //先读config
            Jtext103.StringConfig.ConfigString.Load(HttpRuntime.AppDomainAppPath + "Static\\StringConfig");

            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            //FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //BundleConfig.RegisterBundles(BundleTable.Bundles);
            Configure(System.Web.Http.GlobalConfiguration.Configuration);
            string db           = ConfigurationSettings.AppSettings["DataBase"];
            string eventHandler = ConfigurationSettings.AppSettings["EventHandler"];
            string connection   = @"mongodb://115.156.252.5:27017";
            //new service and inject to entity
            MongoDBRepository <Entity>             entityRepository                         = new MongoDBRepository <Entity>(connection, db, "volunteer");
            MongoDBRepository <Message>            messageRepository                        = new MongoDBRepository <Message>(connection, db, "message");
            MongoDBRepository <Message>            feedRepository                           = new MongoDBRepository <Message>(connection, db, "feed");
            MongoDBRepository <TagEntity>          activityTagRepository                    = new MongoDBRepository <TagEntity>(connection, db, "activityTag");
            MongoDBRepository <TagEntity>          affiliationRepository                    = new MongoDBRepository <TagEntity>(connection, db, "affiliation");
            MongoDBRepository <TokenModel>         tokenRepository                          = new MongoDBRepository <TokenModel>(connection, db, "token");
            MongoDBRepository <AuthorizationModel> authorizationRepository                  = new MongoDBRepository <AuthorizationModel>(connection, "Volunteer", "authorization");
            MongoDBRepository <Event>                    eventRepository                    = new MongoDBRepository <Event>(connection, db, "event");
            MongoDBRepository <Subscriber>               subscriberRepository               = new MongoDBRepository <Subscriber>(connection, db, "subscriber");
            MongoDBRepository <BadgeDescription>         badgeDescriptionRepository         = new MongoDBRepository <BadgeDescription>(connection, db, "badgeDescription");
            MongoDBRepository <BadgeEntity>              badgeEntityRepository              = new MongoDBRepository <BadgeEntity>(connection, db, "badgeEntity");
            MongoDBRepository <FriendRelationshipEntity> friendRelationshipEntityRepository = new MongoDBRepository <FriendRelationshipEntity>(connection, db, "friendRelationship");
            MongoDBRepository <ActionValidationModel>    actionValidationRepository         = new MongoDBRepository <ActionValidationModel>(connection, db, "actionValidation");
            MongoDBRepository <CommentEntity>            commentRepository                  = new MongoDBRepository <CommentEntity>(connection, db, "comment");
            MongoDBRepository <BlogPostEntity>           summaryRepository                  = new MongoDBRepository <BlogPostEntity>(connection, db, "summary");

            //初始化service
            VolunteerService        myService               = new VolunteerService(entityRepository);
            TokenService            tokenService            = new TokenService(tokenRepository);
            MessageService          messageService          = new MessageService(messageRepository);
            MessageService          feedService             = new MessageService(feedRepository);
            TagService              activityTagService      = new TagService(activityTagRepository);
            TagService              affiliationService      = new TagService(affiliationRepository);
            ActionValidationService actionValidationService = new ActionValidationService(actionValidationRepository);
            BlogService             blogService             = new BlogService(commentRepository, summaryRepository);

            Entity.SetServiceContext(myService);
            EventService.InitService(eventRepository, subscriberRepository, 100, 1000, eventHandler);
            BadgeService.InitService(badgeDescriptionRepository, badgeEntityRepository);
            FriendService.InitService(friendRelationshipEntityRepository);
            ValidationService.InitService(tokenService, myService, authorizationRepository);
            myService.InitVolunteerService(messageService, feedService, activityTagService, affiliationService, actionValidationService, blogService);
            //新建badgeDescription
            BadgeService.RegisterBadgeDescriptions(getIBadge(EventService.EventHandlerList));

            ShortMessageService shortMessageService = new ShortMessageService("VerifyShortMessageSenderAccount.xml");
            MailService         mailService         = new MailService("NoReplyMailSenderAccount.xml");

            //setActivityCover(myService);
        }
Ejemplo n.º 7
0
        public static ShortMessageService Translate(this SmsRequest from)
        {
            ShortMessageService to = new ShortMessageService()
            {
                SentDateTime    = DateTime.UtcNow,
                From            = from.From,
                To              = from.To,
                Text            = from.Text,
                CreatedDateTime = DateTime.UtcNow
            };

            return(to);
        }
Ejemplo n.º 8
0
 public string NewSMS(ShortMessageService sms, bool validateSMS = false)
 {
     sms.MobileNumber = FixMobileNumber(sms.MobileNumber);
     if (validateSMS)
     {
         if (sms.MobileNumber.Length != 11)
         {
             throw new Exception("Invalid format of mobile number");
         }
         var hasUnicode = ContainsUnicodeCharacter(sms.MessageBody);
         if (hasUnicode)
         {
             throw new Exception("Message body should not contain unicode characters (ex. emojis)");
         }
     }
     sms.ShortMessageService_Id = AutoNumber.GenerateSMSID(_context);
     _context.ShortMessageService.Add(sms);
     _context.SaveChanges();
     return(sms.Id);
 }
Ejemplo n.º 9
0
        public static string Send_Message_Short(string msg, string phone, int type = 0)
        {
            string result = "ok";

            //禁止浏览器直接访问ajax页面
            if (HttpContext.Current.Request.UrlReferrer.Host != HttpContext.Current.Request.Url.Host)
            {
                HttpContext.Current.Response.Redirect("/404");
            }
            else
            {
                string send_type = ConfigHelper.GetConfigString("Short_Message");


                if (type == 1)
                {
                    send_type = "zhiqingwangluo";
                }

                //志晴网络
                if (send_type == "zhiqingwangluo")
                {
                    #region  志晴网络短信
                    ShortMessageService sms = new ShortMessageService();

                    result = sms.sendmessage(msg + "【X职 场】", phone);

                    result = result.Replace("</int>", "");
                    result = result.Substring(result.LastIndexOf(">") + 1);

                    if (result == "0")
                    {
                        result = "ok";
                    }
                    else
                    {
                        result = "1";
                    }

                    #endregion
                }
                else//华亿无线
                {
                    #region  华亿无线短信
                    //shortMessageWord = "您的验证码是:" + code + "。请不要把验证码泄露给其他人。";//shortMessageWord;

                    sms sms1 = new sms();

                    DateTime dtn = DateTime.Now;

                    int minute_one = 0;
                    int cnt        = 0;
                    int cntip      = 0;
                    //是否在做活动,0:否,1:是
                    int IsActive_Now = ConfigHelper.GetConfigInt("IsActive_Now");
                    //当天发送的总记录数
                    int send_total_cnt = 0;


                    #region  验证是否1分钟之内重复发送

                    try
                    {
                        minute_one = Convert.ToInt32(DbHelperSQL.GetSingle("select count(*) as cnt from HRENH_SEND_TEL_CODE where tel='" + phone + "' and datediff(ss,addtime,'" + dtn + "')<=60 and datediff(ss,addtime,'" + dtn + "')>=0").ToString());
                    }
                    catch (Exception ex)
                    {
                    }
                    #endregion

                    if (minute_one > 0)
                    {
                        result = "one";
                    }
                    else
                    {
                        //验证手机号格式是否正确
                        //(13[0-9]{9})|(15[0-9]{9})|(170[0-9]{8})|(176[0-9]{8})|(177[0-9]{8})|(178[0-9]{8})|(18[0-9]{9})
                        bool f = System.Text.RegularExpressions.Regex.IsMatch(phone, @"^(13[0-9]{9})|(15[0-9]{9})|(170[0-9]{8})|(176[0-9]{8})|(177[0-9]{8})|(178[0-9]{8})|(18[0-9]{9})");

                        if (!f)
                        {
                            result = "1";
                        }
                        else
                        {
                            #region  添加发送记录并验证是否已经发送超过5次
                            try
                            {
                                DbHelperSQL.ExecuteSql("insert into HRENH_SEND_TEL_CODE(tel,num,addtime,ip) values('" + phone + "',1,'" + dtn + "','" + RequestHelper.GetIP() + "')");
                            }
                            catch (Exception ex)
                            {
                            }


                            try
                            {
                                cnt = Convert.ToInt32(DbHelperSQL.GetSingle("select (isnull((select count(*) from THINK_SNS_DB.DBO.HRENH_SEND_TEL_CODE where tel='" + phone + "'),0)+isnull((select count(*) from Reds_Parliament.DBO.HRENH_SEND_TEL_CODE where tel='" + phone + "'),0)) as cnt").ToString());
                            }
                            catch (Exception ex)
                            {
                                cnt = 0;
                            }


                            try
                            {
                                send_total_cnt = Convert.ToInt32(DbHelperSQL.GetSingle("select (isnull((select count(*) from THINK_SNS_DB.DBO.HRENH_SEND_TEL_CODE),0)+isnull((select count(*) from Reds_Parliament.DBO.HRENH_SEND_TEL_CODE),0)) as cnt").ToString());
                            }
                            catch (Exception ex)
                            {
                            }


                            #region   一个IP每天只能发送10次记录
                            try
                            {
                                cntip = Convert.ToInt32(DbHelperSQL.GetSingle("select (isnull((select count(*) from THINK_SNS_DB.DBO.HRENH_SEND_TEL_CODE where ip='" + RequestHelper.GetIP() + "'),0)+isnull((select count(*) from Reds_Parliament.DBO.HRENH_SEND_TEL_CODE where ip='" + RequestHelper.GetIP() + "'),0)) as cnt").ToString());
                            }
                            catch (Exception ex)
                            {
                            }

                            if (cntip <= 10)
                            {
                                #region  添加发送记录并验证是否已经发送超过5次
                                if (cnt > 5)
                                {
                                    result = "5";
                                }
                                else
                                {
                                    #region  发送验证码

                                    if (IsActive_Now == 0)
                                    {
                                        if (send_total_cnt <= 1000)
                                        {
                                            SubmitResult SubmitResult1 = sms1.Submit("", "", phone, msg);

                                            result = SubmitResult1.code.ToString();

                                            string result_msg = SubmitResult1.msg;

                                            if (result == "2")
                                            {
                                                result = "ok";
                                            }
                                            else if (result_msg.IndexOf("5") >= 0)
                                            {
                                                result = "5";
                                            }
                                            else
                                            {
                                                result = "1";
                                            }
                                        }
                                        else
                                        {
                                            #region  当天发送的短信的条数大于1000则发送通知给孙传、子龙和我

                                            try
                                            {
                                                if (send_total_cnt == 1001)
                                                {
                                                    string more_100 = "衣品搭配系统提示今日:衣品搭配发送短信数已超过1000条,请即时查看。";

                                                    //孙伟
                                                    SubmitResult SubmitResult1000 = sms1.Submit("", "", "18600863778", more_100);

                                                    //子龙
                                                    SubmitResult1000 = sms1.Submit("", "", "15831601607", more_100);

                                                    //我
                                                    SubmitResult1000 = sms1.Submit("", "", "13426021774", more_100);
                                                }
                                            }
                                            catch (Exception ex)
                                            {
                                            }

                                            #endregion

                                            result = "1";
                                        }
                                    }
                                    else
                                    {
                                        SubmitResult SubmitResult1 = sms1.Submit("", "", phone, msg);

                                        result = SubmitResult1.code.ToString();

                                        string result_msg = SubmitResult1.msg;

                                        if (result == "2")
                                        {
                                            result = "ok";
                                        }
                                        else if (result_msg.IndexOf("5") >= 0)
                                        {
                                            result = "5";
                                        }
                                        else
                                        {
                                            result = "1";
                                        }
                                    }
                                    #endregion
                                }
                                #endregion
                            }
                            else
                            {
                                result = "10";
                            }
                            #endregion


                            #endregion


                            #region  添加发送记录,生成txt文档

                            string[] error_msg_arr = { "1分钟:" + minute_one, "发送次数:" + cnt, "同一个IP的发送次数:" + cntip, "返回结果(result):" + result };

                            Message.WriteError(phone, "发送短信验证码,IP:" + RequestHelper.GetIP(), "register_PC", error_msg_arr);

                            #endregion
                        }
                    }


                    #endregion
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
 public ActionResult ServiceUpdate(ShortMessageService model)
 {
     this.SMSUIService.Update <ShortMessageService>(model);
     return(RedirectToAction("SMSServices", new { id = model.SpId }));
 }
Ejemplo n.º 11
0
 public ActionResult ServiceAdd(ShortMessageService model)
 {
     SMSUIService.Add <ShortMessageService>(model);
     return(RedirectToAction("SMSServices", new { id = model.SpId }));
 }
Ejemplo n.º 12
0
 public AddSmsCommand(ShortMessageService message)
 {
     ID      = Guid.NewGuid();
     Message = message;
 }
Ejemplo n.º 13
0
        public ChannelResult QueryChannel(string imsi, string mobile, ServiceType serviceType, float?amount, string userNo)
        {
            ChannelResult result = null;
            List <ShortMessageService> services = new List <ShortMessageService>();
            var mobileInfo = this.GetMobileInfoByPhoneNumber(mobile);
            IList <ShortMessageService> smsServices;

            if (serviceType == ServiceType.SMS)
            {
                smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType);
            }
            else
            {
                if (mobileInfo == null)
                {
                    result = new ChannelResult {
                        Status = ChannelRequestStatus.MissingMobileInfo
                    };
                    return(result);
                }
                // filter by operator
                switch (mobileInfo.OperatorId)
                {
                case 1:
                    smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType && s.IsMobile == true);
                    break;

                case 2:
                    smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType && s.IsUnicom == true);
                    break;

                case 3:
                    smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType && s.IsTelcom == true);
                    break;

                default:
                    smsServices = this.Find <ShortMessageService>(s => s.Type == serviceType);
                    break;
                }
            }


            if (smsServices != null && smsServices.Count > 0)
            {
                services = smsServices.ToList();
                ShortMessageService service             = new ShortMessageService();
                Instruction         selectedInstruction = new Instruction();
                SMSChannel          channel             = new SMSChannel();
                ServiceProvider     sp = new ServiceProvider();
                for (int i = 0; i < services.Count; i++)
                {
                    service = services[i];
                    sp      = this.Single <ServiceProvider>(x => x.Id == service.SpId);

                    // TODO: check channel restriction here

                    if (!service.IsManully)
                    {
                        var instructions = this.Find <Instruction>(s => s.ServiceId == service.Id);
                        channel = this.Single <SMSChannel>(x => x.ServiceId == service.Id);
                        // TODO: check instruction restriction here

                        if (instructions != null && instructions.Count > 0)
                        {
                            selectedInstruction = instructions[0];
                            result = new ChannelResult();
                            result.ServiceNumber = service.ServiceNumber;
                            result.Code          = instructions[0].Code;
                            break;
                        }
                    }
                    else
                    {
                        switch (sp.DynamicSP)
                        {
                        case DynamicSP.CTU:
                            return(CTUSMSPayRequest(amount.GetValueOrDefault(), userNo, mobileInfo, service.Id, sp.Id, mobile));
                        }
                    }
                }

                if (serviceType == ServiceType.SMSCharge && selectedInstruction != null && channel != null && result != null)
                {
                    // create order
                    var orderNo = PaymentsService.CreateOrder("[短代]", selectedInstruction.Amount, "短信充值:" + selectedInstruction.Amount.ToString(), mobile);
                    result.OrderNo = orderNo;

                    // initial channel log
                    if (mobileInfo == null)
                    {
                        mobileInfo = new MobileInfo();
                    }
                    SMSChannelLog log = new SMSChannelLog
                    {
                        Amount        = selectedInstruction.Amount,
                        ChargeStatus  = SMSChargeStatus.Initial,
                        CityId        = mobileInfo.CityId,
                        OpId          = mobileInfo.OperatorId,
                        ProvinceId    = mobileInfo.ProvinceId,
                        ServiceNumber = result.ServiceNumber,
                        Instruction   = result.Code,
                        Mobile        = mobile,
                        IMSI          = GetIMSI(mobile),
                        OrderNo       = orderNo
                    };
                    this.AddLog <SMSChannelLog>(log);
                    result.LogId = log.ID;

                    // set channel setting
                    if (channel != null)
                    {
                        var settings = this.Find <SMSChannelSetting>(x => x.ChannelId == channel.Id);
                        if (settings != null && settings.Count > 0)
                        {
                            result.SMSChannelSetting = settings[0];
                        }
                    }
                }
            }
            return(result);
        }