public static async Task<bool> SaveUserPreRegisterToRedis(string preRegisterOpenid, string preRegisterAccount = "", string preRegisterValidationCode = "", string preRegisterTryTimes = "")
        {
            UserInfoRedis obj = new UserInfoRedis();
            obj.PreRegisterAccount = preRegisterAccount;
            obj.PreRegisterValidationCode = preRegisterValidationCode;
            obj.PreRegisterTryTimes = preRegisterTryTimes;
            obj.Openid = preRegisterOpenid;

            return await RedisManager.SaveObjectAsync(obj);
        }
        public static async Task<bool> SaveOAuthUserTokenAsync(OAuthAccessTokenResult result)
        {
            double now = CommonHelper.GetUnixTimeNow();

            UserInfoRedis u = new UserInfoRedis();
            u.Openid = result.openid;
            u.Unionid = result.unionid;
            u.AccessToken = result.access_token;
            u.ExpireIn = (now + result.expires_in).ToString();
            u.RefreshToken = result.refresh_token;
            return await RedisManager.SaveObjectAsync(u);
        }
 public static async Task<bool> CheckUserInfoPhoto(UserInfo userinfo, UserInfoRedis userinfoRedis)
 {
     bool result = false;
     if(string.IsNullOrEmpty(userinfo.Photo) || userinfo.Photo == "pic/header/HeaderDefault.jpg")
     {
         userinfo.Photo = WebApiHelper.UploadHeadPic(userinfoRedis.HeadImageUrl.Substring(0, userinfoRedis.HeadImageUrl.LastIndexOf("/0")));
         result = true;
     }
     if(!result && await WXAuthHelper.IsTester(userinfoRedis.Openid))
     {
         userinfo.Photo = WebApiHelper.UploadHeadPic(userinfoRedis.HeadImageUrl.Substring(0, userinfoRedis.HeadImageUrl.LastIndexOf("/0")));
         result = true;
     }
     return result;
 }
        /// <summary>
        /// 在微信页面认证后如果需要绑定用户的OPenid,则需要存储必要的用户信息。
        /// 头像,昵称等。
        /// </summary>
        /// <param name="userinfo"></param>
        /// <returns></returns>
        public static async Task<bool> SaveOAuthUserInfoToRedis(OAuthUserInfo userinfo)
        {
            LogHelper.LogInfoAsync(typeof(object), "nick name is:" + userinfo.nickname);
            UserInfoRedis obj = new UserInfoRedis();
            obj.City = userinfo.city;
            obj.Country = userinfo.country;
            obj.Province = userinfo.province;
            obj.HeadImageUrl = userinfo.headimgurl;
            obj.NiceName = userinfo.nickname;
            obj.Sex = userinfo.sex.ToString();
            obj.Openid = userinfo.openid;
            obj.Unionid = userinfo.unionid;

            return await RedisManager.SaveObjectAsync(obj);
        }
Beispiel #5
0
        public async Task<UserInfoRedis> TestSave()
        {
            UserInfoRedis obj = new UserInfoRedis();
            obj.City = "city";
            obj.Country = "userinfo.country";
            obj.Province = "userinfo.province";
            obj.HeadImageUrl = "userinfo.headimgurl";
            obj.NiceName = "userinfo.nickname";
            obj.Sex = "userinfo.sex.ToString()";
            obj.Openid = "userinfo.openid";
            obj.Unionid = "userinfo.unionid";

            double now = CommonHelper.GetUnixTimeNow();
            obj.AccessToken = "result.access_token";
            obj.ExpireIn = (now + 7200).ToString();
            obj.RefreshToken = "result.refresh_token";
            await RedisManager.SaveObjectAsync(obj);

            UserInfoRedis u = await RedisManager.GetObjectFromRedis<UserInfoRedis>("oYI97wWcPgbNVXrdm7NSNjT5qZYY");
            return u;
        }
Beispiel #6
0
        public async Task<HttpResponseMessage> PostComplement([FromBody]ComplementParameter registerParam, [FromUri]string type)
        {
            string openid = registerParam.openID;
            string university = registerParam.university;
            string faculty = registerParam.faculty;
            int researchFieldId = registerParam.researchFieldId;
            short degree = registerParam.degree;
            short enrollment = registerParam.enrollment;
            string gender = registerParam.Gender;
            string name = registerParam.name;
            string position = registerParam.position;
            short isBusiness = registerParam.isBusiness;
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(university) || string.IsNullOrEmpty(faculty) || researchFieldId == 0 || string.IsNullOrEmpty(gender) || string.IsNullOrEmpty(name))
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            if (string.IsNullOrEmpty(position) && isBusiness == 0)
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }
            if (isBusiness == 2 && enrollment == 0)
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.InvalidArguments);
            }

            var preRegisterRedis = await UserInfoControllerHelper.GetUserInfoRedisByOpenid(openid);
            string preRegisterAccount = preRegisterRedis.PreRegisterAccount;
            pre_register preRegister = null;

            if (type != "update")
            {
                using (UserRepository userRepository = new UserRepository())
                {
                    userinfo = await userRepository.GetUserInfoByAccount(preRegisterAccount);
                    preRegister = await userRepository.GetPreRegisterByOpenid(openid);
                }
                if (userinfo != null)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.AccountExist);
                if (preRegister == null)
                    return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.NotFound);
            }

            //更新数据库的userinfo
            bool result = await UserInfoControllerHelper.SaveUserInfo(registerParam, preRegister);
            if (result)
            {
                //更新redis的性别
                UserInfoRedis redisUser = new UserInfoRedis();
                redisUser.Openid = openid;
                redisUser.Sex = gender;
                await RedisManager.SaveObjectAsync(redisUser);

                using (UserRepository userRepository = new UserRepository())
                {
                    userinfo = await userRepository.GetUserInfoByOpenid(openid);
                }

                if (await ComplexLocationManager.UpdateComplexLocationAsync(openid, userinfo.IsBusiness ?? 0, int.Parse(userinfo.Gender), userinfo.ResearchFieldId ?? 0))
                {
                    //位置索引添加供筛选字段
                }

                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Success);
            }
            else
            {
                return WebApiHelper.HttpRMtoJson(null, HttpStatusCode.OK, customStatus.Fail);
            }
        }