Esempio n. 1
0
 public void GetUsers()
 {
     if (Context.Session["OpenId"] != null)
     {
         string OpenId   = Context.Session["OpenId"].ToString();//"o_w1Kw8Uxh4dEoRDCe-HNYnyYlhY";//
         string deviceId = QrChildManager.GetChildDeviceId(OpenId);
         if (deviceId == "" || deviceId == null)
         {
             return;
         }
         DataTable     dt   = QrChildManager.GetOpenId(deviceId);
         Device_user   du   = new Device_user();
         List <string> list = new List <string>();
         foreach (DataRow row in dt.Rows)
         {
             list.Add(row["OpenId"].ToString());
         }
         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 list)
         {
             Dictionary <string, string> dic3 = new Dictionary <string, string>();
             dic3.Add("openid", item);
             dic3.Add("lang", "zh_CN");
             list2.Add(dic3);
         }
         dic2.Add("user_list", list2);
         string data2 = du.GetUserInformation(JsonConvert.SerializeObject(dic2));
         Write(data2);
     }
 }
Esempio n. 2
0
 protected void But_delete_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(Request.QueryString["id"]))
     {
         int id = Convert.ToInt32(Request.QueryString["id"]);
         if (!string.IsNullOrEmpty(Session["OpenIdE"].ToString()))
         {
             string openId     = Convert.ToString(Session["OpenIdE"]);
             string xingeToken = QrChildManager.GetXingeToken(openId);//得到token
             string DeviceId   = QrChildManager.GetDeviceId(xingeToken);
             if (AlarmClocksLogic.deleteAlarm(id))
             {
                 JObject content_json = new JObject();
                 content_json.Add("flag", 1);
                 content_json.Add("Id", id);
                 JObject ms_json = new JObject();
                 ms_json.Add("Title", "推送消息");
                 ms_json.Add("Type", 13);
                 ms_json.Add("OpenId", openId);
                 ms_json.Add("Content", content_json);
                 Response.Write(" <script type=\"text/javascript\"> alert(\"删除成功!\");</script>");
                 Response.Write(" <script type=\"text/javascript\"> window.location.href =\" AlarmClock.aspx\";</script>");
                 Message ms = new Message("幼儿伴侣", ms_json.ToString());
                 JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                 string  returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                 JObject json      = JObject.Parse(returnStr);
                 returnStr = json["ret_code"].ToString();
             }
         }
     }
 }
Esempio n. 3
0
        public void Get_UserInformation(string deviceId, string token)
        {
            DataTable dt = QrChildManager.GetOpenId(deviceId);

            if (dt.Rows.Count == 0)
            {
                HttpContext.Current.Response.Write("null");
                return;
            }
            string sql = string.Format("update ChildChatUser set Token = '{0}' where deviceId = '{1}'", token, deviceId);

            SqlHelper.ExecuteNonQuery(sql);
            List <string> list = new List <string>();

            foreach (DataRow item in dt.Rows)
            {
                list.Add(item["OpenId"].ToString());
            }
            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 list)
            {
                Dictionary <string, string> dic3 = new Dictionary <string, string>();
                dic3.Add("openid", item);
                dic3.Add("lang", "zh_CN");
                list2.Add(dic3);
            }
            dic2.Add("user_list", list2);
            string data2 = du.GetUserInformation(JsonConvert.SerializeObject(dic2));

            HttpContext.Current.Response.Write(data2);
        }
