Example #1
0
        private string BindWeChat(string OpenId, string SceneId)
        {
            StringBuilder str = new StringBuilder();
            TempBind      tb  = ve.TempBind.FirstOrDefault(q => q.SceneId == SceneId);

            if (tb != null)
            {
                WeChatUser tempwcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == OpenId && q.DeviceId == tb.DeviceId);
                if (tempwcu != null)
                {
                    if (tb.Token != tempwcu.Token)
                    {
                        tempwcu.Token = tb.Token;
                        ve.SaveChanges();
                    }
                    str.Append("你的帐号已绑定【" + tempwcu.DeviceName + "】该设备!");
                }
                else
                {
                    string     js  = "";
                    Message    ms  = null;
                    WeChatUser wcu = new WeChatUser();
                    wcu.OpenId     = OpenId;
                    wcu.Token      = tb.Token;
                    wcu.DeviceId   = tb.DeviceId;
                    wcu.DeviceName = tb.DeviceId;
                    wcu.State      = true;
                    wcu.UserPhone  = "";
                    wcu.HeadImg    = "../Img/ejq.jpg";
                    wcu.CreateDate = DateTime.Now;
                    ve.WeChatUser.Add(wcu);
                    ve.SaveChanges();
                    List <WeChatUser> list = ve.WeChatUser.Where(x => x.OpenId == OpenId).ToList();
                    foreach (var item in list)
                    {
                        if (item.DeviceId == wcu.DeviceId)
                        {
                            continue;
                        }
                        item.State = false;
                        ve.SaveChanges();
                    }
                    str.Append("\n请在下方回复“绑定设备+手机号”\n如:绑定设备13212345678\n即可激活设备!");
                    js = "{\"Title\":\"绑定推送\",\"Type\":6,\"OpenId\":\"" + OpenId + "\",\"Content\":\"\"}";
                    ms = new Message("e家亲", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                    string  returnStr = PushHelper.PushMsg(tb.Token, jsonSerializer.Serialize(ms));
                    JObject json      = JObject.Parse(returnStr);
                    returnStr = json["ret_code"].ToString();
                }
            }
            return(str.ToString());
        }
Example #2
0
 public void EDelDevice(string deviceId)
 {
     if (Context.Session["OpenIdE"] != null)
     {
         string     OpenId = Context.Session["OpenIdE"].ToString();
         WeChatUser wcu    = ve.WeChatUser.FirstOrDefault(x => x.OpenId == OpenId && x.DeviceId == deviceId);
         string     js     = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + OpenId + "\",\"Content\":\"\"}";
         Message    ms     = new Message("e家亲", js);
         PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms));
         ve.WeChatUser.Remove(wcu);
         ve.SaveChanges();
         Write("true");
     }
 }
Example #3
0
        //接受视频消息  备注:"&"=>"@1"  "="=>"@2"  "%"=>"@3"
        public string VideoHandle(XmlDocument xmldoc)
        {
            string  responseContent = "";
            XmlNode ToUserName      = xmldoc.SelectSingleNode("/xml/ToUserName");
            XmlNode FromUserName    = xmldoc.SelectSingleNode("/xml/FromUserName");
            XmlNode MediaId         = xmldoc.SelectSingleNode("/xml/MediaId");
            XmlNode ThumbMediaId    = xmldoc.SelectSingleNode("/xml/ThumbMediaId");

            if (MediaId != null)
            {
                WeChatUser wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText && q.State == true);
                if (wcu != null)
                {
                    string url = string.Format("https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", ToKen, MediaId.InnerText);
                    string img = string.Format("https://api.weixin.qq.com/cgi-bin/media/get?access_token={0}&media_id={1}", ToKen, ThumbMediaId.InnerText);
                    string js  = "{\"url\":\"" + url + "\",\"img\":\"" + img + "\"}";
                    js = "{\"Title\":\"推送视频\",\"Type\":4,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":" + js + "}";
                    Message ms        = new Message("e家亲", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                    string  returnStr = PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms));
                    JObject json      = JObject.Parse(returnStr);
                    returnStr = json["ret_code"].ToString();
                    if (returnStr == "0")
                    {
                        responseContent = string.Format(ReplyType.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "你向设备【" + wcu.DeviceName + "】推送了一段视频!");
                    }
                    else
                    {
                        responseContent = string.Format(ReplyType.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "推送视频失败!/:bome");
                    }
                }
                else
                {
                    responseContent = string.Format(ReplyType.Message_Text,
                                                    FromUserName.InnerText,
                                                    ToUserName.InnerText,
                                                    DateTime.Now.Ticks,
                                                    "请先绑定设备!/::)");
                }
            }
            return(responseContent);
        }
