コード例 #1
0
    public WWW HttpRequestWithSession(string url, WWWForm form)
    {
        EginTools.Log(url);

        string    cookie         = (EginUser.Instance.session != null)?EginUser.Instance.session:"";
        Hashtable requestHeaders = new Hashtable();

        requestHeaders.Add("Cookie", cookie);


        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers.Add("Cookie", cookie);

        if (form == null)
        {
            form = new WWWForm();
        }
        form.AddField("Cookie", cookie);

        if (form != null)
        {
            long   ms    = EginTools.nowMinis();
            long   mms   = ms + EginTools.localBeiJingTime;
            string ccode = EginTools.encrypTime(mms.ToString());

            form.AddField("client_code", ccode);
        }

        WWW www = new WWW(url, form.data, headers);

        return(www);
    }
コード例 #2
0
    public HttpResult BaseResultSocket(WWW www)
    {
        HttpResult result = new HttpResult();

        if (www.error != null)
        {
            EginTools.Log("Http Failed: " + www.error);
            PlatformGameDefine.playform.swithGameHostUrl();                             //切换游戏IP
        }
        else
        {
            string tempResultStr = www.text.Trim();
            EginTools.Log("base socket:::" + tempResultStr);

            JSONObject resultObj = new JSONObject(tempResultStr);

            if (resultObj)
            {
                result.resultObject = resultObj;
                result.resultType   = HttpResult.ResultType.Sucess;
            }
            else
            {
                Debug.Log("解析出错了---HttpConnect.cs -- 60");
            }
        }
        return(result);
    }
コード例 #3
0
    public HttpResult BaseResultSocket2(WWW www)
    {
        HttpResult result = new HttpResult();

        if (www.error != null)
        {
            EginTools.Log("Http Failed: " + www.error);
            PlatformGameDefine.playform.swithGameHostUrl();             //切换游戏IP
        }
        else
        {
            string tempResultStr = www.text.Trim();
            EginTools.Log(tempResultStr);

            if ("ok".Equals(tempResultStr))
            {
                result.resultType = HttpResult.ResultType.Sucess;
            }
            else
            {
                result.resultObject = ZPLocalization.Instance.Get("HttpConnectError");
            }
        }
        return(result);
    }
コード例 #4
0
    public WWW HttpRequestAli(string url)
    {
        EginTools.Log(url);

        WWW www = new WWW(url);

        return(www);
    }
コード例 #5
0
    IEnumerator refreshYanImg()
    {
        WWW www2 = HttpConnect.Instance.HttpRequest(ConnectDefine.YAN_ZHENG_URL, null);

        yield return(www2);

        HttpResult result2 = HttpConnect.Instance.BaseResult(www2);
        string     yanUrl;

        if (HttpResult.ResultType.Sucess == result2.resultType)
        {
            JSONObject resultObj2 = new JSONObject(result2.resultObject.ToString());
            yanUrl             = ConnectDefine.HostURL + resultObj2["imageurl"].str;
            captcha_hiddentext = resultObj2["hiddentext"].str;
            EginTools.Log("yanUrl:" + yanUrl);

            WWW www = new WWW(yanUrl);
            yield return(www);

            UITexture uiT = kYanImg.GetComponent <UITexture>();
            uiT.mainTexture = www.texture;

            errNum  = 0;
            isClick = true;
        }
        else
        {
            errNum++;
            if (!result2.isSwitchHost)
            {
                PlatformGameDefine.playform.swithWebHostUrl();
            }
            if (errNum < 4)
            {
                StartCoroutine(refreshYanImg());
            }
            else
            {
                isClick = true;
            }
        }
    }
コード例 #6
0
    public WWW HttpRequest(string url, WWWForm form)
    {
        EginTools.Log(url);

        if (form == null)
        {
            form = new WWWForm();
        }

        if (form != null)
        {
            long   ms    = EginTools.nowMinis();
            long   mms   = ms + EginTools.localBeiJingTime;
            string ccode = EginTools.encrypTime(mms.ToString());
            form.AddField("client_code", ccode);
        }


        WWW www = (form == null) ? new WWW(url) : new WWW(url, form);

        return(www);
    }
