Esempio n. 1
0
        public RssFeed ShowFeedNews(string LinkAnchor)
        {
            var       cacheKey  = LinkAnchor;
            RssReader rssReader = null;

            try
            {
                RssFeed rssFeed = Caching.GetCache(LinkAnchor) as RssFeed;

                if (rssFeed != null && rssFeed.RssItems != null && rssFeed.RssItems.Any())
                {
                    return(rssFeed);
                }
                else
                {
                    rssReader = new RssReader();
                    rssFeed   = rssReader.OnGetFeed(LinkAnchor);
                    if (rssFeed != null)
                    {
                        Caching.SetCache(cacheKey, rssFeed, BaseEnums.CacheDuration.Small);
                    }

                    return(rssFeed);
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex.Message, "BL", "FeedManager", "ShowFeedNews");
                return(null);
            }
        }
        public ActionResult ReplyMessageCallBack(string target)
        {
            string result = "";

            result = WeChat_Util.Instance.GetPostData();//获取xml数据
            if (string.IsNullOrEmpty(result))
            {
                SysLog.Write("事件通知返回", "返回结果为空");
            }
            else
            {
                SysLog.Write("事件通知返回", "返回结果:" + result);
            }

            var Client = JsonConvert.DeserializeObject <TempleteMessage>(result);

            if (Client != null)
            {
                var user = new LoginUser
                {
                    ClientID = Client.FromUserName
                };
                var ustr = JsonConvert.SerializeObject(user);
                LoginAuth.Instance.SetCookie(ustr);

                var cache = Caching.GetCache("access_token");
                if (cache == null || cache == "")
                {
                    var token = WeChat_Util.Instance.GetToken();
                    if (string.IsNullOrEmpty(token.errcode))
                    {
                        Caching.SetCache("access_token", token.access_token, DateTime.Now.AddSeconds(7000), TimeSpan.Zero);
                        SysLog.Write("系统异常", "access_token:" + token.access_token);
                    }
                }
            }

            if (string.IsNullOrEmpty(target))
            {
                return(null);
            }
            else
            {
                return(Redirect(target));
            }
        }
        public ActionResult CallBack(string code, string state)
        {
            // appid  wx07973d1c80ac4c18
            //appsecret   fb3b492e8bd2176dd151dcd24be71fe6
            //https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN
            //"https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code"

            //SysLog.Write("oauth2","code:"+code);
            var result = Util.CustWebRequest("https://api.weixin.qq.com/sns/oauth2/access_token", "appid=" + Util.Appid + "&secret=" + Util.Secret + "&code=" + code + "&grant_type=authorization_code");
            //SysLog.Write("oauth2","result:"+result);

            //https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

            var Client = JsonConvert.DeserializeObject <OAuth2Info>(result);

            if (Client != null)
            {
                var user = new LoginUser {
                    ClientID = Client.openid
                };
                var ustr = JsonConvert.SerializeObject(user);
                LoginAuth.Instance.SetCookie(ustr);

                var cache = Caching.GetCache("access_token");
                //SysLog.Write("系统异常","Cache:"+cache);
                if (cache == null || cache == "")
                {
                    var token = WeChat_Util.Instance.GetToken();
                    if (string.IsNullOrEmpty(token.errcode))
                    {
                        Caching.SetCache("access_token", token.access_token, DateTime.Now.AddSeconds(7000), TimeSpan.Zero);
                        SysLog.Write("系统异常", "access_token:" + token.access_token);
                    }
                }
            }

            return(Redirect("/OrderManage/Create"));
        }
