/// <summary>
    /// Get网络数据.
    /// </summary>
    IEnumerator SendGet(string _url, PostCmd cmd, int userIdVal = 0)
    {
        WWW getData = new WWW(_url);

        yield return(getData);

        if (getData.error != null)
        {
            Debug.Log("Unity:" + "GetError: " + getData.error);
            //网络故障,请检查网络并重启游戏.

            /*if (SSUIRoot.GetInstance().m_GameUIManage != null)
             * {
             *  SSUIRoot.GetInstance().m_GameUIManage.CreatWangLuoGuZhangUI();
             * }*/
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> GetData: " + getData.text);
            switch (cmd)
            {
            case PostCmd.GET_HDD_GAME_SCREEN_ID:
            {
                //红点点线下游戏屏幕码Id.
                //{"code":0,"message":"成功","data":{"id":10004,"boxId":"89leitingzhanche68q1q6o30765"}}
                break;
            }

            case PostCmd.GET_HDD_PLAYER_PAY_DATA:
            {
                //玩家在红点点平台的账户信息.
                //{"code":-1,"message":"NO ACCOUNT FOR THIS MEMBER"} //没有该账户.
                //{"code":0,"message":"成功","data":{"account":1,"memberId":93124}} //成功获取账户信息.
                JsonData jd = JsonMapper.ToObject(getData.text);
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    //如果有账户信息数据,需要将账户信息数据转换为游戏币.
                    int userId = Convert.ToInt32(jd["data"]["memberId"].ToString());
                    int money  = Convert.ToInt32(jd["data"]["account"].ToString());
                    //money = 200; //test
                    ReceivedWXPlayerHddPayData(userId, money);
                }
                else
                {
                    //没有账户信息.
                    //发送充值消息给微信手柄.
                    if (m_WebSocketSimpet != null)
                    {
                        m_WebSocketSimpet.NetSendWeiXinPadShowTopUpPanel(userIdVal);
                    }
                }
                break;
            }

            case PostCmd.ServerTimeGet:
            {
                //GetData: {"code":0,"message":"成功","data":"2018-09-28 12:58:56"}
                JsonData jd = JsonMapper.ToObject(getData.text);
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    string   timeSystem   = DateTime.Now.ToString("yyyy-MM-dd");
                    string   serverTime   = jd["data"].ToString().Substring(0, 10);
                    DateTime systemTimeDt = DateTime.Now;
                    DateTime serverTimeDt = Convert.ToDateTime(jd["data"].ToString());
                    //test
                    //systemTimeDt = Convert.ToDateTime("2018-10-01 15:58:56");
                    //serverTimeDt = Convert.ToDateTime("2018-09-30 12:58:56");
                    //test
                    TimeSpan sp         = systemTimeDt.Subtract(serverTimeDt);
                    int      daysOffset = sp.Days;
                    //if (pcvr.GetInstance() != null)
                    //{
                    //    pcvr.GetInstance().AddDebugMsg("Unity: daysOffset == " + Mathf.Abs(daysOffset));
                    //    pcvr.GetInstance().AddDebugMsg("Unity: serverTime == " + serverTime + ", systemTime == " + timeSystem);
                    //}

                    if (Mathf.Abs(daysOffset) > 1)
                    {
                        //系统与服务器日期信息不一致,请修改机器系统日期信息!
                        if (GameMovieCtrl.GetInstance() != null)
                        {
                            GameMovieCtrl.GetInstance().CreatFixSystemTimeUI();
                        }
                    }

                    //string timeSystem = DateTime.Now.ToString("yyyy-MM-dd");
                    //string serverTime = jd["data"].ToString().Substring(0, 10);
                    //if (pcvr.GetInstance() != null)
                    //{
                    //    pcvr.GetInstance().AddDebugMsg("Unity: serverTime == " + serverTime + ", systemTime == " + timeSystem);
                    //}
                    //Debug.Log("Unity: serverTime == " + serverTime + ", systemTime == " + timeSystem);
                    //if (serverTime != timeSystem)
                    //{
                    //    //系统与服务器日期信息不一致,请修改机器系统日期信息!
                    //    if (GameMovieCtrl.GetInstance() != null)
                    //    {
                    //        GameMovieCtrl.GetInstance().CreatFixSystemTimeUI();
                    //    }
                    //}
                }
                break;
            }

            case PostCmd.WX_XCX_URL_GET:
            {
                /**
                 * code : 响应码
                 * message:响应状态说明
                 * data:数据信息
                 *         qrcodeUrl:获取微信小程序码的请求地址
                 *         scene:传入的boxNumber
                 *         page:小程序码对应的小程序入口
                 */
                JsonData jd = JsonMapper.ToObject(getData.text);
                //m_BoxLoginRt = (BoxLoginRt)Convert.ToInt32(jd["code"].ToString());
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    if (m_BoxLoginData != null)
                    {
                        string scene    = jd["data"]["scene"].ToString();
                        string sceneTmp = m_BoxLoginData.boxNumber + "," + m_BoxLoginData.GetWXCodeGame(m_GamePadState);
                        Debug.Log("Unity: scene == " + scene + ", sceneTmp ==== " + sceneTmp);
                        if (sceneTmp == scene)
                        {
                            //盒子编号和游戏代码信息一致.
                            //重新刷新微信虚拟手柄二维码.
                            string qrcodeUrl = jd["data"]["qrcodeUrl"].ToString();
                            string page      = jd["data"]["page"].ToString();
                            Debug.Log("Unity: qrcodeUrl == " + qrcodeUrl + ", page == " + page);

                            WeiXinXiaoChengXuData data = new WeiXinXiaoChengXuData();
                            data.qrcodeUrl = qrcodeUrl;
                            data.scene     = scene;
                            data.page      = page;
                            HttpRequestWeiXinXiaoChengXuErWeiMa(data);
                        }
                        else
                        {
                            //盒子编号信息错误.
                            Debug.LogWarning("Unity: scene was wrong! scene ==== " + scene + ", sceneTmp == " + sceneTmp);
                        }
                    }
                    HttpSendGetGameScreenId();
                }
                else
                {
                    Debug.Log("Unity:" + "Get  WX_XCX_URL failed! code == " + jd["code"]);
                }
                break;
            }
            }
        }
    }
    /// <summary>
    /// 向微信请求游戏虚拟手柄小程序的二维码图片信息.
    /// </summary>
    void HttpRequestWeiXinXiaoChengXuErWeiMa(WeiXinXiaoChengXuData data)
    {
        string   url      = data.qrcodeUrl;
        Encoding encoding = Encoding.GetEncoding("utf-8");
        postData postdata = new postData();

        postdata.scene = data.scene;
        postdata.page  = data.page;
        Debug.Log("HttpRequestWeiXinXiaoChengXuErWeiMa -> url   ==== " + url);
        Debug.Log("HttpRequestWeiXinXiaoChengXuErWeiMa -> scene ==== " + postdata.scene);
        Debug.Log("HttpRequestWeiXinXiaoChengXuErWeiMa -> page  ==== " + postdata.page);

        string str = JsonMapper.ToJson(postdata);

        byte[]           postData         = Encoding.UTF8.GetBytes(str);
        PostHttpResponse postHttpResponse = new PostHttpResponse();
        HttpWebResponse  response         = postHttpResponse.CreatePostHttpResponse(url, postData, encoding);
        //打印返回值.
        Stream stream = null; //获取响应的流.

        try
        {
            //以字符流的方式读取HTTP响应.
            stream = response.GetResponseStream();
            //System.Drawing.Image.FromStream(stream).Save(path);
            MemoryStream ms = null;
            byte[]       buffer = new byte[response.ContentLength];
            int          offset = 0, actuallyRead = 0;
            do
            {
                actuallyRead = stream.Read(buffer, offset, buffer.Length - offset);
                offset      += actuallyRead;
            }while (actuallyRead > 0);

            ms = new MemoryStream(buffer);
            byte[] buffurPic = ms.ToArray();
            Debug.Log("Unity: buffurPic.length ==================== " + buffurPic.Length);

            string path = m_BoxLoginData.WX_XiaoChengXu_ErWeiMa_Path;
            Debug.Log("Unity: path ==== " + path);
            File.WriteAllBytes(path, buffurPic);
        }
        finally
        {
            //释放资源.
            if (stream != null)
            {
                stream.Close();
            }

            if (response != null)
            {
                response.Close();
            }
        }

        //更新微信小程序二维码.
        if (ErWeiMaUI.GetInstance() != null)
        {
            ErWeiMaUI.GetInstance().ReloadGameWXPadXiaoChengXuErWeiMa();
        }
    }
