Exemplo n.º 1
0
        /// <summary>
        /// 如token过期重新获取token
        /// </summary>
        /// <returns></returns>
        public string SelectToken()
        {
            var key   = WeChatConfig.WeChildChatId;
            var token = CacheCore.Get <string>(key);

            if (string.IsNullOrEmpty(token))
            {
                token = GetToken();
                CacheCore.Set <string>(key, token, 60);
            }
            return(token);
        }
Exemplo n.º 2
0
        private string GetToken()
        {
            var key   = "gh_a2e48791ecc1";
            var token = CacheCore.Get <string>(key);

            if (string.IsNullOrEmpty(token))
            {
                token = WeChatInteractiveHelper.GetToken("wxf9ade153117809bf", "c876b01424956a2f7f7d1bee9dbb0acd");
                CacheCore.Set <string>(key, token, 60);
            }
            return(token);
        }
Exemplo n.º 3
0
        //[WebMethod]
        //public void SetFile()
        //{
        //    WebClient wc = new WebClient();
        //    string url = string.Format("https://api.weixin.qq.com/cgi-bin/media/upload?access_token={0}&type={1}", GetToken(), "image");
        //    byte[] responseArray = wc.UploadFile(url, "F:/1.png");
        //    Write(Encoding.GetEncoding("UTF-8").GetString(responseArray));
        //}
        private string GetToken()
        {
            var key   = WeChatConfig.WeChatId;
            var token = CacheCore.Get <string>(key);

            if (string.IsNullOrEmpty(token))
            {
                var dic = WeChatHelper.GetToken();
                token = dic["access_token"].ToString();
                CacheCore.Set <string>(key, token, 60);
            }
            return(token);
        }