You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.5 KiB
63 lines
2.5 KiB
3 years ago
|
package com.fr.plugin.xx.sso.util;
|
||
|
import cn.hutool.core.map.MapUtil;
|
||
|
import cn.hutool.core.util.ObjectUtil;
|
||
|
import cn.hutool.crypto.asymmetric.KeyType;
|
||
|
import cn.hutool.crypto.asymmetric.RSA;
|
||
|
import cn.hutool.http.HttpGlobalConfig;
|
||
|
import cn.hutool.http.HttpUtil;
|
||
|
import com.auth0.jwt.JWT;
|
||
|
import com.auth0.jwt.interfaces.DecodedJWT;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.xx.sso.conf.PortalSsoConfig;
|
||
|
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* @author xx
|
||
|
*/
|
||
|
public class CallUtil {
|
||
|
/**
|
||
|
* @param code
|
||
|
*/
|
||
|
public static String call(String code) {
|
||
|
String account = "", userCode, accountName, certNumber;
|
||
|
PortalSsoConfig authConfig = PortalSsoConfig.getInstance();
|
||
|
Map<String, Object> paramMap = MapUtil.newHashMap(5);
|
||
|
paramMap.put("grant_type", "authorization_code");
|
||
|
paramMap.put("code", code);
|
||
|
paramMap.put("client_id", authConfig.getClientId());
|
||
|
paramMap.put("client_secret", authConfig.getClientSecret());
|
||
|
paramMap.put("redirect_uri", authConfig.getRedirectUri());
|
||
|
try {
|
||
|
HttpGlobalConfig.setTimeout(6000);
|
||
|
String rsp = HttpUtil.post(authConfig.getMethodGetAccessToken(), paramMap);
|
||
|
LogUtils.debug4plugin("get url {} param is {} account res is {}",authConfig.getMethodGetAccessToken(),paramMap,rsp);
|
||
|
if (ObjectUtil.isNotEmpty(rsp)) {
|
||
|
JSONObject hashMap = new JSONObject(rsp);
|
||
|
if (0 == (int) hashMap.get("code")) {
|
||
|
RSA rsa = new RSA(authConfig.getPrivateKey(), null);
|
||
|
String decryptStr = rsa.decryptStr((String) hashMap.get("data"), KeyType.PrivateKey);
|
||
|
JSONObject map = new JSONObject(decryptStr);
|
||
|
//解析 accessToken
|
||
|
DecodedJWT decodeToken = JWT.decode((String) map.get("access_token"));
|
||
|
//获取门户帐号信息
|
||
|
//account = decodeToken.getClaim("account").asString();
|
||
|
//获取门户UID信息
|
||
|
account = decodeToken.getClaim("userCode").asString();
|
||
|
//获取门户姓名信息
|
||
|
//accountName = decodeToken.getClaim("accountName").asString();
|
||
|
//获取门户证件信息
|
||
|
//certNumber = decodeToken.getClaim("certNumber").asString();
|
||
|
}
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
LogUtils.error("调用门户code换取token异常{}", e.getMessage());
|
||
|
}
|
||
|
|
||
|
return account;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
}
|