This commit is contained in:
@@ -7,6 +7,7 @@ package com.wentch.redkale.service.weixin;
|
||||
|
||||
import com.wentch.redkale.convert.json.*;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
|
||||
/**
|
||||
* 微信企业号Service
|
||||
@@ -29,6 +30,8 @@ public class WeiXinQYMessage {
|
||||
|
||||
private String safe;
|
||||
|
||||
private Supplier<String> contentSupplier;
|
||||
|
||||
public WeiXinQYMessage() {
|
||||
}
|
||||
|
||||
@@ -37,11 +40,20 @@ public class WeiXinQYMessage {
|
||||
setTextMessage(text);
|
||||
}
|
||||
|
||||
public WeiXinQYMessage(String agentid, Supplier<String> contentSupplier) {
|
||||
this.agentid = agentid;
|
||||
this.contentSupplier = contentSupplier;
|
||||
}
|
||||
|
||||
public final void setTextMessage(String content) {
|
||||
if (text == null) text = new HashMap<>();
|
||||
text.put("content", content);
|
||||
}
|
||||
|
||||
public void supplyContent() {
|
||||
if (contentSupplier != null) setTextMessage(contentSupplier.get());
|
||||
}
|
||||
|
||||
public String getAgentid() {
|
||||
return agentid;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.lang.reflect.*;
|
||||
import java.nio.charset.*;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import java.util.function.*;
|
||||
import java.util.logging.*;
|
||||
import javax.annotation.*;
|
||||
import javax.crypto.*;
|
||||
@@ -99,10 +100,15 @@ public class WeiXinQYService implements Service {
|
||||
sendQYMessage(new WeiXinQYMessage(agentid, message));
|
||||
}
|
||||
|
||||
public void sendQYTextMessage(String agentid, Supplier<String> contentSupplier) {
|
||||
sendQYMessage(new WeiXinQYMessage(agentid, contentSupplier));
|
||||
}
|
||||
|
||||
public void sendQYMessage(WeiXinQYMessage message) {
|
||||
submit(() -> {
|
||||
String result = null;
|
||||
try {
|
||||
message.supplyContent();
|
||||
String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + getQYAccessToken();
|
||||
result = postHttpContent(url, convert.convertTo(message));
|
||||
if (finest) logger.finest("sendQYMessage ok: " + message + " -> " + result);
|
||||
|
||||
Reference in New Issue
Block a user