Esempio n. 4
0
        //为设备授权,可以绑定
        public string UpdateDevice(string device_id, string mac, string xingeToken, string qrticket)
        {
            try {
                QrChildManager.ChildUser(xingeToken, device_id, mac, qrticket);
            } catch (Exception ex) {
                HttpContext.Current.Response.Write(ex.Message);
            }
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("device_num", "1");
            Dictionary <string, string> dic2 = new Dictionary <string, string>();

            //string json = "[{id:" + device_id + ",mac:" + mac + ",connect_protocol:4,auth_key:1234567890ABCDEF1234567890ABCDEF,close_strategy:1,conn_strategy:1,crypt_method:0,auth_ver:0,manu_mac_pos:-1,ser_mac_pos:-2}]";
            dic2.Add("id", device_id);
            dic2.Add("mac", mac);
            dic2.Add("connect_protocol", "4");
            dic2.Add("auth_key", "1234567890ABCDEF1234567890ABCDEF");
            dic2.Add("close_strategy", "1");
            dic2.Add("conn_strategy", "1");
            dic2.Add("crypt_method", "0");
            dic2.Add("auth_ver", "0");
            dic2.Add("manu_mac_pos", "-1");
            dic2.Add("ser_mac_pos", "-2");
            dic.Add("device_list", dic2);
            dic.Add("op_type", "1");
            string jsonData = LitJson.JsonMapper.ToJson(dic);

            jsonData = jsonData.Insert(jsonData.LastIndexOf('{'), "[").Insert(jsonData.IndexOf('}') + 2, "]");
            return(du.UpdateDevice(jsonData));
            //return du.UpdateDevice(jsonData);
        }
Esempio n. 5
0
 public void QHDevices(string deviceId)
 {
     if (Context.Session["OpenId"] != null)
     {
         string OpenId = Context.Session["OpenId"].ToString();
         QrChildManager.UpdateState3(OpenId, deviceId);
         Write("true");
     }
 }
Esempio n. 6
0
 public void DelDevice(string deviceId)
 {
     if (Context.Session["OpenId"] != null)
     {
         string OpenId     = Context.Session["OpenId"].ToString();
         string xingeToken = QrChildManager.GetXingeToken(OpenId);
         QrChildManager.DelDervice(OpenId, deviceId);
         string  js = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + OpenId + "\",\"Content\":\"\"}";
         Message ms = new Message("e家亲幼儿伴侣", js);
         XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
         Write("true");
     }
 }
Esempio n. 7
0
 public void GetDevices()
 {
     if (Context.Session["OpenId"] != null)
     {
         string OpenId = Context.Session["OpenId"].ToString();//"o_w1Kw8Uxh4dEoRDCe-HNYnyYlhY";
         List <Dictionary <string, string> > list = QrChildManager.GetDevices(OpenId);
         if (list == null)
         {
             Write("null");
             return;
         }
         Write(JsonConvert.SerializeObject(list));
     }
 }
Esempio n. 8
0
 /// <summary>
 /// 页面加载事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     try {
         if (!IsPostBack)
         {
             if (Session["OpenIdE"] == null)
             {
                 if (!string.IsNullOrEmpty(Request.QueryString["code"]))
                 {
                     string  code      = Convert.ToString(Request.QueryString["code"]);
                     string  returnStr = getOpenId(code);
                     JObject json      = JObject.Parse(returnStr);
                     openId             = json["openid"].ToString();
                     Session["OpenIdE"] = openId;
                     string DeviceId = QrChildManager.GetChildDeviceId(openId);
                     Session["DeviceId"] = DeviceId;
                     List <AlarmClocks> mis = AlarmClocksLogic.Instance().GetAlarmClock(DeviceId);
                     RpList.DataSource = mis;
                     RpList.DataBind();
                 }
             }
             else if (Session["OpenIdE"] != null)
             {
                 openId = Session["OpenIdE"].ToString();                    //得到OpenId
                 string DeviceId = QrChildManager.GetChildDeviceId(openId); //得到token
                 if (DeviceId != "" || DeviceId != null)
                 {
                     Session["DeviceId"] = DeviceId;
                     if (DeviceId.Length != 0)
                     {
                         List <AlarmClocks> Almc = AlarmClocksLogic.Instance().GetAlarmClock(DeviceId);
                         RpList.DataSource = Almc;
                         RpList.DataBind();
                     }
                 }
             }
         }
         string             deviceId = Session["DeviceId"].ToString();
         List <AlarmClocks> miss     = AlarmClocksLogic.Instance().GetAlarmClock(deviceId);
         RpList.DataSource = miss;
         RpList.DataBind();
     } catch (Exception ex) {
         // Response.Write(" <script type=\"text/javascript\"> alert(\"登录过期,请重新登录\");</script>");
         Response.Write(" <script type=\"text/javascript\"> alert(\"登录过期,请重新进入\");</script>");
         //Response.Write(" <script type=\"text/javascript\"> window.close(); </script>");
         //Response.Write(" <script type=\"text/javascript\">history.go(-2);</script>");
     }
 }
