点QQ登录按钮调用的方法
private void qqlogin()
{
//app_id
string key = "21****";
//app_id 对应的key pwd
string secret = "5dedd5c2a88a14b0156d5553b669f3d6";
QzoneSDK.Context.QzoneContext context = new QzoneSDK.Context.QzoneContext(key, secret);
//回调地址,一般只需填写你网站的域名
string callbackUrl = "http://www.domain.com/";
QzoneSDK.OAuth.Tokens.OAuthToken requestToken = context.GetRequestToken(callbackUrl);
//Session["requestToken"] = requestToken;
//request token, request token secret 需要保存起来
//在demo演示中,直接保存在全局变量中.真实情况需要网站自己处理
Session["requesttokenkey"] = requestToken.TokenKey;
Session["requesttokensecret"] = requestToken.TokenSecret;
string authenticationUrl = context.GetAuthorizationUrl(requestToken, callbackUrl);
Session["qqurl"] = authenticationUrl;
Response.Redirect(authenticationUrl);
}
在回调地址中处理如下:
得到的open_id 跟QQ是一一对应的,但得不到QQ号
protected void QQLoginCallback()
{
#region qqlogin
//处理QQ登录
try
{
string oauth_token = "";
string openid = "";
string oauth_signature = "";
string oauth_vericode = "";
string code = "";
if (Request["oauth_token"] != null)
{
oauth_token = Request["oauth_token"];
}
if (Request["code"] != null)
{
code = Request["code"];
}
if (Request["openid"] != null)
{
openid = Request["openid"];
Response.Redirect("index.aspx");//成功后跳转到的页面
}
if (Request["oauth_signature"] != null)
{
oauth_signature = Request["oauth_signature"];
}
if (Request["oauth_vericode"] != null)
{
oauth_vericode = Request["oauth_vericode"];
}
}
catch (Exception ex1)
{
}
#endregion
}