Example #4
0
        //接受图片消息 备注:"&"=>"@1"  "="=>"@2"  "%"=>"@3"
        public string ImageHandle(XmlDocument xmldoc)
        {
            string  responseContent = "";
            XmlNode ToUserName      = xmldoc.SelectSingleNode("/xml/ToUserName");
            XmlNode FromUserName    = xmldoc.SelectSingleNode("/xml/FromUserName");
            XmlNode PicUrl          = xmldoc.SelectSingleNode("/xml/PicUrl");

            if (PicUrl != null)
            {
                WeChatUser wcu = ve.WeChatUser.FirstOrDefault(q => q.OpenId == FromUserName.InnerText && q.State == true);
                if (wcu != null)
                {
                    string  js        = "{\"Title\":\"推送图片\",\"Type\":2,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":\"" + PicUrl.InnerText + "\"}";
                    Message ms        = new Message("e家亲", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                    string  returnStr = PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms));
                    JObject json      = JObject.Parse(returnStr);
                    returnStr = json["ret_code"].ToString();
                    if (returnStr == "0")
                    {
                        responseContent = string.Format(ReplyType.Message_News_Main,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "1",
                                                        string.Format(ReplyType.Message_News_Item, "e家亲", "你向设备【" + wcu.DeviceName + "】推送了一张图片!",
                                                                      PicUrl.InnerText, ""));
                    }
                    else
                    {
                        responseContent = string.Format(ReplyType.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "推送图片失败!/:bome");
                    }
                }
                else
                {
                    responseContent = string.Format(ReplyType.Message_Text,
                                                    FromUserName.InnerText,
                                                    ToUserName.InnerText,
                                                    DateTime.Now.Ticks,
                                                    "请先绑定设备!/::)");
                }
            }
            return(responseContent);
        }
Example #5
0
 public void WeChatPushMsg(string msg, string post)
 {
     if (Context.Session["OpenIdE"] != null)
     {
         string     OpenId = Context.Session["OpenIdE"].ToString();
         WeChatUser wcu    = ve.WeChatUser.FirstOrDefault(q => q.OpenId == OpenId && q.State == true);
         if (wcu != null)
         {
             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\":\"e家亲推送\",\"Type\":5,\"Content\":" + js + "}";
             Messages ms        = new Messages("e家亲", js);
             string   returnStr = PushHelper.PushMsg(wcu.Token, jsonSerializer.Serialize(ms));
             JObject  json      = JObject.Parse(returnStr);
             returnStr = json["ret_code"].ToString();
             if (returnStr == "0")
             {
                 new WeChat1().SetMsg(wcu.OpenId, "【" + vt.Title + "-" + vi.Title + "】推送成功!/:sun");
                 Write("推送成功!");
             }
             else
             {
                 Write("推送失败!" + returnStr);
             }
         }
         else
         {
             Write("您没绑定设备!");
         }
     }
     else
     {
         Write("没有登陆,推送失败!");
     }
 }
Example #6
0
 public void EDelUsers(string openId)
 {
     if (Context.Session["OpenIdE"] != null)
     {
         string            OpenId = Context.Session["OpenIdE"].ToString();
         WeChatUser        wcu    = ve.WeChatUser.FirstOrDefault(x => x.OpenId == OpenId && x.State == true);
         List <WeChatUser> list   = ve.WeChatUser.Where(x => x.DeviceId == wcu.DeviceId).OrderBy(x => x.CreateDate).ToList();
         if (OpenId == list[0].OpenId)
         {
             Device_user du = new Device_user();
             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.OpenId);
                 dic3.Add("lang", "zh_CN");
                 list2.Add(dic3);
             }
             dic2.Add("user_list", list2);
             string data2 = du.GetUserInformation2(JsonConvert.SerializeObject(dic2), GetToken());
             Dictionary <string, List <Dictionary <string, object> > > list3 = JsonConvert.DeserializeObject <Dictionary <string, List <Dictionary <string, object> > > >(data2);
             //string[] ids = openId.Split(',');
             //foreach (var id in ids) {
             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"])
             {
                 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.SendNews2(data, GetToken());
             }
             WeChatUser wcu2 = ve.WeChatUser.FirstOrDefault(x => x.OpenId == openId && x.DeviceId == wcu.DeviceId);
             string     js   = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + openId + "\",\"Content\":\"\"}";
             Message    ms   = new Message("e家亲", js);
             PushHelper.PushMsg(wcu2.Token, jsonSerializer.Serialize(ms));
             ve.WeChatUser.Remove(wcu2);
             ve.SaveChanges();
             //}
             Write("true");
         }
         else
         {
             Write("你不是管理员,没有权限删除成员!");
         }
     }
 }
