public void EGetEwm() { if (Context.Session["OpenIdE"] != null) { string OpenId = Context.Session["OpenIdE"].ToString(); WeChatUser wcu = ve.WeChatUser.FirstOrDefault(x => x.OpenId == OpenId && x.State == true); TempBind tb = null; int num = 0; do { num = TextStr.RandomArray(1, 50000, 100000)[0]; string str = num + ""; tb = ve.TempBind.FirstOrDefault(q => q.SceneId == str); } while (tb != null); tb = new TempBind(); tb.Token = wcu.Token; tb.SceneId = num + ""; tb.CreateDate = DateTime.Now; tb.DeviceId = wcu.DeviceId; ve.TempBind.Add(tb); ve.SaveChanges(); Context.Response.Clear(); Context.Response.ContentType = "image/jpg"; Context.Response.BinaryWrite(QrCodeManager.GenerateTemp(GetToken(), num)); Context.Response.End(); } }
public void Get_UserInformation(string deviceId, string token) { VideoEntities ve = DBContextFactory.GetDbContext(); Device_user du = new Device_user(); List <WeChatUser> wlist = ve.WeChatUser.Where(x => x.DeviceId == deviceId).ToList(); if (wlist.Count == 0) { HttpContext.Current.Response.Write("null"); return; } foreach (var item in wlist) { item.Token = token; ve.SaveChanges(); } Dictionary <string, List <Dictionary <string, string> > > dic2 = new Dictionary <string, List <Dictionary <string, string> > >(); List <Dictionary <string, string> > list2 = new List <Dictionary <string, string> >(); foreach (var item in wlist) { Dictionary <string, string> dic3 = new Dictionary <string, string>(); dic3.Add("openid", item.OpenId); dic3.Add("lang", "zh_CN"); list2.Add(dic3); } dic2.Add("user_list", list2); string data2 = du.GetUserInformation2(JsonConvert.SerializeObject(dic2), GetToken()); HttpContext.Current.Response.Write(data2); }
public List <ObjectResult <T> > Adds(List <T> entity) { List <ObjectResult <T> > result = new List <ObjectResult <T> >(); foreach (var item in entity) { ObjectResult <T> added = new ObjectResult <T>(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(item).State = EntityState.Added; context.SaveChanges(); added.obj = item; added.status.OK(); } } catch (Exception ex) { added.obj = item; added.status.Error("Database Error", ex.Message); } result.Add(added); } return(result); }
public ServiceResult Remove(T entity) { ServiceResult result = new ServiceResult(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(entity).State = EntityState.Deleted; context.SaveChanges(); result.OK(); } } catch (Exception ex) { result.Error("Database Error", ex.Message); } return(result); }
public void GetQrCodeImg(string Token, string deviceId) { TempBind tb = null; int num = 0; do { num = TextStr.RandomArray(1, 50000, 100000)[0]; string str = num + ""; tb = ve.TempBind.FirstOrDefault(q => q.SceneId == str); } while (tb != null); tb = new TempBind(); tb.Token = Token; tb.SceneId = num + ""; tb.CreateDate = DateTime.Now; tb.DeviceId = deviceId; ve.TempBind.Add(tb); ve.SaveChanges(); WriteImg(QrCodeManager.GenerateTemp(GetToken(), num)); }
public ObjectResult <T> Add(T entity) { ObjectResult <T> result = new ObjectResult <T>(); try { using (VideoEntities context = new VideoEntities()) { context.Entry(entity).State = EntityState.Added; context.SaveChanges(); result.status.OK(); result.obj = entity; } } catch (Exception ex) { result.status.Error("Database Error", ex.Message); } return(result); }
public void GetQrCodeImg(string token, string deviceId) { //TempBind temp = new TempBind(); //var ChildBind = (from c in ve.ChildBind orderby c.ID descending select new { sceneId = c.sceneId, deviceId = c.deviceId }).FirstOrDefault().sceneId; ////int sceneId = Convert.ToInt32(ChildBind.sceneId); //int scendIdOne = Convert.ToInt32(ve.ChildBind.OrderByDescending(cb=>cb.sceneId).FirstOrDefault().sceneId); //string sqlStr = string.Format("select top 1 sceneId from ChildBind order by ID desc"); //int SceneId = Convert.ToInt32(SqlHelper.ExecuteScalar(sqlStr)); int num = Convert.ToInt32(ve.ChildBind.OrderByDescending(cb => cb.sceneId).First().sceneId) + 1; ChildBind child = new ChildBind(); child.sceneId = num; child.token = token; child.deviceId = deviceId; child.BindDate = DateTime.Now; ve.ChildBind.Add(child); ve.SaveChanges(); WriteImg(QrCodeManager.GenerateTemp(GetToken(), num)); //WriteImg(QrCodeManager.GenerateTemp(GetToken(), 11)); }
public int AddModel(DataLog dl) { ve.DataLog.Add(dl); return(ve.SaveChanges()); }
//事件 public string EventHandle(XmlDocument xmldoc) { string responseContent = ""; XmlNode Event = xmldoc.SelectSingleNode("/xml/Event"); XmlNode EventKey = xmldoc.SelectSingleNode("/xml/EventKey"); XmlNode ToUserName = xmldoc.SelectSingleNode("/xml/ToUserName"); XmlNode FromUserName = xmldoc.SelectSingleNode("/xml/FromUserName"); if (Event != null) { StringBuilder str = new StringBuilder(); WeChatUser wcu = null; switch (Event.InnerText.ToLower()) { case "subscribe": str.Append("欢迎关注金龙锋【e家亲】服务号/:hug"); if (!string.IsNullOrEmpty(EventKey.InnerText)) { str.Append("\n"); string SceneId = EventKey.InnerText; SceneId = SceneId.Split('_')[1]; str.Append(BindWeChat(FromUserName.InnerText, SceneId)); } responseContent = string.Format(ReplyType.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, str.ToString()); break; case "unsubscribe": //取消关注 wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText); ve.WeChatUser.RemoveRange(ve.WeChatUser.Where(q => q.OpenId == FromUserName.InnerText)); ve.SaveChanges(); if (wcu != null) { string js = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":\"\"}"; Message ms = new Message("e家亲", js); PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms)); } break; case "scan": try { str.Append("欢迎关注金龙锋【e家亲】服务号/:hug"); if (!string.IsNullOrEmpty(EventKey.InnerText)) { string SceneId = EventKey.InnerText; str.Append(BindWeChat(FromUserName.InnerText, SceneId)); } } catch (Exception) { str = new StringBuilder("请勿重复扫描二维码绑定设备!"); throw; } responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, str.ToString()); break; case "click": if (EventKey.InnerText.Equals("V1001_GOOD")) //点击视频抓拍选项 { //DBHelper.ExecuteNonQueryString("insert into xmlString values('" + FromUserName.InnerText + "')"); try { wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText && q.State == true); if (wcu != null) { string showStr = ""; string js = "{\"Title\":\"推送消息\",\"Type\":10,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":\"\"}"; Message ms = new Message("e家亲", js); string returnStr = PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms)); JObject json = JObject.Parse(returnStr); returnStr = json["ret_code"].ToString(); if (returnStr == "0") { showStr = "视频抓拍请求已发送,等待回复(如果远程设备无响应,则无回复信息)"; } else { showStr = "请求失败,请稍后重试!"; } responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, showStr); } else { responseContent = string.Format(ReplyType.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, "你还未绑定设备/:bome"); } } catch (Exception ex) { SqlHelper.ExecuteNonQuery("insert into xmlString values('" + ex.Message + "')", null, System.Data.CommandType.Text); } } else if (EventKey.InnerText.Equals("V1002_GOOD")) //点击远程定位选项 { wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText && q.State == true); if (wcu != null) { string showStr = ""; string js = "{\"Title\":\"推送消息\",\"Type\":11,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":\"\"}"; Message ms = new Message("e家亲", js); string returnStr = PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms)); JObject json = JObject.Parse(returnStr); returnStr = json["ret_code"].ToString(); if (returnStr == "0") { showStr = "定位请求已发送,等待回复(如果远程设备无响应,则无回复信息)"; } else { showStr = "请求失败,请稍后重试!"; } responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, showStr); } else { responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, "你还未绑定设备/:bome"); } } else if (EventKey.InnerText.Equals("V1003_GOOD")) //点击一键抓拍选项 { wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText && q.State == true); if (wcu != null) { string showStr = ""; string js = "{\"Title\":\"推送消息\",\"Type\":8,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":\"\"}"; Message ms = new Message("e家亲", js); string returnStr = PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms)); JObject json = JObject.Parse(returnStr); returnStr = json["ret_code"].ToString(); if (returnStr == "0") { showStr = "图片抓拍请求已发送,等待回复(如果远程设备无响应,则无回复信息)"; } else { showStr = "请求失败,请稍后重试!"; } responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, showStr); } else { responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, "你还未绑定设备/:bome"); } } else { responseContent = string.Format(ReplyTyper.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, "未知错误!"); } //菜单单击事件 /*if (EventKey.InnerText.Equals("T12"))//click_one * { * wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText); * if (wcu != null) * { * responseContent = string.Format(ReplyType.Message_Text, * FromUserName.InnerText, * ToUserName.InnerText, * DateTime.Now.Ticks, * "你已绑定设备【" + wcu.Token + "】,可以正常使用推送功能!/:sun\n\n推送消息格式:@消息/::)"); * } * else * { * responseContent = string.Format(ReplyType.Message_Text, * FromUserName.InnerText, * ToUserName.InnerText, * DateTime.Now.Ticks, * "你还未绑定设备/:bome"); * } * } * else if (EventKey.InnerText.Equals("T13")) * { * var data = ve.Video.Where(q=>q.State==true).OrderByDescending(q=>q.CreateDate).Take(10); * string tempstr = ""; * foreach (Video item in data) * { * tempstr += string.Format(ReplyType.Message_News_Item, * item.Title, * "", * item.Cover, * item.Id); * } * responseContent = string.Format(ReplyType.Message_News_Main, * FromUserName.InnerText, * ToUserName.InnerText, * DateTime.Now.Ticks, * data.Count(), * tempstr); * }*/ break; default: break; } } return(responseContent); }
public object GetVideoUrl(int id, ref int count) { //UpdVideoUrl(id, 999); DataLog dl = new DataLog(); dl.KeyId = id; dl.Type = (int)LogEnum.VIDEOLOG; dl.OpenId = ""; dl.Describe = ""; dl.CreateTime = DateTime.Now; var tempdata = from a in ve.VideoUrl where a.Vid == id orderby a.Sort ascending, a.Id ascending select new { a.Id, a.Source, a.Path, a.TempPath }; foreach (var item in tempdata.ToList()) { string TempPath = item.Path; TempPath = TempPath.Replace("\t", ""); TempPath = TempPath.Replace("\\t", ""); string encryptPath = EncryptHelper.Encrypt(TempPath); if (string.IsNullOrEmpty((item.TempPath + "").Trim()) || (item.TempPath + "").Trim() == "7NTyKCzlI8jyXd7WRF1wFA==" || !encryptPath.Equals((item.TempPath + "").Trim())) //if (string.IsNullOrEmpty((item.TempPath + "").Trim()) || (item.TempPath + "").Trim() == "7NTyKCzlI8jyXd7WRF1wFA==" || item.Source.Trim() == "youku") { //IParsing jx = null; switch (item.Source.Trim()) { //case "youku": // jx = new YouKu(); // break; //case "360": // jx = new Yun360(); // break; //case "qq": // jx = new QQ(); // break; //case "Ku6": //case "ku6": // jx = new Ku6(); // break; //case "QQYun": // TempPath = item.Path.Replace(",", "/,"); // break; //case "myfile": // TempPath = item.Path.Replace(",", "/,"); // break; case "AES_baby": continue; //return item.TempPath; } //if (jx != null) //{ // try // { // TempPath = jx.Parsing(item.Path); // } // catch // { // TempPath = item.Path; // } //} Models.VideoUrl model = new VideoUrl(); model.Id = item.Id; model.TempPath = EncryptHelper.Encrypt(TempPath); DbEntityEntry <VideoUrl> entry = ve.Entry <VideoUrl>(model); entry.State = EntityState.Unchanged; entry.Property("TempPath").IsModified = true; ve.SaveChanges(); } } var data = from a in ve.VideoUrl where a.Vid == id orderby a.Sort ascending, a.Id ascending select new { a.Id, a.State, a.Source, a.Path, a.TempPath }; count = data.Count(); dlh.AddModel(dl); return(data); }