Пример #1
0
        public ActionResult Register(Vip vip, string verifyCode)
        {
            ViewBag.Title = "注册";

            if (string.IsNullOrEmpty(vip.MobileNo) || string.IsNullOrEmpty(vip.Password) || string.IsNullOrEmpty(vip.VipName))
            {
                ViewBag.Error = "请完善资料";
                return(View());
            }
            //验证手机号是否存在
            var isCheck = _dal.GetByMobile(vip.MobileNo);

            if (isCheck != null)
            {
                ViewBag.Error = "手机号已存在";
                return(View());
            }

            //验证身份证
            var user = _dal.GetByCardNo(vip.CardNo);

            if (user != null)
            {
                ViewBag.Error = "身份证号已存在";
                return(View());
            }

            //验证码
            if (Session["VerCode"] == null || Session["PhoneNo"] == null || Session["VerCode"].ToString() != verifyCode || Session["PhoneNo"].ToString() != vip.MobileNo)
            {
                ViewBag.Error = "验证码不正确";
                return(View());
            }

            var token = AccessTokenContainer.TryGetAccessToken(AppConfig.Instance.AppId, AppConfig.Instance.AppSecret);

            if (!string.IsNullOrEmpty(vip.CardImg))
            {
                var fileName = $"/upload/cardimg/{Guid.NewGuid().ToString("N")}.jpg";
                Senparc.Weixin.MP.AdvancedAPIs.MediaApi.Get(token, vip.CardImg, Server.MapPath("~" + fileName));

                vip.CardImg = fileName;
            }

            //添加用户
            vip.CreatedBy   = "system";
            vip.CreatedTime = DateTime.Now;
            vip.UpdatedBy   = "system";
            vip.UpdatedTime = DateTime.Now;
            vip.ImgPath     = "/assets/web/images/i_03.png";

            _dal.Insert(vip);

            OAuthHelper.DoOAuth(HttpContext, vip.MobileNo);

            return(new EmptyResult());
        }