Esempio n. 1
0
        private DataTable SendImage(M_WX_MsgTlp tlpMod, string appids)
        {
            DataTable   dt      = GetResultStruct();
            M_WXImgItem itemMod = JsonConvert.DeserializeObject <M_WXImgItem>(tlpMod.MsgContent);

            foreach (string id in appids.Split(','))
            {
                if (DataConvert.CLng(id) < 1)
                {
                    continue;
                }
                api = WxAPI.Code_Get(Convert.ToInt32(id));
                DataRow dr = dt.NewRow();
                dr["isok"]  = true;
                dr["appid"] = api.AppId.APPID.ToString();
                dr["alias"] = api.AppId.Alias;
                switch (Request["mode_rad"])
                {
                case "loop":
                    M_WxImgMsg imgMod = new M_WxImgMsg();
                    imgMod.Articles.Add(itemMod);
                    api.SendAllBySingle(imgMod);
                    break;
                }
            }
            return(dt);
        }
Esempio n. 2
0
    /// <summary>
    /// 系统事件,如订阅等处理
    /// </summary>
    public void WxEventHandler(M_WxTextMsg reqMod)
    {
        M_WX_User userMod = null;

        errmsg += ",事件:" + reqMod.Event;
        switch (reqMod.Event)
        {
        case "subscribe":
            userMod       = api.GetWxUserModel(reqMod.FromUserName);
            userMod.CDate = DateTime.Now;
            userMod.AppId = api.AppId.ID;
            wxuserBll.Insert(userMod);
            M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr);
            msgmod.ToUserName   = reqMod.FromUserName;
            msgmod.FromUserName = reqMod.ToUserName;
            if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl))     //如未设置图片则以纯文本格式发送,纯文本支持内置超链接
            {
                M_WxTextMsg textMod = ImageToText(msgmod);
                RepToClient(textMod.ToXML());
            }
            else
            {
                RepToClient(msgmod.ToXML());
            }
            break;

        case "unsubscribe":
            wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName);
            break;

        default:
            break;
        }
    }
Esempio n. 3
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); }
    }
Esempio n. 4
0
        private DataTable SendMulti(M_WX_MsgTlp tlpMod, string appids)
        {
            DataTable          dt       = GetResultStruct();
            List <M_WXImgItem> itemList = JsonConvert.DeserializeObject <List <M_WXImgItem> >(tlpMod.MsgContent);

            foreach (string id in appids.Split(','))
            {
                if (DataConvert.CLng(id) < 1)
                {
                    continue;
                }
                api = WxAPI.Code_Get(Convert.ToInt32(id));
                DataRow dr = dt.NewRow();
                dr["isok"]  = true;
                dr["appid"] = api.AppId.APPID.ToString();
                dr["alias"] = api.AppId.Alias;
                //每个APPID都需要独立上传一次
                //----------------------------------------------
                try
                {
                    string media = "";
                    UploadMultiNews(itemList, ref media);
                    dr["media"] = media;
                    switch (Request["mode_rad"])
                    {
                    case "loop":
                    {
                        M_WxImgMsg msg = new M_WxImgMsg();
                        msg.Articles = itemList;
                        api.SendAllBySingle(msg);
                    }
                    break;

                    case "api":
                    default:
                    {
                        M_WXAllMsg model = new M_WXAllMsg()
                        {
                            filter = new M_WXFiter()
                            {
                                group_id = "", is_to_all = true
                            }, msgtype = "mpnews", mpnews = new M_WXMsgMedia()
                            {
                                media_id = media
                            }
                        };
                        api.SendAll(model);
                    }
                    break;
                    }
                }
                catch (Exception ex) { dr["result"] = ex.Message; dr["isok"] = false; }
                dt.Rows.Add(dr);
            }
            return(dt);
        }
Esempio n. 5
0
    //图文消息转文本(存储时以图片消息为准)
    //文本的优点在于,可以内置超链接
    private M_WxTextMsg ImageToText(M_WxImgMsg msgmod)
    {
        M_WxTextMsg textMod = new M_WxTextMsg();

        textMod.ToUserName   = msgmod.ToUserName;
        textMod.FromUserName = msgmod.FromUserName;
        textMod.Content      = msgmod.Articles[0].Description;
        textMod.CreateTime   = DateTime.Now.Millisecond;
        textMod.MsgType      = "text";
        return(textMod);
    }