コード例 #7
0
    /* ------ Register ------ */
    public HttpResult RegisterResult(WWW www)
    {
        HttpResult result = new HttpResult();

        if (www.error != null)
        {
            EginTools.Log("Http Failed: " + www.error);
        }
        else
        {
            string tempResultStr = www.text.Trim();
            EginTools.Log(tempResultStr);

            if ("ok".Equals(tempResultStr))
            {
                result.resultType = HttpResult.ResultType.Sucess;
            }
            else if (tempResultStr.Length > 0)
            {
                JSONObject resultObj = new JSONObject(tempResultStr);
                if (resultObj.type == JSONObject.Type.NULL)
                {
                    result.resultObject = Regex.Unescape(tempResultStr);
                }
                else
                {
                    result.resultObject = Regex.Unescape(resultObj["error"].str);
                }
            }
            else
            {
                result.resultObject = ZPLocalization.Instance.Get("HttpConnectError");
            }
        }
        return(result);
    }
コード例 #8
0
    private IEnumerator DoCheckBaiduTime()
    {
        if (m_CurTimeOutCount >= mTimeUrl.Length * 2)//超时重连只进行1次
        {
            EginTools.localBeiJingTime = 0;
            yield break;
        }



        using (WWW www = HttpConnect.Instance.HttpRequestAli(mTimeUrl[m_CurTimeOutCount / 2]))
        {
            bool isTimeOut = false;
            yield return(StartCoroutine(CheckTimeOut(www, () => isTimeOut = true)));

            if (isTimeOut)
            {
                m_CurTimeOutCount++;
                StartCoroutine(DoCheckBaiduTime());
                yield break;
            }

            yield return(www);

            Debug.Log("加载网络时间");
            if (www.error != null)
            {
                EginTools.Log("加载网络时间出错: " + www.error);
                EginTools.localBeiJingTime = 0;
            }
            else
            {
                string tempResultStr = www.text.Trim();
                Debug.Log("网络时间数据打印====>" + tempResultStr);

                long time = 0;
                //第一个和第二个时间网站的数据处理
                if (m_CurTimeOutCount / 2 == 0 || m_CurTimeOutCount / 2 == 1)
                {
                    try
                    {
                        int firstIndex  = tempResultStr.IndexOf("new Date().getTime();", 0);
                        int secondIndex = tempResultStr.IndexOf("s=document.URL", firstIndex);

                        string childStr = tempResultStr.Substring(firstIndex + 21, secondIndex - firstIndex - 21);

                        //Debug.Log("截取的数据====>" + childStr);
                        //  nyear=2016;nmonth=5;nday=12;nwday=4;nhrs=16;nmin=0;nsec=47;
                        int firstTinmeIndex  = 0;
                        int secondTinmeIndex = 0;
                        firstTinmeIndex  = childStr.IndexOf("nyear=", firstTinmeIndex);
                        secondTinmeIndex = childStr.IndexOf(";", firstTinmeIndex);
                        int year = int.Parse(childStr.Substring(firstTinmeIndex + 6, secondTinmeIndex - firstTinmeIndex - 6));

                        firstTinmeIndex  = childStr.IndexOf("nmonth=", firstTinmeIndex);
                        secondTinmeIndex = childStr.IndexOf(";", firstTinmeIndex);
                        int month = int.Parse(childStr.Substring(firstTinmeIndex + 7, secondTinmeIndex - firstTinmeIndex - 7));

                        firstTinmeIndex  = childStr.IndexOf("nday=", firstTinmeIndex);
                        secondTinmeIndex = childStr.IndexOf(";", firstTinmeIndex);
                        int day = int.Parse(childStr.Substring(firstTinmeIndex + 5, secondTinmeIndex - firstTinmeIndex - 5));

                        firstTinmeIndex  = childStr.IndexOf("nhrs=", firstTinmeIndex);
                        secondTinmeIndex = childStr.IndexOf(";", firstTinmeIndex);
                        int hour = int.Parse(childStr.Substring(firstTinmeIndex + 5, secondTinmeIndex - firstTinmeIndex - 5));

                        firstTinmeIndex  = childStr.IndexOf("nmin=", firstTinmeIndex);
                        secondTinmeIndex = childStr.IndexOf(";", firstTinmeIndex);
                        int minute = int.Parse(childStr.Substring(firstTinmeIndex + 5, secondTinmeIndex - firstTinmeIndex - 5));

                        firstTinmeIndex  = childStr.IndexOf("nsec=", firstTinmeIndex);
                        secondTinmeIndex = childStr.IndexOf(";", firstTinmeIndex);
                        int second = int.Parse(childStr.Substring(firstTinmeIndex + 5, secondTinmeIndex - firstTinmeIndex - 5));

                        Debug.Log(year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second);
                        DateTime        tempTime = new DateTime(year, month, day, hour, minute, second);
                        System.DateTime d1       = new System.DateTime(1970, 1, 1);
                        System.TimeSpan ts       = new System.TimeSpan(tempTime.ToUniversalTime().Ticks - d1.Ticks);
                        time = (long)ts.TotalMilliseconds;
                    }
                    catch
                    {
                        Debug.Log("错误====" + m_CurTimeOutCount);
                        m_CurTimeOutCount++;
                        StartCoroutine(DoCheckBaiduTime());
                        yield break;
                    }
                }
                long ms = EginTools.nowMinis(); //返回 1970 年 1 月 1 日至今的毫秒数
                EginTools.localBeiJingTime = time - ms;

                Debug.Log(time + "EginTools.localBeiJingTime====>" + EginTools.localBeiJingTime);
            }
        }
    }
