예제 #1
0
        /// <summary>
        /// https://api.weixin.qq.com/sns/auth?access_token=ACCESS_TOKEN&openid=OPENID
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openid"></param>
        /// <returns></returns>
        public static bool WebAccessTokenIsTimeOut(string accessToken, string openid)
        {
            HttpClient http   = new HttpClient();
            var        result = http.GetAsync("https://api.weixin.qq.com/sns/auth?access_token=" + accessToken + "&openid=" + openid).Result;

            if (result.StatusCode == System.Net.HttpStatusCode.OK)
            {
                WXStateModel model = JsonConvert.DeserializeObject <WXStateModel>(result.Content.ReadAsStringAsync().Result);
                if (model.errcode == 0)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        private static void Error(WXStateModel stateModel)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("失败啦:" + stateModel.errmsg);
            Console.ForegroundColor = ConsoleColor.Green;
            string errMsg;

            if (TokenErrCode.TryGetValue(stateModel.errcode, out errMsg))
            {
                throw new Exception(errMsg);
            }
            else
            {
                throw new Exception("未知异常");
            }
        }