Example #1
0
    /// <summary>
    /// Post网络数据.
    /// </summary>
    IEnumerator SendPost(string _url, WWWForm _wForm, PostCmd cmd)
    {
        WWW postData = new WWW(_url, _wForm);

        yield return(postData);

        if (postData.error != null)
        {
            Debug.Log("Unity:" + "PostError: " + postData.error);
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> PostData: " + postData.text);
            switch (cmd)
            {
            case PostCmd.BoxLogin:
            {
                JsonData jd = JsonMapper.ToObject(postData.text);
                m_BoxLoginRt = (BoxLoginRt)Convert.ToInt32(jd["code"].ToString());
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    m_BoxLoginDt.serverIp = jd["data"]["serverIp"].ToString();
                    m_BoxLoginDt.token    = jd["data"]["token"].ToString();
                    Debug.Log("Unity:" + "serverIp " + m_BoxLoginDt.serverIp + ", token " + m_BoxLoginDt.token);
                    ConnectWebSocketServer();
                }
                else
                {
                    Debug.Log("Unity:" + "Login box failed! code == " + jd["code"]);
                }
                break;
            }
            }
        }
    }
Example #2
0
        public BaseQandAPageVM(string dbcontextName) : base(dbcontextName)
        {
            //Commands
            SaveFormCmd      = new SaveCmd(this);
            DeleteCmd        = new DeleteCmd(this);
            UploadImageCmd   = new UploadImageCmd(this);
            ToggleMarkQCmd   = new ToggleMarkQCmd(this);
            ToggleMarkACmd   = new ToggleMarkACmd(this);
            CancelCmd        = new CancelCmd(this);
            NewModeCmd       = new NewModeCmd(this);
            PostCmd          = new PostCmd(this);
            DeleteCommentCmd = new DeleteCommentCmd(this);
            EditCommentCmd   = new EditCommentCmd(this);

            //setup
            QVisConDTO            = new QuestionStateConverterDTO();
            AVisConDTO            = new AnswerStateConverterDTO();
            AnswerSearchTxt       = "";
            QuestionSearchTxt     = "";
            rowLimit              = 20;
            openFileDialog        = new OpenFileDialog();
            openFileDialog.Title  = "Select a picture";
            openFileDialog.Filter = "All supported graphics|*.jpg;*.jpeg;*.png|" +
                                    "JPEG (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                                    "Portable Network Graphic (*.png)|*.png";

            Mediator.Register(MediatorChannels.PoolingUpdate.ToString(), PoolingUpdate);
        }
    /// <summary>
    /// Post网络数据.
    /// </summary>
    IEnumerator SendPost(string _url, WWWForm _wForm, PostCmd cmd)
    {
        WWW postData = null;

        if (_wForm == null)
        {
            postData = new WWW(_url);
        }
        else
        {
            postData = new WWW(_url, _wForm);
        }
        yield return(postData);

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

            /*if (SSUIRoot.GetInstance().m_GameUIManage != null)
             * {
             *  SSUIRoot.GetInstance().m_GameUIManage.CreatWangLuoGuZhangUI();
             * }*/
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> PostData: " + postData.text);
            switch (cmd)
            {
            case PostCmd.BoxLogin:
            {
                JsonData jd = JsonMapper.ToObject(postData.text);
                m_BoxLoginRt = (BoxLoginRt)Convert.ToInt32(jd["code"].ToString());
                if (Convert.ToInt32(jd["code"].ToString()) == (int)BoxLoginRt.Success)
                {
                    m_BoxLoginDt.serverIp = jd["data"]["serverIp"].ToString();
                    m_BoxLoginDt.token    = jd["data"]["token"].ToString();
                    Debug.Log("Unity:" + "serverIp " + m_BoxLoginDt.serverIp + ", token " + m_BoxLoginDt.token);
                    ConnectWebSocketServer();
                }
                else
                {
                    Debug.Log("Unity:" + "Login box failed! code == " + jd["code"]);
                }
                break;
            }
            }
        }
    }
    /// <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;
            }
            }
        }
    }
    //void Update()
    //{
    //    if (Input.GetKeyUp(KeyCode.P))
    //    {
    //        //test
    //        HttpSendPostGameBaoYueChaXun();
    //        HttpSendPostGetDingDanIDGameBaoYue();
    //    }
    //}

    /// <summary>
    /// Post网络数据.
    /// </summary>
    IEnumerator SendPost(string _url, JsonData jData, PostCmd cmd)
    {
        Debug.Log("Unity: url == " + _url);
        byte[] postBytes = Encoding.Default.GetBytes(jData.ToJson());
        Dictionary <string, string> header = new Dictionary <string, string>();

        //设置Content-Type.
        header["Content-Type"] = "application/json";
        WWW postData = new WWW(_url, postBytes, header);

        yield return(postData);

        if (postData.error != null)
        {
            Debug.Log("Unity:" + "PostError: " + postData.error);
        }
        else
        {
            Debug.Log("Unity:" + cmd + " -> PostData: " + postData.text);
            if (pcvr.GetInstance() != null)
            {
                pcvr.GetInstance().AddDebugMsg(cmd + " -> PostData: " + postData.text);
            }

            switch (cmd)
            {
            case PostCmd.BaoYueChaXun:
            {
                //咪咕包月查询.

                /** ***************************************************************
                ##### 3.1.1 返回值说明
                #####参数类型 | 参数说明
                #####---|---
                #####code | 0:用户支付成功,其他返回值表示支付失败,一般只需要判断是否为0即可
                #####validTime |
                #####parameters | 用户体验时间
                ******************************************************************/
                //PostData: {"code":3,"msg":"未支付","data":{"validTime":2592000,"parameters":"{\"experienceTime\":0}"}}
                JsonData jd = JsonMapper.ToObject(postData.text);
                if (m_BaoYueChaXunData != null)
                {
                    m_BaoYueChaXunData.code      = jd["code"].ToString();
                    m_BaoYueChaXunData.msg       = jd["msg"].ToString();
                    m_BaoYueChaXunData.validTime = jd["data"]["validTime"].ToString();
                    //m_BaoYueChaXunData.experienceTime = jd["data"]["parameters"]["experienceTime"].ToString();
                }

                if (Convert.ToInt32(jd["code"].ToString()) == (int)BaoYueState.Success)
                {
                    Debug.Log("Unity:" + "Player have baoYue! code == " + jd["code"]);
                }
                else
                {
                    Debug.Log("Unity:" + "Player have not baoYue! code == " + jd["code"]);
                }
                break;
            }

            case PostCmd.BaoYueDingDanIDGet:
            {
                //获取包月订单ID.

                /** ****************************************
                 ##### 3.2.1
                 #####参数类型 | 参数说明
                 #####---|---
                 #####amount | 订单金额
                 #####orderId | 服务器生成的订单编号
                 #####code | 0:正常,其他表示异常
                 #####msg | 状态说明
                 ********************************************/
                //PostData: {"code":0,"msg":"","data":{"amount":0.01,"orderId":10000055}}
                JsonData jd = JsonMapper.ToObject(postData.text);
                if (m_BaoYueDingDanData != null)
                {
                    m_BaoYueDingDanData.code    = jd["code"].ToString();
                    m_BaoYueDingDanData.msg     = jd["msg"].ToString();
                    m_BaoYueDingDanData.amount  = jd["data"]["amount"].ToString();
                    m_BaoYueDingDanData.orderId = jd["data"]["orderId"].ToString();
                }
                break;
            }
            }
        }
    }
Example #6
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;
            }
            }
        }
    }