コード例 #1
0
        /// <summary>
        /// 完善手机
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public ActionResult PostMobile(string mobile, string code)
        {
            if (!MyRegex.IsPhone(mobile))
            {
                return(JsonResult(APIErrCode.PhoneFormatError, "手机格式错误"));
            }

            var authenticationUser = BLLAuthentication.GetAuthenticationUser();
            var obj = new XCache().Get("Code" + authenticationUser.openid);//写入缓存

            if (obj == null)
            {
                return(JsonResult(APIErrCode.CheckCodeErr, "验证码已过期"));
            }
            if (obj.ToString().ToUpper() != code.Trim().ToUpper())
            {
                return(JsonResult(APIErrCode.CheckCodeErr, "验证码错误"));
            }
            ht_user user = BLLUser.GetUserByOpenid(authenticationUser.openid);

            if (user == null)
            {
                user          = new ht_user();
                user.addtime  = DateTime.Now;
                user.username = user.openid;
                user.openid   = authenticationUser.openid;
                user.salt     = Utils.GetSalt();
                user.password = EncryptUtil.DesEncrypt("123456", user.salt);
                user.points   = 0;
                user.money    = 0;
                if (authenticationUser.parent_id.HasValue)
                {
                    user.parent_id = authenticationUser.parent_id;
                    ht_user parentUser = BLLUser.GetUserById(authenticationUser.parent_id.Value);
                    if (parentUser != null && parentUser.parent_id.HasValue)
                    {
                        user.pparent_id = parentUser.parent_id;
                    }
                }
            }
            user.mobile   = mobile;
            user.avatar   = authenticationUser.avatar;
            user.nickname = authenticationUser.nickname;
            if (BLLUser.PostUser(user) > 0)
            {
                BLLAuthentication.LoginAuthenticationTicket(user);
                return(JsonResult(APIErrCode.Success, "提交成功"));
            }
            return(JsonResult(APIErrCode.CheckCodeErr, "提交失败"));
        }
コード例 #2
0
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCode(string mobile)
        {
            if (!MyRegex.IsPhone(mobile))
            {
                return(JsonResult(APIErrCode.PhoneFormatError, "手机格式错误"));
            }
            AuthenticationUser authenticationUser = BLLAuthentication.GetAuthenticationUser();
            string             code = HT.Utility.Utils.Number(6);

            return(JsonResult(APIErrCode.Success, "获取验证码成功", code));

            string sms_expire = BLLConfig.Get("sms_expire");
            int    expire     = Convert.ToInt32(sms_expire);
            string msg        = "";

            if (BLLSendSms.SendMsg(mobile, code, "mobile", expire, out msg))
            {
                new XCache().Add("Code" + authenticationUser.openid, code, expire);//写入缓存
                return(JsonResult(APIErrCode.Success, "获取验证码成功", code));
            }
            return(JsonResult(APIErrCode.OperateFail, msg));
        }