コード例 #9
0
    /* ------ Socket Listener ------ */
    public void SocketReceiveMessage(string message)
    {
        //UnityEngine.Debug.Log("CK : ------------------------------desks SocketReceiveMessage = " + message);

        JSONObject messageObj = new JSONObject(message);
        string     type       = messageObj["type"].str;
        string     tag        = messageObj["tag"].str;

        EginTools.Log(type + "====" + tag);
        if ("account".Equals(type))
        {
            if ("login_success".Equals(tag))
            {
                ProcessAccountSucess(messageObj);
            }
            else if (tag.Contains("login_failed_"))
            {
                string errorInfo = "";
                if ("login_failed_auth".Equals(tag))
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_login_failed_auth");
                }
                else if ("login_failed_inactive".Equals(tag))
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_login_failed_inactive");
                }
                else if ("login_failed_otherroom".Equals(tag))
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_login_failed_otherroom");
                }
                else if ("login_failed_nomoney".Equals(tag))
                {
                    errorInfo  = ZPLocalization.Instance.Get("Socket_login_failed_nomoney");
                    errorInfo += "\n";
                    errorInfo += ZPLocalization.Instance.Get("Socket_login_failed_nomoney_min");
                    errorInfo += SocketConnectInfo.Instance.roomMinMoney;
                }
                else if ("login_failed_nousemoney".Equals(tag))
                {
                    errorInfo  = ZPLocalization.Instance.Get("Socket_login_failed_nousemoney");
                    errorInfo += "\n";
                    errorInfo += ZPLocalization.Instance.Get("Socket_login_failed_nomoney_min");
                    errorInfo += SocketConnectInfo.Instance.roomMinMoney;
                }
                else if ("login_failed_notexist".Equals(tag))
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_login_failed_notexist");
                }
                else if ("login_failed_online".Equals(tag))
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_login_failed_online");
                }
                else if ("login_failed_closed".Equals(tag))
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_login_failed_closed");
                    if (messageObj["body"] != null && messageObj["body"].str.Length > 0)
                    {
                        errorInfo += ZPLocalization.Instance.Get("Socket_login_failed_closed_reason");
                        errorInfo += Regex.Unescape(messageObj["body"].str);
                    }
                }
                else
                {
                    errorInfo = ZPLocalization.Instance.Get("Socket_Unkonw");
                }
                ProcessAccountFailed(errorInfo);
            }
            else if ("login_from_somewhere".Equals(tag))
            {
                ProcessAccountFailed(ZPLocalization.Instance.Get("Socket_login_from_somewhere"));
            }
            else if ("update_intomoney".Equals(tag))
            {
                // shawn.debug
            }
            else
            {
                ProcessAccountFailed(ZPLocalization.Instance.Get("Socket_Unkonw"));
            }
        }
        else if ("seatmatch".Equals(type))
        {
            if ("seatlist".Equals(tag))
            {
                ProcessSeatlist(messageObj);
            }
            else if ("on_sitdown".Equals(tag))
            {
                ProcessSitdown(messageObj);
            }
            else if ("on_situp".Equals(tag))
            {
                ProcessSitup(messageObj);
            }
            else if ("on_begin".Equals(tag))
            {
                ProcessGameBegin(messageObj);
            }
            else if ("on_end".Equals(tag))
            {
                ProcessGameEnd(messageObj);
            }
            else if ("sit_fail".Equals(tag))
            {
                ProcessSitFail(messageObj);
            }
        }
        else if ("game".Equals(type))
        {
            if ("enter".Equals(tag))
            {
                SocketManager.Instance.socketListener = null;
                SocketManager.Instance.SocketMessageRollback(message);
                PlatformGameDefine.game.StartGame();
            }
        }
    }
