Esempio n. 1
0
        public string GetToken()
        {
            string url      = string.Format(WeChatAccess_Token_Url, AppId, AppSecret);
            var    response = new HttpWebResponseUtility().CreateGetHttpResponse(url);

            Stream       myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader   = new StreamReader(myResponseStream, Encoding.UTF8);
            string       retString        = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            myResponseStream.Close();

            return(retString);
        }
Esempio n. 2
0
        public HttpResponseMessage OAuth(string code)
        {
            var openUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code";

            string       url              = string.Format(openUrl, AppId, AppSecret, code);
            var          response         = new HttpWebResponseUtility().CreateGetHttpResponse(url);
            Stream       myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader   = new StreamReader(myResponseStream, Encoding.UTF8);
            string       retString        = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            myResponseStream.Close();

            return(new HttpResponseMessage
            {
                Content = new StringContent(retString, Encoding.GetEncoding("UTF-8"), "text/html")
            });
        }