This commit is contained in:
雷欧(林平凡)
2025-01-22 16:57:39 +08:00
parent b62ab3ea5c
commit 888702297f

View File

@@ -45,18 +45,19 @@ public class MessageConsumerService implements RocketMQListener<JSONObject> {
// 处理消息
try {
rateLimiter.acquire(); // 请求许可。如果超过速率,则此方法会阻塞
logger.info("消费到消息:{}", jsonObject);
String body = jsonObject.getString("body");
byte[] decodedBody = Base64.getDecoder().decode(body);
String decodedBodyStr = new String(decodedBody, StandardCharsets.UTF_8);
JSONObject decodedBodyJson = JSONObject.parseObject(decodedBodyStr);
String jsonStr = JSONUtil.toJsonStr(decodedBodyJson);
String responseStr = HttpRequest.post(WX_BASE_URL)
.body(JSONUtil.toJsonStr(decodedBodyJson))
.body(jsonStr)
.execute()
.body();
logger.info("消费消息:{}", jsonStr);
if (ObjectUtil.isNotEmpty(responseStr)) {
JSONObject response = JSONObject.parseObject(responseStr);
logger.info("消息成功发送并得到响应:{}", response);
if (response.getInteger("code") != 200) {
// TODO: 如果需要处理错误,您可以在这里添加逻辑
wxtsUtil.sendNotify("消息发送失败: " + responseStr);