Esempio n. 6
0
    //用户文件信息处理
    public string UserTextDeal(M_WxTextMsg reqMod)
    {
        M_WX_ReplyMsg rpMod  = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, reqMod.Content);
        M_WxImgMsg    msgMod = new M_WxImgMsg();

        msgMod.ToUserName   = reqMod.FromUserName;
        msgMod.FromUserName = reqMod.ToUserName;
        //如果未匹配到则直接返回
        string result = "";

        if (rpMod == null)
        {
            M_WxImgMsg msgmod1 = new M_WxImgMsg();
            msgmod1.ToUserName   = reqMod.FromUserName;
            msgmod1.FromUserName = reqMod.ToUserName;
            M_WX_ReplyMsg rpMod1 = new M_WX_ReplyMsg();
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "头图");
            if (rpMod1 != null)
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod1.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            RepToClient(msgmod1.ToXML());
        }
        else//如果匹配到
        {
            M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod.Content);
            if (item.Description.Contains("{$UserName}"))
            {
                M_WX_User wuserMod = api.GetWxUserModel(reqMod.FromUserName);
                item.PicUrl      = wuserMod.HeadImgUrl;
                item.Description = item.Description.Replace("{$UserName}", wuserMod.Name);
            }
            msgMod.Articles.Add(item);
            switch (rpMod.MsgType)
            {
            case "0":
                M_WxTextMsg textMod = ImageToText(msgMod);
                result = textMod.ToXML();
                break;

            case "1":
                result = msgMod.ToXML();
                break;
            }
        }
        return(result);
    }
Esempio n. 7
0
        public IActionResult WelPage_Submit(M_WXImgItem itemMod)
        {
            M_WxImgMsg msgMod = new M_WxImgMsg();

            itemMod.PicUrl = StrHelper.UrlDeal(itemMod.PicUrl);
            itemMod.Url    = StrHelper.UrlDeal(itemMod.Url);
            msgMod.Articles.Add(itemMod);
            M_WX_APPID appmod = appBll.SelReturnModel(AppId);

            appmod.WelStr = JsonConvert.SerializeObject(msgMod);
            appBll.UpdateByID(appmod);
            WxAPI.Code_Get(appmod).AppId.WelStr = appmod.WelStr;
            return(WriteOK("操作成功", ""));
        }
Esempio n. 8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         string     alias  = "";
         M_WX_APPID appmod = appBll.SelReturnModel(AppID);
         if (!string.IsNullOrEmpty(appmod.WelStr))
         {
             msgMod         = JsonConvert.DeserializeObject <M_WxImgMsg>(appmod.WelStr);
             Title_T.Text   = msgMod.Articles[0].Title;
             Content_T.Text = msgMod.Articles[0].Description;
             PicUrl_T.Text  = msgMod.Articles[0].PicUrl;
             Url_T.Text     = msgMod.Articles[0].Url;
         }
         alias = " [公众号:" + appmod.Alias + "]";
         Call.SetBreadCrumb(Master, "<li><a href='/Admin/Main.aspx'>工作台</a></li><li><a href='WxAppManage.aspx'>公众号管理</a></li><li class='active'>欢迎语" + alias + "</li>");
     }
 }
Esempio n. 9
0
    //private void SendMsg(Object info)
    //{
    //    try
    //    {
    //        M_WxTextMsg reqMod = (M_WxTextMsg)info;
    //        System.Threading.Thread.Sleep(1000);//延迟1秒,避免先于欢迎消息
    //        M_WX_APPID appmod = new B_WX_APPID().GetAppByWxNo(reqMod.ToUserName);
    //        if (appmod == null) { throw new Exception("目标公众号[" + reqMod.ToUserName + "]不存在"); }
    //        WxAPI.Code_Get(appmod).SendMsg(reqMod.FromUserName, "test");
    //    }
    //    catch (Exception ex) { ZLLog.L("微信多信息出错,原因:" + ex.Message); }
    //}
    /// <summary>
    /// 自定义单击事件处理,按需扩展
    /// </summary>
    public void WxMenuBtnHandler(M_WxTextMsg reqMod, M_WxImgMsg msgMod, M_UserInfo mu)
    {
        //switch (reqMod.Event)
        //{
        //    case "CLICK":
        //        break;
        //}
        //<xml><ToUserName><![CDATA[gh_02d7c9c8ec54]]></ToUserName>
        //<FromUserName><![CDATA[obaF_jigkjUCPDpFeCMx25TV7qQk]]></FromUserName>
        //<CreateTime>1450326669</CreateTime>
        //<MsgType><![CDATA[event]]></MsgType>
        //<Event><![CDATA[CLICK]]></Event>
        //<EventKey><![CDATA[menu_0_btn_0]]></EventKey>
        //</xml>
        switch (reqMod.EventKey)
        {
        case "menu_0_btn_0":    //项目进度
        {
            msgMod.Articles.Add(new M_WXImgItem()
                {
                    Title       = mu.UserName + "[项目进度]的信息1",
                    Description = "点击访问[项目进度]信息",
                    //PicUrl=baseUrl+"/Template/Ke/style/images/login1.png",
                    Url = baseUrl + "/User/Default.aspx"
                });
        }
        break;

        case "menu_0_btn_1":
        {
            M_WxTextMsg textMod = new M_WxTextMsg()
            {
                MsgType      = "text",
                CreateTime   = reqMod.CreateTime,
                Content      = "点击访问[<a href='" + baseUrl + "/User/Default.aspx'>发布项目</a>]信息",
                FromUserName = msgMod.FromUserName,
                ToUserName   = msgMod.ToUserName
            };
            RepToClient(textMod.ToXML());
        }
        break;
        }
        RepToClient(msgMod.ToXML());
    }
