?If you feel this project is good, please click on the upper right corner of the project to encourage the author, thank you?.
wecom-sdk is the Java implementation of the open source enterprise WeChat open API. It is currently the most complete Java open source implementation. After nearly three years of iteration, enterprise WeChat open interfaces such as address book management, customer management, WeChat customer service, material management, message push, enterprise microbots, identity verification, application management, OA office, and enterprise payment have been implemented. Developers You can quickly and elegantly access corporate WeChat without high learning costs.
/**
* 企微机器人
*
* @throws IOException the io exception
*/
@ Test
void webHooks () throws IOException {
// 发 markdown
WebhookBody markdownBody = WebhookMarkdownBody . from ( "这里为markdown消息" );
// 发纯文本
WebhookBody textBody = WebhookTextBody . from ( "这里为纯文本" );
// 发图文
WebhookArticle article = new WebhookArticle ( "这里为标题" , "这里为图文链接" )
. picurl ( "这里为封面图链接" )
. description ( "这里为摘要信息" );
WebhookBody newsBody = WebhookNewsBody . from ( Collections . singletonList ( article ));
// 从base64发图片
String base64 = "图片base64" ;
String md5 = "图片base64的md5" ;
WebhookBody imageBody1 = WebhookImageBody . from ( base64 , md5 );
// 从流发送图片
String path = "C: \ Users \ Administrator \ Desktop \ 0.png" ;
InputStream inputStream = Files . newInputStream ( Paths . get ( path ));
WebhookBody imageBody2 = WebhookImageBody . from ( inputStream );
WeComResponse weComResponse = WorkWeChatApi . webhookApi (). send ( "机器人key" , markdownBody );
Assertions . assertTrue ( weComResponse . isSuccessful ());
}
See SpringBootWecomSdkTests.java for more examples
At present, self-built applications can be easily adapted, but service providers and agency developers are not open source for the time being.
2.11.0
4.12.0
3.1.8
2.15.2
1.4.20
< dependency >
< groupId >cn.felord</ groupId >
< artifactId >wecom-sdk</ artifactId >
< version >1.3.2</ version >
</ dependency >
< dependency >
< groupId >cn.felord</ groupId >
< artifactId >rx-wecom-sdk</ artifactId >
< version >1.3.2</ version >
</ dependency >
Since the implementation is too complete, if you want to find the API accurately, you can do this:
public interface TagApi {
/**
* 创建标签
*
* @param request the request
* @return GenericResponse generic response
* @throws WeComException the weComException
*/
@ POST ( "tag/create" )
GenericResponse < String > createTag ( @ Body Tag request ) throws WeComException ;
}
First go to the Enterprise WeChat API documentation to find the API you need, such as creating a tag https://qyapi.weixin.qq.com/cgi-bin/tag/create?access_token=ACCESS_TOKEN
, and intercept tag/create
to search globally.
The NoSuchMethod error is reported because your project itself has introduced Okhttp, but the version is relatively low, resulting in incompatibility. You can introduce wecom-sdk through the following dependencies.
< dependency >
< groupId >cn.felord</ groupId >
< artifactId >wecom-sdk</ artifactId >
< version >1.3.2</ version >
< exclusions >
< exclusion >
< groupId >com.squareup.okhttp3</ groupId >
< artifactId >okhttp</ artifactId >
</ exclusion >
< exclusion >
< groupId >com.squareup.okhttp3</ groupId >
< artifactId >logging-interceptor</ artifactId >
</ exclusion >
</ exclusions >
</ dependency >
< dependency >
< groupId >com.squareup.okhttp3</ groupId >
< artifactId >okhttp</ artifactId >
< version >4.12.0</ version >
</ dependency >
< dependency >
< groupId >com.squareup.okhttp3</ groupId >
< artifactId >logging-interceptor</ artifactId >
< version >4.12.0</ version >
</ dependency >
No more documentation, the code is the documentation