qq互联的配置:
app_ID =
app_KEY =
redirect_URI =
只需要改以上三个
scope = get_user_info,add_topic,add_one_blog,add_album,upload_pic,list_album,add_share,check_page_fans,add_t,add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idollist,add_idol,del_ido,get_tenpay_addr
baseURL = https://graph.qq.com/
getUserInfoURL = https://graph.qq.com/user/get_user_info
accessTokenURL = https://graph.qq.com/oauth2.0/token
authorizeURL = https://graph.qq.com/oauth2.0/authorize
getOpenIDURL = https://graph.qq.com/oauth2.0/me
addTopicURL = https://graph.qq.com/shuoshuo/add_topic
addBlogURL = https://graph.qq.com/blog/add_one_blog
addAlbumURL = https://graph.qq.com/photo/add_album
uploadPicURL = https://graph.qq.com/photo/upload_pic
listAlbumURL = https://graph.qq.com/photo/list_album
addShareURL = https://graph.qq.com/share/add_share
checkPageFansURL = https://graph.qq.com/user/check_page_fans
addTURL = https://graph.qq.com/t/add_t
addPicTURL = https://graph.qq.com/t/add_pic_t
delTURL = https://graph.qq.com/t/del_t
getWeiboUserInfoURL = https://graph.qq.com/user/get_info
getWeiboOtherUserInfoURL = https://graph.qq.com/user/get_other_info
getFansListURL = https://graph.qq.com/relation/get_fanslist
getIdolsListURL = https://graph.qq.com/relation/get_idollist
addIdolURL = https://graph.qq.com/relation/add_idol
delIdolURL = https://graph.qq.com/relation/del_idol
getTenpayAddrURL = https://graph.qq.com/cft_info/get_tenpay_addr
getRepostListURL = https://graph.qq.com/t/get_repost_list
version = 2.0.0.0
server
从数据库中查询openid的用户信息
如果数据库中没有openid代表没有关联qq
//查询openid用户信息
@Override
public ResponseBase findByopenidUser(@RequestParam("openid") String openid) {
// 验证参数
if(StringUtils.isEmpty(openid))
{
return setResultErro("系统错误");
}
//使用openid查找数据库对象的user表的信息
UserEntity openid2 = userDao.openid(openid);
if(openid2==null)
{
return setResultErro(Constants.HTTP_RES_CODE_201, "改openid没有关联");
}
//自动登录
return logintoke(openid2);
//授权QQ登录
得到用户的openid如果查找到opendd先进行账号验证,如果验证正确开始自动登录获取token信息
从数据库查找用户userid修改数据库对应的id,修改成功就代表关联成功
@Override
public ResponseBase findBytokenUser(@RequestParam("token") String token) {
//验证参数
if(StringUtils.isEmpty(token))
{
return setResultErro("token不能为空");
}
//从redis中 使用tocken 查找对应userid
String stuserid = (String) baseRedissService.getString(token);
if(StringUtils.isEmpty(stuserid))
{
return setResultErro("tocken无效或者已过期");
}
//使用userid 数据库查询用户返回信息给客户端
Long parseLong = Long.parseLong(stuserid);
UserEntity findById = userDao.findById(parseLong);
if(findById==null)
{
return setResultErro("你查找的用户不存在");
}
return setResultSuccess(findById);
}
//授权QQ登录
@Override
public ResponseBase qqlogin(@RequestBody UserEntity entity) {
//验证参数
String openid = entity.getOpenid();
if(StringUtils.isEmpty(openid))
{
return setResultErro("openid不能为空");
}
//先进行账号登录 需要验证
ResponseBase Logintoke = login(entity);
if(!Logintoke.getRtncode().equals(Constants.HTTP_RES_CODE_200))
{
return Logintoke;
}
// 自动登录
JSONObject data =(JSONObject) Logintoke.getData();
//获取token信息
String string = data.getString("matoken");
ResponseBase FindBytokenUser = findBytokenUser(string);
if(!FindBytokenUser.getRtncode().equals(Constants.HTTP_RES_CODE_200))
{
return FindBytokenUser;
}
UserEntity data2 = (UserEntity) FindBytokenUser.getData();
//修改对应的数据库id
Integer id = data2.getId();
Integer Upadopeniduser = userDao.upadopeniduser(openid, id);
if(Upadopeniduser<=0)
{
return setResultErro("qq账号管理失败");
}
return Logintoke;
}
contllen
//生成qq授权登录连接
@RequestMapping("/LocaQQlogin")
public String locaQQlogin(HttpServletRequest request ) throws QQConnectException
{
//生成授权连接
String authorizeURL = new Oauth().getAuthorizeURL(request);
return "redirect:"+authorizeURL;
}
获取授权码使用授权码查询accctoken 拿到acctoken 使用acctoken获取openid
//调用会员服务接口 使用useropenid 查找是否已经关联账号
//如果已经绑定账号了 自动登录,将token信息存在cokke中
public String QQloginCall(HttpServletRequest request,HttpSession httpSession,HttpServletResponse respons) throws QQConnectException
{
//获取授权码
//使用授权码或去acceetoken
AccessToken accessTokenByRequest = new Oauth().getAccessTokenByRequest(request);
if(accessTokenByRequest==null)
{
request.setAttribute("error", "QQ授权失败");
return "errro";
}
//拿到accken
String accessToken = accessTokenByRequest.getAccessToken();
if(accessToken==null)
{
request.setAttribute("error", "ACCtokennull");
return "errro";
}
//使用acceetoken获取openid
OpenID openID = new OpenID(accessToken);
String userOpenID = openID.getUserOpenID();
if(userOpenID==null)
{
request.setAttribute("openID", "openID不能为空");
return "errro";
}
//qq授权关联页面 没有账号
//得到openid,调用登录接口
public String qqRelation(UserEntity entity,HttpServletResponse respons,HttpServletRequest reques,HttpSession httpSession)
{
//得到openid
String attribute = (String) httpSession.getAttribute("qqrelation");
if(StringUtils.isEmpty(attribute))
{
reques.setAttribute("error", "没有获取opid");
return "error";
}
//调用登录接口,
entity.setOpenid(attribute);
ResponseBase login = memberServicE.qqlogin(entity);
if(!login.getRtncode().equals(Constants.HTTP_RES_CODE_200))
{
reques.setAttribute("error", "账号或者密码错误");
return Longin;
}
//将token信息存放在cookeie里面
LinkedHashMap logindata = (LinkedHashMap) login.getData();
String toke = (String) logindata.get("token");
if(StringUtils.isEmpty(toke))
{
reques.setAttribute("error", "会话失效!");
return Longin ;
}
setcookie(toke, respons);
return CHAXUN;
}