Beispiel #3
0
    /// <summary>
    /// Get网络数据.
    /// </summary>
    IEnumerator SendGet(string _url, PostCmd cmd)
    {
        WWW getData = new WWW(_url);

        yield return(getData);

        if (getData.error != null)
        {
            Debug.Log("Unity:" + "GetError: " + getData.error);
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> GetData: " + getData.text);
            switch (cmd)
            {
            case PostCmd.WX_XCX_URL_POST:
            {
                /**
                 * code : 响应码
                 * message:响应状态说明
                 * data:数据信息
                 *         qrcodeUrl:获取微信小程序码的请求地址
                 *         scene:传入的boxNumber
                 *         page:小程序码对应的小程序入口
                 */
                JsonData jd = JsonMapper.ToObject(getData.text);
                //m_BoxLoginRt = (BoxLoginRt)Convert.ToInt32(jd["code"].ToString());
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    if (m_BoxLoginData != null)
                    {
                        string scene    = jd["data"]["scene"].ToString();
                        string sceneTmp = m_BoxLoginData.boxNumber + "," + m_BoxLoginData.GetWXCodeGame(m_GamePadState);
                        Debug.Log("Unity: scene == " + scene + ", sceneTmp ==== " + sceneTmp);
                        if (sceneTmp == scene)
                        {
                            //盒子编号和游戏代码信息一致.
                            //重新刷新微信虚拟手柄二维码.
                            string qrcodeUrl = jd["data"]["qrcodeUrl"].ToString();
                            string page      = jd["data"]["page"].ToString();
                            Debug.Log("Unity: qrcodeUrl == " + qrcodeUrl + ", page == " + page);

                            WeiXinXiaoChengXuData data = new WeiXinXiaoChengXuData();
                            data.qrcodeUrl = qrcodeUrl;
                            data.scene     = scene;
                            data.page      = page;
                            HttpRequestWeiXinXiaoChengXuErWeiMa(data);
                        }
                        else
                        {
                            //盒子编号信息错误.
                            Debug.LogWarning("Unity: scene was wrong! scene ==== " + scene + ", sceneTmp == " + sceneTmp);
                        }
                    }
                }
                else
                {
                    Debug.Log("Unity:" + "Login box failed! code == " + jd["code"]);
                }
                break;
            }
            }
        }
    }