Пример #1
0
        /// <summary>
        /// 登录 韦德 2018年9月15日22:31:12
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="user"></param>
        /// <returns></returns>
        public LoginResult Login(string username, string password, ref UserDetail user)
        {
            if (username.IsEmpty() || password.IsEmpty() ||
                !Util.LengthValid(username) || !Util.LengthValid(password))
            {
                return(LoginResult.L00005);
            }

            // 查询用户基础信息
            QueryParam queryParam = new QueryParam();

            queryParam.StrWhere = $"username = '******' AND password = '******'";
            var list = userRepository.Query <User>(queryParam);

            if (!(list != null && list.Count > 0))
            {
                return(LoginResult.L00001);
            }
            user = new UserDetail
            {
                User = list.First()
            };

            queryParam          = new QueryParam();
            queryParam.StrWhere = $"userId = {user.User.Uid}";
            var wallets = walletRepository.Query <Wallet>(queryParam);

            if (!(wallets != null && wallets.Count > 0))
            {
                return(LoginResult.L00001);
            }
            user.Wallet = wallets.First();


            // 查询用户权限列表
            var permissions = permissionRepository.SelectList(user.User.Uid);

            if (!(permissions != null && permissions.Count > 0))
            {
                return(LoginResult.L00006);
            }
            user.Permissions = permissions;

            // 查询上级用户
            if (user.User.ParentId > 0)
            {
                queryParam          = new QueryParam();
                queryParam.StrWhere = $"uid IN({user.User.ParentId})";
                queryParam.OrderBy  = "depth DESC";
                var parentUsers = userRepository.Query <User>(queryParam);
                if (parentUsers != null && parentUsers.Count > 0)
                {
                    user.ParentUsers = parentUsers;
                }
            }

            return(LoginResult.L00000);
        }
Пример #2
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="result"></param>
        /// <param name="param"></param>
        public static void SERVICE_SignIn(ReturnModel result, RequestParamsM param)
        {
            #region 参数验证
            if (string.IsNullOrEmpty(param.Account) || string.IsNullOrEmpty(param.Pwd))
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数错误";
                return;
            }
            string account = Base64Util.DecodeBase64(Encoding.UTF8, param.Account);
            string pwd     = Base64Util.DecodeBase64(Encoding.UTF8, param.Pwd);
            if (account == param.Account || pwd == param.Pwd)
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数错误";
                return;
            }
            #endregion

            var model = ibll.FSysUser.Single(a => a.Login == account);
            if (model != null && model.Pwd.ToLower() == MD5Encrypt.MD5(pwd, Encoding.UTF8))
            {
                //写入登录session
                int minute = Convert.ToInt32(ibll.FSys_Config.Single(a => a.SKey == SysConfigType.TokenTimeout.ToString()).SValue);
                FSys_LoginSession login = new FSys_LoginSession();
                login.UID      = model.ID;
                login.Token    = Common.BillToken();
                login.Source   = Common.GetIP();
                login.TimeOut  = DateTime.Now.AddMinutes(minute);
                login.UserType = SysRuleType.view.ToString();
                ibll.FSys_LoginSession.Add(login);
                if (ibll.FSys_LoginSession.SaveChanges() > 0)
                {
                    result.data = new { token = login.Token, username = model.UserName, account = model.Login };
                    result.code = RespCodeConfig.Normal;
                }
                else
                {
                    result.code = RespCodeConfig.Faild;
                    result.msg  = "网络错误,请稍后再试";
                    return;
                }
            }
            else
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "用户名或密码错误";
                return;
            }
        }
Пример #3
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="newPassword"></param>
        /// <param name="agentId"></param>
        /// <returns></returns>
        public async Task <R> ResetPasswordAsync(long Id, string password, long agentId, CurrentUser curUser)
        {
            User user = await UserRep.FindSingleAsync(o => o.Id == Id);

            if (user == null)
            {
                return(R.Err("1001", $"帐号({Id})不存在"));
            }
            password = MD5Encrypt.MD5(password);
            await UserRep.UpdateAsync(o => o.Id == Id, o => new User()
            {
                Password = password
            });

            return(R.Suc());
        }
