唯一
This commit is contained in:
parent
4554fd7896
commit
8ce90f1bf7
@ -73,6 +73,13 @@ public class WecomCallbackController {
|
|||||||
msg == null ? null : msg.getMsgType(),
|
msg == null ? null : msg.getMsgType(),
|
||||||
preview(msg == null ? null : msg.getContent()));
|
preview(msg == null ? null : msg.getContent()));
|
||||||
log.info("wecom callback current user FromUserName={}", msg == null ? null : msg.getFromUserName());
|
log.info("wecom callback current user FromUserName={}", msg == null ? null : msg.getFromUserName());
|
||||||
|
if (msg != null && msg.getFromUserName() != null && !msg.getFromUserName().isBlank()) {
|
||||||
|
WecomUserInfoResponse userInfo = wecomClient.getUserInfo(msg.getFromUserName());
|
||||||
|
if (userInfo != null && userInfo.success()) {
|
||||||
|
log.info("wecom callback resolved member userid={} name={} department={}",
|
||||||
|
userInfo.userId(), userInfo.name(), userInfo.department());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (msg == null || msg.getMsgType() == null || !"text".equalsIgnoreCase(msg.getMsgType())) {
|
if (msg == null || msg.getMsgType() == null || !"text".equalsIgnoreCase(msg.getMsgType())) {
|
||||||
log.info("wecom callback ignored non-text message");
|
log.info("wecom callback ignored non-text message");
|
||||||
return "success";
|
return "success";
|
||||||
|
|||||||
@ -48,6 +48,28 @@ public class WecomClient {
|
|||||||
log.info("wecom sendText success toUser={}", toUser);
|
log.info("wecom sendText success toUser={}", toUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public WecomUserInfoResponse getUserInfo(String userId) {
|
||||||
|
log.info("wecom user/get start userid={}", userId);
|
||||||
|
String token = getAccessToken();
|
||||||
|
WecomUserInfoResponse response = webClient.get()
|
||||||
|
.uri(uriBuilder -> uriBuilder.path("/cgi-bin/user/get")
|
||||||
|
.queryParam("access_token", token)
|
||||||
|
.queryParam("userid", userId)
|
||||||
|
.build())
|
||||||
|
.retrieve()
|
||||||
|
.bodyToMono(WecomUserInfoResponse.class)
|
||||||
|
.block();
|
||||||
|
|
||||||
|
if (response == null || !response.success()) {
|
||||||
|
log.warn("wecom user/get failed userid={} err={}", userId, response == null ? "null" : response.errmsg());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("wecom user/get success userid={} name={} department={} mobile={} position={}",
|
||||||
|
response.userId(), response.name(), response.department(), maskMobile(response.mobile()), response.position());
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
private String getAccessToken() {
|
private String getAccessToken() {
|
||||||
if (cachedToken != null && Instant.now().isBefore(tokenExpireAt)) {
|
if (cachedToken != null && Instant.now().isBefore(tokenExpireAt)) {
|
||||||
log.info("wecom gettoken use cached token expireAt={}", tokenExpireAt);
|
log.info("wecom gettoken use cached token expireAt={}", tokenExpireAt);
|
||||||
@ -81,4 +103,11 @@ public class WecomClient {
|
|||||||
}
|
}
|
||||||
return text.length() <= 80 ? text : text.substring(0, 80) + "...";
|
return text.length() <= 80 ? text : text.substring(0, 80) + "...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String maskMobile(String mobile) {
|
||||||
|
if (mobile == null || mobile.length() < 7) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return mobile.substring(0, 3) + "****" + mobile.substring(mobile.length() - 4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,19 @@
|
|||||||
|
package com.company.agentfoundation.integration.wecom;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public record WecomUserInfoResponse(
|
||||||
|
Integer errcode,
|
||||||
|
String errmsg,
|
||||||
|
@JsonProperty("userid") String userId,
|
||||||
|
String name,
|
||||||
|
List<Integer> department,
|
||||||
|
String mobile,
|
||||||
|
String position
|
||||||
|
) {
|
||||||
|
public boolean success() {
|
||||||
|
return errcode != null && errcode == 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user