QQ登陆接口
这次做了一个QQ登陆接口---简单记录一下
遇到一大坑-----QQ互联里面添加应用的时候,是网站应用,配置回调地址一定要配置 准确,到指定回调页面 否则会出现问题的。
1、首先引用基类 QQConnect.cs 代码下载
2、新建 Index.aspx
private string AppId = AuthConnect.QQ_AppId; private string AppKey = AuthConnect.QQ_AppKey; private string CallbackUrl = AuthConnect.QQ_CallbackUrl; QQConnect connect = new QQConnect(AppId, AppKey, loginedUserInfo.State, this.Server.UrlEncode(CallbackUrl)); this.Response.Redirect(connect.GetAuthorizationCodeUrl("get_user_info"));
2、新建 Notify.aspx
Code = GetParams("code"); State = GetParams("state"); if (!string.IsNullOrEmpty(Code) && !string.IsNullOrEmpty(State) ) { QQConnect connect = new QQConnect(AppId, AppKey, State, this.Server.UrlEncode(CallbackUrl)); if (connect.GetAccessTokenByCode(Code) && connect.GetOpenIdByToken() && !string.IsNullOrEmpty(connect.AccessToken) && !string.IsNullOrEmpty(connect.OpenId)) { string result = string.Empty; QQConnect.UserInfo model = new QQConnect.UserInfo(); if (connect.GetUserInfo(out result, out model) && !string.IsNullOrEmpty(result) && System.String.Compare(model.ret, "0", System.StringComparison.OrdinalIgnoreCase) == 0) { //业务处理和跳转 } } }