public override void Callback(byte[] data)
    {
        SimpleApiResponse response = null;

        try
        {
            response = Serializer.Deserialize <SimpleApiResponse>(new MemoryStream(data));
        }
        catch (Exception)
        {
            Debug.LogError("SimpleApiResponse parse error");
            ShowMessage(ErrorCode.EC_PARSE_DATA_ERROR);
        }

        if (response != null)
        {
            switch (response.code)
            {
            case "0":
            {
                SceneManager.LoadScene("home");
                break;
            }

            default:
            {
                ShowMessage(response.code);
                break;
            }
            }
        }
    }
Exemple #2
0
    public override void Callback(byte[] data)
    {
        SimpleApiResponse response = null;

        try
        {
            response = Serializer.Deserialize <SimpleApiResponse>(new MemoryStream(data));
        }
        catch (Exception)
        {
            Debug.LogError("SimpleApiResponse parse error");
            ShowMessage(ErrorCode.EC_PARSE_DATA_ERROR);
        }

        if (response != null)
        {
            Debug.Log("logout response:" + response);
            switch (response.code)
            {
            case "0":
            {
                DataHelper.GetInstance().CleanProfile(dbManager);
                SceneManager.LoadScene("login");
                break;
            }

            default:
            {
                ShowMessage(response.code);
                break;
            }
            }
        }
    }
        private void ProcessSimpleApiResponse(SimpleApiResponse response)
        {
            JToken jsonResponse = null;

            if (!string.IsNullOrEmpty(response.StringContent))
            {
                try
                {
                    jsonResponse = JToken.Parse(response.StringContent);
                }
                catch (Exception e)
                {
                    jsonResponse = JObject.Parse(@"{""nonJsonResponse"": """", ""error"": """"}");
                    jsonResponse["nonJsonResponse"] = response.StringContent;
                    jsonResponse["error"]           = e.ToString();
                }
            }
            scenarioContext.SetHttpClientActualResponse(response, jsonResponse);
        }
    private void QueryDiamonAmountCallback(byte[] data)
    {
        dataType = 0;
        SimpleApiResponse response = null;

        try
        {
            response = Serializer.Deserialize <SimpleApiResponse>(new MemoryStream(data));
        }
        catch (Exception)
        {
            Debug.LogError("SimpleApiResponse parse error");
            ShowMessage(ErrorCode.EC_PARSE_DATA_ERROR);
        }

        if (response != null)
        {
            switch (response.code)
            {
            case "0":
            {
                string diamondAmount = response.ext1;
                ShowBalance(DataHelper.GetInstance().LoadSession(dbManager).Mobile + "," + diamondAmount);
                dataType = 3;
                CheckGameStatus();
                break;
            }

            default:
            {
                Debug.LogError("QueryDiamonAmountCallback:" + response.code);
                ShowMessage(response.code);
                break;
            }
            }
        }
    }
Exemple #5
0
        void OnRequestFinished(HTTPRequest req, HTTPResponse resp)
        {
            HttpFinished();
            switch (req.State)
            {
            // The request finished without any problem.
            case HTTPRequestStates.Finished:
                if (resp.StatusCode == 200)
                {
                    bool isNormal = false;
                    if (resp.Headers.ContainsKey("normal"))
                    {
                        isNormal = "true".Equals(resp.Headers["normal"][0]);
                    }
                    byte[] protoBytes = GZipHelper.Decompress(DESHelper.DecodeBytes(resp.Data, AppContext.GetInstance().getDesKey()));
                    //Debug.Log("isNormal:" + isNormal);
                    if (!isNormal)
                    {
                        SimpleApiResponse response = null;
                        try
                        {
                            response = Serializer.Deserialize <SimpleApiResponse>(new MemoryStream(protoBytes));
                            Debug.Log("error response:" + response);
                        }
                        catch (Exception)
                        {
                            Debug.LogError("HttpMonoBehaviour SimpleApiResponse parse error");
                            ShowMessage(ErrorCode.EC_PARSE_DATA_ERROR);
                        }
                        if (response != null)
                        {
                            ShowMessage(response.code);
                        }
                    }
                    else
                    {
                        Callback(protoBytes);
                    }
                }
                else
                {
                    ShowMessage(ErrorCode.EC_SERVER_ERROR);
                }
                break;

            // The request finished with an unexpected error.
            // The request's Exception property may contain more information about the error.
            case HTTPRequestStates.Error:
                Debug.LogError("Request Finished with Error! " +
                               (req.Exception != null ?
                                (req.Exception.Message + "\n" + req.Exception.StackTrace) :
                                "No Exception"));
                ShowMessage(ErrorCode.EC_NETWORK_UNREACHED);
                break;

            // The request aborted, initiated by the user.
            case HTTPRequestStates.Aborted:
                Debug.LogWarning("Request Aborted!");
                ShowMessage(ErrorCode.EC_NETWORK_UNREACHED);
                break;

            // Ceonnecting to the server timed out.
            case HTTPRequestStates.ConnectionTimedOut:
                Debug.LogError("Connection Timed Out!");
                ShowMessage(ErrorCode.EC_NETWORK_TIMEOUT);
                break;

            // The request didn't finished in the given time.
            case HTTPRequestStates.TimedOut:
                Debug.LogError("Processing the request Timed Out!");
                ShowMessage(ErrorCode.EC_NETWORK_TIMEOUT);
                break;

            default:
                Debug.LogError("Connection Error!");
                ShowMessage(ErrorCode.EC_NETWORK_TIMEOUT);
                break;
            }
        }
 public static void SetHttpClientActualResponse(this ScenarioContext context, SimpleApiResponse apiResponse, JToken jsonResponse)
 {
     context.Set(apiResponse, Field.ActualHttpResponse);
     context.Set(jsonResponse, Field.ActualJsonResponse);
 }