Beispiel #1
0
        private IEnumerator C_Post(string command, JsonObject args, Action <JsonObject> completed, Action <string> error)
        {
            if (command != "sdk.login")
            {
                if (Controller.instance.nowLogging)
                {
                    while (!Controller.instance.isLogged)
                    {
                        yield return(0);
                    }
                }
                else
                {
                    while (!Controller.instance.isLogged)
                    {
                        var wait = true;

                        Controller.instance.Login(loginData => { wait = false; }, errorMessage => { wait = false; });

                        while (wait)
                        {
                            yield return(0);
                        }
                    }
                }
            }

            LogUtils.Log("!!!SEND " + command + " " + GoWMiniJSON.Serialize(args));
            var argsBytes = Encoding.UTF8.GetBytes(GoWMiniJSON.Serialize(args));
            var headers   = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" },
                { "Content-Length", argsBytes.Length.ToString() }
            };

            var www = new WWW(Settings.serverUrl + "/" + command, argsBytes, headers);

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                var fullError = string.Format("Server: {0} \r\nCommand: {1} \r\nArguments : {2} \r\nError: {3}\r\n", Settings.serverUrl, command, GoWMiniJSON.Serialize(args), www.error);
                Debug.LogError(fullError);
                if (error != null)
                {
                    error(www.error);
                }
            }
            else if (completed != null)
            {
                LogUtils.Log("RESPONSE:" + www.text);
                var obj = (JsonObject)GoWMiniJSON.Deserialize(www.text);
                completed(obj);
            }
        }
Beispiel #2
0
        public void Purchase(string gameKey, string playerId, string productId, string currency, float price,
                             string transactionId, string receipt, Action <JsonObject> completed = null, Action <string> error = null)
        {
            var args = new JsonObject();

            args["game"]          = gameKey;
            args["user"]          = playerId;
            args["product"]       = productId;
            args["currency"]      = currency;
            args["price"]         = price * 100;
            args["receipt"]       = GoWMiniJSON.jsonDecode(receipt);
            args["transactionId"] = transactionId;
            Post("sdk.purchase", args, completed, error);
        }