Пример #1
0
        /// <summary>
        /// 获取用户相关信息
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public static UserProfile GetUserProfile(string userId)
        {
            try
            {
                string            eoopUserProfileUrl = string.Format("{0}?userId={1}", GetEoopAppSettings("EOOP_USER_PROFILE"), userId);
                string            result             = GETEoopHttpRequest(eoopUserProfileUrl);
                UserProfileResult userProfileResult  = (UserProfileResult)JsonConvert.DeserializeObject(result, typeof(UserProfileResult));

                return(userProfileResult.ok ? userProfileResult.objValue : new UserProfile());
            }
            catch (Exception ex)
            {
                Exception apiEx = new Exception("获取用户详情信息失败:" + ex.Message, ex);
                throw apiEx;
            }
        }
Пример #2
0
        public override async Task <UserProfileResult> GetProfile(UserQuery request, ServerCallContext context)
        {
            var result = await _database.GetUserProfileAsync(request.Id);

            if (!result.Success)
            {
                return(new UserProfileResult {
                    Status = Status.Failed
                });
            }

            var output = new UserProfileResult
            {
                Status   = Status.Success, Color = result.Value.Color, Money = result.Value.Money,
                Points   = result.Value.Points, Reputations = result.Value.Reputations, Vault = result.Value.Vault,
                BannerId = result.Value.BannerId
            };

            output.BadgeIds.AddRange(result.Value.BadgeIds);
            return(output);
        }
Пример #3
0
            /// <summary>
            /// Returns more info about the connected user.
            /// </summary>
            /// <remarks>
            /// <para>
            /// Form more information please see <see href="https://docs-staging.venly.io/pages/reference.html#_user_profile_arkane_api">https://docs-staging.venly.io/pages/reference.html#_user_profile_arkane_api</see>
            /// </para>
            /// <para>
            /// The <see cref="UserProfileResult.result"/> is a <see cref="UserProfile"/> object containing details about the local user.
            /// This method assumes you have already authenticated via one of the available login methods such as <see cref="Login_Facebook(string, Action{AuthenticationResult})"/>
            /// </para>
            /// </remarks>
            /// <param name="callback"></param>
            /// <returns>The Unity routine enumerator</returns>
            /// <example>
            /// <para>
            /// How to call:
            /// </para>
            /// <code>
            /// StartCoroutine(HeathenEngineering.BGSDK.API.User.GetProfile(Identity, HandleProfileResult));
            /// </code>
            /// </example>
            public static IEnumerator GetProfile(Action <UserProfileResult> callback)
            {
                if (BGSDKSettings.current == null)
                {
                    callback(new UserProfileResult()
                    {
                        hasError = true, message = "Attempted to call BGSDK.User.GetProfile with no BGSDK.Settings object applied."
                    });
                    yield return(null);
                }
                else
                {
                    if (BGSDKSettings.user == null)
                    {
                        callback(new UserProfileResult()
                        {
                            hasError = true, message = "BGSDKIdentity required, null identity provided.\nPlease initalize Settings.user before calling GetProfile", result = null
                        });
                        yield return(null);
                    }
                    else
                    {
                        UnityWebRequest www = UnityWebRequest.Get(BGSDKSettings.current.api[BGSDKSettings.current.UseStaging] + "/api/profile");
                        www.SetRequestHeader("Authorization", BGSDKSettings.user.authentication.token_type + " " + BGSDKSettings.user.authentication.access_token);

                        var co = www.SendWebRequest();
                        while (!co.isDone)
                        {
                            yield return(null);
                        }

                        if (!www.isNetworkError && !www.isHttpError)
                        {
                            var results = new UserProfileResult();
                            try
                            {
                                string resultContent = www.downloadHandler.text;
                                results.result   = JsonUtility.FromJson <UserProfile>(resultContent);
                                results.message  = "Wallet refresh complete.";
                                results.httpCode = www.responseCode;
                            }
                            catch (Exception ex)
                            {
                                results           = null;
                                results.message   = "An error occured while processing JSON results, see exception for more details.";
                                results.exception = ex;
                                results.httpCode  = www.responseCode;
                            }
                            finally
                            {
                                callback(results);
                            }
                        }
                        else
                        {
                            callback(new UserProfileResult()
                            {
                                hasError = true, message = "Error:" + (www.isNetworkError ? " a network error occured while requesting the user's wallets." : " a HTTP error occured while requesting the user's wallets."), result = null, httpCode = www.responseCode
                            });
                        }
                    }
                }
            }