コード例 #10
0
    public HttpResult BaseResult(WWW www, bool isSwitchUrl)
    {
        HttpResult result = new HttpResult();

        if (www.error != null)
        {
            EginTools.Log("Http Failed: " + www.error);             //UnityEngine.Debug.Log("CK : ------------------------------ error = " + www.error);
            if (isSwitchUrl)
            {
                PlatformGameDefine.playform.swithWebHostUrl();//切换网页IP
                result.isSwitchHost = true;
            }
        }
        else
        {
            string tempResultStr = www.text.Trim(); //
            UnityEngine.Debug.Log("CK : ------------------------------ text = " + tempResultStr);

            EginTools.Log("base:::" + tempResultStr);

            JSONObject resultObj = new JSONObject(tempResultStr);
            if (resultObj.type == JSONObject.Type.NULL)
            {
                if (isSwitchUrl)
                {
                    PlatformGameDefine.playform.swithWebHostUrl();//切换网页IP
                    result.isSwitchHost = true;
                }
                result.resultObject = ZPLocalization.Instance.Get("HttpConnectError");
            }
            else
            {
                if (resultObj)
                {
                    string resultType = null;                    //= resultObj["result"].str;
                    if (resultObj["result"] != null)
                    {
                        resultType = resultObj["result"].str;
                    }
                    if ("ok".Equals(resultType))
                    {
                        result.resultObject = resultObj["body"];
                        result.resultType   = HttpResult.ResultType.Sucess;
                    }
                    else
                    {
                        if (resultObj["body"] != null)
                        {
                            result.resultObject = Regex.Unescape(resultObj["body"].str);
                        }
                        else
                        {
                            result.resultObject = null;
                        }
                    }
                }
                else
                {
                    Debug.Log("解析出错了---HttpConnect.cs -- 60");
                }
            }
        }
        return(result);
    }
コード例 #11
0
    IEnumerator DoClickLogin()
    {
        EginProgressHUD.Instance.ShowWaitHUD(ZPLocalization.Instance.Get("HttpConnectLogin"));

        //yield return StartCoroutine(PlatformGameDefine.playform.LoadConfig());

        WWWForm form = new WWWForm();

        form.AddField("username", kUsername.value);
        form.AddField("password", kPassword.value);
        form.AddField("device_id", "unity_" + SystemInfo.deviceUniqueIdentifier);      //

        if (PlatformGameDefine.playform.IsYan)
        {
            form.AddField("captcha_text", kYanZheng.value ?? "");
            form.AddField("captcha_hiddentext", captcha_hiddentext ?? "");
        }

#if UNITY_ANDROID
        int mVersionCode = Mathf.Max(PlayerPrefs.GetInt("VersionCode", PlatformGameDefine.game.VersionCode), PlatformGameDefine.game.VersionCode);
        //Debug.Log("======login======"+mVersionCode);
        form.AddField("version", mVersionCode);
        form.AddField("platform", "Android");
#else
        form.AddField("platform", "iOS");
#endif

        EginTools.Log("ConnectDefine.LOGIN_URL:" + ConnectDefine.LOGIN_URL);

        WWW www = HttpConnect.Instance.HttpRequest(ConnectDefine.LOGIN_URL, form); //UnityEngine.Debug.Log("CK : ------------------------------ ConnectDefine.LOGIN_URL = " + ConnectDefine.LOGIN_URL);

        yield return(www);

        HttpResult result = HttpConnect.Instance.UserLoginResult(www);
        //result.resultObject = "device_verify";

        EginProgressHUD.Instance.HideHUD();
        if (HttpResult.ResultType.Sucess == result.resultType)
        {
            SaveLoginInfo();

            EginLoadLevel("Hall");
        }
        else
        {
            if (result.resultObject.ToString() == "device_verify")
            {
                //SaveLoginInfo();
                verifyView.SetActive(true);
            }
            else
            {
                bool isSwitchHost = result.isSwitchHost && curReconnectCount < 2;

                if (Utils._IsIPTest)
                {
                    isSwitchHost = string.IsNullOrEmpty(IPTest_Login._WebURL) && result.isSwitchHost && curReconnectCount < 2;
                }

                if (isSwitchHost)
                {
                    curReconnectCount++;
                    //UnityEngine.Debug.Log("CK : ------------------------------ relogin = " + curReconnectCount);
                    StartCoroutine(DoClickLogin());//如果连接失败,则切换ip后重新登入
                }
                else
                {
                    curReconnectCount = 0;
                    //PlatformGameDefine.playform.swithWebHostUrl();

                    EginProgressHUD.Instance.ShowPromptHUD(result.resultObject as string);
                    //yield return new WaitForSeconds(1.5f);
                    //EginProgressHUD.Instance.HideHUD();
                    OnClickRefreshYanZheng();
                }
            }
        }
    }