详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt313

开发平台 
http://connect.qq.com/  
http://open.weibo.com/ 
可以下载相应的sdk 和 API

Java代码

  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    package com.fanbaobao.action;  
       
    import javax.servlet.http.HttpServletRequest;  
    import javax.servlet.http.HttpServletResponse;  
    import javax.servlet.http.HttpSession;  
       
    import com.fanbaobao.service.FbbUser;  
    import com.fanbaobao.service.FbbService.Client;  
    import com.fanbaobao.util.FbbUtil;  
       
    import weibo4j.Oauth;  
    import weibo4j.Users;  
    import weibo4j.Weibo;  
    import weibo4j.http.AccessToken;  
    import weibo4j.model.User;  
    public class SinaAction extends BaseAction {  
        private String errorMsg;   
        public String toLogin()throws Exception{  
            try {  
                HttpServletRequest request=getRequest();  
                Oauth oauth=new Oauth();  
                getResponse().sendRedirect(oauth.authorize("code")); //重定向到新浪授权页面  
            catch (Exception e) {  
                e.printStackTrace();  
            }  
            return null;  
        }  
           
        /** 
         * 新浪微博登录的回调 
         * @return 
         * @throws Exception 
         */  
        public String doLogin() throws Exception{  
               
            HttpServletRequest request=getRequest();  
            HttpSession session=request.getSession();  
            String accesstoken   = null;  
            String code=request.getParameter("code");  
            if(code!=null)  
            {  
               
                Oauth oauth=new Oauth();  
                AccessToken accessToken=oauth.getAccessTokenByCode(code);  
                accesstoken=accessToken.getAccessToken();  
                if(accessToken!=null)  
                {  
                    Weibo weibo=new Weibo();  
                    weibo.setToken(accessToken.getAccessToken());  
                    Users users=new Users();  
                    User weiboUser=users.showUserById(accessToken.getUid());  
                    HttpServletResponse response=getResponse();  
                    System.out.println(weiboUser.getId());  
                    System.out.println(weiboUser.getGender());  
                    System.out.println(weiboUser.getName());  
                    System.out.println(accesstoken);  
    //              if(first<2){  
    //                  if(first==1){ //用户第一次登录,发一条微博,且follow 51bi  
    //                      Timeline timeline=new Timeline();  
    //                      timeline.UpdateStatus("我注册成为了#比购网#会员,免费注册后去淘宝购物,最高有35%的现金返还。最给力的是:到拉手、京东商城、1号店等400多家知名商城不仅能享受最低价格,还能额外省钱40%。喜欢网购的童鞋都去注册一个省钱吧!官方网址:http://www.51bi.com/space/biuser/register.jsp?currentUrl=http://www.51bi.com/taobao/");  
    //                      try {  
    //                          Friendships fm = new Friendships();  
    //                          fm.createFriendshipsById("1718952754");//follow 51bi  
    //                          fm.createFriendshipsById("2908640880");//follow 51bi  
    //                      } catch (Exception e) {  
    //                      }  
    //                  }  
                        //未完善资料  
                        Client client = FbbUtil.getClient();  
                        FbbUser fbbUser= client.doOauth(1, weiboUser.getId());  
                        session.setAttribute("fbbUserInfo", fbbUser);     
                        return SUCCESS;  
                    }  
           
                }else{  
                    errorMsg="新浪oauth 认证请求非法!";  
                    return LOGIN;  
                }  
            return SUCCESS;  
        }  
           
           
           
           
        public String getErrorMsg() {  
            return errorMsg;  
        }  
       
        public void setErrorMsg(String errorMsg) {  
            this.errorMsg = errorMsg;  
        }  
    }

Java代码

  1. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    package com.fanbaobao.action;  
       
    import javax.servlet.http.HttpServletRequest;  
    import javax.servlet.http.HttpServletResponse;  
    import javax.servlet.http.HttpSession;  
       
    import com.fanbaobao.service.FbbUser;  
    import com.fanbaobao.service.FbbService.Client;  
    import com.fanbaobao.util.FbbUtil;  
    import com.qq.connect.QQConnectException;  
    import com.qq.connect.api.OpenID;  
    import com.qq.connect.api.qzone.PageFans;  
    import com.qq.connect.api.qzone.UserInfo;  
    import com.qq.connect.javabeans.AccessToken;  
    import com.qq.connect.javabeans.qzone.PageFansBean;  
    import com.qq.connect.javabeans.qzone.UserInfoBean;  
    import com.qq.connect.oauth.Oauth;  
       
    public class QzoneAction extends BaseAction {  
    private String errorMsg;   
       
        public String toLogin()throws Exception{  
            this.getResponse().setContentType("text/html;charset=utf-8");  
            try {  
                this.getResponse().sendRedirect(new Oauth().getAuthorizeURL(this.getRequest()));  
            catch (QQConnectException e) {  
                e.printStackTrace();  
            }  
            return null;  
        }  
           
        public String doLogin()throws Exception{  
             HttpServletResponse response=this.getResponse();  
             HttpServletRequest request=this.getRequest();  
             HttpSession session=request.getSession();  
             response.setContentType("text/html; charset=utf-8");  
                try {  
                    AccessToken accessTokenObj = 
                    (new Oauth()).getAccessTokenByRequest(request);  
                       
                    String accessToken   = null,  
                           openID        = null;  
                    Long tokenExpireIn = null;  
       
       
                    if (accessTokenObj.getAccessToken().equals("")) {  
                        errorMsg="QQ登录校验失败!";  
                        return LOGIN;  
                    else {  
                        accessToken = accessTokenObj.getAccessToken();  
                        tokenExpireIn = accessTokenObj.getExpireIn();  
                           
                        request.getSession().setAttribute("demo_access_token", accessToken);  
                        request.getSession().setAttribute(
                        "demo_token_expirein", String.valueOf(tokenExpireIn));  
                        OpenID openIDObj =  new OpenID(accessToken);  
                        openID = openIDObj.getUserOpenID();  
       
                        request.getSession().setAttribute("demo_openid", openID);  
                        UserInfo qzoneUserInfo = new UserInfo(accessToken, openID);  
                        UserInfoBean userInfoBean = qzoneUserInfo.getUserInfo();  
    //  
                        PageFans pageFansObj = new PageFans(accessToken, openID);  
                        PageFansBean pageFansBean = pageFansObj.checkPageFans("97700000");  
                        com.qq.connect.api.weibo.UserInfo weiboUserInfo = 
                        new com.qq.connect.api.weibo.UserInfo(accessToken, openID);  
                        com.qq.connect.javabeans.weibo.UserInfoBean weiboUserInfoBean =
                         weiboUserInfo.getUserInfo();  
       
                     // 第三方处理用户绑定逻辑  
                        String user_id=openID;  
                        String nickname=new String(userInfoBean.getNickname());  
                        System.out.println(user_id);  
                        System.out.println(nickname);  
                        Client client = FbbUtil.getClient();  
                        FbbUser fbbUser= client.doOauth(2, user_id);  
                        session.setAttribute("fbbUserInfo", fbbUser);     
                        return SUCCESS;  
    //                  session.setAttribute("oauth_token", oauth_token);  
    //                  session.setAttribute("oauth_token_secret", oauth_token_secret);  
    //                  InterUser interUser=new InterUser(
                                                                Constants.LOGIN_FROM_QQ,user_id,null,nickname);  
    //                  interUser.setBiUserService(biUserService);  
    //                  interUser.setRuledao(ruledao);  
    //                  interUser.setAccesstoken(accessToken);  
    //                  if (tokenExpireIn!=null) {  
    //                      interUser.setExpireIn(String.valueOf(tokenExpireIn));  
    //                  }  
    //                  session.setAttribute("uid", user_id);  
    //                  session.setAttribute("fromsite", Constants.LOGIN_FROM_QQ);  
    //                  int first=interUser.doUserLogin(request,response,false); //接口登录  
    //                  if(first<2){  
    //                      session.setAttribute("loginname",nickname);  
    //                      if (first==-1) {  
    //                          session.setAttribute("msg","save userBind error");  
    //                      }else if (first==-2) {  
    //                          session.setAttribute("msg","error");  
    //                      }  
    //                      return "qzone";  
    //                  }          
       
                    }  
                catch (QQConnectException e) {  
                    e.printStackTrace();  
                    return LOGIN;  
                }  
        }  
           
           
           
        public String getErrorMsg() {  
            return errorMsg;  
        }  
       
        public void setErrorMsg(String errorMsg) {  
            this.errorMsg = errorMsg;  
        }  
    }

Java代码

    1. //login.properties

    2. ############

    3. #t.sina login

    4. ###########

    5. client_ID =xx

    6. client_SERCRET =xx

    7. redirect_URI =xxx

    8. baseURL=https://api.weibo.com/2/

    9. accessTokenURL=https://api.weibo.com/oauth2/access_token

    10. authorizeURL=https://api.weibo.com/oauth2/authorize

    11. ############

    12. #taoBao login

    13. ###########

    14. #TAOBAO_KEY=xxxx

    15. #TAOBAO_SECRET=xxxxxx

    16. #TAOBAO_REDIRECT=xxxx

    17. #authorizeURL=https://oauth.taobao.com/authorize

    18. #accessTokenURL=https://oauth.taobao.com/token

    19. //qqconnectconfig.properties

    20. app_ID = x

    21. app_KEY = xx

    22. redirect_URI = xxx

    23. scope = get_user_info,add_topic,add_one_blog,add_album,upload_pic,list_album,add_share,check_page_fans,add_t,

    24. add_pic_t,del_t,get_repost_list,get_info,get_other_info,get_fanslist,get_idollist,add_idol,del_ido,

    25. get_tenpay_addr

    26. baseURL = https://graph.qq.com/

    27. getUserInfoURL = https://graph.qq.com/user/get_user_info

    28. accessTokenURL = https://graph.qq.com/oauth2.0/token

    29. authorizeURL = https://graph.qq.com/oauth2.0/authorize

    30. getOpenIDURL = https://graph.qq.com/oauth2.0/me

    31. addTopicURL = https://graph.qq.com/shuoshuo/add_topic

    32. addBlogURL = https://graph.qq.com/blog/add_one_blog

    33. addAlbumURL = https://graph.qq.com/photo/add_album

    34. uploadPicURL = https://graph.qq.com/photo/upload_pic

    35. listAlbumURL = https://graph.qq.com/photo/list_album

    36. addShareURL = https://graph.qq.com/share/add_share

    37. checkPageFansURL = https://graph.qq.com/user/check_page_fans

    38. addTURL = https://graph.qq.com/t/add_t

    39. addPicTURL = https://graph.qq.com/t/add_pic_t

    40. delTURL = https://graph.qq.com/t/del_t

    41. getWeiboUserInfoURL = https://graph.qq.com/user/get_info

    42. getWeiboOtherUserInfoURL = https://graph.qq.com/user/get_other_info

    43. getFansListURL = https://graph.qq.com/relation/get_fanslist

    44. getIdolsListURL = https://graph.qq.com/relation/get_idollist

    45. addIdolURL = https://graph.qq.com/relation/add_idol

    46. delIdolURL = https://graph.qq.com/relation/del_idol

    47. getTenpayAddrURL = https://graph.qq.com/cft_info/get_tenpay_addr

    48. getRepostListURL = https://graph.qq.com/t/get_repost_list

    49. version = 2.0.0.0

java 实现微博,QQ联合登录的更多相关文章

  1. QQ联合登录(基于Oauth2.0协议)

    1. 获取授权码Authorization Code https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id= ...

  2. 如何从零开始对接第三方登录(Java版):QQ登录和微博登录

    前言 个人网站最近增加了评论功能,为了方便用户不用注册就可以评论,对接了QQ和微博这2大常用软件的一键登录,总的来说其实都挺简单的,可能会有一点小坑,但不算多,完整记录下来方便后来人快速对接. 后台设 ...

  3. 【Demo】QQ,github,微博第三方社交登录

    本文主要讲解 集成 第三方社交账号登录 为什么会有这个需求? 主要是因为目前互联网的网站数量太多,如果在各个站点都注册一个账号 用户非常不容易记住每个账号的用户名和密码,并且非常难保证每个账号的密码足 ...

  4. 关于使用QQ、新浪微博、腾讯微博等第三方登录网站的开发过程(二)

    (二).新浪微博登录 1. 首先在新浪微博开放平台注册成为开发者.[http://open.weibo.com/connect] 具体自己填写一些相关信息就OK! 2. 注册成功之后,点击[微连接], ...

  5. 微博爬虫“免登录”技巧详解及 Java 实现(业余草的博客)

    一.微博一定要登录才能抓取? 目前,对于微博的爬虫,大部分是基于模拟微博账号登录的方式实现的,这种方式如果真的运营起来,实际上是一件非常头疼痛苦的事,你可能每天都过得提心吊胆,生怕新浪爸爸把你的那些账 ...

  6. QQ第三方登录

    QQ第三方登录 在Android应用程序的开发过程中,很多时候需要加入用户登录/注册模块.除了自己动手设计登录界面并实现相应功能外,现在还可以借助百度.腾讯等开发者平台提供的第三方账号登录模块.最近研 ...

  7. 联合登录 & OAuth 2.0 & OpenID

    联合登录 & OAuth 2.0 & OpenID 第三方联合登录一般可以降低网站的获客成本,所以一般的网站都会做一些联合登录,常用的就是QQ.微信.微博; https://www.z ...

  8. PHP实现QQ第三方登录

    PHP实现QQ第三方登录 学习之前,请大家先看一下oAuth协议. 首先呢,我们进入QQ互联的官方网站 http://connect.qq.com登入我们自己的QQ号,没有QQ号的小伙伴可以忽略本篇博 ...

  9. QQ互联登录回调路径错误redirect uri is illegal(100010)

    QQ互联登录设置的路径设置

随机推荐

  1. 【http】post和get请求的区别

    两种常用的HTTP请求方式:post和get   get:从指定的资源进行请求.数据长度有限制(2048个字符)可被缓存.可被保留在浏览器历史记录中,安全性较差.发送敏感信息如密码时不适用.   po ...

  2. Jetty的工作原理

    Jetty的工作原理 Jetty 的基本架构 Jetty 目前的是一个比较被看好的 Servlet 引擎,它的架构比较简单,也是一个可扩展性和非常灵活的应用服务器,它有一个基本数据模型,这个数据模型就 ...

  3. EntityFramework Core查询问题集锦(一)

    前言 和大家脱离了一段时间,有时候总想着时间挤挤总是会有的,但是并非人愿,后面会借助周末的时间来打理博客,如有问题可以在周末私信我或者加我QQ皆可,欢迎和大家一起探讨,本节我们来讨论EF Core中的 ...

  4. windows本地提权对照表(转载)

    2003     systeminfo>C:\Windows\Temp\temp.txt&(for %i in (KB3057191 KB2840221 KB3000061 KB2850 ...

  5. 实例甜点 Unreal Engine 4迷你教程(5)之函数中的静态变量

    本小节的教程无前置教程,可直接学习,篇幅很短. 本教程浓缩起来就是一句话:函数中的静态变量在调试过程中保留值.所以需要谨慎对待. 什么意思?请先不要一步一步对着做,而整体地看一遍下面的过程: 第一步: ...

  6. swift3.0 从相册选取或者拍照上传图片至阿里云OSS

    导入相应的库 import Photos import AliyunOSSiOS 选取照片需要继承 UIImagePickerControllerDelegate,UINavigationContro ...

  7. hdu--1258--Sum It Up(Map水过)

    Sum It Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  8. Java常用文件操作-1

    在我们的实际工作中经常会用到的文件操作,再此,将工作中碰到的做一个记录,以便日后查看. 1.复制文件夹到新文件夹下 /** * 复制文件夹下所有文件到指定路径 *@param oldPath *@pa ...

  9. python-----运算符及while循环

    一.运算符 计算机可以进行的运算有很多种,不只是加减乘除,它和我们人脑一样,也可以做很多运算. 种类:算术运算,比较运算,逻辑运算,赋值运算,成员运算,身份运算,位运算,今天我们先了解前四个. 算术运 ...

  10. [UWP]了解模板化控件(5.1):TemplatePart vs. VisualState

    1. TemplatePart vs. VisualState 在前面两篇文章中分别使用了TemplatePart及VisualState的方式实现了相同的功能,其中明显VisualState的方式更 ...