예제 #1
0
        public static string GetWechatAccessToken(string appId, string secret, string code)
        {
            try
            {
                string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appId, secret, code);

                string result = RestSharpHelper <string> .GetWithoutDeserialization(url);

                return(result);
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public static string GetWechatUserInfo(string appId, string secret, string code)
        {
            try
            {
                string url1    = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appId, secret, code);
                string result1 = RestSharpHelper <string> .GetWithoutDeserialization(url1);

                JObject jObject = JObject.Parse(result1);

                string url2    = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}", jObject["access_token"], jObject["openid"]);
                string result2 = RestSharpHelper <string> .GetWithoutDeserialization(url2);

                return(result2);
            }
            catch (ApplicationException ex)
            {
                throw ex;
            }
        }