feilong 3.0.9 发布了,让 Java 开发更简便的工具库
feilong 3.0.9 发布了,feilong 是一个让Java开发更简便的工具库。
- 让你从大量重复的底层代码中脱身,提高开发效率;
- 让你的代码
更简炼
,易写
、易读
、易于维护
;
文档地址: http://feilong-core.mydoc.io/
单元测试数
增加至 2259
个, 单元测试覆盖率
增加至 91%
,javadoc
比率 83%
本次升级共有 2
处变更, 具体参见 3.0.9 milestone
其他
#298 修改 SftpFileTransferBeanDefinitionParser javadoc [javadoc]
#297 ✨ 新增 feilong-net-wxwork 企业微信机器人 [enhancement]
使用feilong 发企业微信机器人
企业微信机器人在日常的使用场景中越来越多, 比如服务器关键任务告警,定时发通知提醒等等, 和短信相比即免费又不像短信逐渐只有接收验证码的功能, 那么问题来了,如何使用feilong来发送企业微信机器人呢?
简单 3 步
第1步: jar 依赖
必要依赖
<dependency> <groupId>com.github.ifeilong</groupId> <artifactId>feilong</artifactId> <version>3.0.9</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> <version>4.5.12</version> <exclusions> <exclusion> <artifactId>httpclient</artifactId> <groupId>org.apache.httpcomponents</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> <version>4.5.12</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.2.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.7.RELEASE</version> </dependency>
for test 和日志
<!--下面是for test 和日志--> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.2.7.RELEASE</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.30</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.30</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.13</version> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest-library</artifactId> <version>1.3</version> <scope>test</scope> </dependency>
第2步: 使用xml 配置机器人
wxbot.xml
注意xml中需要使用feilong 的customer xml tag
feilong:wxworkBot 只有一个核心自定义属性, key 是企业微信机器人对应的key , key 参考 如何配置群机器人?
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:feilong="http://www.feilong.com/schema/feilong" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.feilong.com/schema/feilong http://www.feilong.com/schema/feilong/feilong.xsd "> <feilong:wxworkBot id="wxworkBot" key="80fa900e-c601-41a9-987c-ffa48f1d9e27" /> </beans>
第3步: 使用
简单小示例:
package com.feilong.namespace; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.hasProperty; import static org.hamcrest.Matchers.is; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import com.feilong.net.wxwork.bot.WxworkBot; import com.feilong.net.wxwork.bot.message.WxworkResponse; @ContextConfiguration(locations = { "classpath*:wxbot.xml" }) public class WxworkBotTagTest extends AbstractJUnit4SpringContextTests{ @Autowired @Qualifier("wxworkBot") private WxworkBot wxworkBot; //--------------------------------------------------------------- @Test public void test(){ WxworkResponse wxworkResponse = wxworkBot.sendMessage("hello world"); assertThat( wxworkResponse, allOf( hasProperty("isSuccess", is(true)), // hasProperty("errcode", is("0")))); } }
执行这个单元测试, 你将会收到企业微信机器人发的消息
关于 WxworkBot
com.feilong.net.wxwork.bot.WxworkBot 提供了2个易用的方法
- sendMessage(String) 发送普通消息,以及Markdown格式的消息
- sendNewsMessage(Article...) 发送推送图文类型消息
sendMessage(String) 发送普通消息,以及Markdown格式的消息
在上述 hello world示例中, 你可以看到发送简单消息, 也支持markdown格式的消息, 比如
@Test public void test(){ wxworkBot.sendMessage( "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n" + "> 类型:<font color=\"comment\">用户反馈</font>\n" + "> 普通用户反馈:<font color=\"comment\">117例</font>\n" + "> VIP用户反馈:<font color=\"comment\">15例</font>"); }
效果:
sendNewsMessage(Article...) 发送推送图文类型消息
你还可以使用sendNewsMessage 来推送图文类型的消息,
package com.feilong.namespace; import org.junit.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; import com.feilong.net.wxwork.bot.WxworkBot; import com.feilong.net.wxwork.bot.message.news.Article; @ContextConfiguration(locations = { "classpath*:wxbot.xml" }) public class WxworkBotTagNewsMessageTest extends AbstractJUnit4SpringContextTests{ @Autowired @Qualifier("wxworkBot") private WxworkBot wxworkBot; @Test public void test(){ //是 标题,不超过128个字节,超过会自动截断 String title = "提醒您,点击填Timesheet"; //描述,不超过512个字节,超过会自动截断 String description = "@all 点我直接填写Jira Timesheet" + "\n\n" + "我爱工作,工作使我快乐"; //"点我直接填写Jira Timesheet", String url = "http://jira.xxx.cn/plugins/servlet/aio-ts/bridge/pages/aiotimeentry"; String img = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1585320605587&di=9424f8862476b2ce819ac9f5637567b1&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2F503d269759ee3d6d55e89bf048166d224f4adeda.jpg"; wxworkBot.sendNewsMessage(new Article(title, description, url, img)); } }
效果:
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
基于码云的云原生持续集成工作流
本文介绍一种基于码云的持续集成工作流及其实现,读者可以通过阅读本文,从 0 实现一个生产级以 Gitee 仓库为核心的云原生持续集成工作流。 在日常开发过程中,通常会有多个业务或功能模块同时开发,这些在 git 工作流中都以分支的形式共存在一个代码仓库中,当开发完成后向发布分支提交 PR 以合并到发布分支完成发布,这时我们的测试工作就落到了对这些 PR 的部署和测试上,对于多个 PR 的部署我们有什么方便、快捷、自动化的部署方案呢? 于是本文就以开发环境中多 PR 同时部署和测试为例,实现一个包含了 Gitee 源码仓库、 Jenkins 、 Harbor 、 Kubernetes 、 Helm 等功能组件,可以实现从代码托管到发布上线的整套持续集成流程。通过自动化处理构建过程,极大的简化了日常迭代工作的复杂度。 工作流架构图 架构组件说明 码云:国内最大代码托管平台、全球第二大代码托管平台、全球最大中文代码托管平台。提供代码托管、代码质量分析、项目管理、代码演示等一站式企业级公有云服务 Gitee Jenkins Plugin :码云基于 GitLab Jenkins Plugin ...
- 下一篇
Cloudopt Next 更新至 2.0.8.0-BETA
Cloudopt Next 是一个非常轻量级且现代的、基于 Kotlin 编写的全栈开发框架,同时支持 Java 和 Kotlin,您可以处理Url的解析,数据的封装,Json的输出等等,从根本上减少开发时间、提升开发体验。 官网: https://next.cloudopt.net Cloudopt Next 主要拥有以下特点: 简单 极简设计,几乎不要任何配置,不依赖 Tomcat、Jetty 等 Web 容器。 异步 基于 vertx 轻松实现高性能的异步服务。 扩展 支持 vertx 体系的各种组件,同时支持通过插件扩展功能,官方也提供了大量好用的插件。 中文 全中文文档、中文社区,帮助中文开发者快速上手。 性能 测试电脑的 CPU 是 2.2 GHz 六核 Intel Core i7,内存为 16 GB 2400 MHz DDR4。 吞吐量参数为用户数 10,循环 10000 次。 框架名称 吞吐量 Cloudopt Next 20267.5/sec Spring Boot 10698.2/sec Flask 440.8/sec 根据性能测试结果:Cloudopt Nex...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2配置默认Tomcat设置,开启更多高级功能
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- SpringBoot2编写第一个Controller,响应你的http请求并返回结果
- CentOS8,CentOS7,CentOS6编译安装Redis5.0.7
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS7,CentOS8安装Elasticsearch6.8.6
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- Linux系统CentOS6、CentOS7手动修改IP地址
- CentOS7安装Docker,走上虚拟化容器引擎之路