| | |
| | | using UnityEngine; |
| | | using UnityEngine.UI; |
| | | using KTGMGemClient; |
| | | using LitJson; |
| | | using UnityEngine.Networking; |
| | | using System.Net; |
| | | using System.IO; |
| | | using System.Collections.Generic; |
| | | |
| | | public class TestButton : MonoBehaviour |
| | | { |
| | | //public Text t; |
| | |
| | | // string s="<color=red>范围伤害</color>"; |
| | | // t.text=s; |
| | | // Debug.Log(s.Length); |
| | | TestFinalPanel(); |
| | | //TestFinalPanel(); |
| | | isSending = false; |
| | | TestHttp(); |
| | | } |
| | | |
| | | private void OnGUI() |
| | | { |
| | | GUILayout.BeginArea(new Rect(5, 330, 150, 300)); |
| | | if (GUILayout.Button("SendRequest", GUILayout.Width(150), GUILayout.Height(70))) |
| | | { |
| | | //SendRequest("aa", 4700, 28); |
| | | SendPost("aaa", 7890, 1); |
| | | |
| | | } |
| | | if (GUILayout.Button("SendGet", GUILayout.Width(150), GUILayout.Height(70))) |
| | | { |
| | | SendGet(); |
| | | |
| | | } |
| | | GUILayout.EndArea(); |
| | | |
| | | } |
| | | private JsonData loginData; |
| | | |
| | | public string imei0 = "";//设备信息唯一ID |
| | | private bool isSending = false; |
| | | void TestHttp() |
| | | { |
| | | if (Application.platform == RuntimePlatform.Android) |
| | | { |
| | | //GetetDeviceIMEI();//获取安卓手机IMEI |
| | | imei0 = TDAA_SDKManager.Ins.GetDeviceId();//使用设备ID |
| | | } |
| | | else if (Application.platform == RuntimePlatform.WindowsEditor) |
| | | { |
| | | imei0 = "MyTestGemBattle123"; |
| | | } |
| | | Debug.Log("设置imei0:" + imei0); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | /// <param name="nickname"></param> |
| | | /// <param name="score"></param> |
| | | /// <param name="level"></param> |
| | | private void SendPost(string nickname, int score, int level) |
| | | { |
| | | Debug.Log("开始Post"); |
| | | string url = "http://9377-big-data.sbk-h5.com:8600/users/addrank"; |
| | | Dictionary<string, object> keyValues = new Dictionary<string, object>(); |
| | | keyValues.Add("username", imei0); |
| | | keyValues.Add("nickname", nickname); |
| | | keyValues.Add("score", score); |
| | | keyValues.Add("level", level); |
| | | HttpHelper.Request(this, url, HttpHelper.MethodType.POST, keyValues, delegate (object value) |
| | | { |
| | | if (value != null) |
| | | LoadPostTxt(value.ToString()); |
| | | |
| | | }, HttpHelper.DownloadHanlderType.kHttpTEXT); |
| | | |
| | | } |
| | | |
| | | private void LoadPostTxt(string value) |
| | | { |
| | | Debug.Log(value); |
| | | loginData = JsonMapper.ToObject(value); |
| | | if (loginData["error"].ToString() != "0") |
| | | { |
| | | Debug.Log("失败了"); |
| | | } |
| | | else if (loginData["msg"].ToString() == "OK") |
| | | { |
| | | Debug.Log("成功了"); |
| | | SendGet(); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 下载排行榜 |
| | | /// </summary> |
| | | private void SendGet() |
| | | { |
| | | string url = "http://9377-big-data.sbk-h5.com:8600/users/getrank";//9377-big-data.sbk-h5.com:8600/users/getrank?username=0001&limit=100 |
| | | Dictionary<string, object> keyValues = new Dictionary<string, object>(); |
| | | keyValues.Add("username", imei0); |
| | | keyValues.Add("limit", 100); |
| | | |
| | | HttpHelper.Request(this, url, HttpHelper.MethodType.GET, keyValues, delegate (object value) |
| | | { |
| | | if (value != null) |
| | | LoadGetTxt(value.ToString()); |
| | | }, HttpHelper.DownloadHanlderType.kHttpTEXT); |
| | | |
| | | } |
| | | |
| | | private void LoadGetTxt(string value) |
| | | { |
| | | JsonData getData = JsonMapper.ToObject(value); |
| | | int myrank = int.Parse(getData["myrank"].ToString()); |
| | | |
| | | JsonData rank = getData["rank"]; |
| | | List<HttpGetInfo> allHttpGetInfoLis = new List<HttpGetInfo>(); |
| | | foreach (JsonData item in rank) |
| | | { |
| | | allHttpGetInfoLis.Add( |
| | | new HttpGetInfo |
| | | { |
| | | id = int.Parse(item["id"].ToString()), |
| | | username = item["username"].ToString(), |
| | | nickname = item["nickname"].ToString(), |
| | | score = int.Parse(item["score"].ToString()), |
| | | level = int.Parse(item["level"].ToString()), |
| | | extra = item["extra"], |
| | | create_time = int.Parse(item["create_time"].ToString()), |
| | | } |
| | | ); |
| | | } |
| | | |
| | | foreach (HttpGetInfo item in allHttpGetInfoLis) |
| | | { |
| | | Debug.Log($"item.username:{item.username} item.nickname:{item.nickname} item.score:{item.score} item.create_time:{item.create_time}"); |
| | | } |
| | | } |
| | | |
| | | |
| | | void TestFinalPanel() |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | public class HttpGetInfo |
| | | { |
| | | public int id; |
| | | public string username; |
| | | public string nickname; |
| | | public int score; |
| | | public int level; |
| | | public JsonData extra; |
| | | public int create_time; |
| | | } |