Ejemplo n.º 1
0
        /// <summary>
        /// 上传分数(各版本都通用,有回调,测试用)
        /// </summary>
        /// <param name="score">分数</param>
        public void UpLoadScore(string score, UnityAction <string> callback)
        {
            switch (platform)
            {
            case PlatformSelect.NormalPlatform:
                JObject jo = new JObject();
                jo.Add("numberId", new JValue(LoginInformation.NumberId)); //学号
                jo.Add("name", new JValue(LoginInformation.Name));         //名字
                jo.Add("eid", new JValue(LoginInformation.EId));           //实验唯一数据标识
                jo.Add("expScore", new JValue(score));                     //成绩分数
                UpLoadForNormalPlatform(WebInterType.UpLoadScore, JsonConvert.SerializeObject(jo));
                webCallBack = (str) => {
                    try
                    {
                        JObject jObject = JsonConvert.DeserializeObject <JObject>(str);
                        Debug.Log(jObject["status"].ToString());
                        callback(jObject["status"].ToString());
                    }
                    catch (System.Exception)
                    {
                        Debug.LogError("上传分数未成功,错误信息为:" + str);
                        callback("上传分数未成功,错误信息为:" + str);
                    }
                };
                break;

            case PlatformSelect.SimplePlatform:
#if UNITY_STANDALONE
                string  upLoadScoreURL = simplePlatformHostURL + LoginInformation.UpLoadScoreURLKey + "/" + simplePlatformHostID + "/" + LoginInformation.ExpId;
                JArray  body           = new JArray();
                JObject obj            = new JObject();
                obj.Add("moduleFlag", "实验成绩");
                obj.Add("questionNumber", 1);
                obj.Add("questionStem", "学生操作成绩");
                obj.Add("score", score);    //成绩分数
                obj.Add("trueOrFalse", "True");
                body.Add(obj);
                UpLoadScoreForSimplePlatform(upLoadScoreURL, JsonConvert.SerializeObject(body));
                webCallBack = (str) => {
                    Debug.Log(str);
                    callback(str);
                };
#elif UNITY_WEBGL
                JObject scoreValue = new JObject();
                scoreValue.Add("moduleFlag", "实验成绩");
                scoreValue.Add("questionNumber", new JValue(1));
                scoreValue.Add("questionStem", "学生实验操作成绩");
                scoreValue.Add("scores", new JValue(score));
                scoreValue.Add("isTrue", "True");
                JArray value = new JArray();
                value.Add(scoreValue);
                UpLoadScoreForSPWebGL.UpLoadScore(JsonConvert.SerializeObject(value));
                callback("上传操作成功,请到平台上查看是否有成绩");
#elif UNITY_WEBPLAYER
                JObject scoreValue = new JObject();
                scoreValue.Add("moduleFlag", "实验成绩");
                scoreValue.Add("questionNumber", new JValue(1));
                scoreValue.Add("questionStem", "学生实验操作成绩");
                scoreValue.Add("scores", new JValue(score));
                scoreValue.Add("isTrue", "True");
                JArray value = new JArray();
                value.Add(scoreValue);
                Application.ExternalCall("ReciveData", JsonConvert.SerializeObject(value));
                callback("上传操作成功,请到平台上查看是否有成绩");
#endif
                break;

            default:
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 上传分数(各版本都通用)
        /// </summary>
        /// <param name="score">分数</param>
        public void UpLoadScore(string score)
        {
            switch (platform)
            {
            case PlatformSelect.NormalPlatform:
                JObject jo = new JObject();
                jo.Add("numberId", new JValue(LoginInformation.NumberId)); //学号
                jo.Add("name", new JValue(LoginInformation.Name));         //名字
                jo.Add("eid", new JValue(LoginInformation.EId));           //实验唯一数据标识
                jo.Add("expScore", new JValue(score));                     //成绩分数
                UpLoadForNormalPlatform(WebInterType.UpLoadScore, JsonConvert.SerializeObject(jo));
                webCallBack = (str) => {
                    try
                    {
                        JObject jObject = JsonConvert.DeserializeObject <JObject>(str);
                        Debug.Log(jObject["status"].ToString());
                    }
                    catch (System.Exception)
                    {
                        Debug.LogError("上传分数未成功,错误信息为:" + str);
                    }
                };
                break;

            case PlatformSelect.SimplePlatform:
#if UNITY_STANDALONE
                string  upLoadScoreURL = simplePlatformHostURL + LoginInformation.UpLoadScoreURLKey + "/" + simplePlatformHostID + "/" + LoginInformation.ExpId;
                JArray  body           = new JArray();
                JObject obj            = new JObject();
                obj.Add("moduleFlag", "实验成绩");
                obj.Add("questionNumber", 1);
                obj.Add("questionStem", "学生操作成绩");
                obj.Add("score", score);    //成绩分数
                obj.Add("trueOrFalse", "True");
                body.Add(obj);
                UpLoadScoreForSimplePlatform(upLoadScoreURL, JsonConvert.SerializeObject(body));
                webCallBack = (str) => {
                    Debug.Log(str);
                };
#elif UNITY_WEBGL
                JObject scoreValue = new JObject();
                scoreValue.Add("moduleFlag", "实验成绩");
                scoreValue.Add("questionNumber", new JValue(1));
                scoreValue.Add("questionStem", "学生实验操作成绩");
                scoreValue.Add("scores", new JValue(score));
                scoreValue.Add("isTrue", "True");
                JArray value = new JArray();
                value.Add(scoreValue);
                UpLoadScoreForSPWebGL.UpLoadScore(JsonConvert.SerializeObject(value));
#elif UNITY_WEBPLAYER
                JObject scoreValue = new JObject();
                scoreValue.Add("moduleFlag", "实验成绩");
                scoreValue.Add("questionNumber", new JValue(1));
                scoreValue.Add("questionStem", "学生实验操作成绩");
                scoreValue.Add("scores", new JValue(score));
                scoreValue.Add("isTrue", "True");
                JArray value = new JArray();
                value.Add(scoreValue);
                Application.ExternalCall("ReciveData", JsonConvert.SerializeObject(value));
#endif
                //***********如果使用简易平台上传分数,并且使用webGL或者webplayer版本,需要在打包出来的index.html里加入下面这段代码
                //            function GetQueryString(name)
                //            {
                //                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                //                var r = window.location.search.substr(1).match(reg);
                //                if (r != null) return unescape(r[2]); return null;
                //            }

                //            var domainUrl = window.location.protocol + "//" + window.location.host;

                //            var referer = document.referrer;
                //            if (referer)
                //            {
                //                if (referer.indexOf("http://") != -1)
                //                {
                //                    domainUrl = referer.substring(0, referer.indexOf("/", referer.indexOf("http://") + 7));
                //                }
                //                else if (referer.indexOf("https://") != -1)
                //                {
                //                    domainUrl = referer.substring(0, referer.indexOf("/", referer.indexOf("https://") + 8));
                //                }
                //            }


                //            var token = GetQueryString("token").split('_');
                //            var name = "";
                //            var tokenValue = "";
                //            var urlDataPost = "";
                //$.getJSON(domainUrl + "/openapi/" + token[0] + "/" + token[1], function(result) {
                //                name = result.name;
                //                tokenValue = result.token;
                //                urlDataPost = domainUrl + result.urlDataPost;
                //            });

                //            function ReciveData(str)
                //            {
                //    $.ajax({
                //                timeout: 20000,
                //        type: "POST",
                //        dataType: "JSON",
                //        contentType: 'application/json;charset=UTF-8',
                //        url: urlDataPost + "/" + token[0] + "/" + token[1],
                //        data: str,
                //        success: function(data) {
                //                        console.log("恭喜您已经完成实验学习!");
                //                    },
                //        error: function(jqXHR, textStatus, errorThrown) {
                //                        /*弹出jqXHR对象的信息*/
                //                        console.log(jqXHR.responseText);
                //                    }
                //                    //注意:这里不能加下面这行,否则数据会传不到后台
                //                    //contentType:'application/json;charset=UTF-8',
                //                });
                //    }

                //    window.addEventListener('message', function(event) {
                //    console.log(event.data);
                //        if (event.data.name != 'changePosition') {
                //    return;
                //}
                //        if (event.data.switch == true) {
                //    document.getElementById('unityPlayer').style = "position: static;";
                //} else {
                //    document.getElementById('unityPlayer').style = "position: absolute;left: -9999px;top: -9999px;";
                //}
                //}, false);
                //*****************************************************************************************************************************
                break;

            default:
                break;
            }
        }