Пример #1
0
        /// <summary>
        /// 微信授权登录
        /// </summary>
        /// <param name="wxAuth"></param>
        /// <returns></returns>
        public MsgModel AuthLogin(WXAuth wxAuth)
        {
            var wxDecrypt   = WxDecrypt(wxAuth.EncryptData, wxAuth.SessionId, wxAuth.IV);
            var dict        = JsonConvert.DeserializeObject <Dictionary <string, object> >(wxDecrypt);
            var phoneNumber = dict["phoneNumber"].ToString();
            var user        = _baseService.GetModels(a => a.phone == phoneNumber).SingleOrDefault();

            if (user != null) // 登录
            {
                return(_jwtAuthService.Login(user.username, user.password));
            }
            else // 注册
            {
                // 加密登录密码
                var initPassword = PasswordEncoder.Encode(CommonUtils.GetStringRandom(10));
                var userDto      = new SysUser
                {
                    phone    = phoneNumber,
                    password = initPassword
                };
                return(_jwtAuthService.SignUp(userDto));
            }
        }