Esempio n. 10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     ExHelper.CheckUserAuth("wechat");
     if (!IsPostBack)
     {
         M_WX_APPID appmod = ExHelper.WX_SelMyModel();
         if (!string.IsNullOrEmpty(appmod.WelStr))
         {
             try
             {
                 msgMod         = JsonConvert.DeserializeObject <M_WxImgMsg>(appmod.WelStr);
                 Title_T.Text   = msgMod.Articles[0].Title;
                 Content_T.Text = msgMod.Articles[0].Description;
                 PicUrl_T.Text  = msgMod.Articles[0].PicUrl;
                 Url_T.Text     = msgMod.Articles[0].Url;
             }
             catch { Content_T.Text = "数据格式错误:" + appmod.WelStr; }
         }
     }
 }
Esempio n. 11
0
        public IActionResult WelPage()
        {
            //if (!B_ARoleAuth.AuthCheckEx(ZLEnum.Auth.portable, "wechat")) {return WriteErr }
            M_WX_APPID appmod = appBll.SelReturnModel(AppId);
            M_WxImgMsg msgMod = new M_WxImgMsg();

            msgMod.Articles.Add(new M_WXImgItem());
            if (!string.IsNullOrEmpty(appmod.WelStr))
            {
                msgMod = JsonConvert.DeserializeObject <M_WxImgMsg>(appmod.WelStr);
                //try
                //{
                //    Title_T.Text = msgMod.Articles[0].Title;
                //    Content_T.Text = msgMod.Articles[0].Description;
                //    PicUrl_T.Text = msgMod.Articles[0].PicUrl;
                //    Url_T.Text = msgMod.Articles[0].Url;
                //}
                //catch { Content_T.Text = "数据格式错误:" + appmod.WelStr; }
            }
            return(View(viewDir + "WelPage.cshtml", msgMod.Articles[0]));
        }
Esempio n. 12
0
        //多图文必须有图片ID,通过群发接口发送
        protected void TestMPNews_Btn_Click(object sender, EventArgs e)
        {
            //{"media_id":"CNksuQiytlLOh3-6H8Rg3lu8Nd4Gfolve-ViA3o73-M","url":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/Naic0CNHuGhAmUNEYucicibQtWxYcKmU5hCh0dJhzFiawSSyNJ0WcicFQ3ARbSUjZgvFlOkNfKDAmCEK0IvBTmnUhag\/0?wx_fmt=jpeg"}
            //FileInfo file = new FileInfo(Server.MapPath("temp.jpg"));
            //FileStream fs = file.Open(FileMode.Open, FileAccess.Read);
            //string media=wxBll.UploadImg(fs, "temp.jpg");
            //function.WriteErrMsg(media);
            //-------------获取多图文
            //List<M_WXNewsItem> itemList = new List<M_WXNewsItem>();
            //itemList.Add(new M_WXNewsItem() { title = "标题1", digest = "描述", thumb_media_id = "CNksuQiytlLOh3-6H8Rg3lu8Nd4Gfolve-ViA3o73-M", author = "123", content = "jkljklj", content_source_url = "http://demo.z01.com" });
            //itemList.Add(new M_WXNewsItem() { title = "标题2", digest = "描述2", thumb_media_id = "qI6_Ze_6PtV7svjolgs-rN6stStuHIjs9_DidOHaj0Q-mwvBelOXCFZiq2OsIU-p",author="226", content = "jkjl", content_source_url = "http://demo.z01.com" });
            //string result = wxBll.UploadMPNews(itemList); function.WriteErrMsg(result);
            //{"media_id":"CNksuQiytlLOh3-6H8Rg3gOpUqAn8IzcsK4stBKjHJ4"}  多图文
            //----发送多图文
            M_WxImgMsg         msgmod  = new M_WxImgMsg();
            string             json    = Article_Hid.Value;
            List <M_WXImgItem> imgList = JsonConvert.DeserializeObject <List <M_WXImgItem> >(json);

            msgmod.Articles = imgList;
            api.SendAllBySingle(msgmod);
            function.WriteErrMsg("发送成功!");
        }
