protected override AuthUser GetUserInfo(AuthToken authToken)
        {
            string response = DoGetUserInfo(authToken);
            var    jsonObj  = response.ParseObject();

            this.checkResponse(jsonObj);

            // 返回 OpenId 或其他,均代表非当前企业用户,不支持
            if (!jsonObj.ContainsKey("UserId"))
            {
                throw new Exception(AuthResponseStatus.UNIDENTIFIED_PLATFORM.GetDesc());
            }
            string userId             = jsonObj.GetString("UserId");
            string userDetailResponse = getUserDetail(authToken.AccessToken, userId);
            var    userDetailObj      = userDetailResponse.ParseObject();

            this.checkResponse(userDetailObj);

            var authUser = new AuthUser();

            authUser.Username = userDetailObj.GetString("name");
            authUser.Nickname = userDetailObj.GetString("alias");
            authUser.Avatar   = userDetailObj.GetString("avatar");
            authUser.Location = userDetailObj.GetString("address");
            authUser.Email    = userDetailObj.GetString("email");
            authUser.Uuid     = userDetailObj.GetString("userId");
            authUser.Token    = authToken;
            authUser.Source   = source.GetName();
            authUser.Gender   = GlobalAuthUtil.GetWechatRealGender(userDetailObj.GetString("gender"));

            authUser.OriginalUser    = userDetailObj;
            authUser.OriginalUserStr = response;
            return(authUser);
        }
Example #2
0
        protected override AuthUser GetUserInfo(AuthToken authToken)
        {
            string openId = authToken.OpenId;

            string response = DoGetUserInfo(authToken);
            var    jsonObj  = response.ParseObject();

            this.checkResponse(jsonObj);

            //string location = String.format("%s-%s-%s", object.getString("country"), object.getString("province"), object.getString("city"));
            string location = $"{jsonObj.GetString("country")}-{jsonObj.GetString("province")}-{jsonObj.GetString("city")}";

            if (jsonObj.ContainsKey("unionid"))
            {
                authToken.UnionId = jsonObj.GetString("unionid");
            }

            var authUser = new AuthUser();

            authUser.Username = jsonObj.GetString("nickname");
            authUser.Nickname = jsonObj.GetString("nickname");
            authUser.Avatar   = jsonObj.GetString("headimgurl");
            authUser.Location = location;
            authUser.Uuid     = openId;
            authUser.Gender   = GlobalAuthUtil.GetWechatRealGender(jsonObj.GetString("sex"));
            authUser.Token    = authToken;
            authUser.Source   = source.GetName();

            authUser.OriginalUser    = jsonObj;
            authUser.OriginalUserStr = response;

            return(authUser);
        }