1
This commit is contained in:
@@ -70,6 +70,37 @@ public class WxSendGoofishNotifyClient {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 京东物流扫描等:全文发往企微「闲鱼」自建应用(wxSend qywx.app.goofishAgentId)。
|
||||
*
|
||||
* @param optionalToUser 非空时用与 logistics.push.touser.* 相同的成员 ID(逗号/| 亦可);空则用 goofish-notify-touser
|
||||
* @return HTTP 2xx 为 true;未配置密钥或 toUser 为空返回 false
|
||||
*/
|
||||
public boolean pushGoofishAgentText(String optionalToUser, String content) {
|
||||
if (!StringUtils.hasText(wxsendBaseUrl) || !StringUtils.hasText(goofishPushSecret)) {
|
||||
log.debug("wxSend 闲鱼应用物流推送跳过:未配置 wxsend-base-url 或 goofish-push-secret");
|
||||
return false;
|
||||
}
|
||||
String rawTouser = StringUtils.hasText(optionalToUser) ? optionalToUser : goofishNotifyTouser;
|
||||
String toUser = buildTouserParam(rawTouser);
|
||||
if (!StringUtils.hasText(toUser)) {
|
||||
log.warn("wxSend 闲鱼应用物流推送跳过:无接收人(请配置 jarvis.wecom.goofish-notify-touser 或 logistics.push.touser)");
|
||||
return false;
|
||||
}
|
||||
String text = content != null ? content : "";
|
||||
if (text.length() > CONTENT_MAX) {
|
||||
text = text.substring(0, CONTENT_MAX - 1) + "…";
|
||||
}
|
||||
try {
|
||||
String base = normalizeBase(wxsendBaseUrl);
|
||||
String url = base + "/wecom/goofish-active-push";
|
||||
return postJsonReturnsOk(url, toUser, text);
|
||||
} catch (Exception e) {
|
||||
log.warn("wxSend goofish-active-push 物流全文失败 err={}", e.toString());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static String buildContent(String orderNo, String eventType, String source, String message) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("【闲鱼订单】").append(orderNo != null ? orderNo : "-").append("\n");
|
||||
@@ -120,6 +151,10 @@ public class WxSendGoofishNotifyClient {
|
||||
}
|
||||
|
||||
private void postJson(String url, String toUser, String content) throws Exception {
|
||||
postJsonReturnsOk(url, toUser, content);
|
||||
}
|
||||
|
||||
private boolean postJsonReturnsOk(String url, String toUser, String content) throws Exception {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("toUser", toUser);
|
||||
body.put("content", content);
|
||||
@@ -141,9 +176,10 @@ public class WxSendGoofishNotifyClient {
|
||||
String resp = readAll(is);
|
||||
if (code < 200 || code >= 300) {
|
||||
log.warn("wxSend goofish-active-push HTTP {} body={}", code, resp);
|
||||
} else {
|
||||
log.debug("wxSend goofish-active-push OK http={} resp={}", code, resp);
|
||||
return false;
|
||||
}
|
||||
log.debug("wxSend goofish-active-push OK http={} resp={}", code, resp);
|
||||
return true;
|
||||
} finally {
|
||||
if (conn != null) {
|
||||
conn.disconnect();
|
||||
|
||||
Reference in New Issue
Block a user