Пример #4
0
        /// <summary>
        /// 验证支付密码
        /// </summary>
        /// <param name="user"></param>
        /// <param name="security"></param>
        /// <param name="cause"></param>
        /// <returns></returns>
        public bool CheckSecurityPassword(User user, string security, ref string cause)
        {
            // 1.安全hash校对
            var securityPassword  = user.SecurityPassword;
            var nSecurityPassword = MD5Encrypt.MD5(MD5Encrypt.MD5(user.Username + security));

            if (securityPassword != nSecurityPassword)
            {
                cause = "支付密码不正确";
            }
            else
            {
                return(true);
            }
            return(false);
        }
Пример #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string partner     = Config.P1_MCHTID; //商户ID
            string Key         = Config.SIGNKEY;   //商户KEY
            int    orderstatus = Convert.ToInt32(Request["orderstatus"]);
            string ordernumber = Request["ordernumber"];
            string paymoney    = Request["paymoney"];
            string sign        = Request["sign"];
            //string attach = Request["attach"];
            string signSource = string.Format("partner={0}&ordernumber={1}&orderstatus={2}&paymoney={3}{4}", partner, ordernumber, orderstatus, paymoney, Key);

            if (sign.ToUpper() == MD5Encrypt.MD5(signSource, false).ToUpper())//签名正确
            {
                //此处作逻辑处理

                Response.Write("ok");      //ok代表http响应第三方接收通知信息成功
            }
            Response.End();
        }
Пример #6
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="password">旧密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns></returns>
        public async Task <R> ChangePasswordAsync(long Id, string password, string newPassword, long agentId, CurrentUser curUser)
        {
            User user = await UserRep.FindSingleAsync(o => o.Id == Id);

            if (user == null || user.DeleteMark == true)
            {
                return(R.Err("1001", $"帐号({Id})不存在"));
            }
            if (user.Password != MD5Encrypt.MD5(password))
            {
                return(R.Err("1003", $"原密码不正确"));
            }
            newPassword = MD5Encrypt.MD5(newPassword);
            await UserRep.UpdateAsync(o => o.Id == Id, o => new User()
            {
                Password = newPassword
            });

            return(R.Suc());
        }
Пример #7
0
        protected void btnSub_Click(object sender, EventArgs e)
        {
            string        mchtid    = txtpartner.Text;
            string        signType  = ddlsignType.SelectedValue;
            string        orderno   = txtordernumber.Text.Trim();
            string        version   = txtversion.Text.Trim();
            string        checkcode = txtKey.Text.Trim();
            StringBuilder strsb     = new StringBuilder();

            strsb.Append("p1_mchtid=" + mchtid)
            .Append("&p2_signtype=" + signType)
            .Append("&p3_orderno=" + orderno)
            .Append("&p4_version=" + version);
            //.Append(checkcode);
            string signstr   = strsb.ToString() + checkcode;
            string msign     = MD5Encrypt.MD5(signstr, false).ToLower();
            string urlparams = strsb.ToString() + "&sign=" + msign;
            string strResult = new HttpUtil().DoPost(txtUrl.Text, urlparams, Encoding.UTF8);

            Response.Write(strResult);
        }
Пример #8
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="user">用户实体</param>
        /// <param name="currentPassword">当前密码</param>
        /// <param name="newPassword">新密码</param>
        /// <returns>Task<(bool Succeeded, string Msg)></returns>
        public async Task <Messages> ChangePasswordAsync(UserEntity user, string currentPassword, string newPassword)
        {
            if (currentPassword.IsNotNullOrEmpty() && newPassword.IsNotNullOrEmpty())
            {
                currentPassword = MD5Encrypt.MD5(currentPassword + user.U_ENCRYPT);
                if (currentPassword == user.U_PWD)
                {
                    string encrypt = RandomHelper.CreateRandomStr(6);
                    newPassword = MD5Encrypt.MD5(newPassword + encrypt);
                    bool result = await userRepository.ModifyPwdAsync(user.U_ID, newPassword, encrypt);

                    messages.Msg     = result ? "修改密码成功,请重新登录!!" : "修改密码失败!!";
                    messages.Success = result;
                }
                else
                {
                    messages.Msg = "旧密码错误!!";
                }
            }
            await logService.AddLogAsync(OperatorLogEnum.Update, messages.Msg, user.U_ID, user.U_NAME);

            return(messages);
        }
