IEnumerator coSendCoin()
    {
        string        url  = MG.WalletURL + "sendDion";
        body_sendDion body = new body_sendDion {
            sender = "company",
            amount = MG.AccumulateAmount,
            memo   = "Earn points"
        };
        string json = JsonConvert.SerializeObject(body);

        byte[] bytes = System.Text.Encoding.ASCII.GetBytes(json);
        using (UnityWebRequest www = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST)) {
            UploadHandlerRaw      uH = new UploadHandlerRaw(bytes);
            DownloadHandlerBuffer dH = new DownloadHandlerBuffer();

            www.uploadHandler   = uH;
            www.downloadHandler = dH;
            www.SetRequestHeader("Content-Type", "application/json");
            yield return(www.SendWebRequest());


            coWait_loop     = false;
            tx_recvLog.text = "";

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.LogError("인터넷에 연결되어있는지 확인하세요");
                tx_recvLog.text = "<color=red>" + www.error + "</color>";
                but_X.gameObject.SetActive(true);
            }
            else
            {
                if (www.responseCode == 200)  //성공
                {
                    var    jo   = JObject.Parse(www.downloadHandler.text);
                    string txID = jo["transaction_id"].Value <string>();
                    tx_recvLog.text = "Transfer completed \nTxID = " + txID;
                    Debug.Log(tx_recvLog.text);

                    MG.dion_Stock[0] -= (int)MG.AccumulateAmount;
                    home.TotalUpdate();
                    MG.AccumulateAmount = 0m;

                    yield return(new WaitForSeconds(0.5f));

                    home.BalanceUpdate();
                    yield return(new WaitForSeconds(0.2f));

                    viewPan.OpenCloseObjectAnimation();
                }
                else  // Fail
                {
                    tx_recvLog.text = "<color=red>" + www.error + "</color>";
                    but_X.gameObject.SetActive(true);
                }
            }
        }
    }
Beispiel #2
0
    IEnumerator coSendCoin()
    {
        string        url  = MG.WalletURL + "sendDion";
        body_sendDion body = new body_sendDion {
            sender = "user",
            amount = send_Amount,
            memo   = "Payment at the " + tx_sendDest.text
        };
        string json = JsonConvert.SerializeObject(body);

        byte[] bytes = System.Text.Encoding.ASCII.GetBytes(json);
        using (UnityWebRequest www = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST)) {
            UploadHandlerRaw      uH = new UploadHandlerRaw(bytes);
            DownloadHandlerBuffer dH = new DownloadHandlerBuffer();

            www.uploadHandler   = uH;
            www.downloadHandler = dH;
            www.SetRequestHeader("Content-Type", "application/json");
            yield return(www.SendWebRequest());

            coWait_loop       = false;
            tx_sendDebug.text = "";

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.LogError("인터넷에 연결되어있는지 확인하세요");
                tx_sendDebug.text = "<color=red>" + www.error + "</color>";
            }
            else
            {
                if (www.responseCode == 200)  //성공
                {
                    var    jo   = JObject.Parse(www.downloadHandler.text);
                    string txID = jo["transaction_id"].Value <string>();
                    tx_sendDebug.text = "Transfer completed \nTxID = " + txID;
                    Debug.Log(tx_sendDebug.text);
                    home.BalanceUpdate();
                    bt_Success.gameObject.SetActive(true);
                }
                else  // Fail
                {
                    tx_sendDebug.text = "<color=red>" + www.error + "</color>";
                }
            }
        }
    }