public IHttpActionResult Register(JObject request) { Logger.WriterLogger("Account.Register, Params: " + request.ToString(), LoggerType.Info); ParamRegister param = new ParamRegister(); try { param = request.ToObject <ParamRegister>(); } catch { //throw new CommonException(40100); return(base.JsonFaultResult(new CommonException(40100).GetMessage(), request.ToString())); } string accessToken = param.accessToken; string sessionKey = ""; string sessionSecret = ""; // 验证令牌 int accessTookenCode = VerifyAccessToken(accessToken, out sessionKey, out sessionSecret); if (accessTookenCode > 0) { return(base.JsonFaultResult(new CommonException(accessTookenCode).GetMessage(), request.ToString())); } string username = param.username; string code = param.code; string password = param.password; int accountType = param.accountType; int channel = param.channel; int platform = param.platform; string ver = param.ver; // 保存访问信息 base.SaveVisitInfo("", channel, platform, ver); string decryptUsername = username; string decryptPassword = password; string decryptCode = code; if ((platform == 3 && base.AndroidIsEncryption) || (platform == 2 && base.IOSIsEncryption) || (platform == 1 && base.PCIsEncryption)) { decryptUsername = base.Decrypt(username, sessionKey, sessionSecret); //TODO 解密 decryptPassword = base.Decrypt(password, sessionKey, sessionSecret); //decryptCode = base.Decrypt(code, sessionKey, sessionSecret); } string email = ""; string mobile = ""; switch (accountType) { case 1: break; case 2: mobile = decryptUsername; //email = decryptUsername + "@mail.haimylife.com"; if (string.IsNullOrEmpty(decryptUsername)) { return(base.JsonFaultResult(new FaultInfo(40100, "手机号码为空"), request.ToString())); } if (!System.Text.RegularExpressions.Regex.IsMatch(decryptUsername, "^(13|14|15|17|18)\\d{9}$")) { return(base.JsonFaultResult(new FaultInfo(40100, "请输入正确的手机号码"), request.ToString())); } if (UserHelper.IsExistCellPhoneAndUserName(decryptUsername) > 0) { return(base.JsonFaultResult(new FaultInfo(40100, "已经存在相同的手机号码"), request.ToString())); } Verify verifyto = new TelVerifyDao().GetVerify(decryptUsername, 1); if (!(verifyto != null && verifyto.VerifyCode == decryptCode)) { return(base.JsonFaultResult(new CommonException(40205).GetMessage(), request.ToString())); } break; case 3: email = decryptUsername; break; } string msg = ""; int provinceId = 0; int userId = 0; string sessionId = Guid.NewGuid().ToString(); if (string.IsNullOrEmpty(decryptUsername) || string.IsNullOrEmpty(decryptPassword)) { return(base.JsonFaultResult(new FaultInfo(40200, "缺少必填参数"), request.ToString())); } //注册类型为3时检测邮箱 if (accountType == 3) { if (string.IsNullOrEmpty(email.Trim())) { return(base.JsonFaultResult(new FaultInfo(40200, "邮箱帐号不能为空"), request.ToString())); } if (email.Length > 256 || !System.Text.RegularExpressions.Regex.IsMatch(email, "([a-zA-Z\\.0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z0-9_-]{2,4}){1,2})")) { return(base.JsonFaultResult(new FaultInfo(40200, "错误的邮箱帐号"), request.ToString())); } } //判断邀请码是否存在 if (!string.IsNullOrWhiteSpace(param.recemmendCode)) { if (!MemberHelper.IsExsitRecommendCode(param.recemmendCode.Trim(), 0)) { return(base.JsonFaultResult(new FaultInfo(40100, "邀请码错误,请填写正确的邀请码或者选择不填"), request.ToString())); } } Member member = new Member(UserRole.Member); member.GradeId = MemberProcessor.GetDefaultMemberGrade(); member.SessionId = Globals.GetGenerateId(); member.Username = decryptUsername; member.Password = decryptPassword; member.PasswordFormat = System.Web.Security.MembershipPasswordFormat.Hashed; member.TradePasswordFormat = System.Web.Security.MembershipPasswordFormat.Hashed; member.TradePassword = decryptPassword; member.IsApproved = true; member.RealName = string.Empty; member.Address = string.Empty; member.MembershipUser.SessionId = sessionId; member.CellPhone = mobile; member.CreateDate = DateTime.Now; //member.MembershipUser.MobilePIN = mobile; // 手机注册默认验证手机号码 if (accountType == 2) { member.CellPhoneVerification = true; } if (accountType == 3) { member.Email = email; } member.UserType = this.CovertToUserType(param.platform); CreateUserStatus createUserStatus = MemberProcessor.CreateMember(member); if (createUserStatus == CreateUserStatus.DuplicateUsername || createUserStatus == CreateUserStatus.DisallowedUsername) { msg = "已经存在该用户名"; } if (createUserStatus == CreateUserStatus.DuplicateEmailAddress) { msg = "已经存在相同的邮箱"; } if (createUserStatus == CreateUserStatus.DuplicateCellphone) { msg = "已经存在相同的手机号码"; } if (createUserStatus == CreateUserStatus.Created) { Messenger.UserRegister(member, decryptPassword); member.OnRegister(new UserEventArgs(member.Username, decryptPassword, null)); long timestamp = long.Parse(DateTime.Now.AddSeconds(USER_CACHE_KEEP_TIME).ToString("yyyyMMddHHmmss")); string authenTicket = SecurityUtil.MD5Encrypt(sessionId + timestamp.ToString() + sessionSecret).ToLower(); string authenUserId = sessionId.ToLowerGuid(); CacheUserSet(authenUserId, authenTicket, timestamp, member.UserId); #region ==判断是否有优惠卷 if (!MemberHelper.NewUserSendRegisterCoupon(member)) { msg = "注册优惠卷赠送失败"; return(base.JsonFaultResult(new FaultInfo(40200, msg), request.ToString())); } #endregion #region == 判断是否有邀请码 string sourcechars = ConfigurationManager.AppSettings["sourcechars"]; string newsourcechars = ConfigurationManager.AppSettings["newsourcechars"]; string rcode = param.recemmendCode; if (!string.IsNullOrWhiteSpace(rcode)) { string currcode = BaseConvertHelper.BaseConvert(rcode, newsourcechars, sourcechars); string useredId = MemberHelper.GetUserIdByRecommendCode(currcode); if (!string.IsNullOrWhiteSpace(useredId) && !string.IsNullOrWhiteSpace(currcode)) { // 插入到邀请码记录表 MemberHelper.AddRecommendCodeRecord(member.UserId, Convert.ToInt32(useredId), currcode, rcode); } } #endregion StandardResult <RegisterOrLoginResult> okResult = new StandardResult <RegisterOrLoginResult>(); okResult.code = 0; okResult.msg = "注册成功,恭喜您,50元现金券已经打到您的海美账户了,现在就去购物吧!"; okResult.data = new RegisterOrLoginResult() { DisplayName = decryptUsername, AuthenTicket = authenTicket, AuthenUserId = authenUserId, Timestamp = timestamp }; return(base.JsonActionResult(okResult)); } else { msg = "注册用户失败," + msg; } return(base.JsonFaultResult(new FaultInfo(40200, msg), request.ToString())); }