Пример #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string p1_mchtid  = Request["p1_mchtid"];
                string p2_paytype = Request["p2_paytype"];
                p3_paymoney = Request["p3_paymoney"];
                p4_orderno  = Request["p4_orderno"];
                string        p5_callbackurl = Request["p5_callbackurl"];
                string        p6_notifyurl   = Request["p6_notifyurl"];
                string        p7_version     = Request["p7_version"];
                string        p8_signtype    = Request["p8_signtype"];
                string        p9_attach      = Request["p9_attach"];
                string        p10_appname    = Request["p10_appname"];
                string        p11_isshow     = Request["p11_isshow"];
                string        p12_orderip    = Request["p12_orderip"];
                StringBuilder strsb          = new StringBuilder();
                strsb.Append("p1_mchtid=" + p1_mchtid)       //用户ID
                .Append("&p2_paytype=" + p2_paytype)         //支付方式
                .Append("&p3_paymoney=" + p3_paymoney)       //支付金额
                .Append("&p4_orderno=" + p4_orderno)         //订单号码
                .Append("&p5_callbackurl=" + p5_callbackurl) //异步回调通知商户链接
                .Append("&p6_notifyurl=" + p6_notifyurl)     //同步链接
                .Append("&p7_version=" + p7_version)
                .Append("&p8_signtype=" + p8_signtype)
                .Append("&p9_attach=" + p9_attach)
                .Append("&p10_appname=" + p10_appname)
                .Append("&p11_isshow=" + p11_isshow)
                .Append("&p12_orderip=" + p12_orderip);
                string mSign = strsb.ToString() + Config.SIGNKEY;
                string sign  = MD5Encrypt.MD5(mSign, false).ToLower();

                sHtmlText = FormUtil.RequestForm(p1_mchtid, p2_paytype, p3_paymoney, p4_orderno, p5_callbackurl, p6_notifyurl, p7_version,
                                                 p8_signtype, p9_attach, p10_appname, p11_isshow, p12_orderip, sign);
            }
        }
Пример #10
0
        private long AddUser(string username, string password, string contact)
        {
            long pk = 0L;

            try {
                userRepository.InsertReturn(new User()
                {
                    Username = username,
                    Password = MD5Encrypt.MD5(MD5Encrypt.MD5(username + password)),
                    QQ       = contact,
                    ParentId = 0,
                    Level    = 0,
                    RoleId   = "0",
                }, ref pk);
            }
            catch (Exception e) {
                if (e.Message.Contains("Duplicate entry"))
                {
                    return(-1L);
                }
                throw;
            }
            return(pk);
        }
Пример #11
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="userPwd">密码</param>
        /// <returns>Task<(bool Succeeded, string Msg)></returns>
        public async Task <(bool Succeeded, string Msg, int UserId)> Login(string userName, string userPwd)
        {
            bool   succeeded = false;
            string msg       = string.Empty;
            int    userId    = 0;
            var    user      = await _adminRepository.GetModelAsync(new { adminname = userName });

            if (user != null && user.Id > 0)
            {
                userId = user.Id;
                int    errorTimes = 0;
                string pwd1       = MD5Encrypt.MD5(userPwd).ToUpper();
                if (user.Is_state == 1)
                {
                    //登录错误次数
                    int maxLoginFailedTimes = 0;//@TODO应该从配置文件读取
                    if (maxLoginFailedTimes <= 0)
                    {
                        maxLoginFailedTimes = 5;
                    }
                    if (user.ErrorTimes < maxLoginFailedTimes)
                    {
                        if (user.Adminpass == pwd1)
                        {
                            succeeded = true;
                            msg       = "登录系统,成功";
                        }
                        else
                        {
                            errorTimes = user.ErrorTimes + 1;
                            int sErrorTimes = maxLoginFailedTimes - errorTimes;
                            if (sErrorTimes > 0)
                            {
                                msg = "密码错误,您今天还可尝试" + sErrorTimes + "次";
                            }
                            else
                            {
                                msg = "您今天登录错误次数过多,今天不可再登录,欢迎明天回来";
                            }
                        }
                    }
                    else
                    {
                        errorTimes = user.ErrorTimes + 1;
                        msg        = "您今天登录错误次数过多,今天不可再登录,欢迎明天回来";
                    }
                    //更新用户登录信息
                    await _adminRepository.UpdateAsync(new { errorTimes }, new { id = user.Id });
                }
                else
                {
                    msg = "登录系统,该用户状态为禁止登录";
                }
            }
            else
            {
                msg = "用户名不存在";
            }
            //记录登录日志
            Adminlogs logs = new Adminlogs()
            {
                AdminId = userId.ToString(),
                Ip      = _webHelper.GetCurrentIpAddress(),
                Addtime = DateTime.Now
            };
            var a = await _adminlogsRepository.InsertAsync(logs);

            return(succeeded, msg, userId);
        }
