Beispiel #1
0
        public static void InitButton()
        {
            var menuPath = AppDomain.CurrentDomain.BaseDirectory + "Common/Menu.txt";
            var munuStr  = File.ReadAllText(menuPath);
            var munuUri  = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={0}";

            string url             = string.Format(munuUri, AccessTokenManage.GetAccessTokenName());
            var    responseContent = string.Empty;

            HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: munuStr);
            var res = Newtonsoft.Json.JsonConvert.DeserializeObject <WCResult>(responseContent);

            if (res.errcode == "40001")          //token失效码
            {
                url = string.Format(munuUri, AccessTokenManage.GetAccessTokenName(true));
                HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: munuStr);
            }
        }
Beispiel #2
0
        public static string GetJsapiTicket()
        {
            var jsapiTicketRedisStr = HttpRuntime.Cache.Get(ConstString.AppId);

            if (jsapiTicketRedisStr == null)
            {
                string responseContent = string.Empty;
                string tokenName       = AccessTokenManage.GetAccessTokenName();
                string url             = string.Format(urlJsapiTicket, tokenName);
                bool   res             = HttpManager.Request(url, out responseContent, WebRequestMethods.Http.Post, data: "");
                var    ticketObj       = Newtonsoft.Json.JsonConvert.DeserializeObject <Ticket>(responseContent);
                if (ticketObj.ErrorCode == 0)
                {
                    jsapiTicketRedisStr = ticketObj.ticket;
                    HttpRuntime.Cache.Insert(ConstString.AppId, jsapiTicketRedisStr, null, DateTime.Now.AddSeconds(Convert.ToInt32(ticketObj.expires_in) - 100), Cache.NoSlidingExpiration);
                }
            }

            return(jsapiTicketRedisStr.ToString());
        }