Esempio n. 1
0
        public string BindDevice(string openId, string sendId)
        {
            StringBuilder str = new StringBuilder();
            Dictionary <string, object> dic = QrChildManager.OldBind(sendId);
            string BindToken = Convert.ToString(dic["token"]);
            string deviceId  = Convert.ToString(dic["deviceId"]);

            if (BindToken != null && BindToken != "")
            {
                str.Append("\n请在下方回复“绑定设备+手机号”\n如:绑定设备13212345678\n即可激活设备!");

                if (!QrChildManager.OldChildUser(openId, BindToken, deviceId))
                {
                    str.Append("\n你已绑定此设备无需重复绑定!");
                    return(str.ToString());
                }
                SendNews(deviceId, openId);
                string  js = "";
                Message ms = null;
                js = "{\"Title\":\"绑定推送\",\"Type\":6,\"OpenId\":\"" + openId + "\",\"Content\":\"\"}";
                ms = new Message("e家亲幼儿伴侣", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                string  returnStr = XinGePush.PushMsg(BindToken, jsonSerializer.Serialize(ms));
                JObject json      = JObject.Parse(returnStr);
                returnStr = json["ret_code"].ToString();
            }
            return(str.ToString());
        }
Esempio n. 2
0
        //接受视频消息  备注:"&"=>"@1"  "="=>"@2"  "%"=>"@3"
        public string VideoHandler(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)
            {
                string openId = FromUserName.InnerText;
                if (BindWeChat(openId) == "")
                {
                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                    FromUserName.InnerText,
                                                    ToUserName.InnerText,
                                                    DateTime.Now.Ticks,
                                                    "请先绑定设备!/::)");
                }
                string xingeToken = QrChildManager.GetXingeToken(openId);
                string deviceName = QrChildManager.GetChildDeviceName(openId);
                if (xingeToken != null && xingeToken.Length != 0)
                {
                    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\":\"" + openId + "\",\"Content\":" + js + "}";
                    Message ms        = new Message("幼儿伴侣", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                    string  returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                    JObject json      = JObject.Parse(returnStr);
                    returnStr = json["ret_code"].ToString();
                    if (returnStr == "0")
                    {
                        responseContent = string.Format(ReplyTyper.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "你向设备【" + deviceName + "】推送了一段视频!");
                    }
                    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,
                                                    "请先绑定设备!/::)");
                }
            }
            return(responseContent);
        }
Esempio n. 3
0
        //接受图片消息 备注:"&"=>"@1"  "="=>"@2"  "%"=>"@3"
        public string ImageHandler(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)
            {
                string openId = FromUserName.InnerText;
                if (BindWeChat(openId) == "")
                {
                    responseContent = string.Format(ReplyTyper.Message_Text,
                                                    FromUserName.InnerText,
                                                    ToUserName.InnerText,
                                                    DateTime.Now.Ticks,
                                                    "请先绑定设备!/::)");
                }
                string xingeToken = QrChildManager.GetXingeToken(openId);
                string deviceName = QrChildManager.GetChildDeviceName(openId);
                if (xingeToken != null && xingeToken.Length != 0)
                {
                    string js = "{\"url\":\"" + PicUrl.InnerText + "\",\"format\":\"" + "png" + "\"}";
                    js = "{\"Title\":\"推送图片\",\"Type\":2,\"OpenId\":\"" + openId + "\",\"Content\":" + js + "}";
                    Message ms        = new Message("幼儿伴侣", js.Replace("&", "@1").Replace("=", "@2").Replace("%", "@3"));
                    string  returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                    JObject json      = JObject.Parse(returnStr);
                    returnStr = json["ret_code"].ToString();
                    if (returnStr == "0")
                    {
                        responseContent = string.Format(ReplyTyper.Message_News_Main,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "1",
                                                        string.Format(ReplyTyper.Message_News_Item, "智能学习陪伴机器人", "你向设备【" + deviceName + "】推送了一张图片!",
                                                                      PicUrl.InnerText, ""));
                    }
                    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,
                                                    "请先绑定设备!/::)");
                }
            }
            return(responseContent);
        }