Пример #12
0
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="result"></param>
        /// <param name="param"></param>
        public static void SERVICE_SignUp(ReturnModel result, RequestParamsM param)
        {
            #region 参数验证

            if (string.IsNullOrEmpty(param.Account.Trim()) || string.IsNullOrEmpty(param.Pwd.Trim()) || string.IsNullOrEmpty(param.UserName.Trim()) || string.IsNullOrEmpty(param.Content))
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数不能为空";
                return;
            }
            string account = Base64Util.DecodeBase64(Encoding.UTF8, param.Account);
            string pwd     = Base64Util.DecodeBase64(Encoding.UTF8, param.Pwd);
            if (account == param.Account || pwd == param.Pwd)
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "参数错误";
                return;
            }
            #endregion


            //验证邀请码
            var invitemodel = ibll.FSysUser_Invite.Single(a => a.InviteCode == param.Content);
            if (invitemodel != null)
            {
                var model = ibll.FSysUser.Single(a => a.Login == account);
                if (model == null)
                {
                    //注册新账号
                    FSysUser user = new FSysUser();
                    user.Login       = account;
                    user.Pwd         = MD5Encrypt.MD5(pwd, Encoding.UTF8);
                    user.UserName    = param.UserName;
                    user.Remark      = "";
                    user.RoleID      = (int)SysRuleType.view;
                    user.IsAvailable = 1;
                    user.AddDate     = DateTime.Now;
                    ibll.FSysUser.Add(user);
                    int n = ibll.FSysUser.SaveChanges();
                    if (n > 0)
                    {
                        result.msg  = "注册成功";
                        result.code = RespCodeConfig.Normal;
                    }
                    else
                    {
                        result.code = RespCodeConfig.ArgumentExp;
                        result.msg  = "网络错误";
                        return;
                    }
                }
                else
                {
                    result.code = RespCodeConfig.ArgumentExp;
                    result.msg  = "该账号已被注册";
                    return;
                }
            }
            else
            {
                result.code = RespCodeConfig.ArgumentExp;
                result.msg  = "无效的邀请码";
                return;
            }
        }