Esempio n. 4
0
        public string AddNewFeed(string textUrl)
        {
            //textUrl = "https://www.nasa.gov/rss/dyn/lg_image_of_the_day.rss";
            var         cacheKey    = textUrl;
            var         jsonResult  = string.Empty;
            RssFeed     rssFeed     = null;
            NewFeedData newFeedData = new NewFeedData();

            var regex = "^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)[a-z0-9]+([\\-\\.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$";

            try
            {
                var match = Regex.Match(textUrl, regex, RegexOptions.IgnoreCase);

                if (!match.Success)
                {
                    newFeedData.ResponseType = BaseEnums.ResponseType.BadUrl;
                    jsonResult = new JavaScriptSerializer().Serialize(newFeedData);

                    return(jsonResult);
                }

                rssFeed = Caching.GetCache(cacheKey) as RssFeed;

                if (rssFeed == null)
                {
                    RssReader rssReader = new RssReader();
                    rssFeed = rssReader.OnGetFeed(textUrl);


                    //if (rssFeed != null)
                    //{
                    //    Caching.SetCache(cacheKey, rssFeed, BaseEnums.CacheDuration.Small);
                    //}
                }
                if (rssFeed != null)
                {
                    Caching.SetCache(cacheKey, rssFeed, BaseEnums.CacheDuration.Small);

                    //newFeedData = new NewFeedData()
                    //{
                    //    Name = rssFeed.Title,
                    //    LinkAnchor = rssFeed.Links[1],
                    //    ResponseType = BaseEnums.ResponseType.Success;
                    //};
                    newFeedData.Name         = rssFeed.Title;
                    newFeedData.LinkAnchor   = rssFeed.Links[1];
                    newFeedData.ResponseType = BaseEnums.ResponseType.Success;

                    jsonResult = new JavaScriptSerializer().Serialize(newFeedData);
                }
                else
                {
                    newFeedData.ResponseType = BaseEnums.ResponseType.NoResult;
                }

                return(jsonResult);
            }
            catch (Exception ex)
            {
                Log.Write(ex.Message, "BL", "FeedManager", "AddNewFeed");
                return(string.Empty);
            }
        }
        public override void OnActionExecuted(ActionExecutedContext filterContext)
        {
            base.OnActionExecuted(filterContext);
            if (IsSuccessReturn(filterContext))
            {
                try
                {
                    //tLvswWyYgNFKsZBWKf_zK70ZOK6QjohBBeEAZuCa0Pg
                    var cache = Caching.GetCache("access_token");

                    if (cache == null || cache == "")
                    {
                        var token = WeChat_Util.Instance.GetToken();
                        if (string.IsNullOrEmpty(token.errcode))
                        {
                            Caching.SetCache("access_token", token.access_token, DateTime.Now.AddSeconds(7000), TimeSpan.Zero);
                            var tem = new WeChatTemplatecsMsg()
                            {
                                touser = this.CurrentLoginUser.ClientID,
                                template_id = "5Jb1WzFURFbhZCEL4AsxyH7bvQmtqUKVbM4jatymy4A",
                                url = "http://luohe.imwork.net/Authentication/ReplyMessageCallBack?target=/OrderManage/CustomerOrderIndex",
                                data = new Dictionary<string, MessageData>
                                    {
                                        {"first", new MessageData { value = "尊敬的客户:" } },
                                        {"keyword1",new MessageData{value="我们已经接到您的订单,我们会尽快为您分配上门取件的小哥,耐心等待哦。"}},
                                        {"keyword2", new MessageData{ value = DateTime.Now.ToString(AppConst.DateTimeChineseMonth) }},
                                        {"keyword3", new MessageData{ value = DateTime.Now.ToString(AppConst.DateTimeChineseMonth) }},
                                        {"remark", new MessageData{ value = "感谢您的使用。" }}
                                    }
                            };
                            var result = Util.CustWebRequest("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token.access_token, JsonConvert.SerializeObject(tem));
                            var r = JsonConvert.DeserializeObject<MessageReturn>(result);
                            if (r.errmsg != "ok")
                            {
                                SysLog.Write("系统异常", string.Format("异常信息,推送消息失败,失败错误代码:{0},错误消息:{1}", r.errcode, r.errmsg));
                            }
                        }
                        else
                        {
                            SysLog.Write("系统异常", string.Format("异常信息,获取token失败错误代码:{0},错误消息:{1}",token.errcode,token.errmsg));
                        }
                    }
                    else
                    {
                        var tem = new WeChatTemplatecsMsg()
                        {
                            touser = this.CurrentLoginUser.ClientID,
                            template_id = "5Jb1WzFURFbhZCEL4AsxyH7bvQmtqUKVbM4jatymy4A",
                            url = "http://luohe.imwork.net/Authentication/ReplyMessageCallBack?target=/OrderManage/CustomerOrderIndex",
                            data = new Dictionary<string, MessageData>
                                    {
                                        {"first", new MessageData { value = "尊敬的客户:" } },
                                        {"keyword1",new MessageData{value="我们已经接到您的订单,我们会尽快为您分配上门取件的小哥,耐心等待哦。"}},
                                        {"keyword2", new MessageData{ value = DateTime.Now.ToString(AppConst.DateTimeChineseMonth) }},
                                        {"keyword3", new MessageData{ value = DateTime.Now.ToString(AppConst.DateTimeChineseMonth) }},
                                        {"remark", new MessageData{ value = "感谢您的使用。" }}
                                    }
                        };
                        var result = Util.CustWebRequest("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + cache.ToString(), JsonConvert.SerializeObject(tem));
                        var r = JsonConvert.DeserializeObject<MessageReturn>(result);
                        if (r.errmsg != "ok")
                        {
                            SysLog.Write("系统异常", string.Format("异常信息,推送消息失败,失败错误代码:{0},错误消息:{1}", r.errcode, r.errmsg));
                        }
                    }
                }
                catch (Exception ex)
                {
                    //记录错误日志
                }
            }
        }