SpringBoot对接企业微信推送消息
1.使用到的技术
- spring boot
- mongodb
- redis
- rabbitmq
2.系统流程
start=>start: 消息
push=>operation: 通过api推送
save=>operation: 保存到mongodb
get=>operation: 定时任务获取消息推送到消息队列
send=>operation: 推送消息
isSend=>condition: 是否成功?
end=>end: 结束
start->push->save->get->send->isSend
isSend(yes)->end
isSend(no)->send
3.配置说明
application.properties
server.port = 18888
# mongodb
spring.data.mongodb.database=logistics
spring.data.mongodb.host=ip
spring.data.mongodb.port=27017
spring.data.mongodb.repositories.enabled=true
spring.data.mongodb.username=logistics
spring.data.mongodb.password=123456
#rebbitmq
spring.rabbitmq.host=ip
spring.rabbitmq.port=5672
spring.rabbitmq.username=logistics
spring.rabbitmq.password=logistics
spring.rabbitmq.publisher-confirm-type=CORRELATED
spring.rabbitmq.publisher-returns=true
spring.rabbitmq.template.mandatory=true
spring.rabbitmq.listener.simple.acknowledge-mode=AUTO
spring.rabbitmq.listener.simple.concurrency=1
spring.rabbitmq.listener.simple.max-concurrency=10
spring.rabbitmq.listener.simple.prefetch=3
spring.mvc.throw-exception-if-no-handler-found=true
spring.web.resources.add-mappings=false
#logging.level.org.springframework.data.mongodb.core= DEBUG
#redis
spring.redis.host=ip
spring.redis.password=123456
# Redis数据库索引(默认为0)
spring.redis.database=0
# Redis服务器连接端口
spring.redis.port=6379
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.jedis.pool.max-active=20
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.jedis.pool.max-wait=-1
# 连接池中的最大空闲连接
spring.redis.jedis.pool.max-idle=10
# 连接池中的最小空闲连接
spring.redis.jedis.pool.min-idle=0
# 连接超时时间(毫秒)
spring.redis.timeout=1000
#appList
#企业微信公司id
app.corpid=
#企业微信应用id
app.image.agentid=
#企业微信应用密钥
app.image.corpsecret=
4.多应用配置
#appList
#企业微信公司id
app.corpid=
#企业微信应用id
app.image.agentid=
#企业微信应用密钥
app.image.corpsecret=
app.order.agentid=
app.order.corpsecret=
app.product.agentid=
app.product.corpsecret=
app.image/app.order/app.product 会添加在消息里面已区分应用
5.发送消息格式
推送文本消息
{
"app": "app.image",
"duplicate_check_interval": 0,
"enable_duplicate_check": 0,
"enable_id_trans": 0,
"messageId": "",
"msgtype": "text",
"safe": 0,
"status": 0,
"text": {
"content": "string"
},
"toparty": [
""
],
"totag": [
""
],
"touser": [
""
]
}
推送素材消息
{
"app": "app.image",
"duplicate_check_interval": 0,
"enable_duplicate_check": 0,
"enable_id_trans": 0,
"file": {
"description": "string",
"fileContent": "ZGIuY3JlYXRlVXNlcigNCiAgew0KICAgIHVzZXI6ICJsb2dpc3RpY3MiLA0KICAgIHB3ZDogIjEyMzQ1NiIsDQogICAgcm9sZXM6IFsgeyByb2xlOiAidXNlckFkbWluQW55RGF0YWJhc2UiLCBkYjogImxvZ2lzdGljcyIgfSwgInJlYWRXcml0ZUFueURhdGFiYXNlIiBdDQogIH0NCiApDQoNCmRiLmNyZWF0ZVVzZXIoDQogIHsNCiAgICB1c2VyOiAicm9vdCIsDQogICAgcHdkOiAiMTIzNDU2IiwNCiAgICByb2xlczogWyB7IHJvbGU6ICJyb290IiwgZGI6ICJhZG1pbiIgfSBdDQogIH0NCiApDQoNCmRiLmNyZWF0ZVVzZXIoDQogIHsNCiAgICB1c2VyOiAibG9naXN0aWNzIiwNCiAgICBwd2Q6ICIxMjM0NTYiLA0KICAgIHJvbGVzOiBbIHsgcm9sZTogImRiT3duZXIiLCBkYjogImxvZ2lzdGljcyIgfSBdDQogIH0NCiAp",
"title": "string",
"fileExt":".txt"
},
"messageId": "string",
"msgtype": "file",
"safe": 0,
"status": 0,
"toparty": [
],
"totag": [
],
"touser": [
""
]
}