微信获取code

//用户同意授权,获取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

上一篇:移动端如何解决页面返回上次浏览位置问题


下一篇:.NET微信公众号开发系列 - 签名算法