当前位置: 首页 > wzjs >正文

个人可以做医疗信息网站吗超链接友情外链查询

个人可以做医疗信息网站吗,超链接友情外链查询,沧州公司做网站,企业网站用什么数据库1.在谷歌控制台创建客户端信息 https://console.cloud.google.com/auth/clients 注&#xff1a;在重定向的url中一定要是https开头的。 创建完成之后主要获取三个信息 clientID、secret、redirctUrl 2.配置pom <dependency><groupId>com.google.auth</group…

1.在谷歌控制台创建客户端信息

https://console.cloud.google.com/auth/clients

注:在重定向的url中一定要是https开头的。

创建完成之后主要获取三个信息

clientID、secret、redirctUrl

 2.配置pom

<dependency><groupId>com.google.auth</groupId><artifactId>google-auth-library-oauth2-http</artifactId><version>0.22.2</version>
</dependency>
<dependency><groupId>com.google.api-client</groupId><artifactId>google-api-client</artifactId><version>1.32.1</version>
</dependency>

3.获取跳转授权的url

clientID:谷歌控制台创建的

public static String getLoginUrl(){String scope = "openid email profile";String redirectUri = "https://www.baidu.com";String authUrl = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s&scope=%s";return String.format(authUrl, clientId, redirectUri, scope);}

4.接收code,获取accessToken

这个地方需要如果只是自己测试可以直接将重定向的地址,配置成获取code的地址,如果是正式环境我的方案是配置前端的页面,然后有前端将code传给后端。

注意:由于是跳转,code会被转义,自己测试的时候注意decode。

private static String tokenEndpoint = "https://oauth2.googleapis.com/token";
public static String checkCode(String code){MultiValueMap<String, String> params = new LinkedMultiValueMap<>();params.add("client_id", clientId);params.add("client_secret", clientSecret);params.add("code", code);params.add("redirect_uri", "https://www.baidu.com");params.add("grant_type", "authorization_code");HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<>(params, headers);RestTemplate restTemplate = new RestTemplate();ResponseEntity<Map> response = restTemplate.postForEntity(tokenEndpoint, request, Map.class);String accessToken = (String) response.getBody().get("access_token");return accessToken;}

5.根据accessToken获取用户信息

private static String userInfoEndpoint = "https://www.googleapis.com/oauth2/v3/userinfo";
public static Map getUserInfo(String accessToken){HttpHeaders userInfoHeaders = new HttpHeaders();userInfoHeaders.setBearerAuth(accessToken);HttpEntity<String> userInfoRequest = new HttpEntity<>(userInfoHeaders);RestTemplate restTemplate = new RestTemplate();ResponseEntity<Map> userInfoResponse = restTemplate.exchange(userInfoEndpoint, HttpMethod.GET, userInfoRequest, Map.class);Map<String, Object> userInfo = userInfoResponse.getBody();String googleId = (String) userInfo.get("sub");String email = (String) userInfo.get("email");String name = (String) userInfo.get("name");String picture = (String) userInfo.get("picture");return userInfo;}

http://www.dtcms.com/wzjs/197508.html

相关文章:

  • 超碰网站正在建设中优化搜索引擎营销
  • 小男孩做爰网站网络推广一个月的收入
  • 阿里云备案 网站备案域名硬件优化大师
  • 宁波网站关键词推广国内最新新闻消息今天的
  • 网站页尾的作用何鹏seo
  • 沧州公司做网站seo入门书籍
  • 有做思维图的网站吗企拓客软件怎么样
  • 单招网站开发画质优化app下载
  • 嘉兴平湖网站建设网络营销优化
  • 求百度关键词搜索网站郑州seo教程
  • 建筑规范app硬件优化大师下载
  • 宁夏建设注册中心网站免费域名注册永久
  • 传媒网站建设竞价推广哪家公司好
  • 上海城建设计院网站深圳最新政策消息
  • 网站运营可以转行做网站设计吗广州网站设计制作
  • 建网站挣钱靠谱吗怎么自己建网站
  • 旅游网站反链怎么做seo自媒体培训
  • 做二手房销售要开自己的网站吗软件开发公司网站
  • 江阴做网站的公司有营销方式和渠道
  • b2b电子商务网站调研报告电大作业免费营销培训
  • 响应式网站文章亚马逊关键词优化怎么做
  • 外贸网站翻译建设北京seo顾问
  • 怎么创建网站论坛nba最新消息交易
  • 2017企业网站建设方案销售
  • 网站标题怎么改企业网站seo服务
  • 怎样做酒店网站ppt模板腾讯3大外包公司
  • 如何做网站的网页百度自动点击器怎么用
  • 网站域名备案号查询网站联盟
  • 网站搭建徐州百度网络seop
  • wordpress怎么修改主题西安seo技术培训班