Beispiel #1
0
        public HttpResponseMessage EditBackupPwd([FromBody] EditBackupPwdRequest request)
        {
            _logInfo.Info(string.Format("修改代理人UKey备用密码接口请求串:{0}", request.ToJson()));
            var viewModel = new BaseViewModel();

            if (!ModelState.IsValid)
            {
                viewModel.BusinessStatus = -10000;
                string msg = ModelState.Values.Where(a => a.Errors.Count == 1).Aggregate(string.Empty, (current, a) => current + (a.Errors[0].ErrorMessage + ";   "));
                viewModel.StatusMessage = "输入参数错误," + msg;
                return(viewModel.ResponseToJson());
            }

            string param = string.Format("Agent={0}&PwdOne={1}&PwdThree={2}&PwdTwo={3}&ReqSource={4}&UkeyId={5}", request.Agent, request.PwdOne, request.PwdThree, request.PwdTwo, request.ReqSource, request.UkeyId, request.UkeyId);

            if (request.SecCode != param.GetMd5())
            {
                viewModel.BusinessStatus = -10001;
                viewModel.StatusMessage  = "参数校验错误,请检查您的校验码";
                return(viewModel.ResponseToJson());
            }

            var response = _agentUKeyService.EditBackupPwd(request);

            if (response.ErrCode == -1)
            {
                viewModel.BusinessStatus = 0;
                viewModel.StatusMessage  = response.ErrMsg;
            }
            else if (response.ErrCode == 0)
            {
                viewModel.BusinessStatus = 1;
                viewModel.StatusMessage  = "修改成功";
            }
            return(viewModel.ResponseToJson());
        }
        /// <summary>
        /// 修改代理人备份密码 2017-10-20 zky/运营后台
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BaseResponse EditBackupPwd(EditBackupPwdRequest request)
        {
            BaseResponse response = new BaseResponse();

            try
            {
                IBxAgent agentModel = GetAgentModelFactory(request.Agent);
                if (!agentModel.AgentCanUse())
                {
                    response.Status = HttpStatusCode.Forbidden;
                    return(response);
                }
                if (request.ReqSource == 1)
                {//对外的接口才做这一层校验
                    var validateUrl = string.Format("Agent={0}&UkeyId={1}&PassWord1={2}&PassWord2={3}&PassWord3={4}", request.Agent, request.UkeyId, request.PwdOne, request.PwdTwo, request.PwdThree);
                    if (!ValidatePostReqest(validateUrl, agentModel.SecretKey, request.SecCode))
                    {
                        response.Status = HttpStatusCode.Forbidden;
                        return(response);
                    }
                }

                //查询ukey信息
                var ukeyModel = _iagentAgentUKeyRepository.GetModel(request.UkeyId);
                if (ukeyModel == null)
                {
                    response.ErrCode = -1;
                    response.ErrMsg  = "未查到Ukey信息";
                    return(response);
                }

                #region 20170927  L: 密码复杂度正则表达式   校验时候用  暂时做个储备
                Regex Num     = new Regex("(?=.*[0-9])");                                                       //数字
                Regex Cn      = new Regex("[\u4e00-\u9fa5]+");                                                  //中文
                Regex Up      = new Regex("(?=.*[A-Z])");                                                       //大写字母
                Regex Low     = new Regex("(?=.*[a-z])");                                                       //小写字母
                Regex Len     = new Regex(".{8,20}");                                                           //8到20字符
                Regex Special = new Regex("[`~!@#$%^&*()+=|{}':;',\\[\\].<>?/~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]"); //特殊字符
                #endregion

                #region 20170928  L: 密码难度规则校验
                var bl = false;
                //判断密码的复杂度
                string[] lstStrs = new[] { request.PwdOne, request.PwdTwo, request.PwdThree };

                foreach (var item in lstStrs)
                {
                    //判断长度和密码难度  是否符合两种
                    int checkItem = (Num.IsMatch(item) ? 1 : 0) + (Up.IsMatch(item) ? 1 : 0) +
                                    (Low.IsMatch(item) ? 1 : 0) + (Special.IsMatch(item) ? 1 : 0);
                    if (checkItem < 2)
                    {
                        bl = true;
                        break;
                    }

                    //判断是否含有picc  和  长度校验  和  中文字符校验
                    if (item.ToLower().Contains("picc") || !Len.IsMatch(item) || Cn.IsMatch(item))
                    {
                        bl = true;
                        break;
                    }
                }

                //判断密码难度  或者  四个密码是否有相同
                if (bl || lstStrs.Distinct().Count() < lstStrs.Length)
                {
                    response.ErrCode = -1;
                    response.ErrMsg  = "密码格式信息不对,请参照密码格式提示输入!";
                    return(response);
                }

                #endregion

                //调用中心修改备用密码接口
                string url     = string.Format("{0}/api/ChangePassWord/ChangeHistoryPwd", _baoxianCenter);
                var    content = new FormUrlEncodedContent(new Dictionary <string, string>()
                {
                    { "UkeyId", request.UkeyId.ToString() },
                    { "PassWord1", request.PwdOne },
                    { "PassWord2", request.PwdTwo },
                    { "PassWord3", request.PwdThree }
                });
                var handler = new HttpClientHandler {
                    AutomaticDecompression = DecompressionMethods.GZip
                };
                using (var http = new HttpClient(handler))
                {
                    var ResultReturn = http.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
                    var result       = ResultReturn.FromJson <BaseViewModel>();
                    if (result.BusinessStatus == 200)
                    {
                        response.Status = HttpStatusCode.OK;
                        //保存备用密码
                        ukeyModel.backup_pwd_one   = request.PwdOne;
                        ukeyModel.backup_pwd_two   = request.PwdTwo;
                        ukeyModel.backup_pwd_three = request.PwdThree;
                        _iagentAgentUKeyRepository.UpdateModel(ukeyModel);
                    }
                    else
                    {
                        //修改失败
                        response.ErrCode = -1;
                        response.ErrMsg  = result.StatusMessage;
                    }
                }
            }
            catch (Exception ex)
            {
                response        = new BaseResponse();
                response.Status = HttpStatusCode.ExpectationFailed;
                logError.Info("修改保司备份密码请求发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException + ",返回对象信息:" + request.ToJson());
            }
            return(response);
        }