您的位置:首页 > 移动开发 > 微信开发

微信获取code

2016-01-29 15:47 561 查看
//用户同意授权,获取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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: