Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["para"] == null)
            {
                if ((Request.QueryString["openid"] != null) || Session["FromUserName"] != null)
                {
                    //WriteTxt("结束授权");
                    string user         = Request.QueryString["openid"] == null ? Session["FromUserName"].ToString() : Request.QueryString["openid"].ToString();
                    string access_token = Request.QueryString["Access_token"] == null ? Session["Access_token"].ToString() : Request.QueryString["Access_token"].ToString();
                    Session["FromUserName"] = user;
                    Session["Access_token"] = access_token;

                    HttpCookie cookie = Request.Cookies["XYH_COUPON"];
                    if (cookie == null)
                    {
                        cookie = new HttpCookie("XYH_COUPON");
                    }
                    cookie.Values.Set("FromUserName", user);

                    string url   = "https://api.weixin.qq.com/sns/userinfo?access_token=" + access_token + "&openid=" + user + "&lang=zh_CN";
                    string token = PostRequest(url);
                    WriteTxt(url);
                    WriteTxt(token);
                    OpenInfo autho = JsonConvert.DeserializeObject <OpenInfo>(token);
                    if (!string.IsNullOrWhiteSpace(autho.headimgurl))
                    {
                        MySmallShopService mss = new MySmallShopService();
                        OAauth_Log         oa  = mss.GetOA(user, "商业集团送券活动");
                        if (oa == null)
                        {
                            oa = new OAauth_Log();
                            oa.FromUserName = user;
                            oa.ToUserName   = "******";
                            oa.headimgurl   = autho.headimgurl;
                            oa.Nickname     = autho.nickname;
                            oa.CreateDate   = DateTime.Now;
                            mss.SaveOA(oa);
                        }
                    }

                    XHYCouponService _xyhService = new XHYCouponService();
                    //判断是否参加并且可以领取卡券
                    WXCouponGiveInfo model = _xyhService.GetWXCouponGiveInfoByOpenid(user, "SYJT");
                    if (model != null)
                    {
                        if (model.GetCoupon == 1)
                        {
                            var phone = model.Mobile;
                            Response.Redirect("list.html?mobile=" + phone);
                        }
                    }
                }
                else
                {
                    //WriteTxt("开始授权");
                    OAuth(AbsoluteUri);
                }
            }
        }
        const string Token     = "puman";       //与微信平台那边填写的token一致
        protected void Page_Load(object sender, EventArgs e)
        {
            string postStr = "";

            //WXLOG log2 = new WXLOG { CON = postStr + "weixin", TIME = DateTime.Now };
            //mss.SaveLog(log2);
            if (Request.HttpMethod.ToLower() == "post")
            {
                Stream s = System.Web.HttpContext.Current.Request.InputStream;
                byte[] b = new byte[s.Length];
                s.Read(b, 0, (int)s.Length);
                postStr = Encoding.UTF8.GetString(b);
                if (!string.IsNullOrEmpty(postStr))
                {
                    //封装请求类
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(postStr);
                    XmlElement rootElement = doc.DocumentElement;

                    string result_code = rootElement.SelectSingleNode("result_code").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                    if (result_code == "SUCCESS")
                    {
                        string        orderno        = rootElement.SelectSingleNode("out_trade_no").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        string        bank_type      = rootElement.SelectSingleNode("bank_type").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        string        transaction_id = rootElement.SelectSingleNode("transaction_id").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        Pet_XXL_Order order          = nvbo.GetPetXXLOrder(orderno);
                        if (order != null && order.OrderState != 2)
                        {
                            //Pet_XXL_Address add = nvbo.GetAddress(order.AID.Value);
                            //if (add != null)
                            //{
                            //    new SendDX().Send2("我们已收到您的付款,感谢您的支持,半湿粮将会在24小时后统一配送。", add.Phone);
                            //}
                            order.OrderState = 2;
                            order.BankType   = bank_type;
                            order.OutOrderNo = transaction_id;
                            nvbo.SavePetXXLOrder(order);
                            //if (order.yhqid != null && order.yhqid != 0)
                            //{

                            //}
                            try
                            {
                                OAauth_Log o = mss.GetOA(order.FromUserName);
                                if (o != null)
                                {
                                    Pet_JiuZhu_Info j = nvbo.GetJiuZhuInfo(order.Source.Value);
                                    if (j != null && (j.JZType == 1 || j.JZType == 2))
                                    {
                                        Pet_JiuZhu_Love l = new Pet_JiuZhu_Love
                                        {
                                            CreateTime   = DateTime.Now,
                                            Detail       = "捐助基地[" + j.NickName + "][" + (j.JZType == 1 ? "捐粮" : "捐款") + "]",
                                            FromUserName = order.FromUserName,
                                            OID          = order.ID,
                                            Love         = j.JZType == 1 ? Convert.ToInt32(order.TotalPrice) : Convert.ToInt32(order.TotalPrice / 2)
                                        };
                                        int lid = nvbo.SavePetJiuZhuLove(l);
                                        if (lid > 0)
                                        {
                                            o.TotalLove = (o.TotalLove ?? 0) + l.Love;
                                            o.SurLove   = (o.SurLove ?? 0) + l.Love;
                                            mss.SaveOA(o);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                            try
                            {
                                if (order.UrlPara > 0)//非小程序
                                {
                                    string token = Token(mjuserid);
                                    var    temp  = new
                                    {
                                        first            = new { value = "我们已收到您的微信付款", color = "#173177" },
                                        orderMoneySum    = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                        orderProductName = new { value = order.GoodsName, color = "#173177" },
                                        Remark           = new { value = "\n" + "我们已收到您的爱心。", color = "#CD0000" }
                                    };
                                    if (order.PJ != null && order.PJ != 0)
                                    {
                                        temp = new
                                        {
                                            first            = new { value = "我们已收到您的微信付款", color = "#173177" },
                                            orderMoneySum    = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                            orderProductName = new { value = order.GoodsName, color = "#173177" },
                                            Remark           = new { value = "\n" + "我们已收到您的爱心,您已成功捐粮" + Math.Round(order.TotalPrice.Value / 16, 2) + "kg,并且您的爱心被放大,由宠物管家赞助为其配捐" + Math.Round(order.PJ.Value / 16, 2) + "kg", color = "#CD0000" }
                                        };
                                    }
                                    string message = SendTemplateMessage(token, order.FromUserName, "qLJpWtjKj8zm3j8cwOe0u3u7qHwQ04cSx2UUvvVu-Ug", "#FF0000", temp, WebUrl + "/wechat/test/tz.aspx?tousername="******"yyyy年MM月dd日 HH:mm"), color = "#173177" },
                                        keyword2 = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                        keyword3 = new { value = order.GoodsName, color = "#173177" },
                                        keyword4 = new { value = "为毛孩子筹粮/筹款", color = "#173177" },
                                        keyword5 = new { value = order.OrderNo, color = "#173177" }
                                    };
                                    string message = SendTemplateMessageSR(token, order.FromUserName, "IuoZZEIkILzvazy94NRpYrQ9usZ0wc3RyeSSp85gfmA", "#FF0000", temp, "pages/Pet/Detail/Detail?id=" + order.Source, order.buyer_logon_id);
                                    mss.SaveLog(new WXLOG {
                                        CON = message, TIME = DateTime.Now
                                    });
                                }
                            }
                            catch (Exception)
                            {
                            }
                            Response.Write("success");
                            Response.End();
                        }
                    }
                    //WXLOG log = new WXLOG { CON = postStr + "weixin", TIME = DateTime.Now };
                    //mss.SaveLog(log);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["para"] != null && Request.QueryString["para"] == "SendDX")
            {
                Random r       = new Random();
                int    num     = r.Next(100000, 999999);
                string message = "本次获取的验证码是" + num + "。";
                string zt      = new SendDX().Send(message, Request.Params["phone"]);
                if (zt == "发送成功")
                {
                    Session["RanPhone"] = Request.Params["phone"];
                    Session["RanNum"]   = num.ToString();
                    Response.Write("{\"message\":\"发送成功。\",\"status\":\"" + 0 + "\"}");
                }
                else
                {
                    Response.Write("{\"message\":\"发送失败。\",\"status\":\"" + -1 + "\"}");
                }
                Response.End();
            }
            else if (Request.QueryString["para"] != null && Request.QueryString["para"] == "bang")
            {
                if (Session["RanNum"] == null)
                {
                    Response.Write("{\"message\":\"请先获取验证码。\",\"status\":\"" + -1 + "\"}");
                }
                else if (Request.QueryString["phone"] != Session["RanPhone"].ToString() || Request.QueryString["yzm"] != Session["RanNum"].ToString())
                {
                    Response.Write("{\"message\":\"输入的验证码有误。\",\"status\":\"" + -1 + "\"}");
                }
                else
                {
                    string     url = "wo.aspx";
                    OAauth_Log oa1 = mss.GetOAByPhone(Request.QueryString["phone"]);//根据手机号码获取到的信息
                    if ((Request.QueryString["FromUserName"] != null || Session["FromUserName"] != null) && (Request.QueryString["ToUserName"] != null || Session["ToUserName"] != null))
                    {
                        string user  = Request.QueryString["FromUserName"] == null ? Session["FromUserName"].ToString() : Request.QueryString["FromUserName"].ToString();
                        string user2 = Request.QueryString["ToUserName"] == null ? Session["ToUserName"].ToString() : Request.QueryString["ToUserName"].ToString();
                        oa = mss.GetOA(user);//根据微信号获取到的信息

                        if (oa != null && !string.IsNullOrEmpty(oa.Phone))
                        {
                            Response.Write("{\"message\":\"你已经绑定。\",\"status\":\"" + -1 + "\"}");
                        }
                        //else if (oa != null && oa1 != null && !string.IsNullOrEmpty(oa1.FromUserName) && oa1.FromUserName != null&&oa1.ToUserName!="web") //根据手机号码获取到的用户信息,微信号码不同
                        //{
                        //    Response.Write("{\"message\":\"该手机已被其他微信绑定。\",\"status\":\"" + -1 + "\"}");
                        //}
                        //可绑定多个账号
                        else
                        {
                            if (oa != null && oa1 != null && oa1.ID != oa.ID) //根据手机号获取到另一个来自网页的绑定的信息,将手机号绑定到有微信号的信息中,删除无手机号的信息
                            {
                                oa.Phone = Request.QueryString["phone"];
                                //mss.DeteleOA(oa1.ID); //保留原有账号不删除,保留web版账号
                            }
                            else if (oa != null)
                            {
                                oa.Phone = Request.QueryString["phone"];
                            }
                            else
                            {
                                oa = new OAauth_Log
                                {
                                    CreateDate   = DateTime.Now,
                                    FromUserName = user,
                                    ToUserName   = "",
                                    Nickname     = "用户",
                                    Phone        = Request.QueryString["phone"]
                                };
                            }
                            mss.SaveOA(oa);
                            Session["FromUserName"] = oa.FromUserName;
                            Session["ToUserName"]   = oa.ToUserName;
                            if (Session["beforeurl2"] != null)
                            {
                                url = Session["beforeurl2"].ToString().Replace("*", "&");
                            }
                            Response.Write("{\"message\":\"登录成功\",\"status\":\"" + 1 + "\",\"url\":\"" + url + "\"}");
                        }
                    }
                    else
                    {
                        if (oa1 == null)  //web版登录
                        {
                            oa = new OAauth_Log
                            {
                                CreateDate   = DateTime.Now,
                                FromUserName = Guid.NewGuid().ToString("d"),
                                ToUserName   = "******",
                                Nickname     = "用户",
                                Phone        = Request.QueryString["phone"]
                            };
                            mss.SaveOA(oa);
                            Session["FromUserName"] = oa.FromUserName;
                            Session["ToUserName"]   = oa.ToUserName;
                            if (Session["beforeurl2"] != null)
                            {
                                url = Session["beforeurl2"].ToString().Replace("*", "&");
                            }
                            Response.Write("{\"message\":\"登录成功\",\"status\":\"" + 1 + "\",\"url\":\"" + url + "\"}");
                        }
                        else
                        {
                            Session["FromUserName"] = oa1.FromUserName;
                            Session["ToUserName"]   = oa1.ToUserName;
                            if (Session["beforeurl2"] != null)
                            {
                                url = Session["beforeurl2"].ToString().Replace("*", "&");
                            }
                            Response.Write("{\"message\":\"登录成功\",\"status\":\"" + 1 + "\",\"url\":\"" + url + "\"}");
                        }
                    }
                }
                Response.End();
            }
            else
            {
                if (Request.QueryString["beforeurl2"] != null && Session["beforeurl2"] == null)
                {
                    Session["beforeurl2"] = Request.QueryString["beforeurl2"];
                }
                if ((Request.QueryString["FromUserName"] != null || Session["FromUserName"] != null) && (Request.QueryString["ToUserName"] != null || Session["ToUserName"] != null))
                {
                    string user  = Request.QueryString["FromUserName"] == null ? Session["FromUserName"].ToString() : Request.QueryString["FromUserName"].ToString();
                    string user2 = Request.QueryString["ToUserName"] == null ? Session["ToUserName"].ToString() : Request.QueryString["ToUserName"].ToString();
                    oa = mss.GetOA(user);//根据微信号获取到的信息
                }
            }
        }
Beispiel #4
0
    /// <summary>
    /// 海报1
    /// </summary>
    /// <param name="openid"></param>
    /// <returns></returns>
    public string SeadSeaNews(string openid)
    {
        string img = "/assets/img/bottom.jpg";

        img = Server.MapPath(img);
        string     headimg = "/wechat/spa/image/logo.jpg";
        string     qrimg   = "/wechat/spa/image/logo.jpg";
        OAauth_Log oa      = mss.GetOA(openid);

        if (oa != null)
        {
            if (!string.IsNullOrEmpty(oa.MEDIA_ID) && oa.MEDIA_Time.HasValue && oa.MEDIA_Time > DateTime.Now)
            {
                return(oa.MEDIA_ID);             //如果已有海报,并且未过期,则直接返回之前的海报。
            }
            if (string.IsNullOrEmpty(oa.Ticket)) //如果没有生成过邀请二维码,则生成一个。
            {
                //string access_token = w.Token(w.mjuserid);
                string   jason      = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\": {\"scene\": {\"scene_id\": " + (oa.ID + 10000) + "}}}"; //oa的id增加一万
                string   resMessage = WeiPage.HttpXmlPostRequest("https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + Token(mjuserid), jason, Encoding.UTF8);
                string[] a          = resMessage.Split('\"');
                if (a.Length > 3)
                {
                    oa.Ticket = Server.UrlEncode(a[3]);
                    DownQRImage(oa.Ticket);
                    qrimg = "/wechat/QRImage/" + oa.Ticket + ".jpg";
                }
            }
            else
            {
                qrimg = "/wechat/QRImage/" + oa.Ticket + ".jpg";
            }
            qrimg = Server.MapPath(qrimg);
            if (!string.IsNullOrEmpty(oa.DownPic))
            {
                headimg = oa.DownPic;
            }
            else if (!string.IsNullOrEmpty(oa.headimgurl))
            {
                string down = DownHeadImage(oa);
                if (!string.IsNullOrEmpty(down))
                {
                    headimg = down;
                }
            }
            headimg = Server.MapPath(headimg);

            string img2 = @"E:\ASPNETTempFiles\seanews\";
            if (!System.IO.Directory.Exists(img2))
            {
                Directory.CreateDirectory(img2);
            }
            oa.SeaImg = Guid.NewGuid().ToString();
            img2     += oa.SeaImg + ".jpg";
            if (File.Exists(img) && File.Exists(headimg) && File.Exists(qrimg))
            {
                ImageWriter           iw       = new ImageWriter();
                System.Drawing.Bitmap bm       = new System.Drawing.Bitmap(headimg);
                System.Drawing.Image  newImage = CutEllipse(bm, new Rectangle(0, 0, bm.Width, bm.Height), new Size(200, 200));
                iw.SaveWatermark(new System.Drawing.Bitmap(img), (Bitmap)newImage, ImageWriter.WatermarkPosition.LeftTop, 90, 70, new System.Drawing.Bitmap(qrimg), ImageWriter.WatermarkPosition.LeftBottom, 220, 50, img2, oa.Nickname);; // f.FILE_NAME, Server.MapPath("~/assets/images/shuiyin.png"), Server.MapPath("~/assets/images/shuiyin2.png"), Server.MapPath("~/assets/images/shuiyin3.png"), 0.3f, ImageWriter.WatermarkPosition.Center, 10, f.FILE_NAME);
            }

            if (File.Exists(img2))
            {
                List <string> imglist = new List <string>();
                imglist.Add(img2);
                string a        = HttpUploadFile("https://api.weixin.qq.com/cgi-bin/media/upload?access_token=" + Token(mjuserid) + "&type=image", "图片", "application/x-jpg", new System.Collections.Specialized.NameValueCollection {
                }, imglist);
                Rootobject root = JsonConvert.DeserializeObject <Rootobject>(a);
                if (root.media_id != null)
                {
                    oa.MEDIA_ID   = root.media_id;
                    oa.MEDIA_Time = DateTime.Now.AddDays(3).AddHours(-2);
                    mss.SaveOA(oa);
                    return(root.media_id);

                    string message = @"{
                ""touser"":""{0}"",
                ""msgtype"":""image"",
                ""image"":
                {
                  ""media_id"":""{1}""
                }
            }";
                    message = message.Replace("{0}", oa.FromUserName).Replace("{1}", root.media_id);
                    string Access_token = Token(mjuserid);

                    var    postUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + Access_token;
                    string d       = message;
                    //d = d.Replace("{0}", "oS7pm1iNL2P2pjdgHO3xC2NRdWE8").Replace("{1}", Message);
                    string resMessage = HttpXmlPostRequest(postUrl, d, Encoding.UTF8);
                    //Response.Write(resMessage);
                }
            }
        }
        return("err");
    }
        /// <summary>
        /// 回复消息(微信信息返回)
        /// </summary>
        /// <param name="weixinXML"></param>
        private void ResponseMsg(WXCUST_MSG_HIS requestXML)
        {
            WriteTxt(requestXML.MSGTYPE);
            string resxml = "<xml><ToUserName><![CDATA[" + requestXML.FROMUSERNAME + "]]></ToUserName><FromUserName><![CDATA[" + requestXML.TOUSERNAME + "]]></FromUserName><CreateTime>" + ConvertDateTimeInt(DateTime.Now) + "</CreateTime>";

            try
            {
                if (requestXML.MSGTYPE == "text")
                {
                    if (requestXML.CONTENT == "海报")
                    {
                    }
                    else
                    {
                        int count = 0;
                        List <Information_EX> list = sbo.GetModelList(string.Format("  ((KeyWords like '%{0}%' and MatchingType=0) or (KeyWords ='{0}' and MatchingType=1)) AND replytype={1} and ToUserName='******'", requestXML.CONTENT, 1, requestXML.TOUSERNAME));
                        if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                        {
                            Information_EX f = list[0];// ibo.GetModel(requestXML.EventKey, 4); //自定义菜单回复

                            if (f != null)
                            {
                                switch (f.MsgType)
                                {
                                case "text":
                                    resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                    break;

                                case "news":
                                    resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                    resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                    resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                    break;

                                case "music":
                                    resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                    break;

                                default:
                                    //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                    break;
                                }
                            }
                        }
                        else if (list.Count > 1) //多图
                        {
                            count   = list.Count;
                            resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                            for (int i = 0; i < count; i++)
                            {
                                resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                            }
                            resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                        }
                        else
                        {
                            list = sbo.GetModelList(string.Format("   replytype={0} and ToUserName='******'", 3, requestXML.TOUSERNAME));
                            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                            {
                                Information_EX f = list[0];

                                if (f != null)
                                {
                                    switch (f.MsgType)
                                    {
                                    case "text":
                                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "news":
                                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                        resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "music":
                                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                        break;

                                    default:
                                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;
                                    }
                                }
                            }
                            else if (list.Count > 1) //多图
                            {
                                int count2 = list.Count;
                                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                                for (int z = 0; z < count2; z++)
                                {
                                    resxml += "<item><Title><![CDATA[" + list[z].Title + "]]></Title><Description><![CDATA[" + list[z].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[z].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[z].IsURL ? (list[z].FulltextUrl.Contains("?id") ? (list[z].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[z].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[z].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                                }
                                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                            }
                        }
                    }
                }

                else if (requestXML.MSGTYPE == "event")
                {
                    if (requestXML.WXEVENT == "CLICK")
                    {
                        WriteTxt("CLICK");
                        if (requestXML.EVENTKEY == InviteMenuId)
                        {
                            resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[分享海报邀请新用户,福利多多:\n• 邀请关注,赢佰草集太极.昼御夜养.源生霜、清肌养颜太极泥、三丽鸥KITTY礼品杯\n• 关注后注册绑定,还可获得380元代金券 \n\n点击进入<a href='" + WebUrl + "/wechat/SPA/HFOldAndNew.aspx'>活动主会场</a>\n分享海报,赢惊喜大礼!]]></Content><FuncFlag>0</FuncFlag></xml>";
                        }
                        else
                        {
                            List <CustomMenu_EX> list = sbo.GetCustomMenuModelList(string.Format("  c.ID='{0}'", requestXML.EVENTKEY));
                            if (list.Count == 1 || (list.Count > 1 && list[0].MsgType != "news"))
                            {
                                CustomMenu_EX f = list[0];// ibo.GetModel(requestXML.EventKey, 4); //自定义菜单回复

                                if (f != null)
                                {
                                    switch (f.MsgType)
                                    {
                                    case "text":

                                        resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[" + f.Content + "]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "news":
                                        resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>1</ArticleCount><Articles>";
                                        resxml += "<item><Title><![CDATA[" + f.Title + "]]></Title><Description><![CDATA[" + f.Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl + "]]></PicUrl><Url><![CDATA[" + (f.IsURL ? (f.FulltextUrl.Contains("?id") ? (f.FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (f.FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + f.DID)) + "]]></Url></item>";    //URL是点击之后跳转去那里,这里跳转到百度
                                        resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                                        break;

                                    case "music":
                                        resxml += string.Format(@"<MsgType><![CDATA[music]]></MsgType>
                                 <Music>
                                 <Title><![CDATA[{0}]]></Title>
                                 <Description><![CDATA[{1}]]></Description>
                                 <MusicUrl><![CDATA[{2}]]></MusicUrl>
                                 <HQMusicUrl><![CDATA[{2}]]></HQMusicUrl>
                                 </Music>
                                 <FuncFlag>0</FuncFlag>
                                 </xml>", f.Title, f.Description, ConfigurationSettings.AppSettings["WebUrl"] + f.PicUrl);
                                        break;

                                    default:
                                        //resxml += "<MsgType><![CDATA[text]]></MsgType><Content><![CDATA[感谢您的支持]]></Content><FuncFlag>0</FuncFlag></xml>";
                                        break;
                                    }
                                }
                            }
                            else if (list.Count > 1) //多图
                            {
                                int count = list.Count;
                                resxml += "<MsgType><![CDATA[news]]></MsgType><ArticleCount>" + count + "</ArticleCount><Articles>";
                                for (int i = 0; i < count; i++)
                                {
                                    resxml += "<item><Title><![CDATA[" + list[i].Title + "]]></Title><Description><![CDATA[" + list[i].Description + "]]></Description><PicUrl><![CDATA[" + ConfigurationSettings.AppSettings["WebUrl"] + list[i].PicUrl + "]]></PicUrl><Url><![CDATA[" + (list[i].IsURL ? (list[i].FulltextUrl.Contains("?id") ? (list[i].FulltextUrl + "&FromUserName="******"&ToUserName="******"") : (list[i].FulltextUrl + "?FromUserName="******"&ToUserName="******"")) : (ConfigurationSettings.AppSettings["WebUrl"] + "/GraphicDisplay.aspx?id=" + list[i].DID)) + "]]></Url></item>";//URL是点击之后跳转去那里,这里跳转到百度
                                }
                                resxml += "</Articles><FuncFlag>0</FuncFlag></xml>";
                            }
                        }
                    }
                    else if (requestXML.WXEVENT == "unsubscribe")
                    {
                        //取消关注 把粉丝表更新状态为0
                        WriteTxt("取消关注");
                        if (DateTime.Now < DateTime.Parse(ActiveEndDate))
                        {
                            InsertFS(requestXML.FROMUSERNAME, requestXML.TOUSERNAME, 0);  //插入粉丝信息
                            if (DateTime.Now < DateTime.Parse(ActiveEndDate))
                            {
                                MySmallShopService mss = new MySmallShopService();
                                //将表Cust_Old_New中的Jie改成 - 1 ToUserName = openid
                                //将表Cust_Old_New中的Jie改成 - 1 FromUserName = openid  ToUserName = fx
                                mss.UpdateCustOldNewJie(requestXML.FROMUSERNAME);
                                //将表OAauth_Log中的字段SeaImg = '' 参加活动数量-1
                                OAauth_Log oa = mss.GetOA(requestXML.FROMUSERNAME);
                                if (oa != null)
                                {
                                    oa.SeaImg    = "";
                                    oa.SeaSource = null;
                                    mss.SaveOA(oa);
                                }
                            }
                        }
                    }
                    else if (requestXML.WXEVENT.ToLower() == "location") //获取地理位置
                    {
                        WriteTxt("获取地理位置");
                    }
                    else if (requestXML.WXEVENT.ToLower() == "scan" || (requestXML.WXEVENT.ToLower() == "subscribe" && requestXML.EVENTKEY.ToLower().Contains("qrscene"))) //扫描二维码
                    {
                        WriteTxt("扫二维码");
                        string EVENTKEY = requestXML.EVENTKEY;
                        requestXML.EVENTKEY = requestXML.EVENTKEY.ToLower().Contains("qrscene") ? requestXML.EVENTKEY.Split('_')[1] : requestXML.EVENTKEY;
                        int num = int.Parse(requestXML.EVENTKEY);

                        if (requestXML.WXEVENT.ToLower() == "subscribe")
                        {
                            if (num > 10000) //邀请海报
                            {
                                resxml = OldAndNew(requestXML, resxml, num);
                            }
                            resxml = Subscribe(requestXML, resxml);
                        }
                    }

                    //关注
                    else if (requestXML.WXEVENT.ToLower() == "subscribe")
                    {
                        WriteTxt("关注");
                        resxml = Subscribe(requestXML, resxml);
                        if (DateTime.Now < DateTime.Parse(ActiveEndDate))
                        {
                        }
                    }
                }
                requestXML.RESXML = resxml;
                if (!resxml.Contains("</xml>"))
                {
                    resxml = "";
                }


                AddCUST_MSG_HISHandler handler = new AddCUST_MSG_HISHandler(sbo.AddCUST_MSG_HIS);
                int result = handler.Invoke(requestXML);
                //sbo.AddCUST_MSG_HIS(requestXML);
            }
            catch (Exception ex)
            {
                resxml = "";
            }
            finally
            {
                Response.Write(resxml);
                Response.End();
            }
        }
        const string Token     = "puman";       //与微信平台那边填写的token一致
        protected void Page_Load(object sender, EventArgs e)
        {
            string postStr = "";

            //WXLOG log2 = new WXLOG { CON = postStr + "weixin", TIME = DateTime.Now };
            //mss.SaveLog(log2);
            if (Request.HttpMethod.ToLower() == "post")
            {
                Stream s = System.Web.HttpContext.Current.Request.InputStream;
                byte[] b = new byte[s.Length];
                s.Read(b, 0, (int)s.Length);
                postStr = Encoding.UTF8.GetString(b);
                if (!string.IsNullOrEmpty(postStr))
                {
                    //封装请求类
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(postStr);
                    XmlElement rootElement = doc.DocumentElement;

                    string result_code = rootElement.SelectSingleNode("result_code").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                    if (result_code == "SUCCESS")
                    {
                        string        orderno        = rootElement.SelectSingleNode("out_trade_no").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        string        bank_type      = rootElement.SelectSingleNode("bank_type").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        string        transaction_id = rootElement.SelectSingleNode("transaction_id").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        string        openid         = rootElement.SelectSingleNode("openid").InnerXml.Replace("<![CDATA[", "").Replace("]]>", "");
                        Pet_XXL_Order order          = nvbo.GetPetXXLOrder(orderno);
                        if (order != null && order.OrderState != 2)
                        {
                            //Pet_XXL_Address add = nvbo.GetAddress(order.AID.Value);
                            //if (add != null)
                            //{
                            //    new SendDX().Send2("我们已收到您的付款,感谢您的支持,半湿粮将会在24小时后统一配送。", add.Phone);
                            //}
                            order.OrderState   = 2;
                            order.BankType     = bank_type;
                            order.OutOrderNo   = transaction_id;
                            order.FromUserName = openid;
                            nvbo.SavePetXXLOrder(order);
                            //if (order.yhqid != null && order.yhqid != 0)
                            //{

                            //}

                            try
                            {
                                OAauth_Log o = mss.GetOA(order.FromUserName);
                                if (o != null)
                                {
                                    Pet_JiuZhu_Info j = nvbo.GetJiuZhuInfo(order.Source.Value);
                                    if (j != null && (j.JZType == 1 || j.JZType == 2))
                                    {
                                        Pet_JiuZhu_Love l = new Pet_JiuZhu_Love
                                        {
                                            CreateTime   = DateTime.Now,
                                            Detail       = "捐助基地[" + j.NickName + "][" + (j.JZType == 1 ? "捐粮" : "捐款") + "]",
                                            FromUserName = order.FromUserName,
                                            OID          = order.ID,
                                            Love         = j.JZType == 1 ? Convert.ToInt32(order.TotalPrice) : Convert.ToInt32(order.TotalPrice / 2)
                                        };
                                        int lid = nvbo.SavePetJiuZhuLove(l);
                                        if (lid > 0)
                                        {
                                            o.TotalLove = (o.TotalLove ?? 0) + l.Love;
                                            o.SurLove   = (o.SurLove ?? 0) + l.Love;
                                            mss.SaveOA(o);
                                        }
                                    }
                                }
                            }
                            catch (Exception)
                            {
                            }
                            try
                            {
                                string token = Token(mjuserid);
                                var    temp  = new
                                {
                                    first            = new { value = "我们已收到您的微信付款", color = "#173177" },
                                    orderMoneySum    = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                    orderProductName = new { value = order.GoodsName, color = "#173177" },
                                    Remark           = new { value = "\n" + "我们已收到您的爱心。", color = "#CD0000" }
                                };
                                if (order.PJ != null && order.PJ != 0)
                                {
                                    temp = new
                                    {
                                        first            = new { value = "我们已收到您的微信付款", color = "#173177" },
                                        orderMoneySum    = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                        orderProductName = new { value = order.GoodsName, color = "#173177" },
                                        Remark           = new { value = "\n" + "我们已收到您的爱心,您已成功捐粮" + Math.Round(order.TotalPrice.Value / 16, 2) + "kg,并且您的爱心被放大,由宠物管家赞助为其配捐" + Math.Round(order.PJ.Value / 16, 2) + "kg", color = "#CD0000" }
                                    };
                                }
                                string message = SendTemplateMessage(token, order.FromUserName, "qLJpWtjKj8zm3j8cwOe0u3u7qHwQ04cSx2UUvvVu-Ug", "#FF0000", temp, WebUrl + "/wechat/test/tz.aspx?tousername="******"o3L1MwYudOztZTDDA6yPIhWapZH4", "o3L1MwVjlBoenaSbN5FIXwzQmgNM","o3L1MwZ00yPDw1Ymsk_V4Por1ce4" };
                                //foreach (string o in op)
                                //{
                                //    var temp2 = new
                                //    {
                                //        first = new { value = "新订单提醒", color = "#173177" },
                                //        OrderSn = new { value = order.OrderNo, color = "#173177" },
                                //        OrderStatus = new { value = "已支付", color = "#173177" },
                                //        remark = new { value = "\n" + order.GoodsName + "," + order.TotalPrice.ToString() + "元", color = "#CD0000" }
                                //    };
                                //    message = SendTemplateMessage(token, o, "wY05AHjKkPAmyygWfzM0D1EWeGOrzCAZDI6c1jmGPGY", "#FF0000", temp2, WebUrl + "/wechat/test/tz.aspx?tousername="******"<xml>
  <return_code><![CDATA[SUCCESS]]></return_code>
  <return_msg><![CDATA[OK]]></return_msg>
</xml>");
                            Response.End();
                        }
                    }
                    //WXLOG log = new WXLOG { CON = postStr + "weixin", TIME = DateTime.Now };
                    //mss.SaveLog(log);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string postStr = "";


            //else
            //{
            //WXLOG log = new WXLOG { CON = Request.Params[""] + "INDEX2", TIME = DateTime.Now };
            //mss.SaveLog(log);
            if (Request.Params["out_trade_no"] != null && Request.Params["trade_status"] != null)
            {
                if (Request.Params["trade_status"] == "TRADE_SUCCESS")
                {
                    Pet_XXL_Order order = nvbo.GetPetXXLOrder(Request.Params["out_trade_no"]);
                    if (order != null && order.OrderState != 2)
                    {
                        //Pet_XXL_Address add = nvbo.GetAddress(order.AID.Value);
                        //if (add != null)
                        //{
                        //    new SendDX().Send2("我们已收到您的付款,感谢您的支持,半湿粮将会在24小时后统一配送。", add.Phone);
                        //}
                        order.OrderState = 2;
                        order.BankType   = "";
                        order.OutOrderNo = Request.Params["trade_no"];
                        if (Request.Params["buyer_logon_id"] != null)
                        {
                            order.buyer_logon_id = Request.Params["buyer_logon_id"];
                        }
                        else if (Request.Params["buyer_email"] != null)
                        {
                            order.buyer_logon_id = Request.Params["buyer_email"];
                        }
                        nvbo.SavePetXXLOrder(order);
                        try
                        {
                            OAauth_Log o = mss.GetOA(order.FromUserName);
                            if (o != null)
                            {
                                Pet_JiuZhu_Info j = nvbo.GetJiuZhuInfo(order.Source.Value);
                                if (j != null && (j.JZType == 1 || j.JZType == 2))
                                {
                                    Pet_JiuZhu_Love l = new Pet_JiuZhu_Love
                                    {
                                        CreateTime   = DateTime.Now,
                                        Detail       = "捐助基地[" + j.NickName + "][" + (j.JZType == 1 ? "捐粮" : "捐款") + "]",
                                        FromUserName = order.FromUserName,
                                        OID          = order.ID,
                                        Love         = j.JZType == 1 ? Convert.ToInt32(order.TotalPrice) : Convert.ToInt32(order.TotalPrice / 2)
                                    };
                                    int lid = nvbo.SavePetJiuZhuLove(l);
                                    if (lid > 0)
                                    {
                                        o.TotalLove = (o.TotalLove ?? 0) + l.Love;
                                        o.SurLove   = (o.SurLove ?? 0) + l.Love;
                                        mss.SaveOA(o);
                                    }
                                }
                            }
                        }
                        catch (Exception)
                        {
                        }
                        try
                        {
                            string token = Token(mjuserid);
                            var    temp  = new
                            {
                                first            = new { value = "我们已收到您的支付宝付款", color = "#173177" },
                                orderMoneySum    = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                orderProductName = new { value = order.GoodsName, color = "#173177" },
                                Remark           = new { value = "\n" + "我们已收到您的爱心。", color = "#CD0000" }
                            };
                            if (order.PJ != null && order.PJ != 0)
                            {
                                temp = new
                                {
                                    first            = new { value = "我们已收到您的支付宝付款", color = "#173177" },
                                    orderMoneySum    = new { value = order.TotalPrice.ToString() + "元", color = "#173177" },
                                    orderProductName = new { value = order.GoodsName, color = "#173177" },
                                    Remark           = new { value = "\n" + "我们已收到您的爱心,您已成功捐粮" + Math.Round(order.TotalPrice.Value / 16, 2) + "kg,并且您的爱心被放大,由宠物管家赞助为其配捐" + Math.Round(order.PJ.Value / 16, 2) + "kg", color = "#CD0000" }
                                };
                            }
                            string message = SendTemplateMessage(token, order.FromUserName, "qLJpWtjKj8zm3j8cwOe0u3u7qHwQ04cSx2UUvvVu-Ug", "#FF0000", temp, WebUrl + "/wechat/test/tz.aspx?tousername="******"o3L1MwYudOztZTDDA6yPIhWapZH4", "o3L1MwVjlBoenaSbN5FIXwzQmgNM", "o3L1MwZ00yPDw1Ymsk_V4Por1ce4" };
                            //foreach (string o in op)
                            //{
                            //    var temp2 = new
                            //    {
                            //        first = new { value = "新订单提醒", color = "#173177" },
                            //        OrderSn = new { value = order.OrderNo, color = "#173177" },
                            //        OrderStatus = new { value = "已支付", color = "#173177" },
                            //        remark = new { value = "\n" + order.GoodsName + "," + order.TotalPrice.ToString() + "元", color = "#CD0000" }
                            //    };
                            //    message = SendTemplateMessage(token, o, "wY05AHjKkPAmyygWfzM0D1EWeGOrzCAZDI6c1jmGPGY", "#FF0000", temp2, WebUrl + "/wechat/test/tz.aspx?tousername="******"success");
                        Response.End();
                    }
                }
            }
            //WXLOG log2 = new WXLOG { CON = Request.Params.AllKeys + "zhifubao", TIME = DateTime.Now };
            //mss.SaveLog(log2);
            //string cs = "";
            //for (int i = 0; i < Request.Form.Count; i++)
            //{
            //    if (Request.Form.Keys[i].ToString().Substring(0, 1) != "_")
            //        cs += Request.Form.Keys[i].ToString() + " = " + Request.Form[i].ToString()+"&";
            //}
            //WXLOG log3 = new WXLOG { CON = cs + "zhifubao", TIME = DateTime.Now };
            //mss.SaveLog(log3);

            //}
        }