Example #1
0
    /// <summary>
    /// 订阅后回复
    /// </summary>
    /// <param name="xmlDoc"></param>
    /// <returns></returns>
    public static string subscribeRes(XmlDocument xmlDoc)
    {
        string fromUser    = GetFromXML(xmlDoc, "FromUserName");
        string toUser      = GetFromXML(xmlDoc, "ToUserName");
        string Title       = "欢迎关注嘻嘻爸爸开发的公众号";
        string Description = "i love you my baby";
        string PicUrl      = "http://119.29.20.29/image/test.jpg";
        string Url         = "http://q4chvj.natappfree.cc/index.aspx";
        string result      = WeiXinXML.ReArticle(fromUser, toUser, Title, Description, PicUrl, Url);

        return(result);
    }
Example #2
0
        public void ProcessRequest(HttpContext context)
        {
            wxmessage   wxGlobal = new wxmessage();
            FunctionAll fuc      = new FunctionAll();
            XmlDocument doc      = new XmlDocument();

            try
            {
                fuc.MyMenu();
                string postXmlStr = PostInput();
                if (!string.IsNullOrEmpty(postXmlStr))
                {
                    doc.LoadXml(postXmlStr);
                    XmlElement root = doc.DocumentElement;
                    wxGlobal = fuc.GetWxMessage(doc);

                    string result         = "";
                    string requestContent = "";
                    if (wxGlobal.MsgType == null)
                    {
                        return;
                    }
                    else
                    {
                        //获取用户发来的信息
                        switch (wxGlobal.MsgType)
                        {
                        case "text":    //文本
                            requestContent = WeiXinXML.CreateTextMsg(doc, wxGlobal.Content);
                            LogHelper.WriteLog(requestContent);

                            string[] openids = { "oSsyq09bnj5hSW7lcaMS5R2gHmnk", "oSsyq07cxXuYW8FnCP1-MYt_B_5o", "oSsyq0weqN9UK8JoTpDyht1-TlyU", "oSsyq06MZ7HZmG3Q4gckkHGSLMWE",
                                                 "oZTyM02MtDG3IeLJn2RcMO7U4pws", "oZTyM07BSndJcyK9dRx6YgJqko1s", "oZTyM04WHKk60iaxtieCLTtzNw6I" };
                            string[] types = { "1", "2", "3", "4", "5", "6", "7" };
                            if (openids.Contains(wxGlobal.FromUserName))
                            {
                                string str   = string.Empty;
                                string Title = string.Empty;
                                if (types.Contains(wxGlobal.Content))
                                {
                                    DataTable dt = OrderQuery.getOrder(wxGlobal.Content);
                                    str = OrderQuery.test(dt);
                                    switch (wxGlobal.Content)
                                    {
                                    case "1":
                                        Title = "全程陪诊";
                                        break;

                                    case "2":
                                        Title = "检查代预约";
                                        break;

                                    case "3":
                                        Title = "专家号源预约";
                                        break;

                                    case "4":
                                        Title = "专家诊疗建议";
                                        break;

                                    case "5":
                                        Title = "手术直通车";
                                        break;

                                    case "6":
                                        Title = "病床预约";
                                        break;

                                    case "7":
                                        Title = "代领代寄代解读报告单";
                                        break;

                                    default:
                                        Title = "";
                                        break;
                                    }
                                }
                                else
                                {
                                    str = OrderQuery.test();
                                }

                                switch (wxGlobal.Content)
                                {
                                case "1":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                case "2":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                case "3":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                case "4":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                case "5":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                case "6":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                case "7":
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您有一条新的" + Title + "消息!", str, "http://119.29.20.29/image/单车.jpg", "http://www.guahao.com");
                                    break;

                                default:
                                    result = WeiXinXML.CreateTextMsg(doc, str);
                                    break;
                                }
                            }
                            else
                            {
                                result = WeiXinXML.CreateTextMsg(doc, TuLing.GetTulingMsg(wxGlobal.Content));
                            }
                            break;

                        case "location":    //文本
                            result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您附近的XXX", "XXXXXXXX", "http://119.29.20.29/image/test.jpg", FunctionAll.GetCodeUrl(null));
                            break;

                        case "event":
                            switch (wxGlobal.EventName)
                            {
                            case "subscribe":         //订阅
                                result = WeiXinXML.subscribeRes(doc);
                                break;

                            case "unsubscribe":         //取消订阅
                                break;

                            case "CLICK":

                                if (wxGlobal.EventKey == "HELLO")
                                {
                                    result = WeiXinXML.CreateTextMsg(doc, "微医app - 原名 挂号网,用手机挂号,十分方便!更有医生咨询、智能分诊、院外候诊、病历管理等强大功能。\r\n" +
                                                                     "预约挂号 聚合全国超过900家重点医院的预约挂号资源\r\n" +
                                                                     "咨询医生 支持医患之间随时随地图文、语音、视频方式的沟通交流\r\n" +
                                                                     "智能分诊 根据分诊自测系统分析疾病类型,提供就诊建议\r\n" +
                                                                     "院外候诊 时间自由可控,不再无谓浪费\r\n" +
                                                                     "病历管理 病历信息统一管理,个人健康及时监测\r\n" +
                                                                     "贴心服务 医疗支付、报告提取、医院地图\r\n" +
                                                                     "权威保障 国家卫计委(原卫生部)指定的全国健康咨询及就医指导平台\r\n" +
                                                                     "[微医] 目前用户量大,有些不足我们正加班加点的努力完善,希望大家用宽容的心给 [微医] 一点好评,给我们一点激励,让 [微医] 和大家的健康诊疗共成长。");
                                }
                                if (wxGlobal.EventKey == "myprofile")
                                {
                                    result = WeiXinXML.CreateTextMsg(doc, "功能测试中,敬请期待!");
                                }
                                if (wxGlobal.EventKey == "jkzx")
                                {
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "点击图片查看您附近的疾控中心", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", "http://m.amap.com/around/?locations=&keywords=疾控中心&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                                }

                                break;

                            case "LOCATION":         //获取地理位置
                                Lat = wxGlobal.Latitude; Lon = wxGlobal.Longitude;
                                break;
                            }
                            break;
                        }
                    }

                    context.Response.Write(result);
                    context.Response.Flush();
                    LogHelper.WriteLog("系统回复的明文" + result);
                }
                else
                {
                    valid(context);
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex.Message);
            }
        }
Example #3
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="root"></param>
    /// <param name="model"></param>
    /// <returns></returns>
    public wxmessage GetWxMessage(XmlDocument doc)
    {
        wxmessage wxModel = new wxmessage();

        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "FromUserName")))
        {
            wxModel.FromUserName = WeiXinXML.GetFromXML(doc, "FromUserName");
        }
        else
        {
            wxModel.FromUserName = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "ToUserName")))
        {
            wxModel.ToUserName = WeiXinXML.GetFromXML(doc, "ToUserName");
        }
        else
        {
            wxModel.ToUserName = string.Empty;
        }
        wxModel.CreateTime = WeiXinXML.GetFromXML(doc, "CreateTime");
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "MsgType")))
        {
            wxModel.MsgType = WeiXinXML.GetFromXML(doc, "MsgType");
        }
        else
        {
            wxModel.MsgType = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Event")))
        {
            wxModel.EventName = WeiXinXML.GetFromXML(doc, "Event");
        }
        else
        {
            wxModel.EventName = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Content")))
        {
            wxModel.Content = WeiXinXML.GetFromXML(doc, "Content");
        }
        else
        {
            wxModel.Content = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Recognition")))
        {
            wxModel.Recognition = WeiXinXML.GetFromXML(doc, "Recognition");
        }
        else
        {
            wxModel.Recognition = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "MediaId")))
        {
            wxModel.MediaId = WeiXinXML.GetFromXML(doc, "MediaId");
        }
        else
        {
            wxModel.MediaId = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "EventKey")))
        {
            wxModel.EventKey = WeiXinXML.GetFromXML(doc, "EventKey");
        }
        else
        {
            wxModel.EventKey = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Location_X")))
        {
            wxModel.Location_X = WeiXinXML.GetFromXML(doc, "Location_X");
        }
        else
        {
            wxModel.Location_X = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Location_Y")))
        {
            wxModel.Location_Y = WeiXinXML.GetFromXML(doc, "Location_Y");
        }
        else
        {
            wxModel.Location_Y = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Scale")))
        {
            wxModel.Scale = WeiXinXML.GetFromXML(doc, "Scale");
        }
        else
        {
            wxModel.Scale = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Label")))
        {
            wxModel.Label = WeiXinXML.GetFromXML(doc, "Label");
        }
        else
        {
            wxModel.Label = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Latitude")))
        {
            wxModel.Latitude = WeiXinXML.GetFromXML(doc, "Latitude");
        }
        else
        {
            wxModel.Latitude = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Longitude")))
        {
            wxModel.Longitude = WeiXinXML.GetFromXML(doc, "Longitude");
        }
        else
        {
            wxModel.Longitude = string.Empty;
        }
        if (!string.IsNullOrEmpty(WeiXinXML.GetFromXML(doc, "Precision")))
        {
            wxModel.Precision = WeiXinXML.GetFromXML(doc, "Precision");
        }
        else
        {
            wxModel.Precision = string.Empty;
        }
        return(wxModel);
    }
Example #4
0
        public void responseMsg(HttpContext context, XmlDocument xmlDoc)
        {
            string result = "";
            string msgType = WeiXinXML.GetFromXML(xmlDoc, "MsgType");
            switch (msgType)
            {
                case "event":
                    switch (WeiXinXML.GetFromXML(xmlDoc, "Event"))
                    {
                        case "subscribe": //订阅
                            String retUserInfo = getUserInfo(WeiXinXML.GetFromXML(xmlDoc, "FromUserName"));
                            Util.Debuglog("getUserInfo" + retUserInfo, "wxapi.txt");
                            if (retUserInfo.Contains("errcode"))
                            {

                            }
                            else
                            {
                                WeiXinUserInfo info = JsonConvert.DeserializeObject<WeiXinUserInfo>(retUserInfo);
                                if (!string.IsNullOrEmpty(info.OpenId) && !string.IsNullOrEmpty(info.UnionId))
                                {
                                    Util.Debuglog("info=" + info.ToString(), "wxapi.txt");
                                    string sql = "select * from asm_member where unionID='" + info.UnionId + "'";
                                    Util.Debuglog("sql=" + sql, "wxapi.txt");
                                    DataTable dt = DbHelperSQL.Query(sql).Tables[0];
                                    if (dt.Rows.Count <= 0)
                                    {
                                        string insert = "insert into asm_member(name,phone,province,city,country,AvailableMoney,sumConsume,sumRecharge,createDate,companyID,headurl,nickname,sex,unionID,openID,consumeCount)"
                                            + " values(N'" + info.NickName + "','','" + info.Province + "','" + info.City + "','" + info.Conuntry + "',0,0,0,'" + DateTime.Now + "',14,'" + info.HeadImgUrl + "',N'" + info.NickName + "','" + info.Sex + "','" + info.UnionId + "','" + info.OpenId + "',0)";
                                        Util.Debuglog(insert, "wxapi.txt");
                                        DbHelperSQL.ExecuteSql(insert);
                                    }
                                    else
                                    {
                                        //更新
                                        string update = "update asm_member set openID='" + info.OpenId + "' where unionID='" + info.UnionId + "'";
                                        Util.Debuglog("更新" + update, "wxapi.txt");
                                        DbHelperSQL.ExecuteSql(update);
                                    }

                                }
                            }

                            string sqlcom = "select * from asm_company where user_name='" + WeiXinXML.GetFromXML(xmlDoc, "ToUserName") + "'";
                            Util.Debuglog("sqlcom=" + sqlcom, "wxapi.txt");
                            DataTable dtcom = DbHelperSQL.Query(sqlcom).Tables[0];
                            string txt ="";
                            if (dtcom.Rows.Count > 0){
                                txt = dtcom.Rows[0]["subscribe_info"].ToString();
                            }
                            result = WeiXinXML.CreateTextMsg(xmlDoc,txt);
                            Util.Debuglog("用户关注result="+ result, "wxapi.txt");

                            break;
                        case "unsubscribe": //取消订阅
                            Util.Debuglog("取消订阅", "wxapi.txt");
                            break;
                        case "LOCATION":
                            string Latitude = WeiXinXML.GetFromXML(xmlDoc, "Latitude");
                            string Longitude = WeiXinXML.GetFromXML(xmlDoc, "Longitude");
                            Util.Debuglog("Latitude="+ Latitude+ ";Longitude="+ Longitude, "wxapi.txt");
                            break;
                        default:

                            break;
                    }
                    break;

                default:
                    break;
            }

            WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
            string signature = context.Request["msg_signature"];
            string timestamp = context.Request["timestamp"];
            string nonce = context.Request["nonce"];
            string stmp = "";
            int ret = wxcpt.EncryptMsg(result, timestamp, nonce, ref stmp);
            context.Response.Write(stmp);

            context.Response.Flush();
        }
Example #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Access_token mode = FunctionAll.GetAccessToken();
            Session["accessToken"] = mode.access_token;
            Session.Timeout        = 120;
        }
        Valid();
        wxmessage   wxGlobal = new wxmessage();
        FunctionAll fuc      = new FunctionAll();
        XmlDocument doc      = new XmlDocument();

        try
        {
            fuc.MyMenu();
            string postXmlStr = PostInput();
            if (!string.IsNullOrEmpty(postXmlStr))
            {
                doc.LoadXml(postXmlStr);
                XmlElement root = doc.DocumentElement;
                wxGlobal = fuc.GetWxMessage(doc);

                string result         = "";
                string requestContent = "";
                //var rootElement = doc.DocumentElement;
                if (wxGlobal.MsgType == null)
                {
                    return;
                }
                else
                {
                    //获取用户发来的信息
                    switch (wxGlobal.MsgType)
                    {
                    case "text":    //文本
                        requestContent = WeiXinXML.CreateTextMsg(doc, wxGlobal.Content);
                        if (wxGlobal.Content.Contains("¥"))
                        {
                            decimal req = Convert.ToDecimal(wxGlobal.Content.Replace("¥", ""));
                            result = WeiXinXML.CreateTextMsg(doc, fuc.ConvertToChinese(req));
                        }
                        else
                        {
                            result = WeiXinXML.CreateTextMsg(doc, TuLing.GetTulingMsg(wxGlobal.Content));
                            LogHelper.WriteLog(requestContent);
                            LogHelper.WriteLog(result);
                        }
                        break;

                    case "location":    //文本
                        result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "您附近的XXX", "XXXXXXXX", "http://119.29.20.29/image/test.jpg", FunctionAll.GetCodeUrl(Server.UrlEncode("http://q4chvj.natappfree.cc/index.aspx")));
                        break;

                    case "event":
                        switch (wxGlobal.EventName)
                        {
                        case "subscribe":         //订阅
                            result = WeiXinXML.subscribeRes(doc);
                            break;

                        case "unsubscribe":         //取消订阅
                            break;

                        case "CLICK":

                            if (wxGlobal.EventKey == "myprofile")
                            {
                                result = WeiXinXML.CreateTextMsg(doc, "微医app - 原名 挂号网,用手机挂号,十分方便!更有医生咨询、智能分诊、院外候诊、病历管理等强大功能。\r\n" +
                                                                 "预约挂号 聚合全国超过900家重点医院的预约挂号资源\r\n" +
                                                                 "咨询医生 支持医患之间随时随地图文、语音、视频方式的沟通交流\r\n" +
                                                                 "智能分诊 根据分诊自测系统分析疾病类型,提供就诊建议\r\n" +
                                                                 "院外候诊 时间自由可控,不再无谓浪费\r\n" +
                                                                 "病历管理 病历信息统一管理,个人健康及时监测\r\n" +
                                                                 "贴心服务 医疗支付、报告提取、医院地图\r\n" +
                                                                 "权威保障 国家卫计委(原卫生部)指定的全国健康咨询及就医指导平台\r\n" +
                                                                 "[微医] 目前用户量大,有些不足我们正加班加点的努力完善,希望大家用宽容的心给 [微医] 一点好评,给我们一点激励,让 [微医] 和大家的健康诊疗共成长。");
                            }
                            if (wxGlobal.EventKey == "morefunction")
                            {
                                //  result = WeiXinXML.CreateTextMsg(doc, "更多功能正在开发中,敬请期待!");
                                //if (wxGlobal.EventKey == "jkzx")
                                result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "点击图片查看您附近的疾控中心", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", ConfigurationManager.AppSettings["redirect_uri"].ToString());
                            }

                            break;

                        case "LOCATION":         //获取地理位置
                                                 //string city = fuc.GetLocation(wxGlobal.Latitude,wxGlobal.Longitude);
                                                 //result = WeiXinXML.CreateTextMsg(doc,city);
                            break;
                        }

                        break;
                    }
                    //if (!string.IsNullOrWhiteSpace(sAppId))  //根据appid解密字符串
                    //{

                    //    WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, AESKey, sAppId);
                    //    string signature = context.Request["msg_signature"];
                    //    string timestamp = context.Request["timestamp"];
                    //    string nonce = context.Request["nonce"];
                    //    string stmp = "";
                    //    int ret = wxcpt.DecryptMsg(signature, timestamp, nonce, postXmlStr, ref stmp);
                    //    if (ret == 0)
                    //    {
                    //        doc = new XmlDocument();
                    //        doc.LoadXml(stmp);
                    //    }
                    //}
                }
                Response.Write(result);
            }


            else
            {
                Valid();
                return;
            }
        }
        //context.Response.Write(result);
        //context.Response.Flush();
        //LogHelper.WriteLog("系统回复的明文" + result);

        //    else
        //    {
        //    valid(context);
        //    return;
        //}
        catch (Exception ex)
        {
            throw;
        }
    }
Example #6
0
        public string responseMsg(XmlDocument xmlDoc)
        {
            string result  = "";
            string msgType = WeiXinXML.GetFromXML(xmlDoc, "MsgType");

            switch (msgType)
            {
            case "event":
                switch (WeiXinXML.GetFromXML(xmlDoc, "Event"))
                {
                case "SCAN":        //扫码
                    string msg = "你居然是扫码进来的居然";
                    switch (WeiXinXML.GetFromXML(xmlDoc, "EventKey"))
                    {
                    case "1":             //普通码
                        msg += "是普通码!!";
                        break;

                    case "2":             //商品码
                        msg += "是商品码!!";
                        break;

                    case "11":             //正常码
                        msg += "是正常码!!";
                        break;

                    default:
                        msg += "这码我也不知道";
                        break;
                    }
                    result = WeiXinXML.CreateTextMsg(xmlDoc, msg);
                    break;

                case "subscribe":         //订阅
                    result = WeiXinXML.CreateTextMsg(xmlDoc, "欢迎关注我们");
                    break;

                case "unsubscribe":         //取消订阅
                    result = WeiXinXML.CreateTextMsg(xmlDoc, "你居然取消关注我们了");
                    break;

                case "CLICK":
                    string fileUrl = ConfigurationManager.AppSettings["FileUrl"];
                    result = string.Format(WeiXinXML.Message_News_Main, WeiXinXML.GetFromXML(xmlDoc, "FromUserName"), WeiXinXML.GetFromXML(xmlDoc, "ToUserName"),
                                           DateTime.Now.Ticks,
                                           "1",
                                           string.Format(WeiXinXML.Message_News_Item, "走出大山", "当初的走出大山,才有今天的我,回想往事,记忆犹新。",
                                                         fileUrl + "Image/572386476.jpg",
                                                         "http://mp.weixin.qq.com/s/OgqBk9t1mC3cLubwQnvh3w")
                                           //+
                                           //string.Format(WeiXinXML.Message_News_Item, "订单管理", "",
                                           //"http://www.soso.com/orderManage.jpg",
                                           //"http://www.soso.com/")
                                           );
                    //DataTable dtMenuMsg = MenuMsgDal.GetMenuMsg(WXMsgUtil.GetFromXML(xmlDoc, "EventKey"));
                    //if (dtMenuMsg.Rows.Count > 0)
                    //{
                    //    List<Dictionary<string, string>> dictList = new List<Dictionary<string, string>>();
                    //    foreach (DataRow dr in dtMenuMsg.Rows)
                    //    {
                    //        Dictionary<string, string> dict = new Dictionary<string, string>();
                    //        dict["Title"] = dr["Title"].ToString();
                    //        dict["Description"] = dr["Description"].ToString();
                    //        dict["PicUrl"] = dr["PicUrl"].ToString();
                    //        dict["Url"] = dr["Url"].ToString();
                    //        dictList.Add(dict);
                    //    }
                    //    result = WXMsgUtil.CreateNewsMsg(xmlDoc, dictList);
                    //}
                    //else
                    //{
                    //    result = WXMsgUtil.CreateTextMsg(xmlDoc, "无此消息哦");
                    //}
                    break;
                //case "VIEW":
                //    result = string.Format(WeiXinXML.Message_News_Main, WeiXinXML.GetFromXML(xmlDoc, "FromUserName"), WeiXinXML.GetFromXML(xmlDoc, "ToUserName"),
                //          "Image/572386476.jpg",
                //     "http://mp.weixin.qq.com/s/OgqBk9t1mC3cLubwQnvh3w");
                //    LogHelper.WriteFile(Server.MapPath("~/Logs/" + DateTime.Now.ToString("yyyyMMdd") + "view.txt"), "123");

                //    break;
                default:
                    break;
                }
                break;

            case "text":
                string text = WeiXinXML.GetFromXML(xmlDoc, "Content");
                if (text == "这个开发者好帅" || text == "土豪是傻逼" || text == "不按规则也能聊天")
                {
                    if (text == "土豪是傻逼")
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, "这个傻逼喜欢谭小芹!");
                    }
                    else if (text == "这个开发者好帅")
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, "你说了句大实话啊!哈哈!");
                    }
                    else
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, TuLing.GetTulingMsg(text));
                    }
                }
                else
                {
                    if (text.Contains("t"))
                    {
                        text   = text.Replace("t", "");
                        result = WeiXinXML.CreateTextMsg(xmlDoc, TuLing.GetTulingMsg(text));
                    }
                    else
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, "你回复错误导致了土豪成为了傻逼,除非你回复:这个开发者好帅  或者回复:土豪是傻逼 或者你想和机器人聊天请回复格式:t+你好(例如:t我饿了)");
                    }
                }

                break;

            default:
                break;
            }

            //if (!string.IsNullOrWhiteSpace(sAppID)) //没有AppID则不加密(订阅号没有AppID)
            //{
            //    //加密
            //    WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
            //    string sEncryptMsg = ""; //xml格式的密文
            //    string timestamp = context.Request["timestamp"];
            //    string nonce = context.Request["nonce"];
            //    int ret = wxcpt.EncryptMsg(result, timestamp, nonce, ref sEncryptMsg);
            //    if (ret != 0)
            //    {
            //        FileLogger.WriteErrorLog(context, "加密失败,错误码:" + ret);
            //        return;
            //    }

            //    context.Response.Write(sEncryptMsg);
            //    context.Response.Flush();
            //}
            //else
            // {
            return(result);
            //   }
        }
