|
|
|
@ -32,39 +32,39 @@ public class AccessTokenUtil {
|
|
|
|
|
//private static String APP_SECRET = "9aa17e9391d8fdf4be44f78e2a26be30";
|
|
|
|
|
private static String APP_SECRET = "3e86b82ada2b72fdd3d7929d5623b04f";
|
|
|
|
|
|
|
|
|
|
private static String HOST = "http://10.6.24.64:20600/papi/openapi";
|
|
|
|
|
// private static String HOST = "http://10.6.24.64:20600/papi/openapi";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取AccessToken
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public static String getToken() throws Exception {
|
|
|
|
|
|
|
|
|
|
// 获取code
|
|
|
|
|
String codeUrl = HOST + "/oauth2/authorize?corpid=" + CORP_ID + "&response_type=code&state=a21";
|
|
|
|
|
String codeResponse = HttpUtil.get(codeUrl);
|
|
|
|
|
System.out.println(codeResponse);
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSONObject.parseObject(codeResponse);
|
|
|
|
|
Object errcode = jsonObject.get("errcode");
|
|
|
|
|
Object code = jsonObject.get("code");
|
|
|
|
|
log.error("本次获取code值"+code+"==> errcode"+errcode);
|
|
|
|
|
|
|
|
|
|
// 根据code 获取token。
|
|
|
|
|
String tokenUrl = HOST + "/oauth2/access_token";
|
|
|
|
|
Map<String, Object> tokanParam = new HashMap<>(4);
|
|
|
|
|
tokanParam.put("app_key", APP_KEY);
|
|
|
|
|
tokanParam.put("app_secret", APP_SECRET);
|
|
|
|
|
tokanParam.put("grant_type", "authorization_code");
|
|
|
|
|
tokanParam.put("code", code);
|
|
|
|
|
|
|
|
|
|
String tokenResponse = HttpUtil.post(tokenUrl, tokanParam);
|
|
|
|
|
log.error("tokenResponse" + tokenResponse);
|
|
|
|
|
|
|
|
|
|
JSONObject tokenResponseObj = JSONObject.parseObject(tokenResponse);
|
|
|
|
|
return Optional.ofNullable(tokenResponseObj.get("accessToken")).map(Object::toString).orElse(new String());
|
|
|
|
|
}
|
|
|
|
|
// public static String getToken() throws Exception {
|
|
|
|
|
//
|
|
|
|
|
// // 获取code
|
|
|
|
|
// String codeUrl = HOST + "/oauth2/authorize?corpid=" + CORP_ID + "&response_type=code&state=a21";
|
|
|
|
|
// String codeResponse = HttpUtil.get(codeUrl);
|
|
|
|
|
// System.out.println(codeResponse);
|
|
|
|
|
//
|
|
|
|
|
// JSONObject jsonObject = JSONObject.parseObject(codeResponse);
|
|
|
|
|
// Object errcode = jsonObject.get("errcode");
|
|
|
|
|
// Object code = jsonObject.get("code");
|
|
|
|
|
// log.error("本次获取code值"+code+"==> errcode"+errcode);
|
|
|
|
|
//
|
|
|
|
|
// // 根据code 获取token。
|
|
|
|
|
// String tokenUrl = HOST + "/oauth2/access_token";
|
|
|
|
|
// Map<String, Object> tokanParam = new HashMap<>(4);
|
|
|
|
|
// tokanParam.put("app_key", APP_KEY);
|
|
|
|
|
// tokanParam.put("app_secret", APP_SECRET);
|
|
|
|
|
// tokanParam.put("grant_type", "authorization_code");
|
|
|
|
|
// tokanParam.put("code", code);
|
|
|
|
|
//
|
|
|
|
|
// String tokenResponse = HttpUtil.post(tokenUrl, tokanParam);
|
|
|
|
|
// log.error("tokenResponse" + tokenResponse);
|
|
|
|
|
//
|
|
|
|
|
// JSONObject tokenResponseObj = JSONObject.parseObject(tokenResponse);
|
|
|
|
|
// return Optional.ofNullable(tokenResponseObj.get("accessToken")).map(Object::toString).orElse(new String());
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static String getAccessToken(String tenantKey) {
|
|
|
|
|