为方便更多的开发朋友,将当前市面上所有支持第三方联合登录的接口集为一体,以前需要多次开发才能完成的登录现在只需要一次即可搞定。再也不需要因为等待审核而耽误进度项目进度了。使用方便,操作简单,点此进入

进入网站,点击使用说明,你会得到一个Word文档。文档里面有详细说明,这里我就不说明了。

下面我来说说需要注意的点:

1.当我们在创建应用时回调地址需要注意。如图:

2.appid:申请到的appid值 ( 网页上点击应用名称获取 )

token:申请到的token值 ( 网页上点击应用名称获取 )

JAVA代码:

HttpRequest.java

package wzh.Http;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

import java.io.PrintWriter;

import java.net.URL;

import java.net.URLConnection;

import java.util.List;

import java.util.Map;

public class HttpRequest {

/**

* 向指定URL发送GET方法的请求

*

* @param url

* 发送请求的URL

* @param param

* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。

* @return URL 所代表远程资源的响应结果

*/

public static String sendGet(String url, String param) {

String result = "";

BufferedReader in = null;

try {

String urlNameString = url + "?" + param;

URL realUrl = new URL(urlNameString);

// 打开和URL之间的连接

URLConnection connection = realUrl.openConnection();

// 设置通用的请求属性

connection.setRequestProperty("accept", "*/*");

connection.setRequestProperty("connection", "Keep-Alive");

connection.setRequestProperty("user-agent",

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

// 建立实际的连接 connection.connect();

// 获取所有响应头字段

Map> map = connection.getHeaderFields();

// 遍历所有的响应头字段

for (String key : map.keySet()) {

System.out.println(key + "--->" + map.get(key));

}

// 定义 BufferedReader输入流来读取URL的响应

in = new BufferedReader(new InputStreamReader(

connection.getInputStream()));

String line;

while ((line = in.readLine()) != null) {

result += line;

}

} catch (Exception e) {

System.out.println("发送GET请求出现异常!" + e);

e.printStackTrace();

}

// 使用finally块来关闭输入流

finally {

try {

if (in != null) {

in.close();

}

} catch (Exception e2) {

e2.printStackTrace();

}

}

return result;

}

/**

* 向指定 URL 发送POST方法的请求

*

* @param url

* 发送请求的 URL

* @param param

* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。

* @return 所代表远程资源的响应结果

*/

public static String sendPost(String url, String param) {

PrintWriter out = null;

BufferedReader in = null;

String result = "";

try {

URL realUrl = new URL(url);

// 打开和URL之间的连接

URLConnection conn = realUrl.openConnection();

// 设置通用的请求属性

conn.setRequestProperty("accept", "*/*");

conn.setRequestProperty("connection", "Keep-Alive");

conn.setRequestProperty("user-agent",

"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");

// 发送POST请求必须设置如下两行

conn.setDoOutput(true);

conn.setDoInput(true);

// 获取URLConnection对象对应的输出流

out = new PrintWriter(conn.getOutputStream());

// 发送请求参数

out.print(param);

// flush输出流的缓冲

out.flush();

// 定义BufferedReader输入流来读取URL的响应

in = new BufferedReader(

new InputStreamReader(conn.getInputStream()));

String line;

while ((line = in.readLine()) != null) {

result += line;

}

} catch (Exception e) {

System.out.println("发送 POST 请求出现异常!"+e);

e.printStackTrace();

}

//使用finally块来关闭输出流、输入流

finally{

try{

if(out!=null){

out.close();

}

if(in!=null){

in.close();

}

}

catch(IOException ex){

ex.printStackTrace();

}

}

return result;

}

}

UserthirdpartyAction .java

package wzh.Http;

import java.util.Date;

import java.util.UUID;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import org.json.JSONException;

import org.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.context.annotation.Scope;

import org.springframework.stereotype.Controller;

import com.zking.mvc.framework.ActionSupport;

@SuppressWarnings("serial")

@Controller

@Scope("prototype")

public class UserthirdpartyAction extends ActionSupport{

//第三方平台提供的参数(即创建应用后)

private static String appid="*********";

private static String token="*********";

public String thirdlogin(){

HttpServletRequest request = ServletActionContext.getRequest();

String code = request.getParameter("code");

System.out.println("第三方登录返回结果:"+code );

if("".equals(code )||null==code ){

System.out.println("回调函数没有执行");

return "fail";

}else{

String url=HttpRequest.sendPost("http://open.51094.com/user/auth.html", "type=get_user_info&code="+code+"&appid="+appid+"&token="+token+"");

System.out.println(url);

//解析结果

try {

JSONObject jsonObj = new JSONObject(url);

} catch (JSONException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

// 得到指定json key对象的value对象

//解析封装对象

return "Redirect";

}

}

}

第三方登录页面java_第三方登录接口使用说明(JAVA)相关推荐