Esempio n. 13
0
    /// <summary>
    /// 系统事件,如订阅等处理
    /// </summary>
    public void WxEventHandler(M_WxTextMsg reqMod)
    {
        M_WX_User userMod = null;

        errmsg += ",事件:" + reqMod.Event;
        switch (reqMod.Event.ToLower())
        {
        case "subscribe":
            userMod       = api.GetWxUserModel(reqMod.FromUserName);
            userMod.CDate = DateTime.Now;
            userMod.AppId = api.AppId.ID;
            wxuserBll.Insert(userMod);
            M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr);
            msgmod.ToUserName   = reqMod.FromUserName;
            msgmod.FromUserName = reqMod.ToUserName;
            if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl))     //如未设置图片则以纯文本格式发送,纯文本支持内置超链接
            {
                M_WxTextMsg textMod = ImageToText(msgmod);
                RepToClient(textMod.ToXML());
            }
            else
            {
                RepToClient(msgmod.ToXML());
            }
            //关注时发送多条信息
            //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod);
            break;

        case "unsubscribe":
            wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName);
            break;

        case "location":    //用户进入公众号(包含定位信息)
            break;

        default:
            break;
        }
    }
Esempio n. 14
0
    //用户文件信息处理
    public string UserTextDeal(M_WxTextMsg reqMod)
    {
        M_WX_ReplyMsg rpMod  = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, reqMod.Content);
        M_WxImgMsg    msgMod = new M_WxImgMsg();

        msgMod.ToUserName   = reqMod.FromUserName;
        msgMod.FromUserName = reqMod.ToUserName;
        //如果未匹配到则直接返回
        string result = "";

        if (rpMod == null)
        {
            msgMod.Articles.Add(new M_WXImgItem()
            {
                Title = "未找到相关联的操作"
            });
            result = msgMod.ToXML();
        }
        else//如果匹配到
        {
            M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod.Content);
            msgMod.Articles.Add(item);
            switch (rpMod.MsgType)
            {
            case "0":
                M_WxTextMsg textMod = ImageToText(msgMod);
                result = textMod.ToXML();
                break;

            case "1":
                result = msgMod.ToXML();
                break;
            }
        }
        return(result);
    }
