wangguan
2020-12-03 19a439d778c8ddc0cefb71d341da4e7329911d57
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections;
using System.Collections.Generic;
using KTGMGemClient;
using LitJson;
using UnityEngine;
 
public class FinalHttp : MonoBehaviour
{
    Action<List<HttpGetInfo>, int> callBack;
    int _limit;
    public void Init(Action<List<HttpGetInfo>, int> ac, int limit)
    {
        isSending = false;
        callBack = ac;
        _limit = limit;
    }
    private JsonData loginData;
    private bool isSending = false;
    void LoadImei()
    {
        if (Application.platform == RuntimePlatform.Android)
        {
            //GetetDeviceIMEI();//获取安卓手机IMEI
 
            GameConfig.Imei = TDAA_SDKManager.Ins.GetDeviceId();//使用设备ID
        }
        else if (Application.platform == RuntimePlatform.WindowsEditor)
        {
            GameConfig.Imei = "MyTestGemBattle123";
        }
        Debug.Log("设置imei0:" + GameConfig.Imei);
    }
 
 
    /// <summary>
    /// 
    /// </summary>
    /// <param name="nickname"></param>
    /// <param name="score"></param>
    /// <param name="level"></param>
    public void SendPost(string nickname, int score, int level, string waveInfo)
    {
        LoadImei();
        Debug.Log("开始Post" + nickname);
        string url = "http://9377-big-data.sbk-h5.com:8600/users/addrank";
        Dictionary<string, object> keyValues = new Dictionary<string, object>();
        keyValues.Add("username", GameConfig.Imei);
        keyValues.Add("nickname", nickname);
        keyValues.Add("score", score);
        keyValues.Add("level", level);
 
        keyValues.Add("extra", waveInfo);
 
        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", GameConfig.Imei);
        keyValues.Add("limit", _limit);
 
        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());
        Debug.Log("当前排名:" + myrank);
 
        JsonData rank = getData["rank"];
        List<HttpGetInfo> allHttpGetInfoLis = new List<HttpGetInfo>();
        HttpGetInfo info;
        string tmpStr;
        foreach (JsonData item in rank)
        {
            info = new HttpGetInfo();
            info.id = int.Parse(item["id"].ToString());
            info.username = item["username"].ToString();
            info.nickname = item["nickname"].ToString();
            info.score = int.Parse(item["score"].ToString());
            info.level = int.Parse(item["level"].ToString());
 
            tmpStr = item["extra"].ToString();
            tmpStr = tmpStr.Remove(0, 1);
            tmpStr = tmpStr.Remove(tmpStr.Length - 1, 1);
 
            info.waveInfo = tmpStr;
            info.create_time = int.Parse(item["create_time"].ToString());
            allHttpGetInfoLis.Add(info);
        }
 
        if (callBack != null)
        {
            callBack(allHttpGetInfoLis, myrank);
        }
    }
 
}