码迷,mamicode.com
首页 > 微信 > 详细

微信获取code

时间:2016-01-29 19:46:58      阅读:349      评论:0      收藏:0      [点我收藏+]

标签:

//用户同意授权,获取code
    public static string Get_code(string RedirectUri)
    {

        string MyAppid = "";//微信应用Id
        string URL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + MyAppid + "&redirect_uri=" + RedirectUri + "&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
        return URL;
    }

//获得Token
    public static volume_OAuth_Token Get_token(string Code)
    {
        string Appid = "";
        string appsecret = "";
        string Str = GetJson("https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + Appid + "&secret=" + appsecret + "&code=" + Code + "&grant_type=authorization_code");
        volume_OAuth_Token Oauth_Token_Model = Volume_JsonHelper.ParseFromJson<volume_OAuth_Token>(Str);
        return Oauth_Token_Model;
    }
    //下载数据
    public static string GetJson(string url)
    {
        string res = "";
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
        req.Method = "GET";
        using (WebResponse wr = req.GetResponse())
        {
            HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            res = reader.ReadToEnd();
        }

        return res;
    }

微信获取code

标签:

原文地址:http://www.cnblogs.com/zhubenxi/p/5169219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!