Esempio n. 15
0
    /// <summary>
    /// 系统事件,如订阅等处理
    /// </summary>
    public void WxEventHandler(M_WxTextMsg reqMod)
    {
        M_WX_User userMod = null;

        switch (reqMod.Event.ToLower())
        {
        case "subscribe":
            userMod       = api.GetWxUserModel(reqMod.FromUserName);
            userMod.CDate = DateTime.Now;
            userMod.AppId = api.AppId.ID;
            wxuserBll.Insert(userMod);
            M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr);
            msgmod.ToUserName   = reqMod.FromUserName;
            msgmod.FromUserName = reqMod.ToUserName;

            int        pid      = DataConvert.CLng(reqMod.EventKey.Replace("qrscene_", ""));
            Appinfo    uappMod1 = new Appinfo();
            B_UserAPP  uappBll1 = new B_UserAPP();
            M_UserInfo mu1      = new M_UserInfo();
            M_WX_User  wuserMod = new M_WX_User();
            M_Uinfo    mubase   = new M_Uinfo();
            uappMod1 = uappBll1.SelModelByOpenID(reqMod.FromUserName, "wechat");
            wuserMod = api.GetWxUserModel(reqMod.FromUserName);
            if (uappMod1 != null)
            {
                mu1 = buser.GetUserByUserID(uappMod1.UserID);
                if (mu1 != null && mu1.UserID > 0)
                {
                    mu1.TrueName = wuserMod.Name;
                    mu1.GroupID  = 1;
                    buser.UpdateByID(mu1);
                }
                else
                {
                    mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower();
                    mu1.UserPwd  = StringHelper.MD5(function.GetRandomString(6));
                    mu1.Email    = function.GetRandomString(10) + "@wx.com";
                    mu1.Question = function.GetRandomString(5);
                    mu1.Answer   = function.GetRandomString(5);
                    mu1.TrueName = wuserMod.Name;
                    mu1.GroupID  = 1;
                    mu1.UserID   = buser.Add(mu1);

                    uappMod1.UserID     = mu1.UserID;
                    uappMod1.SourcePlat = "wechat";
                    uappMod1.OpenID     = reqMod.FromUserName;
                    uappBll1.UpdateByID(uappMod1);
                    mubase.UserId = mu1.UserID;
                    buser.AddBase(mubase);
                }
            }
            else
            {
                uappMod1     = new Appinfo();
                mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower();
                mu1.UserPwd  = StringHelper.MD5(function.GetRandomString(6));
                mu1.Email    = function.GetRandomString(10) + "@wx.com";
                mu1.Question = function.GetRandomString(5);
                mu1.Answer   = function.GetRandomString(5);
                mu1.TrueName = wuserMod.Name;
                mu1.GroupID  = 1;
                mu1.UserID   = buser.Add(mu1);

                uappMod1.UserID     = mu1.UserID;
                uappMod1.SourcePlat = "wechat";
                uappMod1.OpenID     = reqMod.FromUserName;
                uappBll1.Insert(uappMod1);
                mubase.UserId = mu1.UserID;
                buser.AddBase(mubase);
            }

            if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl))     //如未设置图片则以纯文本格式发送,纯文本支持内置超链接
            {
                M_WxTextMsg textMod = ImageToText(msgmod);
                RepToClient(textMod.ToXML());
            }
            else
            {
                RepToClient(msgmod.ToXML());
            }
            //关注时发送多条信息
            if (pid > 0)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod);
            }
            //关注时发送多条信息
            //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod);
            break;

        case "unsubscribe":
            wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName);
            break;

        case "location":    //用户进入公众号(包含定位信息)
            M_WxImgMsg msgmod1 = new M_WxImgMsg();
            msgmod1.ToUserName   = reqMod.FromUserName;
            msgmod1.FromUserName = reqMod.ToUserName;
            M_WX_ReplyMsg rpMod = new M_WX_ReplyMsg();
            rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "头图");
            if (rpMod != null)
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod.Content);
                msgmod1.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
//                rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送1");
//                {
//                    M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content);
//                    msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl });
//                }
//                rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送2");
//                {
//                    M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content);
//                    msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl });
//                }
//                rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送3");
//                {
//                    M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content);
//                    msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl });
//                }
//                rpMod = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送4");
//                {
//                    M_WXImgItem item = JsonConvert.DeserializeObject<M_WXImgItem>(rpMod.Content);
//                    msgmod1.Articles.Add(new M_WXImgItem() { Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl });
//                }
            RepToClient(msgmod1.ToXML());
            break;

        case "scan":
            Appinfo     uappMod  = new Appinfo();
            B_UserAPP   uappBll  = new B_UserAPP();
            M_UserInfo  mu       = new M_UserInfo();
            M_WxTextMsg textMod2 = new M_WxTextMsg();
            textMod2.FromUserName = reqMod.ToUserName;
            textMod2.ToUserName   = reqMod.FromUserName;
            textMod2.MsgType      = "text";
            textMod2.Content      = "";
            uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat");
            if (uappMod != null)
            {
                mu = buser.GetUserByUserID(uappMod.UserID);
                M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey));
                if (mu != null && mu.UserID > 0)
                {
                    if (DataConvert.CLng(mu.ParentUserID) > 0)
                    {
                        textMod2.Content = "您已绑定了推荐人不能重复绑定!";
                        RepToClient(textMod2.ToXML());
                    }
                    else
                    {
                        if (mu.UserID == DataConvert.CLng(reqMod.EventKey))
                        {
                            textMod2.Content = "您扫描的是您自己的二维码!";
                        }
                        else
                        {
                            mu.ParentUserID = DataConvert.CLng(reqMod.EventKey).ToString();
                            if (pmu != null && pmu.UserID > 0)
                            {
                                string err = "";
                                if (CheckParentUser(pmu.UserID, mu.UserID, ref err))
                                {
                                    mu.ParentUserID = pmu.UserID.ToString();
                                    if (buser.UpdateByID(mu))
                                    {
                                        textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!";
                                    }

                                    else
                                    {
                                        textMod2.Content = "绑定推荐人失败!";
                                    }
                                }
                                else
                                {
                                    textMod2.Content = "绑定推荐失败,错误信息:" + err;
                                }
                            }
                            else
                            {
                                textMod2.Content = "绑定推荐失败,推荐人不存在!";
                            }
                        }
                        RepToClient(textMod2.ToXML());
                    }
                }
            }
            break;

        default:
            break;
        }
    }
