//QQ URL   public ActionResult QQLocation()   {    

var response_type = "code";    

string state = "1";    

string url = string.Format("https://graph.qq.com/oauth2.0/authorize?response_type={0}&client_id={1}&redirect_uri={2}&state={3}", response_type, WebTools.QQAppID, Uri.EscapeDataString("url"), state);    

return Content("var qqloginurl = \"" + url + "\"", "application/x-javascript");   

}   

//QQ 回调页面  

 public ActionResult QQLogin()   {    

string code = string.IsNullOrEmpty(Request.QueryString["code"]) ? "" : Request.QueryString["code"];    

if (code != "")    {     

string url = string.Format("https://graph.qq.com/oauth2.0/token?grant_type=authorization_code&client_id={0}&client_secret={1}&code={2}&redirect_uri={3}", QQAppID, QQAppKey, code,  Uri.EscapeDataString("url"));    

 var strResult = Library.HelpsGet(url);     

Match m = Regex.Match(strResult, @"access_token=(([\d|a-zA-Z]*))");     

if (!m.Success) {      return View();     }     

url = string.Format("https://graph.qq.com/oauth2.0/me?access_token={0}", m.Groups[1].Value);     

var newResult = Library.HelpsGet(url);     

m = Regex.Match(newResult, @"\""openid\"":\""([\d|a-zA-Z]+)\""");     

if (!m.Success)     {      

return View();     

}   

   return View();   

}   

//微信URL  

 public ActionResult WxLocation()   {   

 var response_type = "code";   

 var scope = "snsapi_login";    

string state = "1";    

string url = string.Format("https://open.weixin.qq.com/connect/qrconnect?appid={0}&redirect_uri={1}&response_type={2}&scope={3}&state={4}#wechat_redirect", WebTools.WxAppID, "url", response_type, scope, state);    return Content("var wxloginurl = \"" + url + "\"", "application/x-javascript"); 

  }   

//微信 回调页面  

 public ActionResult WeixinLogin()   {    

string code = string.IsNullOrEmpty(Request.QueryString["code"]) ? "" : Request.QueryString["code"];    

if (code != "")    {  

   string url = string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", WebTools.WxAppID, WebTools.WxAppSecret, code);    

 var strResult = JsonConvert.DeserializeAnonymousType(Library.HelpsGet(url), new     {      access_token = string.Empty,      expires_in = 0,      refresh_token = string.Empty,      openid = string.Empty,      scope = string.Empty     });    

 url = string.Format("https://api.weixin.qq.com/sns/userinfo?access_token={0}&openid={1}&lang=zh_CN", strResult.access_token, strResult.openid);    

 var newResult = JsonConvert.DeserializeAnonymousType(Library.HelpsGet(url), new     {   

   openid = string.Empty,      nickname = string.Empty,      sex = 0,      province = string.Empty,      city = string.Empty,      country = string.Empty,      headimgurl = string.Empty,      privilege = new JArray(),      unionid = string.Empty    

 });     

  return View();  

 

posted on 2016-01-20 18:23  村夫哥哥  阅读(174)  评论(0编辑  收藏  举报