Пример #1
0
        public HttpResponseMessage EditAgentUKey([FromBody] EditAgentUKeyRequest 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());
            }
            //对外接口的OldPassWord不能为空
            if (request.ReqSource == 1 && string.IsNullOrWhiteSpace(request.OldPassWord))
            {
                viewModel.BusinessStatus = -10000;
                viewModel.StatusMessage  = "输入参数错误";
                return(viewModel.ResponseToJson());
            }

            //请求ukey修改密码接口
            var response = _agentUKeyService.EditAgentUKey(request, Request.GetQueryNameValuePairs());

            if (response.Status == HttpStatusCode.Forbidden)
            {
                viewModel.BusinessStatus = -10001;
                viewModel.StatusMessage  = "参数校验错误,请检查您的校验码";
                return(viewModel.ResponseToJson());
            }
            if (response.Status == HttpStatusCode.ExpectationFailed)
            {
                viewModel.BusinessStatus = -10003;
                viewModel.StatusMessage  = "服务发生异常";
                return(viewModel.ResponseToJson());
            }
            if (response.Status == HttpStatusCode.OK)
            {
                viewModel.BusinessStatus = 1;
                viewModel.StatusMessage  = "修改信息成功";
            }
            else
            {
                viewModel.BusinessStatus = 0;
                viewModel.StatusMessage  = response.ErrMsg;
            }
            return(viewModel.ResponseToJson());
        }
        public BaseResponse EditAgentUKey(EditAgentUKeyRequest request, IEnumerable <KeyValuePair <string, string> > pairs)
        {
            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("UserCode={0}&UkeyId={1}&OldPassWord={2}&NewPassWord={3}&Agent={4}", request.UserCode, request.UkeyId, request.OldPassWord, request.NewPassWord, request.Agent);
                    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);
                }
                //请求中心修改密码接口
                string strUrl  = string.Format("{0}/api/ChangePassWord/ChangePwd", _baoxianCenter);
                string oldPwd  = request.ReqSource == 1 ? request.OldPassWord : string.Empty;
                var    objPost = new
                {
                    UserCode    = request.UserCode,
                    UkeyId      = request.UkeyId,
                    OldPassWord = oldPwd,
                    NewPassWord = request.NewPassWord
                };
                StringBuilder postData = new StringBuilder();
                postData.Append("UserCode=").Append(request.UserCode)
                .Append("&UkeyId=").Append(request.UkeyId)
                .Append("&OldPassWord="******"&NewPassWord="******"&ReqSource=").Append(request.ReqSource);
                string result = string.Empty;
                int    i      = HttpWebAsk.Post(strUrl, postData.ToString(), out result);
                logInfo.Info("调用中心修改密码接口Url:" + strUrl + ";请求参数为:" + objPost.ToJson() + ";返回结果为:" + result);
                if (!string.IsNullOrWhiteSpace(result))
                {
                    var ret = result.FromJson <UKeyEdit>();
                    if (ret.ErrCode == 0)
                    {//修改成功
                        response.Status = HttpStatusCode.OK;
                        //如果修改成功,则保存用户名
                        if (string.IsNullOrEmpty(ukeyModel.InsuranceUserName))
                        {
                            ukeyModel.InsuranceUserName = request.UserCode;
                            int u = _iagentAgentUKeyRepository.UpdateModel(ukeyModel);
                            logInfo.Info(string.Format("修改保司密码成功,数据库修改{0}条记录。", u));
                        }
                    }
                    else
                    {
                        //修改失败
                        response.ErrCode = -1;
                        response.ErrMsg  = ret.ErrMsg;
                    }
                }
            }
            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);
        }