Browse Source

获取accessToken接口

huyy 7 years ago
parent
commit
90dbb4a80b

+ 52 - 0
sso-server/src/main/java/com/uas/sso/bihe/entity/OAuthInfo.java

@@ -0,0 +1,52 @@
+package com.uas.sso.bihe.entity;
+
+import java.io.Serializable;
+
+/**
+ * @author: huyy
+ * @date: 2018/7/18 10:57
+ */
+public class OAuthInfo implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    private String accessToken;
+
+    private Integer expires_in;
+
+    private String refreshToken;
+
+    private String openId;
+
+    public String getAccessToken() {
+        return accessToken;
+    }
+
+    public void setAccessToken(String accessToken) {
+        this.accessToken = accessToken;
+    }
+
+    public Integer getExpires_in() {
+        return expires_in;
+    }
+
+    public void setExpires_in(Integer expires_in) {
+        this.expires_in = expires_in;
+    }
+
+    public String getRefreshToken() {
+        return refreshToken;
+    }
+
+    public void setRefreshToken(String refreshToken) {
+        this.refreshToken = refreshToken;
+    }
+
+    public String getOpenId() {
+        return openId;
+    }
+
+    public void setOpenId(String openId) {
+        this.openId = openId;
+    }
+}

+ 28 - 0
sso-server/src/main/java/com/uas/sso/bihe/entity/OAuthRoot.java

@@ -0,0 +1,28 @@
+package com.uas.sso.bihe.entity;
+
+/**
+ * @author: huyy
+ * @date: 2018/7/18 15:07
+ */
+public class OAuthRoot {
+
+    private String code;
+
+    private OAuthInfo data;
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public OAuthInfo getData() {
+        return data;
+    }
+
+    public void setData(OAuthInfo data) {
+        this.data = data;
+    }
+}

+ 18 - 0
sso-server/src/main/java/com/uas/sso/bihe/service/BiHeService.java

@@ -0,0 +1,18 @@
+package com.uas.sso.bihe.service;
+
+import com.uas.sso.bihe.entity.OAuthRoot;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: huyy
+ * @date: 2018/7/18 10:54
+ */
+@Service
+public interface BiHeService {
+    /**
+     * 获取accessToken接口
+     * @param code
+     * @return
+     */
+    OAuthRoot getOAuthInfoByCode(String code);
+}

+ 39 - 0
sso-server/src/main/java/com/uas/sso/bihe/service/impl/BiHeServiceImpl.java

@@ -0,0 +1,39 @@
+package com.uas.sso.bihe.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.uas.sso.bihe.entity.OAuthRoot;
+import com.uas.sso.bihe.service.BiHeService;
+import com.uas.sso.common.util.HttpUtil;
+import com.uas.sso.core.BHParam;
+import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
+
+/**
+ * @author: huyy
+ * @date: 2018/7/18 11:26
+ */
+@Service
+public class BiHeServiceImpl implements BiHeService {
+    @Override
+    public OAuthRoot getOAuthInfoByCode(String code){
+        String url = "https://opengwtest.bgycc.com/open/oauth/token";
+        String appid = BHParam.DEFAULT_APPID;
+        String appSecret = BHParam.DEFAULT_APPSECRET;
+        ModelMap data = new ModelMap();
+        data.put("code", "XIH1G4");
+        data.put("appId", appid);
+        data.put("appSecret", appSecret);
+
+        try {
+            HttpUtil.ResponseWrap res = HttpUtil.doHttpsPost(url, data.toString(), 10000);
+            if (res.getContent() != null) {
+                System.out.println(res.getContent().toString());
+                OAuthRoot oAuthRoot = JSON.parseObject(res.getContent().toString(), OAuthRoot.class);
+                return oAuthRoot;
+            }
+        } catch (Exception e) {
+            System.out.println(e);
+        }
+        return null;
+    }
+}

+ 12 - 0
sso-server/src/main/java/com/uas/sso/core/BHParam.java

@@ -0,0 +1,12 @@
+package com.uas.sso.core;
+
+/**
+ * @author: huyy
+ * @date: 2018/7/18 11:27
+ */
+public class BHParam {
+
+    public static final String DEFAULT_APPID = "a9f624cbbdb947049f5638880b0ecbb2";
+
+    public static final String DEFAULT_APPSECRET = "8a9d398c70f842309472a69bc730038d";
+}