广州市南沙区建设局网站,网络服务器施工方案,网站创建公司,wordpress目录图片现在使用飞书的人越来越多了#xff0c;飞书有一个最大的好处#xff0c;可以使用webhook简便的发送群消息。而在工作中#xff0c;也经常会因为一些运维方面的工作#xff0c;需要给飞书发送群消息#xff0c;来实时提醒相关负责人,及时处理工作。
一、先看一下效果吧飞书有一个最大的好处可以使用webhook简便的发送群消息。而在工作中也经常会因为一些运维方面的工作需要给飞书发送群消息来实时提醒相关负责人,及时处理工作。
一、先看一下效果吧
最后有整个项目代码下载 二、飞书创建群 三、java通过webhook发飞书发送消息
通过上一步已经获取到如下信息根据实际情况复制出来后面会用到
webhook地址https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxx
签名校验xxxxxxx
上面两个获取到了下面就是java发送了
1、bootstrap.yml中配置如下
spring:application:name: base
server:port: 9080servlet:context-path: /
feishu:aiUrl: https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxx #飞书机器人通知secret: xxxxxxxxxxxxxxxxsignName: 基础平台
2、controller代码
package com.ck.controller;import com.ck.config.FeiShuAiClient;
import com.ck.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;RestController
RequestMapping(/test)
Api(tags TestController, description 测试)
public class TestController {private static final Logger logger LoggerFactory.getLogger(TestController.class);Autowiredprivate TestService testService;Autowiredprivate FeiShuAiClient feiShuAiClient;GetMapping(/send)ApiOperation(发送内空)public String find(String name) {name当前发送内容name;feiShuAiClient.sendMsg(name);return 发送成功;}
}3、发送飞书代码 /*** 发送结果* param content*/public void sendMsg(String content){content【signName】content;Long timestamp getTimestamp();String sign Sign(timestamp);FeiShuContentVo contentVo new FeiShuContentVo(content);FeiShuAiVo aiVo new FeiShuAiVo();aiVo.setTimestamp(timestamp.toString());aiVo.setSign(sign);aiVo.setMsg_type(text);aiVo.setContent(contentVo);String paramJson GsonUtils.toJson(aiVo);String result doPost(aiUrl,paramJson);log.info(飞书发送内容content发送结果result);}public String genSign(String secret, long timestamp) {//把timestamp\n密钥当做签名字符串String stringToSign timestamp \n secret;//使用HmacSHA256算法计算签名Mac mac null;try {mac Mac.getInstance(HmacSHA256);mac.init(new SecretKeySpec(stringToSign.getBytes(StandardCharsets.UTF_8), HmacSHA256));byte[] signData mac.doFinal(new byte[]{});return new String(Base64.encodeBase64(signData));} catch (Exception e) {e.printStackTrace();}return null;}
四、验证 五代码下载地址百度网盘 请输入提取码
通过百度网盘分享的文件send-feishu-msg 链接https://pan.baidu.com/s/1Dlyy64Tqwer8sSJu7vJGgQ?pwdyv0l 提取码yv0l