Пример #13
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="userPwd">密码</param>
        /// <returns>Task<(bool Succeeded, string Msg)></returns>
        public async Task <(bool Succeeded, string Msg, int UserId)> Login(string userName, string userPwd)
        {
            bool       succeeded = false;
            string     msg       = string.Empty;
            int        userId    = 0;
            UserEntity user      = this.GetModelByUserName(userName);

            if (user != null && user.U_ID > 0)
            {
                userId = user.U_ID;
                int    errorTimes = 0;
                string pwd1       = MD5Encrypt.MD5(userPwd + user.U_ENCRYPT);
                if (user.U_DISABLED == false)
                {
                    //登录错误次数
                    int maxLoginFailedTimes = config.MaxLoginFailedTimes;
                    if (maxLoginFailedTimes <= 0)
                    {
                        maxLoginFailedTimes = 5;
                    }
                    if (user.U_ERRORTIMES < maxLoginFailedTimes)
                    {
                        if (user.U_PWD == pwd1)
                        {
                            succeeded = true;
                            msg       = "登录系统,成功";
                        }
                        else
                        {
                            errorTimes = user.U_ERRORTIMES + 1;
                            int sErrorTimes = maxLoginFailedTimes - errorTimes;
                            if (sErrorTimes > 0)
                            {
                                msg = "密码错误,您今天还可尝试" + sErrorTimes + "次";
                            }
                            else
                            {
                                msg = "您今天登录错误次数过多,今天不可再登录,欢迎明天回来";
                            }
                        }
                    }
                    else
                    {
                        errorTimes = user.U_ERRORTIMES + 1;
                        msg        = "您今天登录错误次数过多,今天不可再登录,欢迎明天回来";
                    }
                    //更新用户登录信息
                    await this.UpdateByLoginAsync(user.U_ID, webHelper.GetCurrentIpAddress(), errorTimes);
                }
                else
                {
                    msg = "登录系统,该用户状态为禁止登录";
                }
            }
            else
            {
                msg = "用户名不存在";
            }
            //记录登录日志
            await logService.AddLogAsync(OperatorLogEnum.Login, msg, userId, userName);

            return(succeeded, msg, userId);
        }