Example #7
0
        /// <summary>
        /// 添加闹钟
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void But_xiugai_Click(object sender, EventArgs e)
        {
            string time    = this.Text_Time.Text;
            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"]);
            WeChatUser wcu       = ve.WeChatUser.FirstOrDefault(x => x.OpenId == openId && x.State == true);

            //string xingeToken = QrChildManager.GetXingeToken(openId);//得到token
            if (wcu.Token != "" && wcu.Token != null)
            {
                //string DeviceId ="b84c0210ec00";
                string DeviceId = wcu.DeviceId;//根据得到的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(), "e家亲提醒您!", "<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  = PushHelper.PushMsg(wcu.Token, 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(), "e家亲提醒您!", "<script>alert('请填写完整信息!')</script>");
                    return;
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "e家亲提醒您!", "<script>alert('请先绑定设备!')</script>");
                return;
            }
        }
Example #8
0
        //事件
        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);
        }
Example #9
0
        //接受文本消息
        public string TextHandle(XmlDocument xmldoc)
        {
            string  responseContent = "";
            XmlNode ToUserName      = xmldoc.SelectSingleNode("/xml/ToUserName");
            XmlNode FromUserName    = xmldoc.SelectSingleNode("/xml/FromUserName");
            XmlNode Content         = xmldoc.SelectSingleNode("/xml/Content");

            //WriteLog("ToUserName:"******"---FromUserName:"******"---Content:" + Content.InnerText);
            if (Content != null)
            {
                string str = Content.InnerText;
                if (!str.StartsWith("@"))
                {
                    WeChatUser wcu = ve.WeChatUser.OrderByDescending(x => x.Id).FirstOrDefault(q => q.OpenId == FromUserName.InnerText && q.State == true);
                    if (wcu != null)
                    {
                        if (str.StartsWith("绑定设备") || str.StartsWith("修改设备名称") || str.StartsWith("切换设备"))
                        {
                            Regex regex = new Regex("^绑定设备\\d{11}$");
                            if (regex.IsMatch(str))
                            {
                                string phone = str.Substring(4, 11);
                                try {
                                    wcu.UserPhone = phone;
                                    ve.SaveChanges();
                                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                                    FromUserName.InnerText,
                                                                    ToUserName.InnerText,
                                                                    DateTime.Now.Ticks,
                                                                    "恭喜您绑定设备成功!当前设备名为:" + wcu.DeviceName + "\n在下方回复:“修改设备名称+您指定的设备名称”\n如:修改设备名称大儿子\n即可修改设备名称便于多设备管理!");
                                } catch (Exception) {
                                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                                    FromUserName.InnerText,
                                                                    ToUserName.InnerText,
                                                                    DateTime.Now.Ticks,
                                                                    "绑定失败,请重新绑定!");
                                    return(responseContent);
                                }
                            }
                            else
                            {
                                responseContent = string.Format(ReplyTyper.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "输入格式有误,请重新输入!");
                            }
                            if (str.StartsWith("修改设备名称"))
                            {
                                string deviceName3 = str.Substring(6, str.Length - 6);
                                try {
                                    wcu.DeviceName = deviceName3;
                                    ve.SaveChanges();
                                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                                    FromUserName.InnerText,
                                                                    ToUserName.InnerText,
                                                                    DateTime.Now.Ticks,
                                                                    "修改设备名称成功,当前设备名称为:" + wcu.DeviceName + "\n在下方回复:“切换设备+设备名称”\n如:切换设备大儿子\n即可切换到设备大儿子!");
                                } catch (Exception) {
                                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                                    FromUserName.InnerText,
                                                                    ToUserName.InnerText,
                                                                    DateTime.Now.Ticks,
                                                                    "修改设备名称失败,设备名称有误!");
                                    return(responseContent);
                                }
                            }
                            if (str.StartsWith("切换设备"))
                            {
                                string deviceName4 = str.Substring(4, str.Length - 4);
                                try {
                                    List <WeChatUser> list = ve.WeChatUser.Where(x => x.OpenId == ToUserName.InnerText).OrderBy(x => x.CreateDate).ToList();
                                    foreach (var item in list)
                                    {
                                        item.State = false;
                                        if (item.DeviceName == deviceName4)
                                        {
                                            item.State = true;
                                        }
                                    }
                                    ve.SaveChanges();
                                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                                    FromUserName.InnerText,
                                                                    ToUserName.InnerText,
                                                                    DateTime.Now.Ticks,
                                                                    "切换设备成功,当前设备为:" + wcu.DeviceName);
                                } catch (Exception) {
                                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                                    FromUserName.InnerText,
                                                                    ToUserName.InnerText,
                                                                    DateTime.Now.Ticks,
                                                                    "切换设备失败,设备名称有误!");
                                    return(responseContent);
                                }
                            }
                        }
                        else
                        {
                            string  js        = "{\"Title\":\"推送消息\",\"Type\":1,\"OpenId\":\"" + wcu.OpenId + "\",\"Content\":\"" + str + "\"}";
                            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")
                            {
                                responseContent = string.Format(ReplyType.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "你向设备【" + wcu.DeviceName + "】推送消息成功!/:sun");
                            }
                            else
                            {
                                responseContent = string.Format(ReplyType.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "推送消息失败!/:bome");
                            }
                        }
                    }
                    else
                    {
                        responseContent = string.Format(ReplyType.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "请先绑定设备!/::)");
                    }
                }
                else
                {
                    responseContent = HandleOther(str, FromUserName.InnerText, ToUserName.InnerText);
                }
            }
            return(responseContent);
        }
