HttpDouyinApiCallbackHandler.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using Newtonsoft.Json.Linq;
  6. namespace ET.Server
  7. {
  8. /// <summary>
  9. /// 抖音api回调, 评论添加玩家
  10. /// </summary>
  11. [HttpHandler(SceneType.RouterManager, "/addPlayer")]
  12. public class HttpCommentHandler: IHttpHandler
  13. {
  14. public async ETTask Handle(Entity domain, HttpListenerContext context)
  15. {
  16. Log.Debug($"收到http 评论添加玩家回调...");
  17. HttpDouyinApiCallbackResponse response = new HttpDouyinApiCallbackResponse();
  18. string bodyStr = await HttpHelper.GetBodyParameter(context);
  19. // 判断body是否为空
  20. if (string.IsNullOrEmpty(bodyStr))
  21. {
  22. response.Error = ErrorCode.ERR_ParameterError;
  23. response.Message = "参数错误";
  24. HttpHelper.Response(context, response);
  25. return;
  26. }
  27. JObject parameter = JObject.Parse(bodyStr);
  28. string openId = Convert.ToString(parameter.SelectToken("openId"));
  29. long roomId = Convert.ToInt64(parameter.SelectToken("roomId"));
  30. int serverId = Convert.ToInt32(parameter.SelectToken("serverId"));
  31. Log.Debug($"body参数: openid={openId}, roomId={roomId}, serverId={serverId}");
  32. // 判断参数
  33. if (string.IsNullOrEmpty(openId) || roomId <= 0 || serverId <= 0)
  34. {
  35. response.Error = ErrorCode.ERR_ParameterError;
  36. response.Message = "参数错误";
  37. HttpHelper.Response(context, response);
  38. return;
  39. }
  40. List<StartSceneConfig> list = RealmGateAddressHelper.GetAllGame(1);
  41. foreach (StartSceneConfig config in list.Where(config => config != null && config.Id == serverId))
  42. {
  43. MessageHelper.SendActor(config.InstanceId, new R2G_AddUnitsToMap() { OpenId = openId, RoomId = roomId});
  44. break;
  45. }
  46. HttpHelper.Response(context, response);
  47. await ETTask.CompletedTask;
  48. }
  49. }
  50. /// <summary>
  51. /// 抖音api回调, 点赞10次增加等级
  52. /// </summary>
  53. [HttpHandler(SceneType.RouterManager, "/like")]
  54. public class HttpLikeHandler: IHttpHandler
  55. {
  56. public async ETTask Handle(Entity domain, HttpListenerContext context)
  57. {
  58. Log.Debug($"收到http 点赞10次增加等级回调...");
  59. HttpDouyinApiCallbackResponse response = new HttpDouyinApiCallbackResponse();
  60. string bodyStr = await HttpHelper.GetBodyParameter(context);
  61. if (string.IsNullOrEmpty(bodyStr))
  62. {
  63. response.Error = ErrorCode.ERR_ParameterError;
  64. response.Message = "参数错误";
  65. HttpHelper.Response(context, response);
  66. return;
  67. }
  68. JObject parameter = JObject.Parse(bodyStr);
  69. string openId = Convert.ToString(parameter.SelectToken("openId"));
  70. long roomId = Convert.ToInt64(parameter.SelectToken("roomId"));
  71. int serverId = Convert.ToInt32(parameter.SelectToken("serverId"));
  72. // 点赞数
  73. int likes = Convert.ToInt32(parameter.SelectToken("likes"));
  74. likes = 30;
  75. Log.Debug($"body参数: openid={openId}, roomId={roomId}, serverId={serverId}, likes={likes}");
  76. // 判断参数
  77. if (string.IsNullOrEmpty(openId) || roomId <= 0 || serverId <= 0 || likes < 0)
  78. {
  79. response.Error = ErrorCode.ERR_ParameterError;
  80. response.Message = "参数错误";
  81. HttpHelper.Response(context, response);
  82. return;
  83. }
  84. List<StartSceneConfig> list = RealmGateAddressHelper.GetAllGame(1);
  85. foreach (StartSceneConfig config in list.Where(config => config != null && config.Id == serverId))
  86. {
  87. MessageHelper.SendActor(config.InstanceId, new R2G_AddLevel() { OpenId = openId, RoomId = roomId, Likes = likes});
  88. break;
  89. }
  90. HttpHelper.Response(context, response);
  91. await ETTask.CompletedTask;
  92. }
  93. }
  94. }