Пример #14
0
        private void ServiceThread()
        {
            while (true)
            {
                try
                {
                    if (!isrun)
                    {
                        Thread.CurrentThread.Abort();
                        return;
                    }

                    HttpListenerContext context = listener.GetContext();
                    context.Response.StatusCode = 200;

                    string str_resp_err = "";
                    string str_resp     = "";
                    byte[] buffer       = new byte[1024];

                    #region test
                    //UploadFlowDataReqEntity testentity = new UploadFlowDataReqEntity();
                    //testentity.action = "uploadflowdata";
                    //testentity.TerData = new List<UpLoadFlowDataEntity>();
                    //UpLoadFlowDataEntity testdata1 = new UpLoadFlowDataEntity();
                    //testdata1.terid = "1";
                    //testdata1.flowvalue = "100.123";
                    //testdata1.flowinverted = "2344.0";
                    //testdata1.flowinstant = "233.23";
                    //testdata1.collTime = DateTime.Now.ToString();
                    //testentity.TerData.Add(testdata1);
                    //string strttt = SmartWaterSystem.JSONSerialize.JsonSerialize<UploadFlowDataReqEntity>(testentity);
                    //long timestamp = 0;
                    //TimeSpan tsp = (TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now) - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)));
                    //timestamp = (long)tsp.TotalMilliseconds;
                    //string md51 = MD5Encrypt.MD5(System.Web.HttpUtility.UrlEncode(strttt + timestamp + Settings.Instance.GetString(SettingKeys.HTTPMD5Key)).ToLower());
                    //HTTPEntity ttpentity = new HTTPEntity();
                    //ttpentity.timestamp = timestamp.ToString();
                    //ttpentity.Params = strttt;
                    //ttpentity.digest = md51;
                    //string reqtemp = SmartWaterSystem.JSONSerialize.JsonSerialize<HTTPEntity>(ttpentity);
                    //string urltemp = System.Web.HttpUtility.UrlEncode(reqtemp, Encoding.UTF8);
                    #endregion

                    if (context.Request.HttpMethod.ToLower().Equals("get"))
                    {
                        //GET请求处理
                        str_resp_err = "不支持GET方法";
                    }
                    else if (context.Request.HttpMethod.ToLower().Equals("post"))
                    {
                        //这是在POST请求时必须传参的判断默认注释掉
                        if (!context.Request.HasEntityBody)
                        {
                            str_resp_err = "请传入参数";
                        }
                        else
                        {
                            //POST请求处理
                            Stream SourceStream = context.Request.InputStream;
                            int    readcount    = -1;

                            List <byte> lstbytes = new List <byte>();
                            while ((readcount = SourceStream.Read(buffer, 0, 1024)) > 0)
                            {
                                for (int i = 0; i < readcount; i++)
                                {
                                    lstbytes.Add(buffer[i]);
                                }
                            }
                            string strrequest = Encoding.UTF8.GetString(lstbytes.ToArray());
                            try
                            {
                                strrequest = System.Web.HttpUtility.UrlDecode(strrequest, Encoding.UTF8);                  //UrlDecode
                                OnReceiveMsg("接收到请求[" + DateTime.Now.ToString() + "]:" + strrequest);
                                HTTPEntity httpentity = JSONSerialize.JsonDeserialize_Newtonsoft <HTTPEntity>(strrequest); //jsondeSerialize

                                if (httpentity == null)
                                {
                                    str_resp_err = "无效数据,解析失败!";
                                    goto err;
                                }
                                if (string.IsNullOrEmpty(httpentity.Params))
                                {
                                    str_resp_err = "无效params,解析失败!";
                                    goto err;
                                }
                                if (string.IsNullOrEmpty(httpentity.timestamp))
                                {
                                    str_resp_err = "时间戳不能为空!";
                                    goto err;
                                }
                                else
                                {
                                    System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
                                    DateTime        dtime     = startTime.AddMilliseconds(Convert.ToDouble(httpentity.timestamp));
                                    TimeSpan        ts        = DateTime.Now - dtime;
                                    if (Math.Abs(ts.TotalMinutes) > Settings.Instance.GetInt(SettingKeys.HTTPReqSuviceTime))
                                    {
                                        str_resp_err = "该请求已失效!";
                                        goto err;
                                    }
                                }

                                //MD5(body +时间戳+Key)
                                string md5 = MD5Encrypt.MD5(System.Web.HttpUtility.UrlEncode(httpentity.Params + httpentity.timestamp + Settings.Instance.GetString(SettingKeys.HTTPMD5Key)).ToLower());
                                if (md5 != httpentity.digest)
                                {
                                    str_resp_err = "MD5校验失败!";
                                    goto err;
                                }

                                str_resp_err = "无效action";
                                string action = "";

                                foreach (Match m in Regex.Matches(httpentity.Params, "\"action\" ?: ?\"(?<title>.*?)\"", RegexOptions.IgnoreCase))
                                {
                                    if (m.Success)
                                    {
                                        action = m.Groups["title"].Value;
                                    }
                                }

                                try
                                {
                                    switch (action)
                                    {
                                    case "getgroups":
                                        str_resp_err = "";
                                        GetGroupsRespEntity getgrouprespentity = bll.GetGroupsInfo();
                                        str_resp = SmartWaterSystem.JSONSerialize.JsonSerialize <GetGroupsRespEntity>(getgrouprespentity);
                                        break;

                                    case "uploadnoisedata":      //上传噪声数据
                                        str_resp_err = "";
                                        UploadNoiseDataReqEntity parmentity       = SmartWaterSystem.JSONSerialize.JsonDeserialize_Newtonsoft <UploadNoiseDataReqEntity>(httpentity.Params);
                                        HTTPRespEntity           uploadrespentity = bll.UploadGroups(parmentity.TerData);
                                        str_resp = SmartWaterSystem.JSONSerialize.JsonSerialize <HTTPRespEntity>(uploadrespentity);
                                        break;

                                    case "uploadflowdata":      //未使用
                                        str_resp_err = "";
                                        UploadFlowDataReqEntity parmflowentity = SmartWaterSystem.JSONSerialize.JsonDeserialize_Newtonsoft <UploadFlowDataReqEntity>(httpentity.Params);

                                        if (parmflowentity != null && parmflowentity.TerData != null)
                                        {
                                            foreach (UpLoadFlowDataEntity flowentity in parmflowentity.TerData)
                                            {
                                                GPRSFlowFrameDataEntity framedata = new GPRSFlowFrameDataEntity();
                                                framedata.TerId      = flowentity.terid;
                                                framedata.ModifyTime = DateTime.Now;
                                                framedata.Frame      = "";
                                                GPRSFlowDataEntity data = new GPRSFlowDataEntity();
                                                data.Forward_FlowValue = Convert.ToDouble(flowentity.flowvalue);
                                                data.Reverse_FlowValue = Convert.ToDouble(flowentity.flowinverted);
                                                data.Instant_FlowValue = Convert.ToDouble(flowentity.flowinstant);
                                                data.ColTime           = Convert.ToDateTime(flowentity.collTime);
                                                framedata.lstFlowData.Add(data);
                                                GlobalValue.Instance.GPRS_FlowFrameData.Enqueue(framedata);      //通知存储线程处理
                                            }
                                        }
                                        GlobalValue.Instance.SocketSQLMag.Send(SQLType.InsertFlowValue);

                                        uploadrespentity      = new HTTPRespEntity();
                                        uploadrespentity.code = 1;
                                        str_resp = SmartWaterSystem.JSONSerialize.JsonSerialize <HTTPRespEntity>(uploadrespentity);
                                        break;
                                    }
                                }
                                catch
                                {
                                    str_resp_err = "解析异常";
                                }
                            }
                            catch (Exception ex)
                            {
                                str_resp_err = "无效参数类型";
                            }
                        }
                    }

err:
                    if (!string.IsNullOrEmpty(str_resp_err) || string.IsNullOrEmpty(str_resp))
                    {
                        HTTPRespEntity respent = new HTTPRespEntity();
                        respent.code = -1;
                        if (!string.IsNullOrEmpty(str_resp_err))
                        {
                            respent.msg = str_resp_err;
                        }
                        respent.data = "";

                        str_resp = SmartWaterSystem.JSONSerialize.JsonSerialize <HTTPRespEntity>(respent);
                    }
                    OnReceiveMsg(DateTime.Now.ToString() + " 响应内容:" + str_resp);
                    str_resp = System.Web.HttpUtility.UrlEncode(str_resp);
                    byte[] buffer_resp = Encoding.UTF8.GetBytes(str_resp);
                    context.Response.OutputStream.Write(buffer_resp, 0, buffer_resp.Length);
                    context.Response.OutputStream.Flush();
                    context.Response.OutputStream.Close();

                    context.Response.Close();
                }
                catch (Exception ex)
                {
                    logger.ErrorException("ServiceThread", ex);
                }
            }
        }