Esempio n. 16
0
    /// <summary>
    /// 系统事件,如订阅等处理
    /// </summary>
    public void WxEventHandler(M_WxTextMsg reqMod)
    {
        M_WX_User userMod = null;

        errmsg += ",事件:" + reqMod.Event;
        switch (reqMod.Event.ToLower())
        {
        case "subscribe":
            userMod       = api.GetWxUserModel(reqMod.FromUserName);
            userMod.CDate = DateTime.Now;
            userMod.AppId = api.AppId.ID;
            wxuserBll.Insert(userMod);
            M_WxImgMsg msgmod = JsonConvert.DeserializeObject <M_WxImgMsg>(api.AppId.WelStr);
            msgmod.ToUserName   = reqMod.FromUserName;
            msgmod.FromUserName = reqMod.ToUserName;

            int       pid      = DataConvert.CLng(reqMod.EventKey.Replace("qrscene_", ""));
            M_UserAPP uappMod1 = new M_UserAPP();

            M_UserInfo mu1      = new M_UserInfo();
            M_WX_User  wuserMod = new M_WX_User();
            M_Uinfo    mubase   = new M_Uinfo();
            uappMod1 = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat");
            wuserMod = api.GetWxUserModel(reqMod.FromUserName);
            if (uappMod1 != null)
            {
                mu1 = buser.GetUserByUserID(uappMod1.UserID);
                if (mu1 != null && mu1.UserID > 0)
                {
                    mu1.TrueName = wuserMod.Name;
                    try
                    {
                        string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu1.UserName + mu1.UserID + "/wxheadimg.jpg";
                        HttpHelper.DownFile(wuserMod.HeadImgUrl, vpath);
                        mu1.UserFace = vpath;
                    }
                    catch (Exception ex)
                    {
                        ZLLog.L("微信更新头像错误,原因:" + ex.Message);
                    }

                    mu1.GroupID = 1;
                    buser.UpdateByID(mu1);
                }
                else
                {
                    mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower();
                    mu1.UserPwd  = StringHelper.MD5(function.GetRandomString(6));
                    mu1.Email    = function.GetRandomString(10) + "@wx.com";
                    mu1.Question = function.GetRandomString(5);
                    mu1.Answer   = function.GetRandomString(5);
                    mu1.TrueName = wuserMod.Name;
                    mu1.GroupID  = 1;
                    try
                    {
                        string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu1.UserName + mu1.UserID + "/wxheadimg.jpg";
                        HttpHelper.DownFile(wuserMod.HeadImgUrl, vpath);
                        mu1.UserFace = vpath;
                    }
                    catch (Exception ex)
                    {
                        ZLLog.L("微信更新头像错误,原因:" + ex.Message);
                    }

                    mu1.UserID = buser.Add(mu1);

                    uappMod1.UserID     = mu1.UserID;
                    uappMod1.SourcePlat = "wechat";
                    uappMod1.OpenID     = reqMod.FromUserName;
                    uappBll.UpdateByID(uappMod1);
                    mubase.UserId = mu1.UserID;
                    buser.AddBase(mubase);
                }
            }
            else
            {
                uappMod1     = new M_UserAPP();
                mu1.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower();
                mu1.UserPwd  = StringHelper.MD5(function.GetRandomString(6));
                mu1.Email    = function.GetRandomString(10) + "@wx.com";
                mu1.Question = function.GetRandomString(5);
                mu1.Answer   = function.GetRandomString(5);
                mu1.TrueName = wuserMod.Name;
                mu1.GroupID  = 1;
                try
                {
                    string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu1.UserName + mu1.UserID + "/wxheadimg.jpg";
                    HttpHelper.DownFile(wuserMod.HeadImgUrl, vpath);
                    mu1.UserFace = vpath;
                }
                catch (Exception ex)
                {
                    ZLLog.L("微信更新头像错误,原因:" + ex.Message);
                }

                mu1.UserID = buser.Add(mu1);

                uappMod1.UserID     = mu1.UserID;
                uappMod1.SourcePlat = "wechat";
                uappMod1.OpenID     = reqMod.FromUserName;
                uappBll.Insert(uappMod1);
                mubase.UserId = mu1.UserID;
                buser.AddBase(mubase);
            }

            if (string.IsNullOrEmpty(msgmod.Articles[0].PicUrl))     //如未设置图片则以纯文本格式发送,纯文本支持内置超链接
            {
                M_WxTextMsg textMod = ImageToText(msgmod);
                RepToClient(textMod.ToXML());
            }
            else
            {
                RepToClient(msgmod.ToXML());
            }
            //关注时发送多条信息
            if (pid > 0)
            {
                System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod);
            }
            //关注时发送多条信息
            //System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod);
            break;

        case "unsubscribe":
            wxuserBll.DelByOpenid(api.AppId.ID, reqMod.FromUserName);
            break;

        case "location":    //用户进入公众号(包含定位信息)
            break;

        case "scan":
            M_UserAPP   uappMod   = new M_UserAPP();
            M_UserInfo  mu        = new M_UserInfo();
            M_WxTextMsg textMod2  = new M_WxTextMsg();
            M_WX_User   wuserMod1 = api.GetWxUserModel(reqMod.FromUserName);
            M_Uinfo     mubase1   = new M_Uinfo();

            textMod2.FromUserName = reqMod.ToUserName;
            textMod2.ToUserName   = reqMod.FromUserName;
            textMod2.MsgType      = "text";
            textMod2.Content      = "";
            uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat");
            if (uappMod != null)
            {
                mu = buser.GetUserByUserID(uappMod.UserID);
                M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey));
                if (mu != null && mu.UserID > 0)
                {
                    if (DataConvert.CLng(mu.ParentUserID) > 0)
                    {
                        textMod2.Content = "您已绑定了推荐人不能重复绑定!";
                        RepToClient(textMod2.ToXML());
                    }
                    else
                    {
                        if (mu.UserID == DataConvert.CLng(reqMod.EventKey))
                        {
                            textMod2.Content = "您扫描的是您自己的二维码!";
                        }
                        else
                        {
                            mu.ParentUserID = DataConvert.CLng(reqMod.EventKey).ToString();
                            if (pmu != null && pmu.UserID > 0)
                            {
                                string err = "";
                                try
                                {
                                    if (CheckParentUser(pmu.UserID, mu.UserID, ref err))
                                    {
                                        mu.ParentUserID = pmu.UserID.ToString();
                                        if (buser.UpdateByID(mu))
                                        {
                                            textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!";
                                        }

                                        else
                                        {
                                            textMod2.Content = "绑定推荐人失败!";
                                        }
                                    }
                                    else
                                    {
                                        textMod2.Content = "绑定推荐失败,错误信息:" + err;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    textMod2.Content = "绑定推荐失败,错误信息:" + pmu.TrueName + "的推荐关系有循环!";
                                }
                            }
                            else
                            {
                                textMod2.Content = "绑定推荐失败,推荐人不存在!";
                            }
                        }
                        RepToClient(textMod2.ToXML());
                    }
                }
            }
            else
            {
                uappMod1    = new M_UserAPP();
                mu.UserName = "******" + DateTime.Now.ToString("yyyyMMddHHmmss") + function.GetRandomString(2).ToLower();
                mu.UserPwd  = StringHelper.MD5(function.GetRandomString(6));
                mu.Email    = function.GetRandomString(10) + "@wx.com";
                mu.Question = function.GetRandomString(5);
                mu.Answer   = function.GetRandomString(5);
                mu.TrueName = wuserMod1.Name;
                mu.GroupID  = 1;
                try
                {
                    string vpath = SiteConfig.SiteOption.UploadDir + "User/" + mu.UserName + mu.UserID + "/wxheadimg.jpg";
                    HttpHelper.DownFile(wuserMod1.HeadImgUrl, vpath);
                    mu.UserFace = vpath;
                }
                catch (Exception ex)
                {
                    ZLLog.L("微信更新头像错误,原因:" + ex.Message);
                }

                M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey));
                if (pmu != null && pmu.UserID > 0)
                {
                    mu.ParentUserID = reqMod.EventKey;
                }
                mu.UserID = buser.Add(mu);

                uappMod1.UserID     = mu.UserID;
                uappMod1.SourcePlat = "wechat";
                uappMod1.OpenID     = reqMod.FromUserName;
                uappBll.Insert(uappMod1);
                mubase1.UserId = mu.UserID;
                buser.AddBase(mubase1);

                if (pmu != null && pmu.UserID > 0)
                {
                    textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!";
                    RepToClient(textMod2.ToXML());
                }
            }
            break;

        default:
            break;
        }
    }
