回复
This commit is contained in:
parent
8ce90f1bf7
commit
503c534982
@ -73,13 +73,6 @@ public class WecomCallbackController {
|
||||
msg == null ? null : msg.getMsgType(),
|
||||
preview(msg == null ? null : msg.getContent()));
|
||||
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())) {
|
||||
log.info("wecom callback ignored non-text message");
|
||||
return "success";
|
||||
|
||||
@ -48,28 +48,6 @@ public class WecomClient {
|
||||
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() {
|
||||
if (cachedToken != null && Instant.now().isBefore(tokenExpireAt)) {
|
||||
log.info("wecom gettoken use cached token expireAt={}", tokenExpireAt);
|
||||
@ -104,10 +82,4 @@ public class WecomClient {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
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