Пример #15
0
        public SingleApiResponse Login(UserLoginRequest req)
        {
            var user = RepoBase.Instance.GetWhere <SS_USER>(x => x.U_NAME == req.userName).FirstOrDefault();

            if (user != null && user.U_ID > 0)
            {
                string pwd1 = MD5Encrypt.MD5(req.passWord + user.U_ENCRYPT);
                if (!user.U_DISABLED)
                {
                    if (user.U_PWD == pwd1)
                    {
                        //TokenModelJwt tokenModel = new TokenModelJwt { Uid = user.U_ID, Role = user.U_ID.ToString() };
                        var roles = RoleRepo.GetListByUid <SS_ROLE>(new UserInfoGetRequest()
                        {
                            U_ID = user.U_ID
                        }).Select(x => x.R_ID);
                        TokenModelJwt tokenModel = new TokenModelJwt {
                            Uid = user.U_ID, Role = string.Join(",", roles)
                        };
                        var jwtStr = JwtHelper.IssueJWT(tokenModel); //登录,获取到一定规则的 Token 令牌

                        #region 更新user
                        //登录次数
                        user.U_LOGINTIMES++;

                        //上次登录时间和ip
                        user.U_PREVLOGINIP   = user.U_LASTLOGINIP;
                        user.U_PREVLOGINTIME = user.U_UPDATETIME;

                        //本次登录时间和ip
                        user.U_LASTLOGINTIME = DateTime.Now;
                        user.U_UPDATETIME    = DateTime.Now;
                        user.U_LASTLOGINIP   = req.Ip;

                        RepoBase.Instance.Update(user);

                        #endregion

                        return(new SingleApiResponse()
                        {
                            Data = new LoginDto()
                            {
                                U_ID = user.U_ID, Token = $"Bearer {jwtStr}"
                            }
                        });
                    }
                    return(new SingleApiResponse()
                    {
                        ErrCode = 105, BizErrorMsg = "密码错误"
                    });
                }
                return(new SingleApiResponse()
                {
                    ErrCode = 104, BizErrorMsg = "登录系统,该用户状态为禁止登录"
                });
            }
            return(new SingleApiResponse()
            {
                ErrCode = 103, BizErrorMsg = "用户名不存在"
            });
        }