微信获取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;
}
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;
}
相关文章推荐
- 微信开发注意事项(我会持续更新的)
- 微信之父张小龙的2359篇日记
- perl 微信 获取消息
- 微信上传图片(2)
- 支付宝推吱口令吸引聊天用户 被微信封杀
- 微信二维码的长按识别问题
- 微信分享缩略图,如何增加微信朋友圈分享链接的小图片? facebook、google+、twitter等分享的标签
- 微信公众平台开发入门教程3
- 微信公众平台开发入门教程2
- 微信公众平台开发入门教程
- Android仿微信朋友圈实现滚动条下拉反弹效果
- 微信红包算法
- 微信公众平台开发
- 微信支付接口开发--总
- 微信抢红包
- 微信转发相关脚本
- 基于iOS逆向工程的微信机器人
- 微信五岁了,让我们看看它是如何长大的吧!
- 微信,QQ抢红包软件原理解析
- Fibonacci数列小程序