|
@@ -0,0 +1,186 @@
|
|
|
+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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|