|
|
@@ -2,6 +2,7 @@ package com.malk.service.dingtalk.impl;
|
|
|
|
|
|
import com.malk.server.dingtalk.DDConf;
|
|
|
import com.malk.server.dingtalk.DDR;
|
|
|
+import com.malk.server.dingtalk.DDR_New;
|
|
|
import com.malk.service.dingtalk.DDClient;
|
|
|
import com.malk.utils.UtilHttp;
|
|
|
import com.malk.utils.UtilMap;
|
|
|
@@ -43,6 +44,7 @@ public class DDImplClient implements DDClient {
|
|
|
return accessToken;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
public String getAccessToken(String appKey, String appSecret) {
|
|
|
Map param = UtilMap.map("appkey, appsecret", appKey, appSecret);
|
|
|
@@ -51,6 +53,32 @@ public class DDImplClient implements DDClient {
|
|
|
return r.getAccessToken();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取用户访问授权, ppExt: 生成的refresh_token。可以使用此刷新token,定期的获取用户的accessToken: 过期时间 30 天
|
|
|
+ *
|
|
|
+ * @apiNote https://open.dingtalk.com/document/orgapp/obtain-user-token
|
|
|
+ */
|
|
|
+ @Synchronized
|
|
|
+ @Override
|
|
|
+ public String getUserAccessToken(boolean isRefresh, String code_refreshToken) {
|
|
|
+ String accessToken = UtilToken.get("invalid-user-token-dingtalk");
|
|
|
+ if (StringUtils.isNotBlank(accessToken)) return accessToken;
|
|
|
+ Map boyd = UtilMap.map("clientId, clientSecret", ddConf.getAppKey(), ddConf.getAppSecret());
|
|
|
+ if (isRefresh) {
|
|
|
+ boyd.put("grantType", "refresh_token");
|
|
|
+ boyd.put("refreshToken", code_refreshToken);
|
|
|
+ } else {
|
|
|
+ boyd.put("grantType", "authorization_code");
|
|
|
+ boyd.put("code", code_refreshToken);
|
|
|
+ }
|
|
|
+ DDR_New r = (DDR_New) UtilHttp.doPost("https://api.dingtalk.com/v1.0/oauth2/userAccessToken", null, boyd, DDR_New.class);
|
|
|
+ log.info("用户token, {}", r.getAccessToken());
|
|
|
+ accessToken = r.getAccessToken();
|
|
|
+ // token失效自动重置: DD重新调用会重置过期时间
|
|
|
+ UtilToken.put("invalid-user-token-dingtalk", accessToken, r.getExpiresIn() * 1000L);
|
|
|
+ return accessToken;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* token授权参数: 旧版本
|
|
|
*/
|