Example #10
0
        //事件
        public string EventHandler(XmlDocument xmldoc)
        {
            string  responseContent = "hello";
            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();
                string        openId     = FromUserName.InnerText;
                string        xingeToken = "";
                switch (Event.InnerText.ToLower())
                {
                case "subscribe":
                    str.Append("欢迎使用微信物联智能学习陪伴机器人系统;");
                    if (!string.IsNullOrEmpty(EventKey.InnerText))
                    {
                        string SceneId = EventKey.InnerText;
                        SceneId = SceneId.Split('_')[1];
                        str.Append(BindDevice(openId, SceneId));
                    }
                    else
                    {
                        str.Append(BindWeChat(openId));
                    }
                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                    FromUserName.InnerText,
                                                    ToUserName.InnerText,
                                                    DateTime.Now.Ticks,
                                                    str.ToString());
                    break;

                case "unsubscribe":
                    xingeToken = QrChildManager.GetXingeToken(openId);
                    if (xingeToken != null && xingeToken.Length != 0)
                    {
                        QrChildManager.DeleteOpenId(openId);
                        string  js = "{\"Title\":\"推送消息\",\"Type\":7,\"OpenId\":\"" + openId + "\",\"Content\":\"\"}";
                        Message ms = new Message("e家亲幼儿伴侣", js);
                        PushHelper.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                    }
                    break;

                case "scan":
                    try {
                        str.Append("欢迎使用微信物联智能学习陪伴机器人系统;");
                        if (!string.IsNullOrEmpty(EventKey.InnerText))
                        {
                            string SceneId = EventKey.InnerText;
                            str.Append(BindDevice(openId, SceneId));
                        }
                        else
                        {
                            str.Append(BindWeChat(openId));
                        }
                    } 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"))    //点击视频抓拍选项
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        if (xingeToken != null && xingeToken.Length != 0)
                        {
                            string showStr = "";
                            if (QrChildManager.ManageMenu(openId, xingeToken, 10))
                            {
                                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("V1002_GOOD"))      //点击远程定位选项
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        if (xingeToken != null && xingeToken.Length != 0)
                        {
                            string showStr = "";
                            if (QrChildManager.ManageMenu(openId, xingeToken, 11))
                            {
                                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"))      //点击一键抓拍选项
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        if (xingeToken != null && xingeToken.Length != 0)
                        {
                            string showStr = "";
                            if (QrChildManager.ManageMenu(openId, xingeToken, 8))
                            {
                                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("V1004_GOOD"))
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        if (xingeToken != null && xingeToken.Length != 0)
                        {
                            string showStr = "";
                            if (QrChildManager.ManageMenu(openId, xingeToken, 9))
                            {
                                showStr = "正在截图,请稍候.../:sun";
                            }
                            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("V1005_GOOD"))
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        if (xingeToken != null && xingeToken.Length != 0)
                        {
                            string showStr = "";
                            if (QrChildManager.ManageMenu(openId, xingeToken, 12))
                            {
                                showStr = "锁屏成功.../:sun";
                            }
                            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("V1006_GOOD"))
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        if (xingeToken != null && xingeToken.Length != 0)
                        {
                            string showStr = "";
                            if (QrChildManager.ManageMenu(openId, xingeToken, 14))
                            {
                                showStr = "解锁成功.../:sun";
                            }
                            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("V1007_GOOD"))
                    {
                        xingeToken = QrChildManager.GetXingeToken(openId);
                        string DeviceId = QrChildManager.GetDeviceId(xingeToken);
                        if (DeviceId != null && DeviceId.Length != 0)
                        {
                            //string showStr = "该功能暂未开放!敬请期待/:hug";

                            string url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0e7b25b6f1553eea&redirect_uri=http://v.icoxtech.com/StudyStation.aspx?DeviceId=" + DeviceId + "&response_type=code&scope=snsapi_base&state=1#wechat_redirect";

                            System.Web.HttpContext.Current.Response.Redirect(url);
                            //Response.Redirect("http://v.icoxtech.com/StudyStation.aspx?DeviceId='DeviceId'");
                            //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("V1008_GOOD"))
                    {
                        responseContent = string.Format(ReplyTyper.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        qhsb(openId));
                    }
                    break;

                default:
                    break;
                }
            }
            return(responseContent);
        }