Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
tianjin-cement
Project
Project
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
竹天卫
tianjin-cement
Commits
26c9d30e
Commit
26c9d30e
authored
Oct 27, 2020
by
竹天卫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
消息推送到企业微信中
parent
d97611b9
Show whitespace changes
Inline
Side-by-side
Showing
25 changed files
with
1109 additions
and
89 deletions
+1109
-89
pom.xml
cement-business/pom.xml
+10
-0
WeiXinController.java
.../wise/sc/cement/business/controller/WeiXinController.java
+20
-0
EntrustServiceImpl.java
...e/sc/cement/business/service/impl/EntrustServiceImpl.java
+59
-0
EquipmentServiceImpl.java
...sc/cement/business/service/impl/EquipmentServiceImpl.java
+3
-0
WeiXinService.java
...n/wise/sc/cement/business/service/impl/WeiXinService.java
+77
-17
AccessToken.java
...a/cn/wise/sc/cement/business/util/weixin/AccessToken.java
+30
-0
Global.java
...n/java/cn/wise/sc/cement/business/util/weixin/Global.java
+20
-1
MyX509TrustManager.java
...se/sc/cement/business/util/weixin/MyX509TrustManager.java
+24
-0
WeiXinUtil.java
...va/cn/wise/sc/cement/business/util/weixin/WeiXinUtil.java
+436
-0
WeixinInterfaceUtil.java
...e/sc/cement/business/util/weixin/WeixinInterfaceUtil.java
+0
-64
Article.java
.../sc/cement/business/util/weixin/message/send/Article.java
+43
-0
BaseMessage.java
...cement/business/util/weixin/message/send/BaseMessage.java
+56
-0
FileMessage.java
...cement/business/util/weixin/message/send/FileMessage.java
+30
-0
ImgMessage.java
.../cement/business/util/weixin/message/send/ImgMessage.java
+28
-0
Media.java
...se/sc/cement/business/util/weixin/message/send/Media.java
+21
-0
News.java
...ise/sc/cement/business/util/weixin/message/send/News.java
+23
-0
NewsMessage.java
...cement/business/util/weixin/message/send/NewsMessage.java
+23
-0
Text.java
...ise/sc/cement/business/util/weixin/message/send/Text.java
+22
-0
TextMessage.java
...cement/business/util/weixin/message/send/TextMessage.java
+30
-0
Textcard.java
...sc/cement/business/util/weixin/message/send/Textcard.java
+35
-0
TextcardMessage.java
...nt/business/util/weixin/message/send/TextcardMessage.java
+24
-0
Video.java
...se/sc/cement/business/util/weixin/message/send/Video.java
+36
-0
VideoMessage.java
...ement/business/util/weixin/message/send/VideoMessage.java
+27
-0
VoiceMessage.java
...ement/business/util/weixin/message/send/VoiceMessage.java
+30
-0
application.yml
cement-business/src/main/resources/application.yml
+2
-7
No files found.
cement-business/pom.xml
View file @
26c9d30e
...
...
@@ -129,6 +129,16 @@
<groupId>
com.google.zxing
</groupId>
<artifactId>
core
</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>
com.google.code.gson
</groupId>
<artifactId>
gson
</artifactId>
<version>
2.8.5
</version>
</dependency>
</dependencies>
<build>
...
...
cement-business/src/main/java/cn/wise/sc/cement/business/controller/WeiXinController.java
View file @
26c9d30e
...
...
@@ -123,4 +123,24 @@ public class WeiXinController {
String
s
=
new
String
(
tempArr
);
return
s
;
}
@ApiOperation
(
value
=
"发送消息"
)
@GetMapping
(
"/sendTextMessage"
)
public
BaseResponse
sendTextMessage
()
{
try
{
weiXinService
.
sendTextMessage
(
"1"
,
"hello"
);
return
BaseResponse
.
okData
(
"成功"
);
}
catch
(
Exception
e
)
{
log
.
debug
(
"发送消息{}"
,
e
);
}
return
BaseResponse
.
errorMsg
(
"失败!"
);
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/EntrustServiceImpl.java
View file @
26c9d30e
...
...
@@ -18,6 +18,7 @@ import cn.wise.sc.cement.business.util.CheckCountUtil;
import
cn.wise.sc.cement.business.util.ExcelUtil
;
import
cn.wise.sc.cement.business.util.PageUtil
;
import
cn.wise.sc.cement.business.util.RedisUtil
;
import
cn.wise.sc.cement.business.util.weixin.Global
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
...
...
@@ -111,6 +112,9 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
private
ClientMapper
clientMapper
;
@Autowired
private
ISysUserMessageService
userMessageService
;
@Autowired
private
WeiXinService
weiXinService
;
/**
* 委托分页
...
...
@@ -290,10 +294,21 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
if
(
approvalId
==
null
)
{
return
BaseResponse
.
errorMsg
(
"委托评审信息错误"
);
}
SysUser
approvalUser
=
userService
.
getById
(
approvalId
);
if
(
approvalUser
==
null
){
return
BaseResponse
.
errorMsg
(
"委托评审信息错误"
);
}
BaseResponse
wrapper
=
userMessageService
.
sendMessage
(
approvalId
,
"您有一条新的委托单申请等待评审"
,
entrust
.
getId
(),
SysUserMessage
.
MessageType
.
ENTRUST
);
if
(
wrapper
.
getCode
()
!=
200
){
return
wrapper
;
}
//发送企业微信消息内容
if
(
StringUtils
.
isNotBlank
(
approvalUser
.
getWxId
())){
String
content
=
"你好!"
+
loginUser
.
getName
()+
"向您申请了一条委托,请前往\n"
+
Global
.
systemUrl
+
"进行评审。"
;
weiXinService
.
sendTextMessage
(
approvalUser
.
getWxId
(),
content
);
}
return
BaseResponse
.
okData
(
entrust
);
}
...
...
@@ -882,6 +897,8 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
if
(
entrust
.
getStatus
()
!=
1
)
{
return
BaseResponse
.
errorMsg
(
"当前状态不允许样品处理"
);
}
String
userIds
=
""
;
List
<
Integer
>
userIdList
=
new
ArrayList
<>();
if
(
query
.
getSampleHandleQueryList
()
!=
null
&&
query
.
getSampleHandleQueryList
().
size
()
>
0
)
{
List
<
SampleHandleQuery
>
sampleHandleQueryList
=
query
.
getSampleHandleQueryList
();
for
(
SampleHandleQuery
sampleHandleQuery
:
sampleHandleQueryList
)
{
...
...
@@ -927,6 +944,15 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
if
(
wrapper
.
getCode
()
!=
200
){
return
wrapper
;
}
SysUser
handleUser
=
userService
.
getById
(
sampleHandle
.
getUserId
());
if
(
handleUser
==
null
){
return
BaseResponse
.
errorMsg
(
"样品处理人信息错误"
);
}
if
(
StringUtils
.
isNotBlank
(
handleUser
.
getWxId
())
&&
!
userIdList
.
contains
(
handleUser
.
getId
())){
userIdList
.
add
(
handleUser
.
getId
());
userIds
=
userIds
.
equals
(
""
)?
handleUser
.
getWxId
():
userIds
+
"|"
+
handleUser
.
getWxId
();
}
}
}
//委托表改成已发送样品处理,状态改为样品处理状态中
...
...
@@ -934,6 +960,10 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
.
setStatus
(
3
);
entrustMapper
.
updateById
(
entrust
);
logsService
.
saveLog
(
SysLogs
.
ObjType
.
ENTRUST_LOG
,
entrust
.
getId
(),
"发送样品处理任务"
,
null
);
//发送企业微信消息内容
String
content
=
"你好!您有一条新的样品处理任务,请前往\n"
+
Global
.
systemUrl
+
"进行接受。"
;
weiXinService
.
sendTextMessage
(
userIds
,
content
);
return
BaseResponse
.
okMsg
(
"已发送样品处理任务"
);
}
...
...
@@ -1251,6 +1281,8 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
if
(
entrust
.
getStatus
()
!=
4
)
{
return
BaseResponse
.
errorMsg
(
"当前状态不允许派发"
);
}
String
userIds
=
""
;
List
<
Integer
>
userIdList
=
new
ArrayList
<>();
if
(
query
.
getSampleDistributionQueryList
()
!=
null
&&
query
.
getSampleDistributionQueryList
().
size
()
>
0
)
{
List
<
SampleDistributionQuery
>
sampleDistributionQueryList
=
query
.
getSampleDistributionQueryList
();
List
<
SampleDistribution
>
sampleDistributionList
=
new
ArrayList
<>();
...
...
@@ -1282,6 +1314,14 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
if
(
wrapper
.
getCode
()
!=
200
){
return
wrapper
;
}
SysUser
distributionUser
=
userService
.
getById
(
distributionTeamQuery
.
getUserId
());
if
(
distributionUser
==
null
){
return
BaseResponse
.
errorMsg
(
"样品检测人信息错误"
);
}
if
(
StringUtils
.
isNotBlank
(
distributionUser
.
getWxId
())
&&
!
userIdList
.
contains
(
distributionUser
.
getId
())){
userIdList
.
add
(
distributionUser
.
getId
());
userIds
=
userIds
.
equals
(
""
)?
distributionUser
.
getWxId
():
userIds
+
"|"
+
distributionUser
.
getWxId
();
}
}
}
Sample
sample
=
sampleService
.
getById
(
distributionQuery
.
getSampleId
());
...
...
@@ -1297,6 +1337,10 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
entrust
.
setStatus
(
5
).
setIsDistribution
(
1
);
entrustMapper
.
updateById
(
entrust
);
logsService
.
saveLog
(
SysLogs
.
ObjType
.
ENTRUST_LOG
,
entrust
.
getId
(),
"派发检测项目任务"
,
null
);
//发送企业微信消息内容
String
content
=
"你好!您有一条新的样品检测任务,请前往\n"
+
Global
.
systemUrl
+
"进行接受。"
;
weiXinService
.
sendTextMessage
(
userIds
,
content
);
return
BaseResponse
.
okMsg
(
"已派发检测项目任务"
);
}
...
...
@@ -2076,6 +2120,21 @@ public class EntrustServiceImpl extends ServiceImpl<EntrustMapper, Entrust> impl
List
<
Sample
>
sampleNoCheckList
=
sampleMapper
.
getNoCheckList
(
entrust
.
getId
());
if
(
sampleNoCheckList
==
null
||
sampleNoCheckList
.
size
()
==
0
)
{
entrust
.
setStatus
(
8
);
//校核完成之后 ,提醒评审人员查看
Integer
approvalId
=
sysApprovalMapper
.
getApprovalId
(
"委托评审"
);
if
(
approvalId
==
null
)
{
return
BaseResponse
.
errorMsg
(
"委托评审信息错误"
);
}
SysUser
approvalUser
=
userService
.
getById
(
approvalId
);
if
(
approvalUser
==
null
){
return
BaseResponse
.
errorMsg
(
"委托评审信息错误"
);
}
//发送企业微信消息内容
if
(
StringUtils
.
isNotBlank
(
approvalUser
.
getWxId
())){
String
content
=
"你好!"
+
"委托单号"
+
entrust
.
getEntrustCode
()+
"已校核完成,请前往\n"
+
Global
.
systemUrl
+
"进行查看。"
;
weiXinService
.
sendTextMessage
(
approvalUser
.
getWxId
(),
content
);
}
}
entrustMapper
.
updateById
(
entrust
);
logsService
.
saveLog
(
SysLogs
.
ObjType
.
ENTRUST_LOG
,
entrust
.
getId
(),
"数据校核"
,
null
);
...
...
cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/EquipmentServiceImpl.java
View file @
26c9d30e
...
...
@@ -268,6 +268,9 @@ public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper, Equipment
return
BaseResponse
.
okData
(
"检定完成"
);
}
//TODO判断设备检定是否到期,如果到期,提醒检测人员
/**
* 设备检定分页查询
*
...
...
cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/WeiXinService.java
View file @
26c9d30e
...
...
@@ -8,29 +8,23 @@ import cn.wise.sc.cement.business.service.ISysUserService;
import
cn.wise.sc.cement.business.util.JwtUtil
;
import
cn.wise.sc.cement.business.util.RedisUtil
;
import
cn.wise.sc.cement.business.util.weixin.Global
;
import
cn.wise.sc.cement.business.util.weixin.WeiXinUtil
;
import
cn.wise.sc.cement.business.util.weixin.WeixinInterfaceUtil
;
import
cn.wise.sc.cement.business.wrapper.WrapMapper
;
import
cn.wise.sc.cement.business.wrapper.Wrapper
;
import
cn.wise.sc.cement.business.util.weixin.message.send.BaseMessage
;
import
cn.wise.sc.cement.business.util.weixin.message.send.Text
;
import
cn.wise.sc.cement.business.util.weixin.message.send.TextMessage
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.google.gson.Gson
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Map
;
@Service
public
class
WeiXinService
{
@Value
(
"${weixin.corpid}"
)
private
String
corpid
;
@Value
(
"${weixin.corpsecret}"
)
private
String
corpsecret
;
@Value
(
"${weixin.corpsecretPC}"
)
private
String
corpsecretPC
;
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
WeiXinService
.
class
);
@Autowired
private
ISysUserService
userService
;
@Autowired
...
...
@@ -53,7 +47,7 @@ public class WeiXinService {
System
.
out
.
println
(
"==================code==================="
);
System
.
out
.
println
(
code
);
try
{
String
accessToken
=
null
;
/*
String accessToken = null;
if (type.equals("PC")) {
accessToken = getAccessToken();
} else if (type.equals("APP")) {
...
...
@@ -70,10 +64,10 @@ public class WeiXinService {
String UserId = jsonObject.getString("UserId");
System.out.println("==================UserId===================");
System.out.println(UserId);
JSONObject
userJson
=
getUser
(
accessToken
,
UserId
);
JSONObject userJson = getUser(accessToken, UserId);
*/
QueryWrapper
<
SysUser
>
wrapper
=
new
QueryWrapper
<>();
wrapper
.
eq
(
"phone"
,
userJson
.
get
(
"mobile"
));
//
wrapper.eq("phone", code); //暂时用手机号代替code
//
wrapper.eq("phone", userJson.get("mobile"));
wrapper
.
eq
(
"phone"
,
code
);
//暂时用手机号代替code
SysUser
sysUser
=
userService
.
getOne
(
wrapper
);
if
(
sysUser
==
null
)
{
return
BaseResponse
.
errorMsg
(
"非系统用户不允许登录!"
);
...
...
@@ -89,6 +83,8 @@ public class WeiXinService {
sysUser
.
getName
(),
sysUser
.
getPhone
());
System
.
out
.
println
(
token
);
redisUtil
.
setString
(
sysUser
.
getId
().
toString
(),
token
,
3600
);
// sysUser.setWxId(UserId);
// userService.updateById(sysUser);
return
BaseResponse
.
okData
(
token
);
}
catch
(
Exception
e
)
{
return
BaseResponse
.
errorMsg
(
e
.
getMessage
());
...
...
@@ -110,7 +106,7 @@ public class WeiXinService {
if
(!
redisUtil
.
existsKey
(
ACCESS_TOKEN
))
{
String
param
=
"corpid=%s&corpsecret=%s"
;
param
=
String
.
format
(
param
,
corpid
,
corps
ecret
);
param
=
String
.
format
(
param
,
Global
.
corpId
,
Global
.
agentS
ecret
);
JSONObject
jsonObject
=
WeixinInterfaceUtil
.
doGet
(
Global
.
ACCESSTOKENURL
,
param
);
accessToken
=
jsonObject
.
getString
(
"access_token"
);
redisUtil
.
setString
(
ACCESS_TOKEN
,
accessToken
,
7100
);
...
...
@@ -174,4 +170,68 @@ public class WeiXinService {
}
/**
* 发送消息
* @param touser 指定接收消息的成员,成员ID列表(多个接收者用‘|’分隔,最多支持1000个)。
* 特殊情况:指定为”@all”,则向该企业应用的全部成员发送
* @param content 消息内容,最长不超过2048个字节,超过将截断(支持id转译)
*/
public
void
sendTextMessage
(
String
touser
,
String
content
){
//1.创建文本消息对象
TextMessage
message
=
new
TextMessage
();
//1.1非必需
message
.
setTouser
(
touser
);
//不区分大小写
//textMessage.setToparty("1");
//txtMsg.setTotag(totag);
//txtMsg.setSafe(0);
//1.2必需
message
.
setMsgtype
(
"text"
);
message
.
setAgentid
(
Global
.
agentId
);
Text
text
=
new
Text
();
text
.
setContent
(
content
);
message
.
setText
(
text
);
//2.获取access_token:根据企业id和通讯录密钥获取access_token,并拼接请求url
// String accessToken= WeiXinUtil.getAccessToken(corpid, WeiXinParamesUtil.agentSecret).getToken();
String
accessToken
=
getAccessToken
();
System
.
out
.
println
(
"accessToken:"
+
accessToken
);
//3.发送消息:调用业务类,发送消息
sendMessage
(
accessToken
,
message
);
}
/**
* @desc :0.公共方法:发送消息
*
* @param accessToken
* @param message void
*/
public
void
sendMessage
(
String
accessToken
,
BaseMessage
message
){
//1.获取json字符串:将message对象转换为json字符串
Gson
gson
=
new
Gson
();
String
jsonMessage
=
gson
.
toJson
(
message
);
//使用gson.toJson(user)即可将user对象顺序转成json
System
.
out
.
println
(
"jsonTextMessage:"
+
jsonMessage
);
//2.获取请求的url
String
url
=
Global
.
SENDMESSAGE
.
replace
(
"ACCESS_TOKEN"
,
accessToken
);
//3.调用接口,发送消息
JSONObject
jsonObject
=
WeiXinUtil
.
httpRequest
(
url
,
"POST"
,
jsonMessage
);
System
.
out
.
println
(
"jsonObject:"
+
jsonObject
.
toString
());
//4.错误消息处理
if
(
null
!=
jsonObject
)
{
if
(
0
!=
jsonObject
.
getInteger
(
"errcode"
))
{
log
.
error
(
"消息发送失败 errcode:{} errmsg:{}"
,
jsonObject
.
getInteger
(
"errcode"
),
jsonObject
.
getString
(
"errmsg"
));
}
}
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/AccessToken.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
;
/**
* @desc : 微信通用接口凭证
*
* @author: shirayner
* @date : 2017-8-20 下午9:35:11
*/
public
class
AccessToken
{
// 获取到的凭证
private
String
token
;
// 凭证有效时间,单位:秒
private
int
expiresIn
;
public
String
getToken
()
{
return
token
;
}
public
void
setToken
(
String
token
)
{
this
.
token
=
token
;
}
public
int
getExpiresIn
()
{
return
expiresIn
;
}
public
void
setExpiresIn
(
int
expiresIn
)
{
this
.
expiresIn
=
expiresIn
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/Global.java
View file @
26c9d30e
...
...
@@ -10,6 +10,23 @@ package cn.wise.sc.cement.business.util.weixin;
public
interface
Global
{
//企业应用的id,整型。可在应用的设置页面查看
public
final
static
int
agentId
=
1000002
;
//企业ID
public
final
static
String
corpId
=
"ww348f91b2573c1867"
;
//应用的凭证密钥
public
final
static
String
agentSecret
=
"gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o"
;
//编译后的回调地址
public
final
static
String
backUrl
=
"https%3a%2f%2fprogram.oxogroup.com%2flab-system"
;
//实验室管理系统链接
public
final
static
String
systemUrl
=
"<a href=\"+https://open.weixin.qq.com/connect/oauth2/authorize?appid="
+
corpId
+
"&redirect_uri="
+
backUrl
+
"%2f&response_type=code&scope=snsapi_base&state=#wechat_redirect\">天津院实验室管理系统</a>,"
;
//应用的凭证密钥PC
public
final
static
String
agentSecretPC
=
"itCLYcwl9ggA9VfZam_iz96Ikp9StDFfVr4Adb0yY7A"
;
/**
* 微信公众平台,获取AccessToken的接口地址,Https请求方式:GET
* 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=id&corpsecret=secrect
...
...
@@ -35,10 +52,12 @@ public interface Global {
* 微信公众平台,发送应用消息的接口地址,Https请求方式:GET
* 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN
*/
public
static
final
String
SENDMESSAGE
=
"https://qyapi.weixin.qq.com/cgi-bin/message/send"
;
public
static
final
String
SENDMESSAGE
=
"https://qyapi.weixin.qq.com/cgi-bin/message/send
?access_token=ACCESS_TOKEN
"
;
public
static
final
String
userTicket
=
"https://qyapi.weixin.qq.com/cgi-bin/ticket/get"
;
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/MyX509TrustManager.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
;
import
javax.net.ssl.X509TrustManager
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
/**
* 证书信任管理器(用于https请求)
*
* @author liufeng
* @date 2013-08-08
*/
public
class
MyX509TrustManager
implements
X509TrustManager
{
public
void
checkClientTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
}
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
}
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/WeiXinUtil.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
;
import
com.alibaba.fastjson.JSONException
;
import
com.alibaba.fastjson.JSONObject
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
javax.net.ssl.HttpsURLConnection
;
import
javax.net.ssl.SSLContext
;
import
javax.net.ssl.SSLSocketFactory
;
import
javax.net.ssl.TrustManager
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.*
;
import
java.net.ConnectException
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.Formatter
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
public
class
WeiXinUtil
{
private
static
Logger
log
=
LoggerFactory
.
getLogger
(
WeiXinUtil
.
class
);
//微信的请求url
//获取access_token的接口地址(GET) 限200(次/天)
public
final
static
String
access_token_url
=
"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpId}&corpsecret={corpsecret}"
;
//获取jsapi_ticket的接口地址(GET) 限200(次/天)
public
final
static
String
jsapi_ticket_url
=
"https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=ACCESSTOKEN"
;
@Value
(
"${weixin.corpid}"
)
private
String
corpid
;
@Value
(
"${weixin.corpsecret}"
)
private
String
corpsecret
;
/**
* 1.发起https请求并获取结果
*
* @param requestUrl 请求地址
* @param requestMethod 请求方式(GET、POST)
* @param outputStr 提交的数据
* @return JSONObject(通过JSONObject.get(key)的方式获取json对象的属性值)
*/
public
static
JSONObject
httpRequest
(
String
requestUrl
,
String
requestMethod
,
String
outputStr
)
{
JSONObject
jsonObject
=
null
;
StringBuffer
buffer
=
new
StringBuffer
();
try
{
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager
[]
tm
=
{
new
MyX509TrustManager
()
};
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"SSL"
,
"SunJSSE"
);
sslContext
.
init
(
null
,
tm
,
new
java
.
security
.
SecureRandom
());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory
ssf
=
sslContext
.
getSocketFactory
();
URL
url
=
new
URL
(
requestUrl
);
HttpsURLConnection
httpUrlConn
=
(
HttpsURLConnection
)
url
.
openConnection
();
httpUrlConn
.
setSSLSocketFactory
(
ssf
);
httpUrlConn
.
setDoOutput
(
true
);
httpUrlConn
.
setDoInput
(
true
);
httpUrlConn
.
setUseCaches
(
false
);
// 设置请求方式(GET/POST)
httpUrlConn
.
setRequestMethod
(
requestMethod
);
if
(
"GET"
.
equalsIgnoreCase
(
requestMethod
))
httpUrlConn
.
connect
();
// 当有数据需要提交时
if
(
null
!=
outputStr
)
{
OutputStream
outputStream
=
httpUrlConn
.
getOutputStream
();
// 注意编码格式,防止中文乱码
outputStream
.
write
(
outputStr
.
getBytes
(
"UTF-8"
));
outputStream
.
close
();
}
// 将返回的输入流转换成字符串
InputStream
inputStream
=
httpUrlConn
.
getInputStream
();
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"UTF-8"
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
str
=
null
;
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
bufferedReader
.
close
();
inputStreamReader
.
close
();
// 释放资源
inputStream
.
close
();
inputStream
=
null
;
httpUrlConn
.
disconnect
();
// jsonObject = JSONObject.fromObject(buffer.toString());
jsonObject
=
JSONObject
.
parseObject
(
buffer
.
toString
());
}
catch
(
ConnectException
ce
)
{
log
.
error
(
"Weixin server connection timed out."
);
}
catch
(
Exception
e
)
{
log
.
error
(
"https request error:{}"
,
e
);
}
return
jsonObject
;
}
/**
* 2.发送https请求之获取临时素材
* @param requestUrl
* @param savePath 文件的保存路径,此时还缺一个扩展名
* @return
* @throws Exception
*/
public
static
File
getFile
(
String
requestUrl
,
String
savePath
)
throws
Exception
{
//String path=System.getProperty("user.dir")+"/img//1.png";
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager
[]
tm
=
{
new
MyX509TrustManager
()
};
SSLContext
sslContext
=
SSLContext
.
getInstance
(
"SSL"
,
"SunJSSE"
);
sslContext
.
init
(
null
,
tm
,
new
java
.
security
.
SecureRandom
());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory
ssf
=
sslContext
.
getSocketFactory
();
URL
url
=
new
URL
(
requestUrl
);
HttpsURLConnection
httpUrlConn
=
(
HttpsURLConnection
)
url
.
openConnection
();
httpUrlConn
.
setSSLSocketFactory
(
ssf
);
httpUrlConn
.
setDoOutput
(
true
);
httpUrlConn
.
setDoInput
(
true
);
httpUrlConn
.
setUseCaches
(
false
);
// 设置请求方式(GET/POST)
httpUrlConn
.
setRequestMethod
(
"GET"
);
httpUrlConn
.
connect
();
//获取文件扩展名
String
ext
=
getExt
(
httpUrlConn
.
getContentType
());
savePath
=
savePath
+
ext
;
System
.
out
.
println
(
"savePath"
+
savePath
);
//下载文件到f文件
File
file
=
new
File
(
savePath
);
// 获取微信返回的输入流
InputStream
in
=
httpUrlConn
.
getInputStream
();
//输出流,将微信返回的输入流内容写到文件中
FileOutputStream
out
=
new
FileOutputStream
(
file
);
int
length
=
100
*
1024
;
byte
[]
byteBuffer
=
new
byte
[
length
];
//存储文件内容
int
byteread
=
0
;
int
bytesum
=
0
;
while
((
byteread
=
in
.
read
(
byteBuffer
))
!=
-
1
)
{
bytesum
+=
byteread
;
//字节数 文件大小
out
.
write
(
byteBuffer
,
0
,
byteread
);
}
System
.
out
.
println
(
"bytesum: "
+
bytesum
);
in
.
close
();
// 释放资源
out
.
close
();
in
=
null
;
out
=
null
;
httpUrlConn
.
disconnect
();
return
file
;
}
/**
* @desc :2.微信上传素材的请求方法
*
* @param requestUrl 微信上传临时素材的接口url
* @param file 要上传的文件
* @return String 上传成功后,微信服务器返回的消息
*/
public
static
String
httpRequest
(
String
requestUrl
,
File
file
)
{
StringBuffer
buffer
=
new
StringBuffer
();
try
{
//1.建立连接
URL
url
=
new
URL
(
requestUrl
);
HttpURLConnection
httpUrlConn
=
(
HttpURLConnection
)
url
.
openConnection
();
//打开链接
//1.1输入输出设置
httpUrlConn
.
setDoInput
(
true
);
httpUrlConn
.
setDoOutput
(
true
);
httpUrlConn
.
setUseCaches
(
false
);
// post方式不能使用缓存
//1.2设置请求头信息
httpUrlConn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
httpUrlConn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
//1.3设置边界
String
BOUNDARY
=
"----------"
+
System
.
currentTimeMillis
();
httpUrlConn
.
setRequestProperty
(
"Content-Type"
,
"multipart/form-data; boundary="
+
BOUNDARY
);
// 请求正文信息
// 第一部分:
//2.将文件头输出到微信服务器
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"--"
);
// 必须多两道线
sb
.
append
(
BOUNDARY
);
sb
.
append
(
"\r\n"
);
sb
.
append
(
"Content-Disposition: form-data;name=\"media\";filelength=\""
+
file
.
length
()
+
"\";filename=\""
+
file
.
getName
()
+
"\"\r\n"
);
sb
.
append
(
"Content-Type:application/octet-stream\r\n\r\n"
);
byte
[]
head
=
sb
.
toString
().
getBytes
(
"utf-8"
);
// 获得输出流
OutputStream
outputStream
=
new
DataOutputStream
(
httpUrlConn
.
getOutputStream
());
// 将表头写入输出流中:输出表头
outputStream
.
write
(
head
);
//3.将文件正文部分输出到微信服务器
// 把文件以流文件的方式 写入到微信服务器中
DataInputStream
in
=
new
DataInputStream
(
new
FileInputStream
(
file
));
int
bytes
=
0
;
byte
[]
bufferOut
=
new
byte
[
1024
];
while
((
bytes
=
in
.
read
(
bufferOut
))
!=
-
1
)
{
outputStream
.
write
(
bufferOut
,
0
,
bytes
);
}
in
.
close
();
//4.将结尾部分输出到微信服务器
byte
[]
foot
=
(
"\r\n--"
+
BOUNDARY
+
"--\r\n"
).
getBytes
(
"utf-8"
);
// 定义最后数据分隔线
outputStream
.
write
(
foot
);
outputStream
.
flush
();
outputStream
.
close
();
//5.将微信服务器返回的输入流转换成字符串
InputStream
inputStream
=
httpUrlConn
.
getInputStream
();
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"utf-8"
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
str
=
null
;
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
bufferedReader
.
close
();
inputStreamReader
.
close
();
// 释放资源
inputStream
.
close
();
inputStream
=
null
;
httpUrlConn
.
disconnect
();
}
catch
(
IOException
e
)
{
System
.
out
.
println
(
"发送POST请求出现异常!"
+
e
);
e
.
printStackTrace
();
}
return
buffer
.
toString
();
}
/**
* 2.发起http请求获取返回结果
*
* @param requestUrl 请求地址
* @return
*/
public
static
String
httpRequest
(
String
requestUrl
)
{
StringBuffer
buffer
=
new
StringBuffer
();
try
{
URL
url
=
new
URL
(
requestUrl
);
HttpURLConnection
httpUrlConn
=
(
HttpURLConnection
)
url
.
openConnection
();
httpUrlConn
.
setDoOutput
(
false
);
httpUrlConn
.
setDoInput
(
true
);
httpUrlConn
.
setUseCaches
(
false
);
httpUrlConn
.
setRequestMethod
(
"GET"
);
httpUrlConn
.
connect
();
// 将返回的输入流转换成字符串
InputStream
inputStream
=
httpUrlConn
.
getInputStream
();
//InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
str
=
null
;
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
bufferedReader
.
close
();
inputStreamReader
.
close
();
// 释放资源
inputStream
.
close
();
inputStream
=
null
;
httpUrlConn
.
disconnect
();
}
catch
(
Exception
e
)
{
}
return
buffer
.
toString
();
}
/**
* 3.获取access_token
*
* @param appid 凭证
* @param appsecret 密钥
* @return
*/
public
static
AccessToken
getAccessToken
(
String
appid
,
String
appsecret
)
{
AccessToken
accessToken
=
null
;
String
requestUrl
=
access_token_url
.
replace
(
"{corpId}"
,
appid
).
replace
(
"{corpsecret}"
,
appsecret
);
JSONObject
jsonObject
=
httpRequest
(
requestUrl
,
"GET"
,
null
);
// 如果请求成功
if
(
null
!=
jsonObject
)
{
try
{
accessToken
=
new
AccessToken
();
accessToken
.
setToken
(
jsonObject
.
getString
(
"access_token"
));
accessToken
.
setExpiresIn
(
jsonObject
.
getInteger
(
"expires_in"
));
}
catch
(
JSONException
e
)
{
accessToken
=
null
;
// 获取token失败
log
.
error
(
"获取token失败 errcode:{} errmsg:{}"
,
jsonObject
.
getInteger
(
"errcode"
),
jsonObject
.
getString
(
"errmsg"
));
}
}
return
accessToken
;
}
/**
* 4. 获取JsapiTicket
* @param accessToken
* @return
*/
public
static
String
getJsapiTicket
(
String
accessToken
){
String
requestUrl
=
jsapi_ticket_url
.
replace
(
"ACCESSTOKEN"
,
accessToken
);
JSONObject
jsonObject
=
httpRequest
(
requestUrl
,
"GET"
,
null
);
String
jsapi_ticket
=
""
;
// 如果请求成功
if
(
null
!=
jsonObject
)
{
try
{
jsapi_ticket
=
jsonObject
.
getString
(
"ticket"
);
}
catch
(
JSONException
e
)
{
// 获取token失败
log
.
error
(
"获取token失败 errcode:{} errmsg:{}"
,
jsonObject
.
getInteger
(
"errcode"
),
jsonObject
.
getString
(
"errmsg"
));
}
}
return
jsapi_ticket
;
}
/**
* 3.获取企业微信的JSSDK配置信息
* @param request
* @return
*/
public
static
Map
<
String
,
Object
>
getWxConfig
(
HttpServletRequest
request
)
{
Map
<
String
,
Object
>
ret
=
new
HashMap
<
String
,
Object
>();
//1.准备好参与签名的字段
String
nonceStr
=
UUID
.
randomUUID
().
toString
();
// 必填,生成签名的随机串
//System.out.println("nonceStr:"+nonceStr);
String
accessToken
=
WeiXinUtil
.
getAccessToken
(
Global
.
corpId
,
Global
.
agentSecret
).
getToken
();
String
jsapi_ticket
=
getJsapiTicket
(
accessToken
);
// 必填,生成签名的H5应用调用企业微信JS接口的临时票据
//System.out.println("jsapi_ticket:"+jsapi_ticket);
String
timestamp
=
Long
.
toString
(
System
.
currentTimeMillis
()
/
1000
);
// 必填,生成签名的时间戳
//System.out.println("timestamp:"+timestamp);
String
url
=
request
.
getRequestURL
().
toString
();
//System.out.println("url:"+url);
//2.字典序 ,注意这里参数名必须全部小写,且必须有序
String
sign
=
"jsapi_ticket="
+
jsapi_ticket
+
"&noncestr="
+
nonceStr
+
"×tamp="
+
timestamp
+
"&url="
+
url
;
//3.sha1签名
String
signature
=
""
;
try
{
MessageDigest
crypt
=
MessageDigest
.
getInstance
(
"SHA-1"
);
crypt
.
reset
();
crypt
.
update
(
sign
.
getBytes
(
"UTF-8"
));
signature
=
byteToHex
(
crypt
.
digest
());
//System.out.println("signature:"+signature);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
ret
.
put
(
"appId"
,
Global
.
corpId
);
ret
.
put
(
"timestamp"
,
timestamp
);
ret
.
put
(
"nonceStr"
,
nonceStr
);
ret
.
put
(
"signature"
,
signature
);
return
ret
;
}
/**
* 方法名:byteToHex</br>
* 详述:字符串加密辅助方法 </br>
* 开发人员:souvc </br>
* 创建时间:2016-1-5 </br>
* @param hash
* @return 说明返回值含义
* @throws
*
*/
private
static
String
byteToHex
(
final
byte
[]
hash
)
{
Formatter
formatter
=
new
Formatter
();
for
(
byte
b
:
hash
)
{
formatter
.
format
(
"%02x"
,
b
);
}
String
result
=
formatter
.
toString
();
formatter
.
close
();
return
result
;
}
private
static
String
getExt
(
String
contentType
){
if
(
"image/jpeg"
.
equals
(
contentType
)){
return
".jpg"
;
}
else
if
(
"image/png"
.
equals
(
contentType
)){
return
".png"
;
}
else
if
(
"image/gif"
.
equals
(
contentType
)){
return
".gif"
;
}
return
null
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/WeixinInterfaceUtil.java
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
;
import
cn.wise.sc.cement.business.model.ResultVO
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.http.*
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.web.client.RestTemplate
;
import
java.util.*
;
...
...
@@ -16,16 +13,6 @@ import java.util.*;
*/
public
class
WeixinInterfaceUtil
{
private
static
final
String
HOST
=
"https://ydd.whlyj.sh.gov.cn/"
;
//服务器IP与端口
private
static
final
String
APPID
=
"DSACTSYS"
;
private
static
final
String
APPSECRET
=
"uzRpwnG6USeZDR0C"
;
// private static final Long TIMESTAMP = System.currentTimeMillis();
private
static
final
String
NONCE
=
UUID
.
randomUUID
().
toString
();
public
static
void
main
(
String
[]
args
){
String
param
=
"corpid=%s&corpsecret=%s"
;
param
=
String
.
format
(
param
,
"ww348f91b2573c1867"
,
"gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o"
);
...
...
@@ -37,7 +24,6 @@ public class WeixinInterfaceUtil {
e
.
printStackTrace
();
}
}
public
static
JSONObject
doGet
(
String
url
,
String
param
)
{
...
...
@@ -47,55 +33,5 @@ public class WeixinInterfaceUtil {
return
resultMap
;
}
/**
* 向目的URL发送post请求
* @param url 目的url
* @param params 发送的参数
* @return ResultVO
*/
public
static
ResultVO
sendPostRequest
(
String
url
,
MultiValueMap
<
String
,
String
>
params
){
RestTemplate
client
=
new
RestTemplate
();
HttpHeaders
headers
=
new
HttpHeaders
();
HttpMethod
method
=
HttpMethod
.
POST
;
// 以表单的方式提交
headers
.
setContentType
(
MediaType
.
APPLICATION_FORM_URLENCODED
);
//将请求头部和参数合成一个请求
HttpEntity
<
MultiValueMap
<
String
,
String
>>
requestEntity
=
new
HttpEntity
<>(
params
,
headers
);
//执行HTTP请求,将返回的结构使用ResultVO类格式化
ResponseEntity
<
ResultVO
>
response
=
client
.
exchange
(
url
,
method
,
requestEntity
,
ResultVO
.
class
);
return
response
.
getBody
();
}
/**
* 将请求参数放到map里,
* 按照字母请求参数名的字母升序排列非空请求参数(包含 appid)
* @param sortedParams
* @return
*/
private
static
String
getSignContent
(
Map
<
String
,
String
>
sortedParams
)
{
System
.
out
.
println
(
"signData = "
+
JSON
.
toJSONString
(
sortedParams
));
Set
<
String
>
keySet
=
sortedParams
.
keySet
();
StringBuffer
content
=
new
StringBuffer
();
List
<
String
>
keys
=
new
ArrayList
<
String
>();
for
(
String
key
:
keySet
)
{
keys
.
add
(
key
);
}
Collections
.
sort
(
keys
);
int
index
=
0
;
for
(
int
i
=
0
;
i
<
keys
.
size
();
i
++)
{
String
key
=
keys
.
get
(
i
);
String
value
=
sortedParams
.
get
(
key
);
if
(
StringUtils
.
isNotEmpty
(
key
)
&&
StringUtils
.
isNotEmpty
(
value
))
{
content
.
append
((
index
==
0
?
""
:
"&"
)
+
key
+
"="
+
value
);
index
++;
}
}
return
content
.
toString
();
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/Article.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 文章
* @author shirayner
*
*/
public
class
Article
{
//是 标题,不超过128个字节,超过会自动截断
private
String
title
;
//否 描述,不超过512个字节,超过会自动截断
private
String
description
;
//是 点击后跳转的链接。
private
String
url
;
//否 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图640320,小图8080。
private
String
picurl
;
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getPicurl
()
{
return
picurl
;
}
public
void
setPicurl
(
String
picurl
)
{
this
.
picurl
=
picurl
;
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/BaseMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 消息基类(企业号 -> 普通用户)
* @author shirayner
*
*/
public
class
BaseMessage
{
// 否 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all,则向该企业应用的全部成员发送
private
String
touser
;
// 否 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
private
String
toparty
;
// 否 标签ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数
private
String
totag
;
// 是 消息类型
private
String
msgtype
;
// 是 企业应用的id,整型。可在应用的设置页面查看
private
int
agentid
;
public
String
getTouser
()
{
return
touser
;
}
public
void
setTouser
(
String
touser
)
{
this
.
touser
=
touser
;
}
public
String
getToparty
()
{
return
toparty
;
}
public
void
setToparty
(
String
toparty
)
{
this
.
toparty
=
toparty
;
}
public
String
getTotag
()
{
return
totag
;
}
public
void
setTotag
(
String
totag
)
{
this
.
totag
=
totag
;
}
public
String
getMsgtype
()
{
return
msgtype
;
}
public
void
setMsgtype
(
String
msgtype
)
{
this
.
msgtype
=
msgtype
;
}
public
int
getAgentid
()
{
return
agentid
;
}
public
void
setAgentid
(
int
agentid
)
{
this
.
agentid
=
agentid
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/FileMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 文件消息
* @author shirayner
*
*/
public
class
FileMessage
extends
BaseMessage
{
//文件
private
Media
file
;
//否 表示是否是保密消息,0表示否,1表示是,默认0
private
int
safe
;
public
Media
getFile
()
{
return
file
;
}
public
void
setFile
(
Media
file
)
{
this
.
file
=
file
;
}
public
int
getSafe
()
{
return
safe
;
}
public
void
setSafe
(
int
safe
)
{
this
.
safe
=
safe
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/ImgMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 图片消息
* @author shirayner
*
*/
public
class
ImgMessage
extends
BaseMessage
{
//图片
private
Media
image
;
//否 表示是否是保密消息,0表示否,1表示是,默认0
private
int
safe
;
public
Media
getImage
()
{
return
image
;
}
public
void
setImage
(
Media
image
)
{
this
.
image
=
image
;
}
public
int
getSafe
()
{
return
safe
;
}
public
void
setSafe
(
int
safe
)
{
this
.
safe
=
safe
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/Media.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 图片、语音、文件
* @author shirayner
*
*/
public
class
Media
{
//是 图片/语音/文件 媒体文件id,可以调用上传临时素材接口获取
private
String
media_id
;
public
String
getMedia_id
()
{
return
media_id
;
}
public
void
setMedia_id
(
String
media_id
)
{
this
.
media_id
=
media_id
;
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/News.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
import
java.util.List
;
/**
* 图文
* @author shirayner
*
*/
public
class
News
{
//文章列表
private
List
<
Article
>
articles
;
public
List
<
Article
>
getArticles
()
{
return
articles
;
}
public
void
setArticles
(
List
<
Article
>
articles
)
{
this
.
articles
=
articles
;
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/NewsMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 图文消息
* @author shirayner
*
*/
public
class
NewsMessage
extends
BaseMessage
{
//图文
private
News
news
;
public
News
getNews
()
{
return
news
;
}
public
void
setNews
(
News
news
)
{
this
.
news
=
news
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/Text.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 文本
* @author shirayner
*
*/
public
class
Text
{
//是 消息内容,最长不超过2048个字节
private
String
content
;
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/TextMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 文本消息
* @author shirayner
*
*/
public
class
TextMessage
extends
BaseMessage
{
//文本
private
Text
text
;
//否 表示是否是保密消息,0表示否,1表示是,默认0
private
int
safe
;
public
Text
getText
()
{
return
text
;
}
public
void
setText
(
Text
text
)
{
this
.
text
=
text
;
}
public
int
getSafe
()
{
return
safe
;
}
public
void
setSafe
(
int
safe
)
{
this
.
safe
=
safe
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/Textcard.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 文本卡片
* @author shirayner
*
*/
public
class
Textcard
{
//是 标题,不超过128个字节,超过会自动截断
private
String
title
;
//是 描述,不超过512个字节,超过会自动截断
private
String
description
;
//是 点击后跳转的链接。
private
String
url
;
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
public
String
getUrl
()
{
return
url
;
}
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/TextcardMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 文本卡片消息
* @author shirayner
*
*/
public
class
TextcardMessage
extends
BaseMessage
{
//文本
private
Textcard
textcard
;
//btntxt 否 按钮文字。 默认为“详情”, 不超过4个文字,超过自动截断。
public
Textcard
getTextcard
()
{
return
textcard
;
}
public
void
setTextcard
(
Textcard
textcard
)
{
this
.
textcard
=
textcard
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/Video.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 视频
* @author shirayner
*
*/
public
class
Video
{
//是 视频媒体文件id,可以调用上传临时素材接口获取
private
String
media_id
;
//否 视频消息的标题,不超过128个字节,超过会自动截断
private
String
title
;
//否 视频消息的描述,不超过512个字节,超过会自动截断
private
String
description
;
public
String
getMedia_id
()
{
return
media_id
;
}
public
void
setMedia_id
(
String
media_id
)
{
this
.
media_id
=
media_id
;
}
public
String
getTitle
()
{
return
title
;
}
public
void
setTitle
(
String
title
)
{
this
.
title
=
title
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
description
)
{
this
.
description
=
description
;
}
}
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/VideoMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 视频消息
* @author shirayner
*
*/
public
class
VideoMessage
extends
BaseMessage
{
//视频
private
Video
video
;
//否 表示是否是保密消息,0表示否,1表示是,默认0
private
int
safe
;
public
Video
getVideo
()
{
return
video
;
}
public
void
setVideo
(
Video
video
)
{
this
.
video
=
video
;
}
public
int
getSafe
()
{
return
safe
;
}
public
void
setSafe
(
int
safe
)
{
this
.
safe
=
safe
;
}
}
\ No newline at end of file
cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/message/send/VoiceMessage.java
0 → 100644
View file @
26c9d30e
package
cn
.
wise
.
sc
.
cement
.
business
.
util
.
weixin
.
message
.
send
;
/**
* 语音消息
* @author shirayner
*
*/
public
class
VoiceMessage
extends
BaseMessage
{
//语音
private
Media
voice
;
//否 表示是否是保密消息,0表示否,1表示是,默认0
private
int
safe
;
public
Media
getVoice
()
{
return
voice
;
}
public
void
setVoice
(
Media
voice
)
{
this
.
voice
=
voice
;
}
public
int
getSafe
()
{
return
safe
;
}
public
void
setSafe
(
int
safe
)
{
this
.
safe
=
safe
;
}
}
\ No newline at end of file
cement-business/src/main/resources/application.yml
View file @
26c9d30e
...
...
@@ -7,8 +7,8 @@ spring:
active
:
dev
datasource
:
# 192.168.110.85 admin!@#123
url
:
jdbc:mysql://192.168.110.85:3306/sinoma_tcdri?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
#
url: jdbc:mysql://81.68.92.175:3306/sinoma_tcdri?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
#
url: jdbc:mysql://192.168.110.85:3306/sinoma_tcdri?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
url
:
jdbc:mysql://81.68.92.175:3306/sinoma_tcdri?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=UTF-8&useSSL=false
username
:
root
password
:
admin!@#123
driverClassName
:
com.mysql.cj.jdbc.Driver
...
...
@@ -37,8 +37,3 @@ mybatis-plus:
check-config-location
:
true
type-aliases-package
:
cn.wise.sc.cement.business.entity.**
mapper-locations
:
classpath:/cn/wise/sc/cement/business/mapper/xml/*Mapper.xml
weixin
:
corpsecret
:
gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o
corpsecretPC
:
itCLYcwl9ggA9VfZam_iz96Ikp9StDFfVr4Adb0yY7A
corpid
:
ww348f91b2573c1867
\ No newline at end of file
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