/// <summary> /// 获取openid /// </summary> /// <returns></returns> private string GetUID() { List <UrlParameter> parameters = new List <UrlParameter>(); UrlParameter param = new UrlParameter("access_token", access_token); parameters.Add(param); string data = OAuthRequest.Request("https://graph.qq.com/oauth2.0/me", parameters, "GET"); //callback( {"client_id":"101238544","openid":"9990DBF4348CA41F6606530FC20648F2"} ); int st = data.IndexOf('('); data = data.Substring(st); data = data.Substring(1, data.Length - 4); JObject j = JObject.Parse(data); data = (string)j["openid"]; return(data); }
/// <summary> /// 获取accesstoken /// </summary> /// <param name="code"></param> /// <returns></returns> private string GetAccessToken() { List <UrlParameter> parameters = new List <UrlParameter>(); UrlParameter param = new UrlParameter("client_id", client_id); parameters.Add(param); param = new UrlParameter("client_secret", client_secret); parameters.Add(param); param = new UrlParameter("grant_type", "authorization_code"); parameters.Add(param); param = new UrlParameter("redirect_uri", redirect_uri); parameters.Add(param); param = new UrlParameter("code", code); parameters.Add(param); string data = OAuthRequest.Request(accessToken_url, parameters, "POST"); JObject j = JObject.Parse(data); access_token = (string)j["access_token"]; WechatAuthCode = (string)j["uid"]; return(access_token); }
/// <summary> /// 获取accesstoken /// </summary> /// <param name="code"></param> /// <returns></returns> private string GetAccessToken() { List <UrlParameter> parameters = new List <UrlParameter>(); UrlParameter param = new UrlParameter("client_id", client_id); parameters.Add(param); param = new UrlParameter("client_secret", client_secret); parameters.Add(param); param = new UrlParameter("grant_type", "authorization_code"); parameters.Add(param); param = new UrlParameter("code", code); parameters.Add(param); param = new UrlParameter("state", "qq"); parameters.Add(param); param = new UrlParameter("redirect_uri", redirect_uri); parameters.Add(param); string data = OAuthRequest.Request(accessToken_url, parameters, "GET"); access_token = Login.GetValueFromUrlParameter(data, "access_token"); return(access_token); }
/// <summary> /// 获取accesstoken /// </summary> /// <param name="code"></param> /// <returns></returns> private string GetAccessToken() { List <UrlParameter> parameters = new List <UrlParameter>(); UrlParameter param = new UrlParameter("appid", appid); parameters.Add(param); param = new UrlParameter("secret", AppSecret); parameters.Add(param); param = new UrlParameter("grant_type", "authorization_code"); parameters.Add(param); //param = new UrlParameter("redirect_uri", redirect_uri); //parameters.Add(param); param = new UrlParameter("code", code); parameters.Add(param); string data = OAuthRequest.Request(accessToken_url, parameters, "GET"); JObject j = JObject.Parse(data); access_token = (string)j["access_token"]; openid = (string)j["openid"]; return(access_token); }
/// <summary> /// 获取第三方的用户信息 /// </summary> /// <param name="token"></param> /// <returns></returns> public OauthInfo GetUser() { //string accessToken = GetAccessToken(); List <UrlParameter> parameters = new List <UrlParameter>(); UrlParameter param = new UrlParameter("access_token", access_token); parameters.Add(param); param = new UrlParameter("uid", WechatAuthCode); parameters.Add(param); string jsonData = OAuthRequest.Request(user_url, parameters, "GET"); JObject json = JObject.Parse(jsonData); OauthInfo oi = new OauthInfo(); oi.NickName = (string)json["screen_name"]; oi.Avatar = (string)json["avatar_large"]; oi.AuthCode = WechatAuthCode; oi.ChatBack = code; oi.LoginType = LoginType.Sina微博; return(oi); }
/// <summary> /// 获取第三方的用户信息 /// </summary> /// <param name="token"></param> /// <returns></returns> public OauthInfo GetUser() { //string accessToken = GetAccessToken(); List <UrlParameter> parameters = new List <UrlParameter>(); UrlParameter param = new UrlParameter("access_token", access_token); parameters.Add(param); param = new UrlParameter("openid", openid); parameters.Add(param); string jsonData = OAuthRequest.Request(user_url, parameters, "GET"); JObject json = JObject.Parse(jsonData); OauthInfo oi = new OauthInfo(); oi.NickName = (string)json["nickname"]; oi.Avatar = (string)json["headimgurl"]; oi.AuthCode = openid; oi.ChatBack = code; oi.LoginType = LoginType.微信; return(oi); }