Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.HttpMethod == "GET")
        {
            Auth(); return;
        }
        try
        {
            buser      = new B_User(HttpContext.Current);
            requesdata = GetXml();
            //requesdata = "<xml><ToUserName><![CDATA[gh_33273dafc0e4]]></ToUserName> <FromUserName><![CDATA[olwfpsvje_OHogJ8rOANahcqSijk]]></FromUserName> <CreateTime>1434081760</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[pic]]></Content> <MsgId>6159334259197323209</MsgId> </xml>";
            if (string.IsNullOrEmpty(requesdata))
            {
                return;
            }
            M_WxTextMsg reqMod = new M_WxTextMsg(requesdata);
            //获取需要返回的公众号
            M_WX_APPID appmod = appBll.GetAppByWxNo(reqMod.ToUserName);
            if (appmod == null)
            {
                throw new Exception("目标公众号[" + reqMod.ToUserName + "]不存在");
            }
            api     = WxAPI.Code_Get(appmod);
            errmsg += "动作:" + reqMod.MsgType;
            switch (reqMod.MsgType)
            {
            case "event":    //事件--关注处理,后期扩展单击等
            {
                //M_WxImgMsg msgMod = JsonConvert.DeserializeObject<M_WxImgMsg>(appmod.WelStr);
                M_WxImgMsg msgMod = new M_WxImgMsg();
                msgMod.ToUserName   = reqMod.FromUserName;
                msgMod.FromUserName = reqMod.ToUserName;
                WxEventHandler(reqMod);        //系统事件处理
                //登录检测,可按需取消或修改位置
                M_UserInfo mu = UserBindCheck(reqMod);
                //if (mu.IsNull)
                //{
                //    msgMod.Articles.Add(new M_WXImgItem()
                //    {
                //        Title = "请先关联用户",
                //        Description = "你尚未关联用户,点击登录关联用户",
                //        Url = baseUrl + "/User/Login.aspx?WXOpenID=" + reqMod.FromUserName
                //    });
                //    RepToClient(msgMod.ToXML());
                //}
                WxMenuBtnHandler(reqMod, msgMod, mu);
            }
            break;

            case "text":    //接收文本消息
            {
                string xml = UserTextDeal(reqMod);
                RepToClient(xml);
            }
            break;
            }
        }
        catch (Exception ex) { ZLLog.L("微信报错," + errmsg + ",数据:" + requesdata + ",原因:" + ex.Message); }
    }