/// <summary> /// 通过身份证号获取年龄 /// </summary> /// <param name="IDNumber">身份证号字符串</param> /// <returns>年龄</returns> private int GetAgeFromIDNumber(String IDNumber) { if (IDCardValidation.CheckIDCard(IDNumber) == false) { return(-1); } DateTime BirthDate = DateTime.MinValue; if (IDNumber.Length == 15) { String BirthDateStringFromIDNumber = IDNumber.Substring(6, 2) + "-" + IDNumber.Substring(8, 2) + "-" + IDNumber.Substring(10, 2); if (DateTime.TryParse(BirthDateStringFromIDNumber, out BirthDate) == false) { return(-1); } return((int)((DateTime.Now - BirthDate).TotalDays / 365) + 1); } else if (IDNumber.Length == 18) { String BirthDateStringFromIDNumber = IDNumber.Substring(6, 4) + "-" + IDNumber.Substring(10, 2) + "-" + IDNumber.Substring(12, 2); if (DateTime.TryParse(BirthDateStringFromIDNumber, out BirthDate) == false) { return(-1); } return((int)((DateTime.Now - BirthDate).TotalDays / 365) + 1); } return(-1); }
/// <summary> /// 通过身份证号获取性别 /// </summary> /// <param name="IDNumber">身份证号字符串</param> /// <returns>性别</returns> private String GetSexFromIDNumber(String IDNumber) { if (IDCardValidation.CheckIDCard(IDNumber) == false) { return(""); } //0为男,1为女 int Sex = 0; if (IDNumber.Length == 15) { if (int.TryParse(IDNumber.Substring(14, 1), out Sex) == false) { return(""); } return(Sex % 2 == 1 ? "男" : "女"); } else if (IDNumber.Length == 18) { if (int.TryParse(IDNumber.Substring(16, 1), out Sex) == false) { return(""); } return(Sex % 2 == 1 ? "男" : "女"); } return(""); }
/// <summary> /// 查询客户信息 /// </summary> /// <param name="UserID">用户ID</param> /// <param name="Mobile">客户手机号</param> /// <param name="IDNumber">客户身份证号</param> /// <param name="Sign">校验码</param> /// <returns>响应结果</returns> public JsonResult QueryCustomerInfo(String UserID, String Mobile, String IDNumber, String Sign) { CustomerInfoResponse JsonResponse = new CustomerInfoResponse(); if (Mobile == null) { Mobile = ""; } if (IDNumber == null) { IDNumber = ""; } //输入参数有效性检测 if (String.IsNullOrEmpty(UserID)) { JsonResponse.Result = "Failed"; JsonResponse.Message = "UserID not provided."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } if (String.IsNullOrEmpty(Sign)) { JsonResponse.Result = "Failed"; JsonResponse.Message = "Sign not provided."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } if (String.IsNullOrEmpty(Mobile) && String.IsNullOrEmpty(IDNumber)) { JsonResponse.Result = "Failed"; JsonResponse.Message = "At least one of [Mobile] or [IDNumber] should be provided."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } if (!String.IsNullOrEmpty(IDNumber) && !IDCardValidation.CheckIDCard(IDNumber)) { JsonResponse.Result = "Failed"; JsonResponse.Message = "The value of [IDNumber] is not valid."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } if (!String.IsNullOrEmpty(Mobile) && (Mobile.Length != 11 || Mobile[0] != '1')) { JsonResponse.Result = "Failed"; JsonResponse.Message = "The value of [Mobile] is not valid."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //检出接口名称 String InterfaceName = ConfigurationManager.AppSettings["LejuInterfaceName1"].ToString(); DataSet ResultSet = new DataSet(); //用户key,一个GUID String UserKey = ""; //每周期(月)最大查询次数 int MaxQueryTimes = 0; //用户帐号过期时间 DateTime ExpiredTime; //用户记录ID int UserRecordID = 0; //本周期已经查询次数 int CurrentTimes = 0; //获取用户信息记录 try { ResultSet = new DbHelperSQLP(ConnStringCustomerInfo).Query( "select [ID],[UserKey],[ExpiredTime],[MaxQueryTimes] from tb_interface_user " + "where InterfaceName = @InterfaceName and UserID = @UserID and Status = 1 ", new SqlParameter[] { new SqlParameter("@InterfaceName", InterfaceName), new SqlParameter("@UserID", UserID) }); } catch (Exception) { JsonResponse.Result = "Failed"; JsonResponse.Message = "Validation Service failed."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //解析用户信息 try { UserKey = ResultSet.Tables[0].Rows[0]["UserKey"].ToString(); MaxQueryTimes = (int)ResultSet.Tables[0].Rows[0]["MaxQueryTimes"]; ExpiredTime = (DateTime)ResultSet.Tables[0].Rows[0]["ExpiredTime"]; UserRecordID = (int)ResultSet.Tables[0].Rows[0]["ID"]; } catch (Exception) { JsonResponse.Result = "Failed"; JsonResponse.Message = "Invalid user."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //用户过期检测 if (DateTime.Now > ExpiredTime) { JsonResponse.Result = "Failed"; JsonResponse.Message = "User account expired."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //获取查询历史信息 try { //获取本月访问次数 CurrentTimes = (int)(new DbHelperSQLP(ConnStringCustomerInfo).GetSingle( "select count(1) from tb_interface_query_log where [UserRecordID] = @UserRecordID " + "and QueryTime > DATENAME(YEAR,GETDATE())+'-'+DATENAME(MONTH,GETDATE())+'-01'", new SqlParameter[] { new SqlParameter("@UserRecordID", UserRecordID) })); } catch (Exception) { //次数查询失败时认为查询可用 CurrentTimes = 0; } //本周期查询次数检测 if (CurrentTimes >= MaxQueryTimes) { JsonResponse.Result = "Failed"; JsonResponse.Message = "Query times exceeded."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //MD5校验 String SignStr = UserKey; if (!String.IsNullOrEmpty(IDNumber)) { SignStr += "&IDNumber=" + IDNumber; } if (!String.IsNullOrEmpty(Mobile)) { SignStr += "&Mobile=" + Mobile; } if (GetMD5String(SignStr) != Sign) { JsonResponse.Result = "Failed"; JsonResponse.Message = "Sign check failed."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //组装客户信息 PersonTag Tag = null; int AssembleResult = AssembleCustomerInfo(Mobile, IDNumber, out Tag); if (AssembleResult != 0) { if (AssembleResult == -1) { JsonResponse.Message = "DB service failed."; } if (AssembleResult == -2) { JsonResponse.Message = "The value of [Mobile] and [IDNumber] don't match."; } if (AssembleResult == -3) { JsonResponse.Message = "No relative records."; } JsonResponse.Result = "Failed"; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //结果是否有有效数据 以存在五项属性和需求成交信息中的任意一项为有效标准 if (String.IsNullOrWhiteSpace(Tag.ChildrenStatus) && String.IsNullOrWhiteSpace(Tag.FamilyIncome) && String.IsNullOrWhiteSpace(Tag.FamilyStatus) && String.IsNullOrWhiteSpace(Tag.Interests) && String.IsNullOrWhiteSpace(Tag.Profession) && Tag.DemandInfos.Count == 0 && Tag.TradeInfos.Count == 0) { JsonResponse.Result = "Failed"; JsonResponse.Message = "No available records."; return(Json(JsonResponse, JsonRequestBehavior.AllowGet)); } //输出结果 JsonResponse.Data = Tag; JsonResponse.Result = "Succeeded"; //本周期剩余查询次数 JsonResponse.Message = (MaxQueryTimes - CurrentTimes - 1) + " queries available in this month."; JsonResult JR = Json(JsonResponse, JsonRequestBehavior.AllowGet); String JRString = JR.Data.ToJsonString(); //记录查询历史 String Parameters = Request.Url.ToString().Substring(Request.Url.ToString().IndexOf('?') + 1); try { new DbHelperSQLP(ConnStringCustomerInfo).ExecuteSql( "INSERT INTO [tb_interface_query_log] ([UserRecordID],[UserID],[InterfaceName],[Parameters],[Response],[QueryTime]) " + "values (@UserRecordID, @UserID, @InterfaceName, @Parameters, @Response, GetDate())", new SqlParameter[] { new SqlParameter("@UserRecordID", UserRecordID), new SqlParameter("@UserID", UserID), new SqlParameter("@InterfaceName", InterfaceName), new SqlParameter("@Parameters", Parameters), new SqlParameter("@Response", JRString) }); } catch (Exception) { } return(JR); }
protected void ButLogin_Click(object sender, System.EventArgs e) { string strSql=""; string strConn=""; strLoginID=ObjFun.CheckString(Convert.ToString(Request["LoginID"]).Trim()).ToUpper(); strUserPwd=ObjFun.CheckString(Convert.ToString(Request["UserPwd"]).Trim()); if (strUserPwd == ""|| strLoginID=="") //�жϵ�¼ʱ���Ƿ����� { this.RegisterStartupScript("newWindow", "<script language='javascript'>alert('֤���ź�����������Ϊ�գ�');</script>"); return; } if ((TimeRestrict()==true)&&(strLoginID.ToUpper()!="ADMIN"))//�жϵ�¼ʱ���Ƿ����� { this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�Բ�������¼��ʱ�����ޣ�');</script>"); return; } if ((LoginTimeRestrict()==true)&&(strLoginID.ToUpper()!="ADMIN"))//�жϵ�¼ʱ���Ƿ����� { this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�Բ�����ĵ�¼ʱ�������ƣ�');</script>"); return; } if ((IPRestrict()==true)&&(strLoginID.ToUpper()!="ADMIN"))//�жϵ�¼IP�Ƿ����� { this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�Բ�������¼��IP���ޣ�');</script>"); return; } strSql="select * from UserInfo where LoginID='"+strLoginID+"' and UserPwd='"+strUserPwd+"'"; strConn=ConfigurationSettings.AppSettings["strConn"]; SqlConnection ObjConn=new SqlConnection(strConn); ObjConn.Open(); SqlCommand ObjCmd=new SqlCommand(strSql,ObjConn); SqlDataReader ObjDR=ObjCmd.ExecuteReader(CommandBehavior.CloseConnection); if (ObjDR.Read()) { string strUserIP=Convert.ToString(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);//��ȡ�ô���IP if ((strUserIP=="")||(strUserIP==null)) { strUserIP=Convert.ToString(Request.ServerVariables["REMOTE_ADDR"]);//�������IPΪ�վ�ȡֱ��IP } if ((Convert.ToString(ObjDR["LoginIP"])!="")&&(Convert.ToString(ObjDR["LoginIP"])!=strUserIP))//�жϵ�¼IP�Ƿ����� { this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�Բ���������ָ���ĵ�¼IP��');</script>"); } else { if ((Convert.ToInt32(ObjDR["UserState"])==0)&&(strLoginID.ToUpper()!="ADMIN"))//�ж��ʺ��Ƿ��� { this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�Բ��𣬴��ʺ��ѱ����ã�');</script>"); } else { if (Convert.IsDBNull(ObjDR["LoginNum"])||ObjDR["LoginNum"]=="") { Session["UserID"]=Convert.ToString(ObjDR["UserID"]); Session["LoginID"]=Convert.ToString(ObjDR["LoginID"]); Session["UserName"]=Convert.ToString(ObjDR["UserName"]); Session["UserPwd"]=Convert.ToString(ObjDR["UserPwd"]); Response.Redirect("MainLeftMenu.aspx"); } else { int ILoingNum=Convert.ToInt32(ObjDR["LoginNum"]); int IActLoingNum=Convert.ToInt32(ObjDR["ActLoginNum"]); if (IActLoingNum >=ILoingNum)//�ж��ʺ��Ƿ��� { this.RegisterStartupScript("newWindow","<script language='javascript'>alert('�Բ����ѳ����涨�ĵ�¼������');</script>"); } else { Session["UserID"]=Convert.ToString(ObjDR["UserID"]); Session["LoginID"]=Convert.ToString(ObjDR["LoginID"]); Session["UserName"]=Convert.ToString(ObjDR["UserName"]); Session["UserPwd"]=Convert.ToString(ObjDR["UserPwd"]); ObjConn.Close(); SqlCommand SqlCmd=null; ObjConn.Open(); strSql="update UserInfo set ActLoginNum= ActLoginNum+1 where LoginID='"+strLoginID+"' and UserPwd='"+strUserPwd+"'"; SqlCmd=new SqlCommand(strSql,ObjConn); SqlCmd.ExecuteNonQuery(); string strScript=""; strScript=strScript+"<script language='javascript'>"; strScript=strScript+"newWin=window.open('MainFrame.aspx','MainFrame','titlebar=yes,menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=yes,top=0,left=0,width=screen.availWidth,height=screen.availHeight');"; strScript=strScript+"newWin.moveTo(0,0);"; strScript=strScript+"newWin.resizeTo(screen.availWidth,screen.availHeight);"; strScript=strScript+"window.opener=null;"; strScript=strScript+"window.open('','_self');"; strScript=strScript+"window.close();"; strScript=strScript+"window.parent.close();"; strScript=strScript+"</script>"; Response.Write(strScript); } } } } } else { IDCardValidation card = new IDCardValidation(); if (!card.CheckIDCard(strLoginID)) { //У�����֤�� this.RegisterStartupScript("newWindow", "<script language='javascript'>alert('���ǺϷ������֤�ţ�����ϸУ�ԣ�');</script>"); return; } this.RegisterStartupScript("newWindow", "<script language='javascript'>if(confirm('������֤����["+ strLoginID + "]+����["+ strUserPwd + "]�ĵ�һ�ε�¼������ϵͳ����Ϊ��ע�ῼ����Ϣ���Ƿ������')) location.href='/personInfo/RegistUser.aspx?u=" + strLoginID + "&n=" + strUserPwd + "';</script>"); } ObjDR.Close(); ObjConn.Dispose(); }
private bool InputTypeValidate(Control ctl) { IRyanControl c = ctl as IRyanControl; switch (_InputType) { case EMInputTypes.文本: _ValidateState = true; break; case EMInputTypes.数字: ctl.Text = StringCS.ToDBC(ctl.Text); c.RegexExpression = "^([0-9]{1,})$"; c.ErrorMessage = "请输入整数数字。格式:[0-9]!"; _ValidateState = RegexExpressionValidate(ctl); break; case EMInputTypes.货币: ctl.Text = ChgDot(StringCS.ToDBC(ctl.Text)); c.RegexExpression = "^([1-9]\\d*|0)(\\.\\d+)?$"; c.ErrorMessage = "请输入货币类型。格式[9999999999.9999]!"; _ValidateState = RegexExpressionValidate(ctl); break; case EMInputTypes.日期: ctl.Text = StringCS.ToDBC(ctl.Text); //c.RegexExpression = "^[+-]?\\d*[.]?\\d*$"; //c.ErrorMessage = "请输入日期类型。格式[2000-01-01]!"; //_ValidateState = RegexExpressionValidate(ctl); DateTime _dt = DateTime.Now; if (DateTime.TryParse(ctl.Text, out _dt)) { _ValidateState = true; } else { c.ErrorMessage = "请输入日期类型。格式[2000-01-01]!"; ShowErrorMessage(ctl, c.ErrorMessage); c.SelectAll(); _ValidateState = false; } break; case EMInputTypes.身份证: ctl.Text = StringCS.ToDBC(ctl.Text); if (IDCardValidation.CheckIDCard(ctl.Text)) { _ValidateState = true; } else { c.ErrorMessage = "请输入正确的身份证号码。"; _ValidateState = false; } break; case EMInputTypes.手机号: ctl.Text = StringCS.ToDBC(ctl.Text); c.RegexExpression = "^(13|14|15|17|18)\\d{9}$"; c.ErrorMessage = "请输入正确的手机号。"; _ValidateState = RegexExpressionValidate(ctl); break; case EMInputTypes.IP地址: ctl.Text = StringCS.ToDBC(ctl.Text); c.RegexExpression = "^((2[0-4]\\d|25[0-5]|[01]?\\d\\d?)\\.){3}(2[0-4]\\d|25[0-5]|[01]?\\d\\d?)$"; c.ErrorMessage = "请输入正确格式的IP地址。格式[202.202.202.202]。"; _ValidateState = RegexExpressionValidate(ctl); break; default: _ValidateState = true; break; } return(_ValidateState); }