コード例 #1
0
    public override IEnumerator doReauest()
    {
        WWWForm wf = new WWWForm();

//        wf.AddField("userid", Game.UserMgr.PlayerId);
        wf.AddField("identifier", GetRandomIdentifier());
        wf.AddField("checksum", checkSum);
        wf.AddField("platform", GlobalConfig.GetPlatformId.ToString());
        wf.AddField("version", GlobalConfig.GetVersion);

        if (null != args)
        {
            foreach (string key in args.Keys)
            {
                wf.AddField(key, args[key]);
            }
        }

        WWW sdw = new WWW(GlobalConfig.URL_ROOT + uri, wf);

        yield return(sdw);

        if (sdw.error != null)
        {
            Debug.LogWarning("uri:" + uri + "; msg:" + sdw.error);
            if (null != OnError)
            {
                OnError(NetCode.Unknown, sdw.error);
            }

            yield break;
        }
        if (sdw.error == null)
        {
            try
            {
                string result = sdw.text;
                Debug.Log("Return Json:" + result);
                Hashtable sdd = MiniJSON2.jsonDecode(result) as Hashtable;

                int     code    = sdd["code"].GetJsonConverter().toInt();
                NetCode netCode = (NetCode)code;

                if (NetCode.Success == netCode)
                {
                    if (sdd.ContainsKey("data"))
                    {
                        object    ob   = sdd["data"];
                        Hashtable data = ob as Hashtable;
                        if (null != OnComplete)
                        {
                            OnComplete(data);
                        }
                    }
                    else
                    {
                        if (null != OnComplete)
                        {
                            OnComplete(sdd);
                        }
                    }
                }
                else
                {
                    string msg = "";
                    if (sdd.ContainsKey("msg"))
                    {
                        msg = sdd["msg"].GetJsonConverter().toStr();
                    }

                    Debug.LogWarning("Return Error:" + netCode.ToString() + "; msg:" + msg);
                    if (null != OnError)
                    {
                        OnError(netCode, msg);
                    }
                }
            }
            catch (System.Exception e)
            {
                Debug.LogWarning("Return Error:" + NetCode.JsonError.ToString() + "; msg:" + e.Message);
                if (null != OnError)
                {
                    OnError(NetCode.JsonError, e.Message);
                }
            }
        }
    }
コード例 #2
0
ファイル: HttpRequestXXTEA.cs プロジェクト: gitshuaidong/MJ
    public override IEnumerator doReauest()
    {
        bool hasLoadingPage = Game.UIMgr.IsSceneActive(UIPage.LoadingPage);

        if (useMask && !hasLoadingPage)
        {
            Game.LoadingPage.Show(LoadPageType.OnlyMask);
        }

        string url = GlobalConfig.URL_ROOT + uri;

        if (args == null)
        {
            args = new Dictionary <string, string>();
        }

        CheckCommonParam();

        WWWForm wwwform = getForm(url);

        WWW www = new WWW(url, wwwform.data, GetHeader(wwwform));

        yield return(www);

        while (!www.isDone)
        {
            yield return(0);
        }

        if (www.error == null)
        {
            NetCode   netCode = NetCode.Unknown;
            Hashtable sdd     = null;
            string    msg     = "";
            try
            {
                string jsons = www.text;
                // 解密
#if UNITY_IOS || UNITY_IPHONE
                Debug.Log(url + ": net jsons == " + jsons);
#elif UNITY_ANDROID
                jsons = GetJsonFormXXTea(jsons, url);
                Debug.Log(url + ": net jsons == " + jsons);
#endif

                sdd = MiniJSON2.jsonDecode(jsons) as Hashtable;

                int code = sdd["error_code"].GetJsonConverter().toInt();
                netCode = (NetCode)code;
            }
            catch (System.Exception e)
            {
                netCode = NetCode.JsonError;
                msg     = e.Message;
            }

            if (NetCode.Success == netCode)
            {
                Hashtable data = null;
                if (sdd.ContainsKey("data"))
                {
                    object ob = sdd["data"];
                    data = ob as Hashtable;
                }

                if (null != OnComplete)
                {
                    OnComplete(data);
                }
            }
            else
            {
                if (netCode != NetCode.JsonError && null != sdd && sdd.ContainsKey("msg"))
                {
                    msg = sdd["msg"].GetJsonConverter().toStr();
                }

                Debug.LogWarning("Return Error:" + netCode.ToString() + "; msg:" + msg);

                if (null != OnError)
                {
                    OnError(netCode, msg);
                }
            }

            if (useMask && !hasLoadingPage)
            {
                Game.LoadingPage.Hide();
            }
        }
    }