Esempio n. 9
0
        public void Send_Online_News(string deviceId)
        {
            DataTable dt = QrChildManager.GetOpenId(deviceId);

            if (dt == null || dt.Rows.Count == 0)
            {
                HttpContext.Current.Response.Write("flase");
            }
            else
            {
                foreach (DataRow row in dt.Rows)
                {
                    du.SendNews("{\"touser\":\"" + row["OpenId"] + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"你的设备:" + row["deviceName"] + "。已上线!\"}}");
                }
                HttpContext.Current.Response.Write("true");
            }
        }
Esempio n. 10
0
 public void CheckUser()
 {
     if (Context.Session["OpenId"] != null)
     {
         string    OpenId = Context.Session["OpenId"].ToString();
         string    device = QrChildManager.GetChildDeviceId(OpenId);
         DataTable dt     = QrChildManager.GetOpenId(device);
         if (OpenId == dt.Rows[0]["OpenId"].ToString())
         {
             Write("true");
         }
         else
         {
             Write("你不是管理员,没有权限删除成员!");
         }
     }
 }
Esempio n. 11
0
        public void GetQrCodeImg(string deviceId, string xingeToken)
        {
            if (xingeToken == null || xingeToken == "" || xingeToken == "0")
            {
                Write("xingeToken is null");
            }
            else
            {
                var    time     = Stopwatch.StartNew();
                Byte[] imgBytes = QrChildManager.getQrUrl(deviceId, xingeToken, GetChildToken());
                time.Stop();
                WriteLog(string.Format("GetQrCodeImg 耗时:{0},{1}", time.Elapsed.TotalSeconds, imgBytes.Length));
                WriteImg(imgBytes);
            }
            ////string token = QrChildManager.BindXingeToken("9");
            //QrChildManager.ChildUser("o_w1Kw4kn8-m1MZJP_B68t2k0qLQ", "ed34e5f471d45f49492a9a17db2f47ecd6ad468d");

            //string xingeToken1 = QrChildManager.GetXingeToken("o_w1Kw4kn8-m1MZJP_B68t2k0qLQ");
            //Write(xingeToken1);
        }
Esempio n. 12
0
 public void WeChildPushMsg(string msg, string post)
 {
     if (Context.Session["OpenId"] != null)
     {
         //string openId = FromUserName.InnerText;
         //string xingeToken = QrChildManager.GetXingeToken(openId);
         string OpenId      = Context.Session["OpenId"].ToString();
         string xingeOpenId = QrChildManager.GetXingeOpenId(OpenId);
         string xingeToken  = QrChildManager.GetToken(OpenId);
         if (xingeOpenId != null && xingeOpenId != "")
         {
             int       id = Convert.ToInt32(msg);
             Video     vi = ve.Video.FirstOrDefault(q => q.Id == id);
             VideoType vt = ve.VideoType.FirstOrDefault(q => q.Id == vi.Tid);
             string    js = "{\"video_id\":" + id + ",\"video_name\":\"" + vi.Title + "\",\"position\":" + post + ",\"type_id\":" + vi.Tid + ",\"type_title\":\"" + vt.Title + "\",\"type_cover\":\"" + vt.Cover + "\"}";
             js = "{\"Title\":\"幼儿伴侣推送\",\"Type\":5,\"Content\":" + js + "}";
             Messages ms        = new Messages("幼儿伴侣", js);
             string   returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
             JObject  json      = JObject.Parse(returnStr);
             returnStr = json["ret_code"].ToString();
             //Write("推送成功!");
             if (returnStr == "0")
             {
                 new ChildPartner().SetMsgChild(xingeOpenId, "【" + vt.Title + "-" + vi.Title + "】推送成功!/:sun");
                 Write("推送成功!");
             }
             else
             {
                 Write("推送失败!" + returnStr);
             }
         }
         else
         {
             Write("您没绑定设备");
         }
     }
     else
     {
         Write("您还没有登陆,推送失败");
     }
 }