Esempio n. 4
0
        /// <summary>
        /// 远程管理菜单
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="xingeToken"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static Boolean ManageMenu(string openId, string xingeToken, int type)
        {
            ////序列化对象
            JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
            string  js        = "{\"Title\":\"推送消息\",\"Type\":" + type + ",\"OpenId\":\"" + openId + "\",\"Content\":\"\"}";
            Message ms        = new Message("e家亲幼儿伴侣", js);
            string  returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
            JObject json      = JObject.Parse(returnStr);

            returnStr = json["ret_code"].ToString();
            if (returnStr == "0")
            {
                return(true);
            }
            return(false);
        }
Esempio n. 5
0
        //接受文本消息
        public string TextHandler(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("@"))
                {
                    string openId = FromUserName.InnerText;
                    //DBHelper.ExecuteNonQueryString("insert into xmlString values('{" + BindWeChat(openId) + "}')");
                    if (BindWeChat(openId) == "")
                    {
                        WriteLog("请先绑定设备:" + openId);
                        responseContent = string.Format(ReplyTyper.Message_Text,
                                                        FromUserName.InnerText,
                                                        ToUserName.InnerText,
                                                        DateTime.Now.Ticks,
                                                        "请先绑定设备!/::)");
                    }
                    else if (str.StartsWith("绑定设备") || str.StartsWith("修改设备名称") || str.StartsWith("切换设备"))
                    {
                        Regex regex = new Regex("^绑定设备\\d{11}$");
                        if (regex.IsMatch(str))
                        {
                            string phone = str.Substring(4, 11);
                            QrChildManager.UpdatePhone(openId, phone);
                            string deviceName2 = QrChildManager.GetChildDeviceName(openId);
                            responseContent = string.Format(ReplyTyper.Message_Text,
                                                            FromUserName.InnerText,
                                                            ToUserName.InnerText,
                                                            DateTime.Now.Ticks,
                                                            "恭喜您绑定设备成功!当前设备名为:" + deviceName2 + "\n在下方回复:“修改设备名称+您指定的设备名称”\n如:修改设备名称大儿子\n即可修改设备名称便于多设备管理!");
                        }
                        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);
                            if (QrChildManager.UpdateDeviceName(openId, deviceName3))
                            {
                                responseContent = string.Format(ReplyTyper.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "修改设备名称成功,当前设备名称为:" + deviceName3 + "\n在下方回复:“切换设备+设备名称”\n如:切换设备大儿子\n即可切换到设备大儿子!");
                            }
                            else
                            {
                                responseContent = string.Format(ReplyTyper.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "修改设备名称失败,设备名称有误!");
                            }
                        }
                        if (str.StartsWith("切换设备"))
                        {
                            string deviceName4 = str.Substring(4, str.Length - 4);
                            if (QrChildManager.GetD(openId, deviceName4))
                            {
                                QrChildManager.UpdateState2(openId, deviceName4);
                                responseContent = string.Format(ReplyTyper.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "切换设备成功,当前设备为:" + deviceName4);
                            }
                            else
                            {
                                responseContent = string.Format(ReplyTyper.Message_Text,
                                                                FromUserName.InnerText,
                                                                ToUserName.InnerText,
                                                                DateTime.Now.Ticks,
                                                                "切换设备失败,设备名称有误!");
                            }
                        }

                        return(responseContent);
                    }
                    string xingeToken = QrChildManager.GetXingeToken(openId);
                    string deviceName = QrChildManager.GetChildDeviceName(openId);
                    if (xingeToken != null && xingeToken.Length != 0)
                    {
                        //str = str.Substring(1, str.Length - 1);
                        string  js        = "{\"Title\":\"推送消息\",\"Type\":1,\"OpenId\":\"" + openId + "\",\"Content\":\"" + str + "\"}";
                        Message ms        = new Message("e家亲幼儿伴侣", js);
                        string  returnStr = XinGePush.PushMsg(xingeToken, jsonSerializer.Serialize(ms));
                        JObject json      = JObject.Parse(returnStr);
                        returnStr = json["ret_code"].ToString();
                        if (returnStr == "0")
                        {
                            responseContent = string.Format(ReplyTyper.Message_Text,
                                                            FromUserName.InnerText,
                                                            ToUserName.InnerText,
                                                            DateTime.Now.Ticks,
                                                            "你向设备【" + deviceName + "】推送消息成功!/:sun");
                        }
                        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,
                                                        "请先绑定设备!/::)");
                    }
                }
                else
                {
                    responseContent = HandleOther(str, FromUserName.InnerText, ToUserName.InnerText);
                }
            }
            return(responseContent);
        }