public static int PublishMessage(int roomId, int userId, string type, string content, int parentid) { Users users = new Users(userId); string avatarJsonStr = users.GetUserAvatarJson(); string nick = ""; string headImageUrl = ""; if (!avatarJsonStr.Trim().Equals("")) { nick = Util.GetSimpleJsonValueByKey(avatarJsonStr, "nickname"); headImageUrl = Util.GetSimpleJsonValueByKey(avatarJsonStr, "headimgurl"); } if (type == "text") { DataTable keywordDt = DBHelper.GetDataTable("select top 1 * from filter_words", Util.ConnectionString); if (keywordDt != null && keywordDt.Rows.Count > 0) { string keyword = keywordDt.Rows[0][0].ToString(); string[] keywordArr = keyword.Split(','); for (int i = 0; i < keywordArr.Length; i++) { content = content.Replace(keywordArr[i], "***"); } } } string auditState = "1"; ChatRoom chatRoom = new ChatRoom(roomId); DataRow drow = chatRoom._fields; if (drow == null) { return 0; } int Shielding = 0; string expertlist = drow["expertlist"].ToString(); string[] FilterWordArr = { "间断", "听不见", "听不到", "听不清", "听不了", "断了", "退出", "没有声音", "没声", "没音", "时断时续", "时有时无", "不清楚", "声音小", "声音太小", "不能听", "不清晰", "听不成", "进不去", "无法进入", "不能听", "断了", "没反应", "没法听", "掉线", "断断续续", "老断" }; if (type == "text" && Array.IndexOf(expertlist.Split(','), userId.ToString()) < 0) { string defineContent = content; for (int i = 0; i < FilterWordArr.Length; i++) { defineContent = defineContent.Replace(FilterWordArr[i], "******"); if (defineContent.IndexOf("******") > -1) { Shielding = 1; auditState = "0"; break; } } } //string expertlist = drow["expertlist"].ToString(); //if (parentid != 0 || Array.IndexOf(expertlist.Split(','), userId.ToString()) >= 0) //{ // auditState = "1"; //} string[,] insertParameter = {{"chat_room_id", "int", roomId.ToString()}, {"user_id", "int", userId.ToString()}, {"nick", "varchar", nick.Trim()}, {"avatar", "varchar", headImageUrl.Trim()}, {"message_type", "varchar", type.Trim()}, {"message_content", "varchar", content.Trim()}, {"audit_state", "int", auditState}, {"parent_id", "int", parentid.ToString()}}; int result = DBHelper.InsertData("chat_list", insertParameter, Util.ConnectionString); int maxId = 0; if (result > 0) { if (parentid > 0) { //更新为已回答 ChatTimeLine.Update_State(parentid, 2); //回答数+1 Add_SonCount(parentid); } DataTable dt = DBHelper.GetDataTable(" select max([id]) from chat_list ", Util.ConnectionString); if (dt.Rows.Count > 0) maxId = int.Parse(dt.Rows[0][0].ToString()); //自动回复 if (Shielding == 1) { DataTable dtCount = DBHelper.GetDataTable("select count(*) cc from dbo.chat_list where chat_room_id=" + roomId + " and user_id=" + userId + " and audit_state=0", Util.ConnectionString); if (dtCount == null || dtCount.Rows.Count == 0 || (dtCount.Rows.Count > 0 && (int.Parse(dtCount.Rows[0][0].ToString()) - 1) % 5 == 0)) PublishMessage(roomId, 11147, "text", "各位家长好!今晚是新版悦长大问答微课堂的测试版。没有声音的家长,请点击上面的三角播放按钮;如果不行请退出再重新进入教室;如果仍没有声音,请重启手机再进入;如果声音小,请将媒体声音调大些;如果仍无法正常收听,明天在公众号菜单栏【预告回顾】中可以收听语音回顾。我们会逐步改进新功能,希望大家多提意见,谢谢大家!", maxId); if (chatRoom._fields != null && DateTime.Parse(chatRoom._fields["start_date"].ToString()) <= DateTime.Now && DateTime.Parse(chatRoom._fields["end_date"].ToString()) >= DateTime.Now) HttpContext.Current.Session["Shielding"] = "1"; } else { if (HttpContext.Current.Session["Shielding"] != null) HttpContext.Current.Session["Shielding"] = null; } dt.Dispose(); } return maxId; }