123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using Newtonsoft.Json.Linq;
- namespace ET.Server
- {
- /// <summary>
- /// 抖音api回调, 评论添加玩家
- /// </summary>
- [HttpHandler(SceneType.RouterManager, "/addPlayer")]
- public class HttpCommentHandler: IHttpHandler
- {
- public async ETTask Handle(Entity domain, HttpListenerContext context)
- {
- Log.Debug($"收到http 评论添加玩家回调...");
- HttpDouyinApiCallbackResponse response = new HttpDouyinApiCallbackResponse();
- string bodyStr = await HttpHelper.GetBodyParameter(context);
- // 判断body是否为空
- if (string.IsNullOrEmpty(bodyStr))
- {
- response.Error = ErrorCode.ERR_ParameterError;
- response.Message = "参数错误";
- HttpHelper.Response(context, response);
- return;
- }
- JObject parameter = JObject.Parse(bodyStr);
- string openId = Convert.ToString(parameter.SelectToken("openId"));
- long roomId = Convert.ToInt64(parameter.SelectToken("roomId"));
- int serverId = Convert.ToInt32(parameter.SelectToken("serverId"));
- Log.Debug($"body参数: openid={openId}, roomId={roomId}, serverId={serverId}");
- // 判断参数
- if (string.IsNullOrEmpty(openId) || roomId <= 0 || serverId <= 0)
- {
- response.Error = ErrorCode.ERR_ParameterError;
- response.Message = "参数错误";
- HttpHelper.Response(context, response);
- return;
- }
- List<StartSceneConfig> list = RealmGateAddressHelper.GetAllGame(1);
- foreach (StartSceneConfig config in list.Where(config => config != null && config.Id == serverId))
- {
- MessageHelper.SendActor(config.InstanceId, new R2G_AddUnitsToMap() { OpenId = openId, RoomId = roomId});
- break;
- }
- HttpHelper.Response(context, response);
- await ETTask.CompletedTask;
- }
- }
- /// <summary>
- /// 抖音api回调, 点赞10次增加等级
- /// </summary>
- [HttpHandler(SceneType.RouterManager, "/like")]
- public class HttpLikeHandler: IHttpHandler
- {
- public async ETTask Handle(Entity domain, HttpListenerContext context)
- {
- Log.Debug($"收到http 点赞10次增加等级回调...");
- HttpDouyinApiCallbackResponse response = new HttpDouyinApiCallbackResponse();
- string bodyStr = await HttpHelper.GetBodyParameter(context);
- if (string.IsNullOrEmpty(bodyStr))
- {
- response.Error = ErrorCode.ERR_ParameterError;
- response.Message = "参数错误";
- HttpHelper.Response(context, response);
- return;
- }
- JObject parameter = JObject.Parse(bodyStr);
- string openId = Convert.ToString(parameter.SelectToken("openId"));
- long roomId = Convert.ToInt64(parameter.SelectToken("roomId"));
- int serverId = Convert.ToInt32(parameter.SelectToken("serverId"));
- // 点赞数
- int likes = Convert.ToInt32(parameter.SelectToken("likes"));
- likes = 30;
- Log.Debug($"body参数: openid={openId}, roomId={roomId}, serverId={serverId}, likes={likes}");
- // 判断参数
- if (string.IsNullOrEmpty(openId) || roomId <= 0 || serverId <= 0 || likes < 0)
- {
- response.Error = ErrorCode.ERR_ParameterError;
- response.Message = "参数错误";
- HttpHelper.Response(context, response);
- return;
- }
- List<StartSceneConfig> list = RealmGateAddressHelper.GetAllGame(1);
- foreach (StartSceneConfig config in list.Where(config => config != null && config.Id == serverId))
- {
- MessageHelper.SendActor(config.InstanceId, new R2G_AddLevel() { OpenId = openId, RoomId = roomId, Likes = likes});
- break;
- }
- HttpHelper.Response(context, response);
- await ETTask.CompletedTask;
- }
- }
- }
|