Beispiel #1
0
        public string GetAccessToken()
        {
            MpCenter mp = MpCenterService.GetALL().FirstOrDefault();

            try
            {
                if (mp != null && !string.IsNullOrEmpty(mp.AppID) && !string.IsNullOrEmpty(mp.AppSecret))
                {
                    var timespan = DateTime.Now - mp.GetTokenDate.Value;
                    if (timespan.TotalMinutes > 15 || string.IsNullOrEmpty(mp.AccessToken))
                    {
                        AccessTokenResult token = CommonApi.GetToken(mp.AppID, mp.AppSecret);
                        if (token != null && !string.IsNullOrEmpty(token.access_token))
                        {
                            Log4NetImpl.Write("GetAccessToken更新:not null");
                            mp.GetTokenDate = DateTime.Now;
                            mp.AccessToken  = token.access_token;
                            MpCenterService.ExcuteSql("update MpCenter set GetTokenDate='" + DateTime.Now + "',AccessToken='" + token.access_token + "' where Id='" + mp.Id.ToString() + "'");
                            MpCenter mpCache = _cacheManager.Get <MpCenter>("MpCenter");
                            mpCache = mp;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log4NetImpl.Write("GetAccessToken失败:" + e.Message);
                return("");
            }

            return(mp.AccessToken);
        }
Beispiel #2
0
        public string GetAccessToken()
        {
            MpCenter mp = MpCenterCache;

            try
            {
                if (mp != null && !string.IsNullOrEmpty(mp.AppID) && !string.IsNullOrEmpty(mp.AppSecret))
                {
                    var timespan = DateTime.Now - mp.GetTokenDate.Value;
                    if (timespan.TotalMinutes > 15 || string.IsNullOrEmpty(mp.AccessToken))
                    {
                        AccessTokenResult token = CommonApi.GetToken(mp.AppID, mp.AppSecret);
                        if (token != null && !string.IsNullOrEmpty(token.access_token))
                        {
                            mp.GetTokenDate = DateTime.Now;
                            mp.AccessToken  = token.access_token;
                            _mpCenterService.Update(mp);
                            MpCenterCache = mp;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log4NetImpl.Write("GetAccessToken失败:" + e.Message);
                return("");
            }

            return(mp.AccessToken);
        }
Beispiel #3
0
        public ActionResult MpEdit()
        {
            string   id = RQuery["Id"];
            MpCenter mp = string.IsNullOrWhiteSpace(id) ? null : MpCenterService.GetById(new Guid(id));

            return(AdminView(mp));
        }