java快速构建飞书API消息推送、消息加急等功能
import feign.Headers;
import feign.Param;
import feign.RequestLine;
public interface FeishuApi {
@RequestLine("POST /message/v4/send")
@Headers("Content-Type: application/json")
void sendMessage(@Param("body") String body);
@RequestLine("POST /message/v4/batch_send")
@Headers("Content-Type: application/json")
void batchSendMessage(@Param("body") String body);
@RequestLine("POST /message/v4/update")
@Headers("Content-Type: application/json")
void updateMessage(@Param("body") String body);
@RequestLine("POST /bot/v4/app/{{app_id}}/message/send")
@Headers("Content-Type: application/json")
void sendMessageToBot(@Param("app_id") String appId, @Param("body") String body);
// 以下是构建请求体的辅助方法
static String buildSendMessageBody(String receiverId, String content, boolean urgent) {
StringBuilder body = new StringBuilder();
body.append("{\"receiver_id\":\"").append(receiverId).append("\",");
body.append("\"content\":\"").append(content).append("\",");
body.append("\"msg_type\":\"text\",");
body.append("\"extra\":");
if (urgent) {
body.append("{\"urgency\":\"").append("urgent").append("\"}");
} else {
body.append("null");
}
body.append("}");
return body.toString();
}
}
这个代码示例展示了如何使用Feign客户端快速构建飞书(Feishu)API的消息发送功能。其中,buildSendMessageBody
方法用于根据接收者ID、消息内容和是否加急构建请求体。在实际使用时,你需要提供正确的接收者ID、消息内容,并根据业务需求设置是否加急。
评论已关闭