Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bailuntec-api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
huluobin
bailuntec-api
Commits
7254d8ad
Commit
7254d8ad
authored
Nov 17, 2021
by
liyanlin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
企业微信机器人接口
parent
d33fe141
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
115 additions
and
0 deletions
+115
-0
QYApi.java
src/main/java/com/bailuntec/api/wx/QYApi.java
+28
-0
QyMsgContent.java
src/main/java/com/bailuntec/api/wx/request/QyMsgContent.java
+87
-0
No files found.
src/main/java/com/bailuntec/api/wx/QYApi.java
0 → 100644
View file @
7254d8ad
package
com
.
bailuntec
.
api
.
wx
;
import
org.springframework.cloud.openfeign.FeignClient
;
import
org.springframework.http.MediaType
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
/**
* @Author: li.yanlin
* @Description: 企业微信接口
* @Date: Created in 2021-11-17
* @Modified by:
*/
@FeignClient
(
name
=
"qyApi"
,
url
=
"https://qyapi.weixin.qq.com"
)
public
interface
QYApi
{
/**
* 发送机器人消息
* 消息体构建 QyMsgContent ⬇
* @see com.bailuntec.api.wx.request.QyMsgContent
* @param key 机器人key
* @param msg 消息体
* @return
*/
@PostMapping
(
value
=
"/cgi-bin/webhook/send?key={key}"
,
consumes
=
MediaType
.
APPLICATION_JSON_VALUE
)
Void
send
(
@PathVariable
(
name
=
"key"
)
String
key
,
@RequestBody
String
msg
);
}
src/main/java/com/bailuntec/api/wx/request/QyMsgContent.java
0 → 100644
View file @
7254d8ad
package
com
.
bailuntec
.
api
.
wx
.
request
;
import
com.alibaba.fastjson.JSONObject
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
java.util.List
;
import
java.util.Map
;
/**
* @Author: li.yanlin
* @Description:
* @Date: Created in 2021-11-17
* @Modified by:
*/
@Slf4j
public
class
QyMsgContent
{
/**
* 普通消息体
*
* @param content 消息体
* @param mentioned_mobile_list @all,@单人需要手机号
* @return
*/
public
static
String
getTextContent
(
String
content
,
List
<
String
>
mentioned_mobile_list
)
{
assert
StringUtils
.
isNotBlank
(
content
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"msgtype"
,
"text"
);
JSONObject
contentObj
=
new
JSONObject
();
contentObj
.
put
(
"content"
,
content
);
if
(
mentioned_mobile_list
!=
null
)
contentObj
.
put
(
"mentioned_mobile_list"
,
mentioned_mobile_list
);
jsonObject
.
put
(
"text"
,
contentObj
);
return
jsonObject
.
toJSONString
();
}
/**
* markdown类型消息体,无法@用户
*
* @param content 消息主题
* @param typeMsgMap 消息内容item
* @return
*/
public
static
String
getMarkdownContent
(
String
content
,
Map
<
String
,
String
>
typeMsgMap
)
{
assert
StringUtils
.
isNotBlank
(
content
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"msgtype"
,
"markdown"
);
JSONObject
contentObj
=
new
JSONObject
();
StringBuilder
contentBuilder
=
new
StringBuilder
(
content
+
"\n"
);
if
(
typeMsgMap
!=
null
&&
!
typeMsgMap
.
isEmpty
())
{
typeMsgMap
.
forEach
((
type
,
msg
)
->
{
contentBuilder
.
append
(
">"
+
type
+
":"
+
msg
+
"\n"
);
});
}
contentObj
.
put
(
"content"
,
contentBuilder
.
toString
());
jsonObject
.
put
(
"markdown"
,
contentObj
);
log
.
info
(
jsonObject
.
toJSONString
());
return
jsonObject
.
toJSONString
();
}
public
static
String
getMarkdownContent
(
String
content
,
Map
<
String
,
String
>
typeMsgMap
,
Color
color
)
{
assert
StringUtils
.
isNotBlank
(
content
);
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"msgtype"
,
"markdown"
);
JSONObject
contentObj
=
new
JSONObject
();
StringBuilder
contentBuilder
=
new
StringBuilder
(
content
+
"\n"
);
if
(
typeMsgMap
!=
null
&&
!
typeMsgMap
.
isEmpty
())
{
typeMsgMap
.
forEach
((
type
,
msg
)
->
{
contentBuilder
.
append
(
">"
+
type
+
":<font color=\""
+
color
.
toString
()
+
"\">"
+
msg
+
"</font>\n"
);
});
}
contentObj
.
put
(
"content"
,
contentBuilder
.
toString
());
jsonObject
.
put
(
"markdown"
,
contentObj
);
log
.
info
(
jsonObject
.
toJSONString
());
return
jsonObject
.
toJSONString
();
}
public
static
enum
Color
{
info
,
//绿色
comment
,
//灰色
warning
//橙红色
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment