123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using Newtonsoft.Json.Linq;
- namespace ET.Server
- {
- /// <summary>
- /// 抖音回调帮助类
- /// </summary>
- public static class DouyinCallBackHelper
- {
- /// <summary>
- /// 评论加入玩家
- /// </summary>
- /// <param name="domain"></param>
- /// <param name="context"></param>
- /// <param name="roomId"></param>
- public static async void LiveComment(Entity domain, HttpListenerContext context, long roomId)
- {
- 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;
- }
- JArray jsonArray = JArray.Parse(bodyStr);
- foreach (JToken jToken in jsonArray)
- {
- JObject jsonObject = (JObject)jToken;
- string msgId = (string)jsonObject["msg_id"];
- string secOpenId = (string)jsonObject["sec_openid"];
- string content = (string)jsonObject["content"];
- string avatarUrl = (string)jsonObject["avatar_url"];
- string nickname = (string)jsonObject["nickname"];
- long timestamp = (long)jsonObject["timestamp"];
- Log.Debug($"body参数: openid={secOpenId}, roomId={roomId}, content={content}");
- // 判断参数
- if (string.IsNullOrEmpty(secOpenId) || roomId <= 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 is { Id: 10001 }))
- {
- MessageHelper.SendActor(config.InstanceId, new R2G_AddUnitsToMap() { OpenId = secOpenId, RoomId = roomId});
- break;
- }
- HttpHelper.Response(context, response);
- }
- await ETTask.CompletedTask;
- }
- /// <summary>
- /// 刷礼物
- /// </summary>
- /// <param name="domain"></param>
- /// <param name="context"></param>
- /// <param name="roomId"></param>
- public static async void LiveGift(Entity domain, HttpListenerContext context, long roomId)
- {
- 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;
- }
- JArray jsonArray = JArray.Parse(bodyStr);
- foreach (JToken jToken in jsonArray)
- {
- JObject jsonObject = (JObject)jToken;
- string msgId = (string)jsonObject["msg_id"];
- string secOpenId = (string)jsonObject["sec_openid"];
- // 加密的礼物id
- string secGiftId = (string)jsonObject["sec_gift_id"];
- // 送出的礼物数量
- long giftNum = (long)jsonObject["gift_num"];
- // 礼物总价值,单位分
- long giftValue = (long)jsonObject["gift_value"];
- string avatarUrl = (string)jsonObject["avatar_url"];
- string nickname = (string)jsonObject["nickname"];
- long timestamp = (long)jsonObject["timestamp"];
- Log.Debug($"body参数: openid={secOpenId}, roomId={roomId}, secGiftId={secGiftId}, giftNum={giftNum}, giftValue={giftValue}");
- // 判断参数
- if (string.IsNullOrEmpty(secOpenId) || roomId <= 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 is { Id: 10001 }))
- {
- MessageHelper.SendActor(config.InstanceId, new R2G_GiveGift() { OpenId = secOpenId, RoomId = roomId, NickName = nickname, GiftId = secGiftId, GiftNum = giftNum, GiftValue = giftValue});
- break;
- }
- HttpHelper.Response(context, response);
- }
- await ETTask.CompletedTask;
- }
- /// <summary>
- /// 点赞10次增加等级
- /// </summary>
- /// <param name="domain"></param>
- /// <param name="context"></param>
- /// <param name="roomId"></param>
- public static async void LiveLike(Entity domain, HttpListenerContext context, long roomId)
- {
- 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;
- }
- JArray jsonArray = JArray.Parse(bodyStr);
- foreach (JToken jToken in jsonArray)
- {
- JObject jsonObject = (JObject)jToken;
- string msgId = (string)jsonObject["msg_id"];
- string secOpenId = (string)jsonObject["sec_openid"];
- long likeNum = (long)jsonObject["like_num"];
- string avatarUrl = (string)jsonObject["avatar_url"];
- string nickname = (string)jsonObject["nickname"];
- long timestamp = (long)jsonObject["timestamp"];
- Log.Debug($"body参数: openid={secOpenId}, roomId={roomId}, likes={likeNum}");
- // 判断参数
- if (string.IsNullOrEmpty(secOpenId) || roomId <= 0 || likeNum < 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 is { Id: 10001 }))
- {
- MessageHelper.SendActor(config.InstanceId, new R2G_AddLevel() { OpenId = secOpenId, RoomId = roomId, Likes = likeNum});
- break;
- }
- HttpHelper.Response(context, response);
- }
- await ETTask.CompletedTask;
- }
- }
- }
|