Api.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System.Threading.Tasks;
  2. using Ragdoll;
  3. using Newtonsoft.Json;
  4. namespace HttpApi
  5. {
  6. public class Api
  7. {
  8. private static string _dataUrl = "http://47.114.170.126:19996/cock/";
  9. private static string _msgUrl = "http://test.static.cxhy.cn:16002/";
  10. private static volatile string _session;
  11. public static async Task<string> Auth(string token)
  12. {
  13. var httpObj = new AuthObj
  14. {
  15. token = token
  16. };
  17. var response = await RdHttpClient.Instance.PostAsync(_dataUrl + "auth", httpObj.ToJson());
  18. if (response != null)
  19. {
  20. var commonResponseObj = JsonConvert.DeserializeObject<CommonResponseObj>(response);
  21. if (commonResponseObj is { code: 200 })
  22. {
  23. var authRespStr = JsonConvert.SerializeObject(commonResponseObj.data);
  24. var authResp = JsonConvert.DeserializeObject<AuthResponseObj>(authRespStr);
  25. if (authResp != null)
  26. {
  27. _session = authResp.session;
  28. }
  29. }
  30. }
  31. return response;
  32. }
  33. public static async Task<string> RefreshMsgList()
  34. {
  35. var httpObj = new GetMsgObj(_session);
  36. var response = await RdHttpClient.Instance.PostAsync(_msgUrl + "api", httpObj.ToJson());
  37. return response;
  38. }
  39. public static async Task<string> SendMsg(int sendTo, int msgType, string msgContent)
  40. {
  41. var httpObj = new SendMsgObj(_session, sendTo, msgType, msgContent);
  42. var response = await RdHttpClient.Instance.PostAsync(_msgUrl + "epi", httpObj.ToJson());
  43. return response;
  44. }
  45. public static async Task<string> ConsumeMsg(string msgId)
  46. {
  47. var httpObj = new ConsumeMsgObj(_session, msgId);
  48. var response = await RdHttpClient.Instance.PostAsync(_msgUrl + "api", httpObj.ToJson());
  49. return response;
  50. }
  51. // ReSharper disable Unity.PerformanceAnalysis
  52. public static async Task<string> FindPlayer(int[] findPlayer)
  53. {
  54. var httpObj = new PlayerOnlineStatusObj(_session, findPlayer);
  55. var response = await RdHttpClient.Instance.PostAsync(_msgUrl + "api", httpObj.ToJson());
  56. return response;
  57. }
  58. public static async Task<string> GetBattleDetailList()
  59. {
  60. var response =
  61. await RdHttpClient.Instance.GetAsync(_msgUrl + "battle?fromPlayer=8&toPlayer=9&fromCock=1&toCock=1");
  62. return response;
  63. }
  64. }
  65. }