Beispiel #1
0
    private IEnumerator requestPhoneCode(string mobile)
    {
        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers.Add("Cookie", session);

        WWWForm form2 = new WWWForm();

        form2.AddField("Cookie", session);
        form2.AddField("type", "1");
        form2.AddField("mobile", mobile);
        long   ms2    = EginTools.nowMinis();
        long   mms2   = ms2 + EginTools.localBeiJingTime;
        string ccode2 = EginTools.encrypTime(mms2.ToString());

        form2.AddField("client_code", ccode2);

        WWW w2 = new WWW(serverURL + "unity/htddz/send_phone_code/", form2.data, headers);

        yield return(w2);

        if (w2.error == null)
        {
            Debug.LogError(w2.text);
            JSONObject json = new JSONObject(w2.text);
            //Debug.LogError( System.Text.RegularExpressions.Regex.Unescape(json["body"].str) );
            EginProgressHUD.Instance.ShowPromptHUD(System.Text.RegularExpressions.Regex.Unescape(json["body"].str));
        }
        else
        {
            EginProgressHUD.Instance.ShowPromptHUD(w2.error);
        }
    }
Beispiel #2
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);
    }
Beispiel #3
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);
    }
Beispiel #4
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);
            }
        }
    }
Beispiel #5
0
    private IEnumerator requestAward(string mobile, string code)
    {
        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers.Add("Cookie", session);

        WWWForm form2 = new WWWForm();

        form2.AddField("Cookie", session);
        form2.AddField("type", "1");
        form2.AddField("mobile", mobile);
        form2.AddField("phonecode", code);
        long   ms2    = EginTools.nowMinis();
        long   mms2   = ms2 + EginTools.localBeiJingTime;
        string ccode2 = EginTools.encrypTime(mms2.ToString());

        form2.AddField("client_code", ccode2);
        form2.AddField("roomid", "1095");

        WWW w2 = new WWW(serverURL + "unity/htddz/reward_jd_card/", form2.data, headers);

        yield return(w2);

        if (w2.error == null)
        {
            Debug.LogError(w2.text);
            JSONObject json = new JSONObject(w2.text);
            if (json["result"].str == "ok")
            {
                if (awardInfo == null)
                {
                    EginProgressHUD.Instance.ShowPromptHUD("没有排名信息");
                    yield return(0);
                }
                if (awardInfo["add_coin"].n > 0)
                {
                    bonusLb.text = awardInfo["add_coin"].n + "元宝";
                }
                string awardCard = "";
                if (awardInfo["item_id"].n >= 121 && awardInfo["item_id"].n <= 125)
                {
                    string bonusStr = bonusLb.text;

                    if (awardInfo["item_id"].n == 121)
                    {
                        awardCard = "300元京东卡";
                    }
                    else if (awardInfo["item_id"].n == 122)
                    {
                        awardCard = "200元京东卡";
                    }
                    else if (awardInfo["item_id"].n == 123)
                    {
                        awardCard = "100元京东卡";
                    }
                    else if (awardInfo["item_id"].n == 124)
                    {
                        awardCard = "50元京东卡";
                    }
                    else if (awardInfo["item_id"].n == 125)
                    {
                        awardCard = "30元京东卡";
                    }
                    bonusStr    += ("\n" + awardCard);
                    bonusLb.text = bonusStr;
                    collectFlagObj.SetActive(true);
                }
                if (awardInfo["rank"].n <= 20)
                {
                    EginProgressHUD.Instance.ShowPromptHUD("你获得第" + awardInfo["rank"].n + "名,赢得" + awardCard + "! 卡密已发送到手机,请查收");
                }
                toggleAwardBtn(false);
            }
            else
            {
                EginProgressHUD.Instance.ShowPromptHUD(System.Text.RegularExpressions.Regex.Unescape(json["body"].str));
            }
        }
        else
        {
            EginProgressHUD.Instance.ShowPromptHUD(w2.error);
        }
    }