Esempio n. 17
0
    /// <summary>
    /// 系统事件,如订阅等处理
    /// </summary>
    public void WxEventHandler(M_WxTextMsg reqMod)
    {
        M_WX_User userMod = null;

        errmsg += ",事件:" + reqMod.Event;
        switch (reqMod.Event.ToLower())
        {
        case "subscribe":
            userMod       = api.GetWxUserModel(reqMod.FromUserName);
            userMod.CDate = DateTime.Now;
            userMod.AppId = api.AppId.ID;
            wxuserBll.Insert(userMod);
            M_WxImgMsg msgmod = new M_WxImgMsg();
            msgmod.ToUserName   = reqMod.FromUserName;
            msgmod.FromUserName = reqMod.ToUserName;

            M_WX_ReplyMsg rpMod1 = new M_WX_ReplyMsg();
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "头图");
            if (rpMod1 != null)
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送1");
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送2");
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送3");
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送4");
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            rpMod1 = rpBll.SelByFileAndDef(appBll.GetAppByWxNo(reqMod.ToUserName).ID, "推送5");
            {
                M_WXImgItem item = JsonConvert.DeserializeObject <M_WXImgItem>(rpMod1.Content);
                msgmod.Articles.Add(new M_WXImgItem()
                {
                    Title = item.Title, Url = item.Url, Description = item.Description, PicUrl = item.PicUrl
                });
            }
            RepToClient(msgmod.ToXML());
            System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(SendMsg), reqMod);
            break;

        case "unsubscribe":
        {
            userMod = wxuserBll.SelForOpenid(reqMod.FromUserName);
            if (userMod != null)
            {
                wxuserBll.Del(userMod.ID);
            }
        }
        break;

        case "location":    //用户进入公众号(包含定位信息)
            break;

        case "scan":    //带参数的二维码扫描进入(关注事件在上方处理)
            M_UserAPP   uappMod  = new M_UserAPP();
            B_UserAPP   uappBll  = new B_UserAPP();
            M_UserInfo  mu       = new M_UserInfo();
            M_WxTextMsg textMod2 = new M_WxTextMsg();
            textMod2.FromUserName = reqMod.ToUserName;
            textMod2.ToUserName   = reqMod.FromUserName;
            textMod2.MsgType      = "text";
            textMod2.Content      = "";
            uappMod = uappBll.SelModelByOpenID(reqMod.FromUserName, "wechat");
            if (uappMod != null)
            {
                mu = buser.GetUserByUserID(uappMod.UserID);
                M_UserInfo pmu = buser.GetUserByUserID(DataConvert.CLng(reqMod.EventKey));
                if (mu != null && mu.UserID > 0)
                {
                    if (DataConvert.CLng(mu.ParentUserID) > 0)
                    {
                        textMod2.Content = "您已绑定了推荐人不能重复绑定!";
                        RepToClient(textMod2.ToXML());
                    }
                    else
                    {
                        if (mu.UserID == DataConvert.CLng(reqMod.EventKey))
                        {
                            textMod2.Content = "您扫描的是您自己的二维码!";
                        }
                        else
                        {
                            mu.ParentUserID = DataConvert.CLng(reqMod.EventKey).ToString();
                            if (pmu != null && pmu.UserID > 0)
                            {
                                string err = "";
                                if (CheckParentUser(pmu.UserID, mu.UserID, ref err))
                                {
                                    mu.ParentUserID = pmu.UserID.ToString();
                                    if (buser.UpdateByID(mu))
                                    {
                                        textMod2.Content = "您成功绑定了推荐人:" + pmu.TrueName + "!";
                                    }

                                    else
                                    {
                                        textMod2.Content = "绑定推荐人失败!";
                                    }
                                }
                                else
                                {
                                    textMod2.Content = "绑定推荐失败,错误信息:" + err;
                                }
                            }
                            else
                            {
                                textMod2.Content = "绑定推荐失败,推荐人不存在!";
                            }
                        }
                        RepToClient(textMod2.ToXML());
                    }
                }
            }
            break;

        default:
            break;
        }
    }