Esempio n. 13
0
        public void GetEwm()
        {
            if (Context.Session["OpenId"] != null)
            {
                string OpenId   = Context.Session["OpenId"].ToString();
                string deviceId = QrChildManager.GetChildDeviceId(OpenId);
                string token    = QrChildManager.Get_xingeToken(deviceId);

                /*Dictionary<string, string> dic = new Dictionary<string, string>();
                 * dic.Add("deviceId", deviceId);
                 * dic.Add("token", token);  xiiuagiasdasdadsdadasd
                 * Write(JsonConvert.SerializeObject(dic));*/
                Device_user du       = new Device_user();
                Byte[]      imgBytes = QrChildManager.getQrUrl(deviceId, token, du.SelectToken());
                WriteLog("GetEwm END:" + imgBytes.Length);
                Context.Response.Clear();
                Context.Response.ContentType = "image/jpg";
                Context.Response.BinaryWrite(imgBytes);
                Context.Response.End();
            }
        }
Esempio n. 14
0
 public void Images(string image, string deviceId)
 {
     if (Context.Session["OpenId"] != null)
     {
         string OpenId = Context.Session["OpenId"].ToString();
         String header = "data:image/jpeg;base64,";
         if (image.IndexOf(header) != 0)
         {
             return;
         }
         // 去掉头部
         image = image.Substring(header.Length);
         try {
             byte[] bt = Convert.FromBase64String(image);
             System.IO.MemoryStream stream = new System.IO.MemoryStream(bt);
             Bitmap bitmap   = new Bitmap(stream);
             string uid      = Guid.NewGuid().ToString();
             string fileName = string.Format("D:/webSites/www_root/Img/deviceHeadImg/{0}.jpg", uid);
             //http://v.icoxtech.com/Img/deviceHeadImg/
             bitmap.Save(fileName);
             Image srcImage = Image.FromFile(fileName);
             try {
                 Bitmap   b = new Bitmap(500, 500);
                 Graphics g = Graphics.FromImage(b);
                 g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default;
                 g.DrawImage(srcImage, new Rectangle(0, 0, 500, 500), new Rectangle(0, 0, srcImage.Width, srcImage.Height), GraphicsUnit.Pixel);
                 g.Dispose();
                 b.Save(string.Format("D:/webSites/www_root/Img/deviceHeadImg/imgs/{0}.jpg", uid));
             } catch (Exception ex) {
                 throw ex;
             }
             QrChildManager.UpdateHeadImg(OpenId, deviceId, string.Format("http://v.icoxtech.com/Img/deviceHeadImg/imgs/{0}.jpg", uid));
             //return bitmap;
         } catch (Exception e) {
             Write(e.Message);
         }
         Write("true");
     }
 }
Esempio n. 15
0
 public void GetQrticketByMac(string mac, string token)
 {
     if (token == "" || token == null || token == "0")
     {
         HttpContext.Current.Response.Write("token is null");
         return;
     }
     else
     {
         string qrticket = QrChildManager.GetQrticket(mac, token);
         if (qrticket == null)
         {
             Dictionary <string, object> dic = GetQrticket("42321");
             string json = UpdateDevice(dic["deviceid"].ToString(), mac, token, dic["qrticket"].ToString());
             Dictionary <string, List <Dictionary <string, object> > > dic2 = JsonConvert.DeserializeObject <Dictionary <string, List <Dictionary <string, object> > > >(json);
             if (dic2["resp"][0]["errcode"].ToString() == "0" && dic2["resp"][0]["errmsg"].ToString().ToUpper() == "OK")
             {
                 qrticket = QrChildManager.GetQrticket(mac, token);
             }
         }
         HttpContext.Current.Response.Write(qrticket);
     }
 }
Esempio n. 16
0
 public void DelUsers(string openId)
 {
     if (Context.Session["OpenId"] != null)
     {
         string    OpenId = Context.Session["OpenId"].ToString();
         string    device = QrChildManager.GetChildDeviceId(OpenId);
         DataTable dt     = QrChildManager.GetOpenId(device);
         if (OpenId == dt.Rows[0]["OpenId"].ToString())
         {
             Device_user   du   = new Device_user();
             List <string> list = new List <string>();
             foreach (DataRow row in dt.Rows)
             {
                 list.Add(row["OpenId"].ToString());
             }
             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 list)
             {
                 Dictionary <string, string> dic3 = new Dictionary <string, string>();
                 dic3.Add("openid", item);
                 dic3.Add("lang", "zh_CN");
                 list2.Add(dic3);
             }
             dic2.Add("user_list", list2);
             string data2 = du.GetUserInformation(JsonConvert.SerializeObject(dic2));
             Dictionary <string, List <Dictionary <string, object> > > list3 = JsonConvert.DeserializeObject <Dictionary <string, List <Dictionary <string, object> > > >(data2);
             string admin = "";
             string user  = "";
             foreach (var item in list3["user_info_list"])
             {
                 if (item["openid"].ToString() == OpenId)
                 {
                     admin = item["nickname"].ToString();
                 }
                 if (item["openid"].ToString() == openId)
                 {
                     user = item["nickname"].ToString();
                 }
             }
             foreach (var item in list3["user_info_list"])
             {
                 if (user == admin)
                 {
                     return;
                 }
                 else
                 {
                     string content = string.Format("成员{0}已被管理员{1}删除绑定!", user, admin);
                     if (item["openid"].ToString() == openId)
                     {
                         content = string.Format("你已被管理员{0}删除绑定!", admin);
                     }
                     string data = "{\"touser\":\"" + item["openid"] + "\",\"msgtype\":\"text\",\"text\":{\"content\":\"" + content + "\"}}";
                     du.SendNews(data);
                 }
             }
             string xingeToken = QrChildManager.GetXingeToken(openId);
             QrChildManager.DeleteOpenId(openId, device);
             string  js = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + openId + "\",\"Content\":\"\"}";
             Message ms = new Message("e家亲幼儿伴侣", js);
             XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
             Write("true");
         }
         else
         {
             Write("你不是管理员,没有权限删除成员!");
         }
     }
 }
Esempio n. 17
0
 /// <summary>
 /// 修改的单击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void But_xiugai_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(Request.QueryString["id"]))
     {
         AlarmClocks acs = new AlarmClocks();
         acs.Id = Convert.ToInt32(Request.QueryString["id"]);
         if (Text_ClockTime.Value == "" || Text_ClockTime.Value == null)
         {
             Response.Write(" <script type=\"text/javascript\"> alert(\"请选择时间!\");</script>");
             return;
         }
         acs.ClockTime = Text_ClockTime.Value;
         string text = Convert.ToString(Drop_type.Text);
         if (text.Equals("自定义"))
         {
             if (Text_zidingyi.Text == null || Text_zidingyi.Text == "")
             {
                 acs.AlarmType = "自定义";
             }
             else
             {
                 acs.AlarmType = Text_zidingyi.Text;
             }
         }
         else
         {
             acs.AlarmType = text;
         }
         acs.Content = Text_content.Value;
         acs.Repeat  = Convert.ToString(Drop_repater.Text);
         int[] weekDay = new int[7];
         for (int i = 0; i < Chbke_Week.Items.Count; i++)
         {
             if (Chbke_Week.Items[i].Selected == true)
             {
                 weekDay[i] = 1;
             }
         }
         string weekStr = "";
         for (int i = 0; i < weekDay.Length; i++)
         {
             if (weekDay[i] == 1)
             {
                 weekStr += "1";
             }
             else
             {
                 weekStr += "0";
             }
             weekStr += ",";
         }
         weekStr.Remove(weekStr.Length - 1);
         //获取字符串长度
         int length = weekStr.Length;
         //截取除最后一位的前面所有字符
         weekStr        = weekStr.Substring(0, length - 1);
         acs.RepeatDate = weekStr;
         acs.State      = 1;
         acs.Frequency  = Convert.ToInt32(Drop_Frequency.SelectedValue);
         acs.Interval   = Convert.ToInt32(Drop_Interval.SelectedValue);
         string openId     = Convert.ToString(Session["OpenIdE"]);
         string xingeToken = QrChildManager.GetXingeToken(openId);   //得到token
         string DeviceId   = Context.Session["DeviceId"].ToString(); //根据得到的token拿到用户表的DeviceId
         if (AlarmClocksLogic.updateAlarm(acs))
         {
             string[] dts          = acs.ClockTime.Split(':');
             string   hour         = dts[0];
             string   mitner       = dts[1];
             JObject  content_json = new JObject();
             content_json.Add("flag", 2);
             content_json.Add("Id", acs.Id);
             content_json.Add("content", acs.AlarmType);
             content_json.Add("hour", hour);
             content_json.Add("mitner", mitner);
             content_json.Add("state", acs.State);
             content_json.Add("AlarmType", acs.Content);
             content_json.Add("Repeat", acs.Repeat);
             content_json.Add("weekStr", acs.RepeatDate);
             content_json.Add("Frequency", acs.Frequency);
             content_json.Add("Interval", acs.Interval);
             content_json.Add("DeviceId", DeviceId);
             JObject ms_json = new JObject();
             ms_json.Add("Title", "推送消息");
             ms_json.Add("Type", 13);
             ms_json.Add("OpenId", openId);
             ms_json.Add("Content", content_json);
             Response.Write(" <script type=\"text/javascript\"> alert(\"修改成功!\");</script>");
             Response.Write(" <script type=\"text/javascript\">  window.location.href =\" AlarmClock.aspx\"</script>");
             //string js = "{\"Title\":\"推送消息\",\"Type\":13,\"OpenId\":\"" + openId + "\",\"Content\":\"" + content_json.ToString() + "\"}";
             Message ms = new Message("幼儿伴侣", ms_json.ToString());
             JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
             string returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
             //string returnStr = XinGePush.PushMsg(xingeToken, JsonConvert.SerializeObject(ms));
             JObject json = JObject.Parse(returnStr);
             returnStr = json["ret_code"].ToString();
         }
         else
         {
             Response.Write(" <script type=\"text/javascript\"> alert(\"修改失败!\");</script>");
             Response.Write(" <script type=\"text/javascript\"> history.go(-2);</script>");
         }
     }
     else
     //添加事件
     {
         AlarmClocks acs = new AlarmClocks();
         if (Text_ClockTime.Value == "" || Text_ClockTime.Value == null)
         {
             Response.Write(" <script type=\"text/javascript\"> alert(\"请选择时间!\");</script>");
             Response.Write(" <script type=\"text/javascript\"> history.go(-1);</script>");
             return;
         }
         acs.ClockTime = Text_ClockTime.Value;
         acs.Repeat    = Convert.ToString(Drop_repater.Text);
         string text = Convert.ToString(Drop_type.Text);
         if (text.Equals("自定义"))
         {
             if (Text_zidingyi.Text == null || Text_zidingyi.Text == "")
             {
                 acs.AlarmType = "自定义";
             }
             else
             {
                 acs.AlarmType = Text_zidingyi.Text;
             }
         }
         else
         {
             acs.AlarmType = text;
         }
         acs.Content = Text_content.Value;
         acs.State   = 1;
         int[] weekDay = new int[7];
         for (int i = 0; i < Chbke_Week.Items.Count; i++)
         {
             if (Chbke_Week.Items[i].Selected == true)
             {
                 weekDay[i] = 1;
             }
         }
         string weekStr = "";
         for (int i = 0; i < weekDay.Length; i++)
         {
             if (weekDay[i] == 1)
             {
                 weekStr += "1";
             }
             else
             {
                 weekStr += "0";
             }
             weekStr += ",";
         }
         weekStr.Remove(weekStr.Length - 1);
         //获取字符串长度
         int length = weekStr.Length;
         //截取除最后一位的前面所有字符
         weekStr        = weekStr.Substring(0, length - 1);
         acs.RepeatDate = weekStr;
         acs.Frequency  = Convert.ToInt32(Drop_Frequency.SelectedValue);
         acs.Interval   = Convert.ToInt32(Drop_Interval.SelectedValue);
         string openId     = Convert.ToString(Session["OpenIdE"]);
         string xingeToken = QrChildManager.GetXingeToken(openId);   //得到token
         string DeviceId   = Context.Session["DeviceId"].ToString(); //根据得到的token拿到用户表的DeviceId
         if (DeviceId != "" || DeviceId != null)
         {
             acs.DeviceId = DeviceId;
             int insertid = Convert.ToInt32(AlarmClocksLogic.insert_id(acs));
             if (insertid != 0)
             {
                 string[] dts          = acs.ClockTime.Split(':');
                 string   hour         = dts[0];
                 string   mitner       = dts[1];
                 JObject  content_json = new JObject();
                 content_json.Add("flag", 3);
                 content_json.Add("Id", insertid);
                 content_json.Add("hour", hour);
                 content_json.Add("content", acs.AlarmType);
                 content_json.Add("mitner", mitner);
                 content_json.Add("state", acs.State);
                 content_json.Add("AlarmType", acs.Content);
                 content_json.Add("Repeat", acs.Repeat);
                 content_json.Add("weekStr", acs.RepeatDate);
                 content_json.Add("Frequency", acs.Frequency);
                 content_json.Add("Interval", acs.Interval);
                 content_json.Add("DeviceId", DeviceId);
                 JObject ms_json = new JObject();
                 ms_json.Add("Title", "推送消息");
                 ms_json.Add("Type", 13);
                 ms_json.Add("OpenId", openId);
                 ms_json.Add("Content", content_json);
                 Response.Write(" <script type=\"text/javascript\"> alert(\"添加成功!\");</script>");
                 Response.Write(" <script type=\"text/javascript\"> window.location.href =\" AlarmClock.aspx\"</script>");
                 //string js = "{\"Title\":\"推送消息\",\"Type\":13,\"OpenId\":\"" + openId + "\",\"Content\":\"" + content_json.ToString() + "\"}";
                 Message ms = new Message("幼儿伴侣", ms_json.ToString());
                 JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
                 string  returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                 JObject json      = JObject.Parse(returnStr);
                 returnStr = json["ret_code"].ToString();
             }
             else
             {
                 Response.Write(" <script type=\"text/javascript\"> alert(\"添加失败!\");</script>");
                 Response.Write(" <script type=\"text/javascript\"> history.go(-2);</script>");
             }
         }
         else
         {
             Response.Write(" <script type=\"text/javascript\"> alert(\"登录过期,请重新登录\");</script>");
             Response.Write(" <script type=\"text/javascript\"> history.go(-2);</script>");
         }
     }
 }
Esempio n. 18
0
        /// <summary>
        /// 添加闹钟
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void But_xiugai_Click(object sender, EventArgs e)
        {
            //还有一个闹钟类型要添加
            string time    = Request.Form.Get("RTime");  //提醒时间
            string content = this.Text_Content.Text;     //提醒名称
            string Repeat  = Request.Form.Get("Repeat"); //是否重复

            int[] weekDay = new int[7];
            for (int i = 0; i < CheckBoxList1.Items.Count; i++)
            {
                if (CheckBoxList1.Items[i].Selected == true)
                {
                    weekDay[i] = 1;
                }
            }
            string weekStr = "";

            for (int i = 0; i < weekDay.Length; i++)
            {
                if (weekDay[i] == 1)
                {
                    weekStr += "1";
                }
                else
                {
                    weekStr += "0";
                }
                weekStr += ",";
            }
            weekStr.Remove(weekStr.Length - 1);
            //获取字符串长度
            int length = weekStr.Length;

            //截取除最后一位的前面所有字符
            weekStr = weekStr.Substring(0, length - 1);
            string Frequency  = Request["count"];                     //拿到重复次数
            string Interval   = Request.Form.Get("interval");         //拿到闹钟间隔
            string openId     = Convert.ToString(Session["openId"]);
            string xingeToken = QrChildManager.GetXingeToken(openId); //得到token

            if (xingeToken != "" && xingeToken != null)
            {
                //string DeviceId ="b84c0210ec00";
                string DeviceId = QrChildManager.GetDeviceId(xingeToken);//根据得到的token拿到用户表的DeviceId
                if (time != null && time != "" && content != null && content != "" && Repeat != null && Repeat != "" && Frequency != null && Frequency != "" && Interval != null && Interval != "")
                {
                    string sql = string.Format("insert AlarmClock (ClockTime,DeviceId,[Content],[Repeat],RepeatDate,Frequency,Interval) values ('{0}','{1}','{2}','{3}','{4}','{5}','{5}')", time, DeviceId, content, Repeat, weekStr, Frequency, Interval);
                    SqlHelper.ExecuteNonQuery(sql);
                    ClientScript.RegisterStartupScript(this.GetType(), "幼儿伴侣提醒您!", "<script>alert('添加成功!'); location.href='https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0e7b25b6f1553eea&redirect_uri=http://v.icoxtech.com/AlarmClock.aspx?response_type=code&scope=snsapi_base&state=1#wechat_redirect';</script>");
                    JObject  content_json = new JObject();
                    string[] dts          = time.Split(':');
                    string   hour         = dts[0];
                    string   mitner       = dts[1];
                    content_json.Add("flag", 3);
                    content_json.Add("hour", hour);
                    content_json.Add("mitner", mitner);
                    content_json.Add("content", content);
                    content_json.Add("Repeat", Repeat);
                    content_json.Add("weekStr", weekStr);
                    content_json.Add("Frequency", Frequency);
                    content_json.Add("Interval", Interval);
                    content_json.Add("DeviceId", DeviceId);
                    //string js = "{\"Title\":\"推送消息\",\"Type\":13,\"OpenId\":\"" + openId + "\",\"Content\":" + content_json.ToString() + "}";
                    //Message ms = new Message("幼儿伴侣", js);
                    //string returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                    ////string returnStr = XinGePush.PushMsg(xingeToken, JsonConvert.SerializeObject(ms));
                    //JObject json = JObject.Parse(returnStr);
                    //returnStr = json["ret_code"].ToString();
                    //Response.Write(returnStr);

                    JObject ms_json = new JObject();
                    ms_json.Add("Title", "推送消息");
                    ms_json.Add("Type", 13);
                    ms_json.Add("OpenId", openId);
                    ms_json.Add("Content", content_json);//string content_str = "{\"flag\":\"" + 3 + "\",\"hour\":" + hour + ",\"mitner\":\"" + mitner + "\",\"content\":\"" + content + "\",\"YesandNo\":\"" + YesandNo + ",\"weekStr\":\"" + weekStr + "\",\"Frequency\":\"" + Frequency + "\",\"Interval\":\"" + Interval + "\",\"DeviceId\":\"" + DeviceId + "\"}";
                    //string js = "{\"Title\":\"推送消息\",\"Type\":13,\"OpenId\":\"" + openId + "\",\"Content\":\"" + content_str + "\"}";
                    Message ms         = new Message("e家亲幼儿伴侣", ms_json.ToString());
                    string  returnStr  = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                    JObject json       = JObject.Parse(returnStr);
                    string  returnCode = json["ret_code"].ToString();
                    if (returnCode == "0")
                    {
                        //Response.Write(returnStr + ", xingeToken = " + xingeToken + ", js = " + ms_json.ToString());
                    }
                }
                else
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "幼儿伴侣提醒您!", "<script>alert('请填写完整信息!')</script>");
                    return;
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "幼儿伴侣提醒您!", "<script>alert('请先绑定设备!')</script>");
                return;
            }
        }
Esempio n. 19
0
 public void DelDeviceBind(string deviceId)
 {
     Write(QrChildManager.DeleteDevice(deviceId).ToString());
 }