/// <summary>
 /// 策略消息发送
 /// </summary>
 /// <param name="code">策略编码</param>
 /// <param name="content">消息内容</param>
 /// <param name="userlist">用户列表</param>
 /// <returns></returns>
 public ActionResult SendMessage(string code, string content, string userlist)
 {
     try
     {
         var          data         = userIBLL.GetListByUserIds(userlist);
         ResParameter resParameter = lR_StrategyInfoIBLL.SendMessage(code, content, data.ToJson());
         if (resParameter.code.ToString() == "fail")
         {
             return(Fail(resParameter.info));
         }
         else
         {
             return(Success(resParameter.info));
         }
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
        /// <summary>
        /// 成功响应数据
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public Response Success(string info)
        {
            ResParameter res = new ResParameter {
                code = ResponseCode.success, info = info, data = new object { }
            };

            return(Response.AsText(res.ToJson()).WithContentType("application/json"));
        }
        /// <summary>
        /// 成功响应数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="res"></param>
        /// <returns></returns>
        public Response SuccessString(string data)
        {
            ResParameter res = new ResParameter {
                code = ResponseCode.success, info = "响应成功", data = data
            };

            return(Response.AsText(res.ToJson()).WithContentType("application/json"));
        }
示例#4
0
        /// <summary>
        /// 成功响应数据
        /// </summary>
        /// <param name="res"></param>
        /// <returns></returns>
        public Response Success(object data)
        {
            ResParameter res = new ResParameter {
                code = ResponseCode.success, info = "响应成功", data = data
            };

            return(Response.AsText(res.ToJson()).WithContentType("application/json").WithStatusCode(HttpStatusCode.OK));
        }
示例#5
0
        /// <summary>
        /// 接口响应失败
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public Response Fail(string info)
        {
            ResParameter res = new ResParameter {
                code = ResponseCode.fail, info = info, data = new object { }
            };

            return(Response.AsText(res.ToJson()).WithContentType("application/json").WithStatusCode(HttpStatusCode.OK));
        }
示例#6
0
        /// <summary>
        /// 接口响应失败
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public ActionResult Fail(string info)
        {
            var res = new ResParameter {
                code = ResponseCode.fail, info = info, data = new object { }
            };

            return(Content(res.ToJson()));
        }
示例#7
0
        /// <summary>
        /// 成功响应数据
        /// </summary>
        /// <typeparam name="T">实体</typeparam>
        /// <param name="info">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public ActionResult Success <T>(string info, T data) where T : class
        {
            var res = new ResParameter {
                code = ResponseCode.success, info = info ?? "响应成功", data = data
            };

            return(Content(res.ToJson()));
        }
示例#8
0
        /// <summary>
        /// 成功响应数据
        /// </summary>
        /// <param name="info">消息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        public ActionResult Success(string info, object data)
        {
            var res = new ResParameter {
                code = ResponseCode.success, info = info ?? "响应成功", data = data
            };

            return(Content(res.ToJson()));
        }
示例#9
0
 /// <summary>
 /// 获取配置数据
 /// </summary>
 /// <param name="configInfoList">配置信息列表</param>
 /// <returns></returns>
 public List <ConfigInfoDataModel> GetConfigData(List <ConfigInfoModel> configInfoList)
 {
     try
     {
         List <ConfigInfoDataModel> list = new List <ConfigInfoDataModel>();
         foreach (var item in configInfoList)
         {
             ConfigInfoDataModel configInfoDataModel = new ConfigInfoDataModel();
             configInfoDataModel.id        = item.id;
             configInfoDataModel.modelType = item.modelType;
             configInfoDataModel.type      = item.type;
             configInfoDataModel.data      = null;
             configInfoDataModel.dataType  = item.dataType;
             if (item.type == "1")
             {
                 DataTable dt = databaseLinkIBLL.FindTable(item.dbId, item.sql);
                 if (dt.Rows.Count > 0)
                 {
                     configInfoDataModel.data = dt;
                 }
             }
             else
             {
                 var          result       = HttpMethods.Get(item.url);
                 ResParameter resParameter = result.ToObject <ResParameter>();
                 if (resParameter != null)
                 {
                     if (resParameter.code.ToString() == "success")
                     {
                         configInfoDataModel.data = resParameter.data;
                     }
                 }
             }
             list.Add(configInfoDataModel);
         }
         return(list);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
        /// <summary>
        /// 响应前执行登录验证,查看当前用户是否有效
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            //登录拦截是否忽略
            if (_customMode == FilterMode.Ignore)
            {
                return;
            }
            string ActionName = filterContext.RouteData.Values["action"].ToString().ToLower();

            //登录和注册不校验
            if (ActionName == "dm_login" || ActionName == "dm_register" || ActionName == "paycallback")
            {
                return;
            }
            //return Content(new ResParameter { code = ResponseCode.success, info = info, data = new object { } }.ToJson());
            ResParameter modelResult = new ResParameter();

            //参数判断
            if (filterContext.HttpContext.Request.Headers["appid"] == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少appid参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
            else if (filterContext.HttpContext.Request.Headers["token"] == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少token参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
            else if (filterContext.HttpContext.Request.Headers["timestamp"] == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少timestamp参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
        }
示例#11
0
 /// <summary>
 /// 根据接口路径获取接口数据(仅限get方法)
 /// </summary>
 /// <param name="path">接口路径</param>
 /// <returns></returns>
 public object GetApiData(string path)
 {
     try
     {
         var          data         = new object();
         var          result       = HttpMethods.Get(path);
         ResParameter resParameter = result.ToObject <ResParameter>();
         if (resParameter != null)
         {
             if (resParameter.code.ToString() == "success")
             {
                 data = resParameter.data;
             }
             else
             {
                 data = "";
             }
         }
         else
         {
             data = "";
         }
         return(data);
     }
     catch (Exception ex)
     {
         if (ex is ExceptionEx)
         {
             throw;
         }
         else
         {
             throw ExceptionEx.ThrowBusinessException(ex);
         }
     }
 }
示例#12
0
        /// <summary>
        /// 消息处理,在此处处理好数据,然后调用消息发送方法
        /// </summary>
        /// <param name="code">消息策略编码</param>
        /// <param name="content">消息内容</param>
        /// <param name="userlist">用户列表信息</param>
        /// <returns></returns>
        public ResParameter SendMessage(string code, string content, string userlist)
        {
            try
            {
                ResParameter resParameter = new ResParameter();
                if (string.IsNullOrEmpty(code))//判断code编码是否输入
                {
                    resParameter.code = ResponseCode.fail;
                    resParameter.info = "code编码为空";
                }
                else if (string.IsNullOrEmpty(content))//判断是否输入信息内容
                {
                    resParameter.code = ResponseCode.fail;
                    resParameter.info = "content内容为空";
                }
                else
                {
                    LR_MS_StrategyInfoEntity strategyInfoEntity = GetEntityByCode(code); //根据编码获取消息策略
                    if (strategyInfoEntity == null)                                      //如果获取不到消息策略则code编码无效
                    {
                        resParameter.code = ResponseCode.fail;
                        resParameter.info = "code编码无效";
                    }
                    else
                    {
                        #region 用户信息处理
                        List <UserEntity> list = new List <UserEntity>();//消息发送对象
                        if (string.IsNullOrEmpty(userlist))
                        {
                            if (string.IsNullOrEmpty(strategyInfoEntity.F_SendRole))
                            {
                                resParameter.code = ResponseCode.fail;
                                resParameter.info = "消息策略无发送角色,需要输入人员userlist信息";
                            }
                            else
                            {
                                String[] rolecontent = strategyInfoEntity.F_SendRole.Split(',');//根据角色id获取用户信息
                                foreach (var item in rolecontent)
                                {
                                    var    data    = userRelationIBLL.GetUserIdList(item);
                                    string userIds = "";
                                    foreach (var items in data)
                                    {
                                        if (userIds != "")
                                        {
                                            userIds += ",";
                                        }
                                        userIds += items.F_UserId;
                                    }
                                    var userList = userIBLL.GetListByUserIds(userIds);
                                    foreach (var user in userList)
                                    {
                                        list.Add(user);
                                    }
                                }
                            }
                        }
                        else
                        {
                            list = userlist.ToList <UserEntity>();
                        }
                        #endregion
                        if (list.Count <= 0)//判断用户列表有一个或一个以上的用户用于发送消息
                        {
                            resParameter.code = ResponseCode.fail;
                            resParameter.info = "找不到发送人员";
                        }
                        else
                        {
                            if (string.IsNullOrEmpty(strategyInfoEntity.F_MessageType))
                            {
                                resParameter.code = ResponseCode.fail;
                                resParameter.info = "消息类型为空,无法发送消息";
                            }
                            else
                            {
                                string[] typeList = strategyInfoEntity.F_MessageType.Split(',');

                                foreach (var type in typeList)
                                {
                                    switch (type)
                                    {
                                    case "1":    //邮箱,调用邮箱发送方法
                                        EmailSend(content, list);
                                        break;

                                    case "2":    //微信,调用微信发送方法
                                        WeChatSend(content, list);
                                        break;

                                    case "3":     //短信,调用短信发送方法
                                        SMSSend(content, list);
                                        break;

                                    case "4":     //系统IM,效用系统IM发送方法
                                        IMSend(content, list);
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                resParameter.code = ResponseCode.success;
                resParameter.info = "发送成功";

                return(resParameter);
            }
            catch (Exception ex)
            {
                if (ex is ExceptionEx)
                {
                    throw;
                }
                else
                {
                    throw ExceptionEx.ThrowBusinessException(ex);
                }
            }
        }
示例#13
0
        /// <summary>
        /// 响应前执行登录验证,查看当前用户是否有效
        /// </summary>
        /// <param name="filterContext"></param>
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            /*签名生成格式*/
            /*md5(md5(appidplatform=androidtimestamp=1611907265000version=1.2.0appid)+"174PYR5Wwtce")  最后转为小写  参数放在header里面  参数名sign*/
            string ActionName = filterContext.RouteData.Values["action"].ToString().ToLower();

            //登录拦截是否忽略
            if (_customMode == FilterMode.Ignore || nosign.Contains(ActionName))
            {
                return;
            }

            var attrNeeds = filterContext.ActionDescriptor.GetCustomAttributes(typeof(NoNeedLoginAttribute), false);

            if (!attrNeeds.IsEmpty() && attrNeeds.Count() > 0)
            {
                //NoNeedLoginAttribute needPass = attrNeeds[0] as NoNeedLoginAttribute;
                return;
            }

            string       token       = filterContext.HttpContext.Request.Headers["token"];     //用户登录token
            string       platform    = filterContext.HttpContext.Request.Headers["platform"];  //平台类型
            string       appid       = filterContext.HttpContext.Request.Headers["appid"];     //appid
            string       timestamp   = filterContext.HttpContext.Request.Headers["timestamp"]; //时间戳
            string       version     = filterContext.HttpContext.Request.Headers["version"];   //版本号
            string       sign        = filterContext.HttpContext.Request.Headers["sign"];      //请求签名
            DateTime     currentTime = DateTime.Now;
            ResParameter modelResult = new ResParameter();

            //参数判断
            if (filterContext.HttpContext.Request.Headers["appid"] == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少appid参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
            else if (filterContext.HttpContext.Request.Headers["timestamp"] == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少timestamp参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
            else if (filterContext.HttpContext.Request.Headers["version"] == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少version参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
            else if (platform == null)
            {
                modelResult.code     = ResponseCode.fail;
                modelResult.info     = "缺少platform参数!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }

            int version_num = int.Parse(version.Replace(".", ""));

            if ((platform == "ios" && version_num > 103) || (platform == "android" && version_num > 119))
            {
                if (sign != "dlm_hyg")
                {
                    #region 校验签名
                    string signContent = string.Format("{0}platform={1}timestamp={2}version={3}{0}", appid, platform, timestamp, version);
                    string check_sign  = Md5Helper.Encrypt(Md5Helper.Encrypt(signContent, 32) + "174PYR5Wwtce", 32).ToLower();
                    if (sign != check_sign)
                    {
                        modelResult.code     = ResponseCode.fail;
                        modelResult.info     = "签名校验失败!";
                        filterContext.Result = new ContentResult {
                            Content = modelResult.ToJson()
                        };
                        return;
                    }
                    #endregion

                    #region 校验时间戳区间
                    long timestamp_long = long.Parse(timestamp);
                    long startTime      = long.Parse(Time.GetTimeStamp(currentTime.AddMinutes(-2), true));
                    long endTime        = long.Parse(Time.GetTimeStamp(currentTime.AddMinutes(2), true));
                    if (startTime > timestamp_long || timestamp_long > endTime)
                    {
                        modelResult.code     = ResponseCode.fail;
                        modelResult.info     = "本地时间和网络时间存在较大差别,请调整后重新使用APP!";
                        filterContext.Result = new ContentResult {
                            Content = modelResult.ToJson()
                        };
                        return;
                    }
                    #endregion

                    #region 校验请求频率
                    string   ip       = Net.Ip;
                    IP_Limit iP_Limit = CommonConfig.iP_Limits.Where(t => t.IP == ip).FirstOrDefault();//获取IP限制记录
                    if (!iP_Limit.IsEmpty())
                    {
                        double diffTime = (currentTime - iP_Limit.RequestTime).TotalSeconds;//该IP请求时间间隔在1分钟以内  增加接口请求的数量   不在1分钟以内的重新记录IP请求
                        if (diffTime < 60)
                        {
                            if (iP_Limit.RequestCount > 100)
                            {
                                modelResult.code     = ResponseCode.fail;
                                modelResult.info     = "操作过于频繁,请稍后重试!";
                                filterContext.Result = new ContentResult {
                                    Content = modelResult.ToJson()
                                };
                                return;
                            }
                            iP_Limit.RequestCount += 1;
                        }
                        else
                        {
                            iP_Limit.RequestTime  = currentTime;
                            iP_Limit.RequestCount = 1;
                        }
                    }
                    else
                    {
                        CommonConfig.iP_Limits.Add(new IP_Limit
                        {
                            IP           = ip,
                            RequestCount = 1,
                            RequestTime  = currentTime
                        });
                    }
                    CommonConfig.iP_Limits.RemoveAll(t => t.RequestTime < currentTime.AddMinutes(-2));//清空超过2分钟的请求记录
                    #endregion
                }
            }


            #region 屏蔽不需要校验登录的接口
            if (actionNameList.Contains(ActionName))
            {
                return;
            }
            #endregion

            #region 校验当前用户是否在线
            if (token.IsEmpty())
            {
                modelResult.code     = ResponseCode.NoLogin;
                modelResult.info     = "请登录后操作!";
                filterContext.Result = new ContentResult {
                    Content = modelResult.ToJson()
                };
                return;
            }
            else
            {
                dm_userEntity dm_UserEntity = CacheHelper.ReadUserInfo(filterContext.HttpContext.Request.Headers);
                if (dm_UserEntity.IsEmpty())
                {
                    dm_UserEntity = dM_UserIBLL.GetUserInfoByToken(token);
                    if (!dm_UserEntity.IsEmpty())
                    {
                        CacheHelper.UpdateUserInfo(dm_UserEntity);
                    }
                    else
                    {
                        string header = string.Format("ActionName={0}&token={1}&platform={2}", ActionName, token, platform);
                        Hyg.Common.OtherTools.LogHelper.WriteDebugLog("测试token", header);

                        modelResult.code = ResponseCode.LoginExpire;
                        modelResult.info = "您的账号在另一台设备登录。如非本人操作,请注意账户安全!";
                        //modelResult.info = "亲,离开太久了,重新登录一下吧!";
                        filterContext.Result = new ContentResult {
                            Content = modelResult.ToJson()
                        };
                        return;
                    }
                }
            }
            #endregion
        }