Beispiel #6
0
    private IEnumerator requestRankInfo(bool isPopup = false)
    {
        Dictionary <string, string> headers = new Dictionary <string, string>();

        headers.Add("Cookie", session);

        WWWForm form2 = new WWWForm();

        form2.AddField("Cookie", session);
        long   ms2    = EginTools.nowMinis();
        long   mms2   = ms2 + EginTools.localBeiJingTime;
        string ccode2 = EginTools.encrypTime(mms2.ToString());

        form2.AddField("client_code", ccode2);
        form2.AddField("roomid", "1095");

        WWW w2 = new WWW(serverURL + "unity/htddz/user_rank_info/", form2.data, headers);

        yield return(w2);

        if (w2.error == null)
        {
            Debug.LogError(w2.text);
            JSONObject json1 = new JSONObject(w2.text);
            JSONObject json  = json1["body"];

            /*{
             * "result": "ok",
             * "body": {
             *      "rank": 1, # 排名
             *      "uid": 1, # 玩家uid
             *      "name": "test", # 玩家名字
             *      "ave_score": 8000, # 场积分
             *      "update_time": "2016-12-13 14:10:00", # 获得时间
             *      "round": 25, # 当前第几局
             *      "win_round": 25, # 胜几场
             *      "fail_round": 0, # 负几场
             *      "add_coin": 0, # 获得金币
             *      "item_id": 121, # 获得京东卡item_id
             *      "is_reward": 1, # 是否领奖 0否 1是
             * }*/
//			Debug.LogError( System.Text.RegularExpressions.Regex.Unescape(json["body"].str) );
            //JDCard id : 121 to 125  = rank 1 to 5
            if (json1["result"].str == "ok")
            {
                awardInfo = json1["body"];
                //{"result":"ok","body":{"update_time": "2016-12-21 15:00:49", "uid": 299023, "ave_score": 345, "rank": 1,
                //"fail_round": 2, "item_id": 121, "name": "sygame13", "is_reward": 0, "win_round": 2, "add_coin": 0, "round": 4}}
                if (json["is_reward"].n == 1)
                {
                    if (json["add_coin"].n > 0)
                    {
                        bonusLb.text = json["add_coin"].n + "元宝";
                    }
                    if (json["item_id"].n >= 121 && json["item_id"].n <= 125)
                    {
                        string bonusStr = bonusLb.text;
                        if (json["item_id"].n == 121)
                        {
                            bonusStr += "\n 300元京东卡";
                        }
                        else if (json["item_id"].n == 122)
                        {
                            bonusStr += "\n 200元京东卡";
                        }
                        else if (json["item_id"].n == 123)
                        {
                            bonusStr += "\n 100元京东卡";
                        }
                        else if (json["item_id"].n == 124)
                        {
                            bonusStr += "\n 50元京东卡";
                        }
                        else if (json["item_id"].n == 125)
                        {
                            bonusStr += "\n 30元京东卡";
                        }
                        bonusLb.text = bonusStr;
                        collectFlagObj.SetActive(true);
                    }
                    toggleAwardBtn(false);
                }
                else
                {
                    if (json["rank"].n <= 50)
                    {
                        toggleAwardBtn(true);
                    }
                    else
                    {
                        toggleAwardBtn(false);
                    }
                    if (isPopup)
                    {
                        showAward();
                    }
                }
            }
            else
            {
                toggleAwardBtn(false);
                Debug.LogError(System.Text.RegularExpressions.Regex.Unescape(json1["body"].str));
//				EginProgressHUD.Instance.ShowPromptHUD(System.Text.RegularExpressions.Regex.Unescape(json["body"].str));
            }
        }
        else
        {
            EginProgressHUD.Instance.ShowPromptHUD(w2.error);
        }
    }
Beispiel #7
0
 //转移EginTool 里面的函数
 public static long nowMinis()
 {
     return(EginTools.nowMinis());
 }