文档地址:https://www.yunzhijia.com/opendocs/doc.html?#/api/im/im-robot
我这边的需求是使用他们的默认样式的应用类消息
类似这样的。其实也没有什么难度,就是json格式对上就行了。
对象封装:
/**
* 对接云之家请求参数
*
* @author Gangbb
* @date 2022/1/4
**/
@Data
public class RobotDto {
private String content;
private int msgType;
private RobotParamDto param;
}
/**
* 对接云之家请求参数(子项)
*
* @author Gangbb
* @date 2022/1/4
**/
@Data
public class RobotParamDto {
private String appName;
private String title;
private String lightAppId;
private String thumbUrl;
private String webpageUrl;
private int customStyle;
private String content;
}
测试类:
(用了Hutool的http工具)
public static void main(String[] args) {
RobotParamDto param = new RobotParamDto();
param.setAppName("Java客户端测试");
param.setTitle("xxxxx项目-项目预警");
param.setLightAppId("");
param.setThumbUrl("https://img-blog.csdnimg.cn/b738abdc68e549c39a8e6ffa65535a20.png");
param.setWebpageUrl("https://img-blog.csdnimg.cn/b738abdc68e549c39a8e6ffa65535a20.png");
param.setCustomStyle(0);
param.setContent("1小时前 来自:项目经理张三\n作业内容:xxxxxxxx\n风 险:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)。\n");
RobotDto robot = new RobotDto();
robot.setContent("https://img-blog.csdnimg.cn/b738abdc68e549c39a8e6ffa65535a20.png");
robot.setMsgType(1);
robot.setParam(param);
String result1 = HttpRequest.post(ROBOT_URL)
.body(JSONUtil.toJsonStr(robot), "application/json")
.timeout(20000)//超时,毫秒
.execute().body();
System.out.println(result1);
}
}