public string Post() { var request = HttpContext.Current.Request; try { var chatInfo = new LiveChatMessageInfo(request); //Log.Info("Barrage", "Barrage", chatInfo.UserName + "_" + chatInfo.ChatMessage); if (!chatInfo.ParametersIsValid) { Log.Info("Barrage", "Barrage", "參數校驗失敗"); //return BadRequest("LIVEAPI_參數校驗失敗"); return("-1"); } else if (!chatInfo.GameIsExistsAndAvailable) { Log.Info("Barrage", "Barrage", "Game Not Exists or Unavailable."); //return BadRequest("LIVEAPI_直播不存在或停播中"); return("-2"); } else if (!chatInfo.InMinSendInterval) { Log.Info("Barrage", "Barrage", "NotInMinSendInterval:" + chatInfo.UserName); return("-6"); } //else if (chatInfo.IsSystemDefaultChatMessage && !chatInfo.SystemDefaultChatMessageIsExistsAndAvailable) //{ // Log.Info("Barrage", "Barrage", "SystemDefaultChatMessage Not Exists or Unavailable."); // //return BadRequest("LIVEAPI_系統彈幕ID不存在或已停用"); // return -3; //} else if (chatInfo.BlockSpeakDays() != 0) { //if (chatInfo.BlockSpeakDays() < 0) // return "-8,-1"; return("-8," + chatInfo.BlockSpeakDays().ToString()); } else if (chatInfo.BlackWords && chatInfo.BlockSpeakDays() == 0) { //符合黑詞且未被禁言 Log.Info("Barrage", "Barrage", "BlackWord:" + chatInfo.UserName); chatInfo.AddNoSpeak(7); return("-8,7"); } else if (!chatInfo.SensitiveWordsVerify) { if (!chatInfo.WaitToManualReview) { Log.Info("Barrage", "Barrage", "Words block:" + chatInfo.BlockWords); //return BadRequest("LIVEAPI_發言包含禁用詞:" + chatInfo.BlockWords); return("-4"); } Log.Info("Barrage", "Barrage", "Waitfor Manual Review:" + chatInfo.BlockWords); //return BadRequest("LIVEAPI_發言包含敏感詞:" + chatInfo.BlockWords + ", 等待人工審核"); return("-5"); } else { Log.Info("SendBarrage", "SendBarrage", chatInfo.UserName + "_" + chatInfo.ChatMessage); using (var client = new NoKeepAlivesWebClient() { Encoding = Encoding.UTF8 }) { client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var message = new Message() { Target = chatInfo.Target, GameID = chatInfo.GameID, Data = new MessageData() { Level = chatInfo.UserGroup, Message = chatInfo.ChatMessage, NickName = (!string.IsNullOrEmpty(chatInfo.UserNickName) && SensitiveReplace.IsSafeContent(chatInfo.UserNickName)) ? chatInfo.UserNickName : SameMethod.FuzzyName(chatInfo.UserName), Type = "Barrage", UserAvatar = chatInfo.UserAvatar, } }; var data = "content=" + JsonConvert.SerializeObject(message);//.Replace("\"",""); Log.TraceLog("target_SendBarrageToTony", data); Log.Info("Target", "Reward", "username:"******" " + data); // 發送聊天彈幕到Tony_WS var resultg = client.UploadString(Conf.WSUrl, "POST", data); //var resultg = client.UploadString("", "POST", data); Result result = JsonConvert.DeserializeObject <Result>(resultg.ToString()); Log.Info("Barrage", "Tony Response code: ", result.code.ToString()); if (result.code == 1) { //發送彈幕成功 if (chatInfo.IsSystemDefaultChatMessage && chatInfo.SystemDefaultChatMessageIsExistsAndAvailable) { chatInfo.SystemBarrageLog(); } else { chatInfo.UserBarrageLog(); } //return Ok(); return("1"); } else { //return BadRequest("LIVE_廣播失敗"); return("0"); } } } } catch (Exception e) { Log.Info("Barrage", "Barrage 出錯", e.Message); //return BadRequest("LIVE_" + e.Message); return("-10"); } }
public IHttpActionResult Post() { var request = HttpContext.Current.Request; try { var RewardInfo = new RewardGiftInfo(request); if (!RewardInfo.ParametersIsValid) { Log.Info("Reward", "Reward", "參數校驗失敗"); return(BadRequest("LIVEAPI_參數校驗失敗")); } else if (!RewardInfo.GameIsExistsAndAvailable) { Log.Info("Reward", "Reward", "Game Not Exists or Unavailable."); return(BadRequest("LIVEAPI_直播不存在或停播中")); } else { Log.Info("Reward", "Reward", RewardInfo.UserName + "_"); //if (!RewardInfo.RewardVerify) //{ // Log.Info("Reward", "Reward", "Mark:" + RewardInfo.UserNickName); //} using (var client = new NoKeepAlivesWebClient() { Encoding = Encoding.UTF8 }) { client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var message = new { Target = "dafa-" + RewardInfo.Identityid, GameID = RewardInfo.GameId, Data = new { Type = "Reward", UserName = SameMethod.FuzzyName(RewardInfo.UserName), NickName = (!string.IsNullOrEmpty(RewardInfo.UserNickName) && SensitiveReplace.IsSafeContent(RewardInfo.UserNickName)) ? RewardInfo.UserNickName : "", UserPhoto = RewardInfo.UserAvatar, GiftName = RewardInfo.GiftName, Combo = RewardInfo.ComboCount, GiftPrice = RewardInfo.GiftPrice } }; var data = "content=" + JsonConvert.SerializeObject(message);//.Replace("\"",""); var resultg = client.UploadString(Conf.WSUrl, "POST", data); Result result = JsonConvert.DeserializeObject <Result>(resultg.ToString()); Log.Info("Reward", "Reward 發給tony的結果", result.code.ToString()); Log.Info("Target", "Reward", "username:"******" " + data); if (result.code == 1) { return(Ok(1)); } else { return(BadRequest("LIVE_廣播失敗")); } } } } catch (Exception e) { Log.Info("Reward", "Reward 出錯", e.Message); return(BadRequest("LIVE_" + e.Message)); } }
public int Post() { var request = HttpContext.Current.Request; try { var chatInfo = new LiveChatMessageInfo(request); //Log.Info("Barrage", "Barrage", chatInfo.UserName + "_" + chatInfo.ChatMessage); if (!chatInfo.ParametersIsValid) { Log.Info("Barrage", "Barrage", "參數校驗失敗"); //return BadRequest("LIVEAPI_參數校驗失敗"); return(-1); } else if (!chatInfo.GameIsExistsAndAvailable) { Log.Info("Barrage", "Barrage", "Game Not Exists or Unavailable."); //return BadRequest("LIVEAPI_直播不存在或停播中"); return(-2); } //else if (chatInfo.IsSystemDefaultChatMessage && !chatInfo.SystemDefaultChatMessageIsExistsAndAvailable) //{ // Log.Info("Barrage", "Barrage", "SystemDefaultChatMessage Not Exists or Unavailable."); // //return BadRequest("LIVEAPI_系統彈幕ID不存在或已停用"); // return -3; //} else { Log.Info("SendBarrage", "SendBarrage", chatInfo.UserName + "_" + chatInfo.ChatMessage); using (var client = new NoKeepAlivesWebClient() { Encoding = Encoding.UTF8 }) { client.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; var message = new Message() { Target = chatInfo.Target, GameID = chatInfo.GameID, Data = new MessageData() { Level = chatInfo.UserGroup, Message = chatInfo.ChatMessage, NickName = (!string.IsNullOrEmpty(chatInfo.UserNickName) && SensitiveReplace.IsSafeContent(chatInfo.UserNickName)) ? chatInfo.UserNickName : SameMethod.FuzzyName(chatInfo.UserName), Type = "Barrage" } }; var data = "content=" + JsonConvert.SerializeObject(message);//.Replace("\"",""); var resultg = client.UploadString(Conf.WSUrl, "POST", data); //var resultg = client.UploadString("", "POST", data); Result result = JsonConvert.DeserializeObject <Result>(resultg.ToString()); Log.Info("Barrage", "Barrage 發給tony的結果", result.code.ToString()); if (result.code == 1) { //return Ok(); return(1); } else { //return BadRequest("LIVE_廣播失敗"); return(0); } } } } catch (Exception e) { Log.Info("Barrage", "Barrage 出錯", e.Message); //return BadRequest("LIVE_" + e.Message); return(-10); } }