  1. SpringBoot+Vue+Mybatis-plus 博客(一):完成博客后台前端登录页面、后端登录接口

    SpringBoot+Vue+Mybatis-plus 博客:个人博客介绍及效果展示 SpringBoot+Vue+Mybatis-plus 博客(一):完成博客后台前端登录页面.后端登录接口 Spr ...

  2. 问题解决10使用带有框架的页面跳转到登录页面时,登录页面只显示在子框架中,未能铺满整个浏览器--解决方案如下:...

    问题描述: 使用带有框架的页面跳转到登录页面时,登录页面只显示在子框架中,未能铺满整个浏览器,例如: 当登录信息过期时,点击左边的菜单栏会让登录页面显示在右边的框架中,而不能铺满整个浏览器 解决方案: ...

  3. layui 登录页面样式+短信接口

    备注:原代码使用的是阿里某短信接口,代码配置跟具体接口文档有关 <body><h1>物料登录</h1><div class="container w ...

  4. html js验证登录页面,js判断登录与否并确定跳转页面的方法

    本文实例讲述了js判断登录与否并确定@R_384_404@面的方法.分享给大家供大家参考.具体如下: 使用session存储,确定用户是否登录,从而确定页面跳转至哪个页面. 判断本地有无custome ...

  5. 板邓:wordpress自定义登录页面实现用户登录

    首先检查用户是否已经登录,如果已经登录就返回info目录下的页面. <?phpglobal $current_user;$loginuserid = $current_user->ID;i ...

  6. 使用IDEA设计登录页面完成假登录

    第一步:创建web项目,部署到tomcat服务器中 第二步:在index.jsp首页中添加一个a标签,跳转到登录页面  第三步:创建一个login.jsp作为登录页面,书写form表单指定提交地址和提 ...

  7. 用IDEA设计登录页面完成假登录

    1.检查web项目是否部署到tomcat服务器 2.在index.jsp首页中添加一个a标签,跳转到登录页面. 注意:ctrl+超链接标签可以跳转到登录页面 3.创建一个login.jsp作为登录页面 ...

  8. 用html和css语言编写一个登录页面,简单css登录页面

    CSS布局HTML小编今天和大家分享一个简单的登录界面CSS代码 登 陆 微信登陆QQ登陆 注 册 #zuo{ width: 500px; height: 540px; background: whi ...

  9. php代码编写注册登录页面,PHP开发登录注册完整代码之注册HTML页面

    创建 reg.html 文件 我们此页面有一个 表单,里面有四个input输入框,我们用JS对输入框里面的内容作了登录判断,并使用了css对表单进行了布局. 代码如下html> 登陆界面 fun ...

最新文章

  1. shell case
  2. 模拟退火粒子群优化算法控制程序
  3. linux虚拟文件系统vfs
  4. 爬虫系列---Scrapy框架学习
  5. WPF将Ui保存为图片和保存位图
  6. 动手解决jar转txt软件的一个缺陷
  7. UI素材模板|新拟态新趋势图标ICON
  8. python和lua哪个有前途_lua、python对比学习
  9. css用边框实现圆角矩形
  10. localstorage和sessionStorage和cookies
  11. c++ map的存储结构_深度解密Go语言之sync.map
  12. 喜乐美容美发管理系统 v20070625 加强版 下载
  13. 正确使用RecyclerView分割线
  14. Flash XSS 漏洞实例
  15. 彩虹色MD主题1 for Sublime Text Typora EmEditor EverEdit
  16. 天池大数据比赛-天体分类总结
  17. 退出手机QQ依然显示在线
  18. 详解Unity中的粒子系统Particle System (九)
  19. 正好杠杆炒股五粮液主力资金净流入居首
  20. unix常用操作命令

热门文章

  1. java 如何取01 zz_java中synchronized用法(zz)
  2. 【安卓深度控件开发(2.2)】LCDView - 进阶绘图
  3. 2007-11-22 21:24 大端(Big Endian)与小端(Little Endian)详解
  4. swagger : Could not resolve reference because of: Could not resolve pointer
  5. JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式
  6. springBoot整合rabbitmq并测试五种常用模型
  7. /dev/shm目录下产生大量的ora_$ORACLE_SID的二进制文件
  8. ArcGIS 栅格函数在线调用详解
  9. 插上翅膀,让Excel飞起来
  10. 走在网页游戏开发的路上——页游资源管理