Example #7
0
        //protected void Page_Load(object sender, EventArgs e)
        //{
        //    MyMenu();
        //}

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                MyMenu();
                Stream stream    = context.Request.InputStream;
                byte[] byteArray = new byte[stream.Length];
                stream.Read(byteArray, 0, (int)stream.Length);
                string postXmlStr = System.Text.Encoding.UTF8.GetString(byteArray);
                if (!string.IsNullOrEmpty(postXmlStr))
                {
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(postXmlStr);
                    XmlElement root = doc.DocumentElement;
                    wxGlobal              = GetWxMessage(root);
                    wxGlobal.ToUserName   = doc.SelectSingleNode("xml").SelectSingleNode("ToUserName").InnerText;
                    wxGlobal.FromUserName = doc.SelectSingleNode("xml").SelectSingleNode("FromUserName").InnerText;
                    wxGlobal.MsgType      = doc.SelectSingleNode("xml").SelectSingleNode("MsgType").InnerText;
                    if (wxGlobal.MsgType.Trim() == "text")
                    {
                        wxGlobal.Content = doc.SelectSingleNode("xml").SelectSingleNode("Content").InnerText;
                    }
                    if (wxGlobal.MsgType.Trim() == "event")
                    {
                        wxGlobal.EventName = doc.SelectSingleNode("xml").SelectSingleNode("Event").InnerText;
                        wxGlobal.EventKey  = doc.SelectSingleNode("xml").SelectSingleNode("EventKey").InnerText;
                    }
                    if (wxGlobal.MsgType.Trim() == "voice")
                    {
                        wxGlobal.Recognition = doc.SelectSingleNode("xml").SelectSingleNode("Recognition").InnerText;
                    }
                    //if (string.IsNullOrWhiteSpace(AppId))
                    //{
                    //    //DataTable dt = ConfigDal.GetConfig(WXMsgUtil.GetFromXML(doc, "ToUserName"));
                    //    //DataRow dr = dt.Rows[0];
                    //    //sToken = dr["Token"].ToString();
                    //    //sAppID = dr["AppID"].ToString();
                    //    //sEncodingAESKey = dr["EncodingAESKey"].ToString();


                    //}

                    //if (!string.IsNullOrWhiteSpace(sAppID))  //没有AppID则不解密(订阅号没有AppID)
                    //{
                    //    //解密
                    //    WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
                    //    string signature = context.Request["msg_signature"];
                    //    string timestamp = context.Request["timestamp"];
                    //    string nonce = context.Request["nonce"];
                    //    string stmp = "";
                    //    int ret = wxcpt.DecryptMsg(signature, timestamp, nonce, postXmlStr, ref stmp);
                    //    if (ret == 0)
                    //    {
                    //        doc = new XmlDocument();
                    //        doc.LoadXml(stmp);

                    //        try
                    //        {
                    //            responseMsg(context, doc);
                    //        }
                    //        catch (Exception ex)
                    //        {
                    //            FileLogger.WriteErrorLog(context, ex.Message);
                    //        }
                    //    }
                    //    else
                    //    {
                    //        FileLogger.WriteErrorLog(context, "解密失败,错误码:" + ret);
                    //    }
                    //}
                    //else
                    //{
                    //    responseMsg(context, doc);
                    //}
                    string result;
                    var    rootElement = doc.DocumentElement;
                    if (rootElement == null)
                    {
                        return;
                    }
                    else
                    {
                        //获取用户发来的信息
                        string msgType = WeiXinXML.GetFromXML(doc, "MsgType");
                        wxGlobal.FromUserName = WeiXinXML.GetFromXML(doc, "FromUserName");
                        wxGlobal.ToUserName   = WeiXinXML.GetFromXML(doc, "ToUserName");
                        //FunctionAll fuc = new FunctionAll();
                        //fuc.GetMsgModel(doc);
                        //wx.MsgType = WeiXinXML.GetFromXML(doc, "MsgType");
                        switch (msgType)
                        {
                        case "text":    //文本
                            string Content = rootElement.SelectSingleNode("Content").InnerText;

                            RequestLocation = Content;
                            result          = WeiXinXML.CreateTextMsg(doc, Content);
                            LogHelper.WriteLog(result);
                            break;

                        case "event":
                            if (!string.IsNullOrEmpty(wxGlobal.EventName) && wxGlobal.EventName.Trim() == "CLICK")
                            {
                                if (wxGlobal.EventKey == "HELLO")
                                {
                                    result = WeiXinXML.CreateTextMsg(doc, "你好呀,这是测试!");
                                }
                                if (wxGlobal.EventKey == "myprofile")
                                {
                                    result = WeiXinXML.CreateTextMsg(doc, "嘻嘻爸爸就是我!");
                                }
                                if (wxGlobal.EventKey == "jkzx")
                                {
                                    result = WeiXinXML.ReArticle(wxGlobal.FromUserName, wxGlobal.ToUserName, "点击图片查看您附近的疾控中心", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", "http://m.amap.com/around/?locations=&keywords=疾控中心&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                                }
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    //回复消息
                    responseMsg(context, doc);
                    //MyMenu();
                }
                else
                {
                    valid(context);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(ex.Message);
            }
        }
Example #8
0
        public void responseMsg(HttpContext context, XmlDocument xmlDoc)
        {
            //fuc.GetMsgModel(xmlDoc);
            string fromUser = WeiXinXML.GetFromXML(xmlDoc, "FromUserName");
            string toUser   = WeiXinXML.GetFromXML(xmlDoc, "ToUserName");
            //位置没有获取,待完成。
            string Longitude = WeiXinXML.GetFromXML(xmlDoc, "Longitude");
            string Latitude  = WeiXinXML.GetFromXML(xmlDoc, "Latitude");
            string result    = "";
            string msgType   = WeiXinXML.GetFromXML(xmlDoc, "MsgType");

            switch (msgType)
            {
            case "event":
                switch (WeiXinXML.GetFromXML(xmlDoc, "Event"))
                {
                case "subscribe":         //订阅
                    result = WeiXinXML.subscribeRes(xmlDoc);
                    break;

                case "unsubscribe":         //取消订阅
                    break;

                case "click":
                    if (!string.IsNullOrEmpty(wxGlobal.EventName) && wxGlobal.EventName.Trim() == "CLICK")
                    {
                        if (wxGlobal.EventKey == "HELLO")
                        {
                            result = WeiXinXML.CreateTextMsg(xmlDoc, "你好呀,这是测试!");
                        }
                        if (wxGlobal.EventKey == "myprofile")
                        {
                            result = WeiXinXML.CreateTextMsg(xmlDoc, "嘻嘻爸爸就是我!");
                        }
                        if (wxGlobal.EventKey == "jkzx")
                        {
                            result = WeiXinXML.ReArticle(fromUser, toUser, "点击图片查看您附近的疾控中心", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", "http://m.amap.com/around/?locations=" + Longitude + "," + Latitude + "&keywords=疾控中心&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                        }
                    }
                    break;

                default:
                    break;
                }
                break;

            case "text":
                string text = WeiXinXML.GetFromXML(xmlDoc, "Content");
                //if (text == "位置")
                //{
                //    result = WeiXinXML.ReArticle(fromUser, toUser, "点击图片查看您附近的防疫站", "啦啦啦啦啦", "http://119.29.20.29/test.jpg", "http://m.amap.com/around/?locations=" + Longitude + "," + Latitude + "&keywords=" + RequestLocation + "&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                //}
                //else
                if (text != null)
                {
                    int index = text.IndexOf("针");
                    if (index > -1)
                    {
                        text            = "疾控中心";
                        RequestLocation = text;
                        result          = WeiXinXML.ReArticle(fromUser, toUser, "点击图片查看您附近的" + text + "", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", "http://m.amap.com/around/?locations=" + Longitude + "," + Latitude + "&keywords=" + RequestLocation + "&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                    }
                    else
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, TuLing.GetTulingMsg(text));
                        //result = WeiXinXML.ReArticle(fromUser, toUser, "点击图片查看您附近的" + RequestLocation + "", @"测试测试测试测试", "http://119.29.20.29/image/navi.jpg", "http://m.amap.com/around/?locations=" + Longitude + "," + Latitude + "&keywords=" + RequestLocation + "&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                    }
                }
                else
                {
                    result = WeiXinXML.CreateTextMsg(xmlDoc, "回复错误!");
                }

                break;

            case "location":
                //result = WeiXinXML.ReArticle(wx.FromUserName, wx.ToUserName, "点击图片查看您附近的防疫站", "啦啦啦啦啦", "http://119.29.20.29/navi.jpg", "http://m.amap.com/around/?locations=" + wx.Longitude + "," + wx.Latitude + "&keywords=疾控中心&defaultIndex=3&defaultView=map&searchRadius=5000&key=33fe5b1e0fc0023eb1cd28b392d5e70f");
                break;
            }



            /////消息加密
            //if (!string.IsNullOrWhiteSpace(sAppID))
            //{
            //    WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
            //    string sEncryptMsg = ""; //xml格式的密文
            //    string timestamp = context.Request["timestamp"];
            //    string nonce = context.Request["nonce"];
            //    int ret = wxcpt.EncryptMsg(result, timestamp, nonce, ref sEncryptMsg);
            //    if (ret != 0)
            //    {
            //        LogHelper.WriteLog(this.GetType(), context+ "加密失败,错误码:" + ret);
            //        return;
            //    }

            //    context.Response.Write(sEncryptMsg);
            //    context.Response.Flush();
            //}
            //else
            //{

            context.Response.Write(result);
            context.Response.Flush();
            LogHelper.WriteLog(result);
            //}
        }
        public string responseMsg(XmlDocument xmlDoc)
        {
            string result  = "";
            string msgType = WeiXinXML.GetFromXML(xmlDoc, "MsgType");

            switch (msgType)
            {
            case "event":
                switch (WeiXinXML.GetFromXML(xmlDoc, "Event"))
                {
                case "SCAN":        //扫码
                    string msg = "你居然是扫码进来的居然";
                    switch (WeiXinXML.GetFromXML(xmlDoc, "EventKey"))
                    {
                    case "1":             //普通码
                        msg += "是普通码!!";
                        break;

                    case "2":             //商品码
                        msg += "是商品码!!";
                        break;

                    case "11":             //正常码
                        msg += "是正常码!!";
                        break;

                    default:
                        msg += "这码我也不知道";
                        break;
                    }
                    result = WeiXinXML.CreateTextMsg(xmlDoc, msg);
                    break;

                case "subscribe":         //订阅
                    string accessToken = WxHelper.GetWXAccessToken(WxConfig.AppId, WxConfig.Secret);
                    string msgUrl      = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + accessToken;

                    XmlNode ToUserName   = xmlDoc.SelectSingleNode("/xml/ToUserName");
                    XmlNode FromUserName = xmlDoc.SelectSingleNode("/xml/FromUserName");
                    result = string.Format(Message_News_Main,
                                           FromUserName.InnerText,
                                           ToUserName.InnerText,
                                           DateTime.Now.Ticks,
                                           "1",
                                           string.Format(Message_News_Item, "欢迎关注公众号", "这是一个xxx公众号",
                                                         "http://1x687f9296.iok.la:45539/Qrcode/20170707134824.jpg",
                                                         "http://1x687f9296.iok.la:45539"));
                    //result = WeiXinXML.CreateTextMsg(xmlDoc, "欢迎关注我们");
                    break;

                case "unsubscribe":         //取消订阅
                    result = WeiXinXML.CreateTextMsg(xmlDoc, "你居然取消关注我们了");
                    break;

                case "CLICK":
                    //DataTable dtMenuMsg = MenuMsgDal.GetMenuMsg(WXMsgUtil.GetFromXML(xmlDoc, "EventKey"));
                    //if (dtMenuMsg.Rows.Count > 0)
                    //{
                    //    List<Dictionary<string, string>> dictList = new List<Dictionary<string, string>>();
                    //    foreach (DataRow dr in dtMenuMsg.Rows)
                    //    {
                    //        Dictionary<string, string> dict = new Dictionary<string, string>();
                    //        dict["Title"] = dr["Title"].ToString();
                    //        dict["Description"] = dr["Description"].ToString();
                    //        dict["PicUrl"] = dr["PicUrl"].ToString();
                    //        dict["Url"] = dr["Url"].ToString();
                    //        dictList.Add(dict);
                    //    }
                    //    result = WXMsgUtil.CreateNewsMsg(xmlDoc, dictList);
                    //}
                    //else
                    //{
                    //    result = WXMsgUtil.CreateTextMsg(xmlDoc, "无此消息哦");
                    //}
                    break;

                default:
                    break;
                }
                break;

            case "text":
                string text = WeiXinXML.GetFromXML(xmlDoc, "Content");
                if (text == "这个开发者好帅" || text == "土豪是傻逼" || text == "不按规则也能聊天")
                {
                    if (text == "土豪是傻逼")
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, "这个傻逼喜欢谭小芹!");
                    }
                    else if (text == "这个开发者好帅")
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, "你说了句大实话啊!哈哈!");
                    }
                    else
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, TuLing.GetTulingMsg(text));
                    }
                }
                else
                {
                    if (text.Contains("t"))
                    {
                        text   = text.Replace("t", "");
                        result = WeiXinXML.CreateTextMsg(xmlDoc, TuLing.GetTulingMsg(text));
                    }
                    else
                    {
                        result = WeiXinXML.CreateTextMsg(xmlDoc, "你回复错误导致了土豪成为了傻逼,除非你回复:这个开发者好帅  或者回复:土豪是傻逼 或者你想和机器人聊天请回复格式:t+你好(例如:t我饿了)");
                    }
                }

                break;

            default:
                break;
            }

            //if (!string.IsNullOrWhiteSpace(sAppID)) //没有AppID则不加密(订阅号没有AppID)
            //{
            //    //加密
            //    WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sAppID);
            //    string sEncryptMsg = ""; //xml格式的密文
            //    string timestamp = context.Request["timestamp"];
            //    string nonce = context.Request["nonce"];
            //    int ret = wxcpt.EncryptMsg(result, timestamp, nonce, ref sEncryptMsg);
            //    if (ret != 0)
            //    {
            //        FileLogger.WriteErrorLog(context, "加密失败,错误码:" + ret);
            //        return;
            //    }

            //    context.Response.Write(sEncryptMsg);
            //    context.Response.Flush();
            //}
            //else
            // {
            return(result);
            //   }
        }