企业微信推送

This commit is contained in:
雷欧(林平凡)
2025-01-22 11:35:48 +08:00
parent 7b5233a380
commit 530f8ce0a6
3 changed files with 14 additions and 9 deletions

View File

@@ -55,12 +55,12 @@ public class MessageConsumerService implements RocketMQListener<JSONObject> {
JSONObject response = JSONObject.parseObject(responseStr);
if (response.getInteger("code") != 200) {
// TODO: 如果需要处理错误,您可以在这里添加逻辑
wxtsUtil.sendNofity("消息发送失败: " + responseStr);
wxtsUtil.sendNotify("消息发送失败: " + responseStr);
throw new RuntimeException("消息发送失败: " + responseStr);
}
//logger.info("消息成功发送并得到响应:{}", response);
} else {
wxtsUtil.sendNofity("消息发送失败,没有收到响应");
wxtsUtil.sendNotify("消息发送失败,没有收到响应");
throw new RuntimeException("消息发送失败,没有收到响应");
}
} catch (Exception e) {

View File

@@ -31,6 +31,9 @@ public class WXUtil {
public static Map<String, SuperAdmin> super_admins = new HashMap<>();
public static Map<String, String> jdidToWxidMap = new HashMap<>();
@Autowired
private WxtsUtil wxTsUtil;
@Data
@AllArgsConstructor
@NoArgsConstructor
@@ -39,21 +42,23 @@ public class WXUtil {
private String name;
// 联盟ID
private String unionId;
private String appKey ;
private String secretKey ;
private String appKey;
private String secretKey;
}
// 初始化超级管理员
public void initSuperAdmins() {
SuperAdmin admin1 = new SuperAdmin("wxid_ytpc72mdoskt22", "", "2014264913",
"98e21c89ae5610240ec3f5f575f86a59","3dcb6b23a1104639ac433fd07adb6dfb");
"98e21c89ae5610240ec3f5f575f86a59", "3dcb6b23a1104639ac433fd07adb6dfb");
super_admins.put(admin1.getWxid(), admin1);
jdidToWxidMap.put(admin1.getUnionId(), admin1.getWxid());
SuperAdmin admin2 = new SuperAdmin("wxid_yneqf1implxu12", "", "2025353364"
,"e3c161242c8a1416fada5b5564d7ee70","41ae9aabf03b41e6ba309682e36b323e");
SuperAdmin admin2 = new SuperAdmin("wxid_yneqf1implxu12", "", "2025353364"
, "e3c161242c8a1416fada5b5564d7ee70", "41ae9aabf03b41e6ba309682e36b323e");
super_admins.put(admin2.getWxid(), admin2);
jdidToWxidMap.put(admin2.getUnionId(), admin2.getWxid());
wxTsUtil.sendNotify("initSuperAdmins 初始化完成");
// add more admins as needed...
}

View File

@@ -20,13 +20,13 @@ public class WxtsUtil {
private static final String SERVER_URL = "https://wxts.van333.cn";
public void sendNofity(String content) {
public void sendNotify(String content) {
try {
String url = SERVER_URL + "/send/jd?vanToken=" + TOKEN + "&source=XZJ_UBUNTU";
HashMap<String, Object> paramMap = new HashMap<>();
paramMap.put("title", "JD机器人微信推送");
content = content.replaceAll("\\n", "<br>");
String common = "192.168.8.88 (微信机器人),发出告警信息 : ";
String common = "192.168.8.88 (微信机器人), 信息 : ";
content = common + content + "<br><br>";
paramMap.put("text", content);
String post = HttpUtil.post(url, paramMap);