/// <summary> /// 通知列表中同意添加好友 /// </summary> /// <param name="session">本人的session</param> /// <param name="noticeID">通知的ID</param> /// <param name="sessionFriend">好友的session</param> /// <param name="noticeType">标志要请求的通知类型,0全部通知,1个人通知,2系统通知,</param> /// <returns></returns> public string AddFriendByNotice(string session, string noticeID, string sessionFriend, string noticeType) { HF.Cloud.BLL.Common.Logger.Error("AddFriendByNotice方法获取到的参数session:" + session + "---sessionFriend:" + sessionFriend + "---noticeType:" + noticeType); NoticeEL noticeEL = new NoticeEL(); //通过noticeID获取NoticeType=3?说明是审核的通知,修改UserUniteGroup表valid=1 noticeEL.ID = long.Parse(noticeID); DataTable dtNotice = noticeEL.ExecDT(2); if (dtNotice != null & dtNotice.Rows.Count > 0) { //如果是加群审核通知 if (dtNotice.Rows[0]["NoticeType"].ToString() == "3") { long groupID = (long)dtNotice.Rows[0]["GroupID"]; //UserUniteGroup表中的valid改为1,则通过审核 UserUniteGroupEL userGroupEL = new UserUniteGroupEL(); userGroupEL.UserID = long.Parse(dtNotice.Rows[0]["UserID_Friend"].ToString()); userGroupEL.GroupID = groupID; int raG; userGroupEL.ExecNonQuery(21, out raG); //通知notice表中的状态NoticeState要给成1通过 NoticeEL notice_EL = new NoticeEL(); notice_EL.ID = long.Parse(noticeID); notice_EL.NoticeState = 1; notice_EL.IsLook = 1; int raNoti; notice_EL.ExecNonQuery(33, out raNoti); HF.Cloud.BLL.Common.Logger.Error("AddFriendByNotice方法更改UserUniteGroupEL的Valid受影响的行数:" + raG + "更改通知表结果:" + raNoti); //审核后给用户发通知(系统通知) GroupEL groupEL = new GroupEL(); groupEL.ID = groupID; DataTable dt_group = groupEL.ExecDT(3); if (dt_group != null && dt_group.Rows.Count > 0) { string groupName = dt_group.Rows[0]["GroupName"].ToString(); Notice_SystemEL noticeSystemEL = new Notice_SystemEL(); noticeSystemEL.UserID = long.Parse(dtNotice.Rows[0]["UserID_Friend"].ToString()); noticeSystemEL.NoticeTitle = "审核通知!"; noticeSystemEL.NoticeContent = "您加入群\"" + groupName + "\"的申请已通过!"; noticeSystemEL.AddressUrl = "groupid=" + groupID; noticeSystemEL.NoticeType = 2; noticeSystemEL.IsLook = 0; noticeSystemEL.CreateTime = DateTime.Now.ToString(); noticeSystemEL.Valid = 1; int raNS; noticeSystemEL.ExecNonQuery(1, out raNS); } } else { //添加好友 FriendsBLL friendsBLL = new FriendsBLL(); string addFriendResult = friendsBLL.AddFriend(session, sessionFriend); //修改通知表中记录的状态改为好友 noticeEL.ID = long.Parse(noticeID); noticeEL.NoticeState = 1; int ra; noticeEL.ExecNonQuery(31, out ra); HF.Cloud.BLL.Common.Logger.Error("AddFriendByNotice方法更改NoticeState受影响的行数:" + ra); } } //返回通知列表 string resultStr = GetNotice(session, noticeType); return(resultStr); }
/// <summary> /// 加入群组 /// </summary> /// <param name="session">session</param> /// <param name="groupID">群组ID</param> /// <returns></returns> public string IntoGroup(string session, string groupID) { string result = ""; HF.Cloud.BLL.Common.Logger.Error("IntoGroup方法获取的参数session:" + session + "----groupID:" + groupID); //通过session获取UserID UserBLL userBLL = new UserBLL(); long userID = userBLL.GetUserIDBySession(session);//用户ID //判断群是否是私密的群 GroupEL groupEL = new GroupEL(); groupEL.ID = long.Parse(groupID); DataTable dtGroup = groupEL.ExecDT(3); if (dtGroup != null && dtGroup.Rows.Count > 0) { //先查看数据库中是否有记录 UserUniteGroupEL userUniteGroupEL = new UserUniteGroupEL(); userUniteGroupEL.UserID = userID; userUniteGroupEL.GroupID = long.Parse(groupID); DataTable dt = userUniteGroupEL.ExecDT(32); //如果有记录,就不添加直接修改valid就可以 if (dt != null && dt.Rows.Count > 0) { //如果是私密群还需修改通知 if (dtGroup.Rows[0]["IsOpen"].ToString() == "0") { NoticeEL noticeEL = new NoticeEL(); noticeEL.UserID_Friend = userID; noticeEL.GroupID = long.Parse(groupID); noticeEL.NoticeState = 0; noticeEL.IsLook = 0; noticeEL.CreateTime = DateTime.Now.ToString(); noticeEL.Valid = 1; int raNotice; noticeEL.ExecNonQuery(32, out raNotice); HF.Cloud.BLL.Common.Logger.Error("IntoGroup方法从新加入群组,跟新通知,修改结果(大于0成功):" + raNotice); if (raNotice > 0) { result = "secsuccess"; } else { result = "error"; } } else { //修改用户和群关联表 int raup; userUniteGroupEL.ExecNonQuery(21, out raup); HF.Cloud.BLL.Common.Logger.Error("IntoGroup方法用户已经在群组,修改Valid结果(大于0成功):" + raup); if (raup > 0) { result = "success"; } else { result = "error"; } } } //无记录就添加(包括添加通知) else { int userUniteGroup_Valid = 1; //0是私密的群需要审核(发通知),修改Valid为2 if (dtGroup.Rows[0]["IsOpen"].ToString() == "0") { userUniteGroup_Valid = 2;//暂时无效,需要审核 //发通知 NoticeEL noticeEL = new NoticeEL(); noticeEL.UserID = (long)dtGroup.Rows[0]["OwnerUserID"]; noticeEL.UserID_Friend = userID; noticeEL.GroupID = long.Parse(groupID); noticeEL.NoticeType = 3;//3是加入群审核 noticeEL.NoticeState = 0; noticeEL.IsLook = 0; noticeEL.CreateTime = DateTime.Now.ToString(); noticeEL.Valid = 1; int raN; long returnVelue = noticeEL.ExecNonQuery(1, out raN); HF.Cloud.BLL.Common.Logger.Error("IntoGroup方法发审核通知,(大于0成功):" + returnVelue); } userUniteGroupEL.CreateTime = DateTime.Now.ToString(); userUniteGroupEL.IsTop = 0; userUniteGroupEL.Valid = userUniteGroup_Valid; int ra; long exeResult = userUniteGroupEL.ExecNonQuery(1, out ra); HF.Cloud.BLL.Common.Logger.Error("IntoGroup方法加入群组结果(大于0成功):" + exeResult + "----userUniteGroupEL.Valid:" + userUniteGroup_Valid); if (exeResult > 0 && userUniteGroup_Valid == 1) { result = "success"; } else if (exeResult > 0 && userUniteGroup_Valid == 2) { result = "secsuccess"; } else { result = "error"; } } } return(result); }
/// <summary> /// 获取群组小程序码图片路径 /// </summary> /// <param name="path">小程序码跳转路径</param> /// <param name="groupID">群组ID</param> /// <returns></returns> public string GetQRCode_Group(string path, string groupID) { HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,获取的参数path:" + path + "------groupID:" + groupID); string imgPath = ""; //判断数据库中是否有值 GroupEL groupEL = new GroupEL(); groupEL.ID = long.Parse(groupID); DataTable dt = groupEL.ExecDT(3); HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,查找群组记录:" + dt.Rows.Count); if (dt != null && dt.Rows.Count > 0) { //如果数据库中"QRCode"有值,则从数据库中取值 if (!string.IsNullOrEmpty(dt.Rows[0]["QRCode"].ToString()) && dt.Rows[0]["QRCode"].ToString() != "") { //获取图片名称 string qrCodeImageName = dt.Rows[0]["QRCode"].ToString(); //获取图片路径 string qrCodeImagePath = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_Group"]; imgPath = qrCodeImagePath + qrCodeImageName; } //如果没有值则请求小程序服务器获取小程序码图片,并把图片名称保存到数据库中 else { //获取token WX_TokenBLL tokenBLL = new WX_TokenBLL(); string token = tokenBLL.GetToken(); //获取小程序码接口 string url = "https://api.weixin.qq.com/wxa/getwxacode?access_token=" + token; Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("path", path); JavaScriptSerializer js = new JavaScriptSerializer(); js.MaxJsonLength = int.MaxValue; string json = js.Serialize(dic); HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,url:" + url + "-----Path:" + path); //post返回的小程序码流 Stream QRCodeStream = WeChatAppDecrypt.Post(url, json); //将图片流转换成图片 Bitmap tp = new Bitmap(QRCodeStream); string QRCodeSave_Group = System.Configuration.ConfigurationManager.AppSettings["QRCodeSave_Group"]; string image_userName = Guid.NewGuid().ToString(); string qrCodeImageName = image_userName + ".jpg"; tp.Save(QRCodeSave_Group + qrCodeImageName); //把小程序码图片名称保存到数据库中 groupEL.QRCode = qrCodeImageName; int ra; long returnValue = groupEL.ExecNonQuery(21, out ra); HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,保存小程序图片名称结果:" + ra); if (ra > 0) { string QRCodeGet_Group = System.Configuration.ConfigurationManager.AppSettings["QRCodeGet_Group"]; imgPath = QRCodeGet_Group + qrCodeImageName; } else { imgPath = "error"; } } } else { imgPath = "error"; } HF.Cloud.BLL.Common.Logger.Error("GetQRCode_Group方法,小程序码图片路径:" + imgPath); return(imgPath); }
/// <summary> /// 面对面加群(创建新群或加群) /// </summary> /// <param name="session">session</param> /// <param name="password">口令</param> /// <param name="lon">经度</param> /// <param name="lat">纬度</param> /// <returns></returns> public string FaceToFaceCreateGroup(string session, string password, string lon, string lat) { string result = ""; HF.Cloud.BLL.Common.Logger.Error("FaceToFaceCreateGroup方法获取的参数session:" + session + "----password:"******"---lon:" + lon + "---lat:" + lat); if (!string.IsNullOrEmpty(session) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(lon) && !string.IsNullOrEmpty(lat)) { //通过session获取UserID UserBLL userBLL = new UserBLL(); long userID = userBLL.GetUserIDBySession(session);//用户ID //先查找群组Group表中查找当前时间段内是否有口令password的数据 GroupEL groupEL = new GroupEL(); groupEL.GroupPassword = password; DataTable dt = groupEL.ExecDT(31); HF.Cloud.BLL.Common.Logger.Error("FaceToFaceCreateGroup方法获取的群组个数为:" + dt.Rows.Count); if (dt.Rows.Count > 0)//大于0说明可能已经有人创建了此群,继续验证经纬度 { for (int i = 0; i < dt.Rows.Count; i++) { float lon_dt = float.Parse(dt.Rows[i]["lon"].ToString()); float lat_dt = float.Parse(dt.Rows[i]["lat"].ToString()); float lon_u = float.Parse(lon); float lat_u = float.Parse(lat); float lon_re = System.Math.Abs(lon_u - lon_dt); float lat_re = System.Math.Abs(lat_u - lat_dt); //经纬度111.3222222m对应0.001度 //如果距离够小的话说明已经有面对面群,直接加入关联群即可 if (lon_re < 0.1 && lat_re < 0.1) { UserUniteGroupEL uugEL = new UserUniteGroupEL(); //判断是否已经在群里面,如果在群里面则跳出循环,结束 uugEL.UserID = userID; uugEL.GroupID = (long)dt.Rows[i]["ID"]; DataTable dt_IsInGroup = uugEL.ExecDT(33); if (dt_IsInGroup != null && dt_IsInGroup.Rows.Count > 0) { result = dt.Rows[i]["ID"].ToString();//返回群组ID } else { //把用户在用户与群关联表中添加记录关联起来 uugEL.UserID = userID; uugEL.GroupID = (long)dt.Rows[i]["ID"]; uugEL.CreateTime = DateTime.Now.ToString(); uugEL.IsTop = 0; uugEL.Valid = 1; int uugRa; long uugResultID = uugEL.ExecNonQuery(1, out uugRa); HF.Cloud.BLL.Common.Logger.Error("FaceToFaceCreateGroup方法用户与群组关联结果(大于0成功):" + uugResultID); if (uugResultID > 0) { result = dt.Rows[i]["ID"].ToString();//返回群组ID } else { result = "error"; } } break; //跳出for循环 } else if (i == dt.Rows.Count - 1) //执行到最后依然没找到,那么就新创建个面对面群 { result = CreateNewGroup(userID.ToString(), password, lon, lat); } else //距离太大,不是当前的面对面群,继续找其他符合条件的群 { continue; } } } else//无记录说明自己是第一个,然后创建新的面对面群 { result = CreateNewGroup(userID.ToString(), password, lon, lat); } } else { result = "error"; } HF.Cloud.BLL.Common.Logger.Error("FaceToFaceCreateGroup方法返回的数据为:" + result); return(result); }