|
@@ -14,6 +14,7 @@ import java.io.IOException;
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.ACCESS_TOKEN;
|
|
import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.ACCESS_TOKEN;
|
|
|
|
+import static com.tzld.piaoquan.wecom.common.constant.RedisConstant.WE_COM_ACCESS_TOKEN;
|
|
import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.*;
|
|
import static com.tzld.piaoquan.wecom.common.constant.WeComConstant.*;
|
|
|
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -46,4 +47,26 @@ public class AccessTokenServiceImpl implements AccessTokenService {
|
|
}
|
|
}
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getWeComAccessToken() {
|
|
|
|
+ String accessToken = (String) redisTemplate.opsForValue().get(ACCESS_TOKEN);
|
|
|
|
+ if (StringUtils.isNotEmpty(accessToken)) {
|
|
|
|
+ return accessToken;
|
|
|
|
+ }
|
|
|
|
+ JSONObject param = new JSONObject();
|
|
|
|
+ param.put("corp_id", CROP_ID);
|
|
|
|
+ param.put("secret", SECRET);
|
|
|
|
+ try {
|
|
|
|
+ String res = httpPoolClientDefault.get(String.format(GET_WE_COM_ACCESS_TOKEN_URL + "?corpid=%s&corpsecret=%s", WE_COM_CROP_ID, WE_COM_SECRET));
|
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
|
+ Long expiresIn = jsonObject.getLong("expires_in");
|
|
|
|
+ String newAccessToken = jsonObject.getString("access_token");
|
|
|
|
+ redisTemplate.opsForValue().set(WE_COM_ACCESS_TOKEN, newAccessToken, expiresIn, TimeUnit.SECONDS);
|
|
|
|
+ return newAccessToken;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("getWeComAccessToken error", e);
|
|
|
|
+ }
|
|
|
|
+ return "";
|
|
|
|
+ }
|
|
}
|
|
}
|