Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dd_school
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangqi
dd_school
Commits
a59aba76
Commit
a59aba76
authored
Aug 23, 2023
by
baochunxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#G:问题修复:新增推送模板模块
parent
ed2928a3
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
156 additions
and
29 deletions
+156
-29
core-common/src/main/java/com/core/domain/VerificationCodeParam.java
+1
-1
ruoyi-common/pom.xml
+4
-0
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
+36
-0
smart-campus/src/main/java/yangtz/cs/liu/campus/util/VxTemlateSendApi.java
+60
-0
smart-campus/src/main/java/yangtz/cs/liu/wechat/controller/api/VxTemlateController.java
+27
-10
smart-campus/src/main/java/yangtz/cs/liu/wechat/service/impl/api/WxApiServiceImpl.java
+11
-9
smart-campus/src/main/java/yangtz/cs/liu/wechat/service/impl/api/WxLoginServiceImpl.java
+2
-4
smart-campus/src/main/java/yangtz/cs/liu/wechat/utils/AccessTokenUtil.java
+10
-4
smart-campus/src/main/java/yangtz/cs/liu/wechat/utils/CheckUtil.java
+3
-0
smart-campus/src/main/java/yangtz/cs/liu/wechat/utils/SignUtil.java
+1
-0
smart-campus/src/main/resources/mapper/teacher/SchoolTeacherMapper.xml
+1
-1
No files found.
core-common/src/main/java/com/core/domain/VerificationCodeParam.java
View file @
a59aba76
...
@@ -19,7 +19,7 @@ public class VerificationCodeParam {
...
@@ -19,7 +19,7 @@ public class VerificationCodeParam {
/**
/**
* 业务参数
* 业务参数
*/
*/
private
Hash
Map
<
String
,
Object
>
map
;
private
Map
<
String
,
Object
>
map
;
...
...
ruoyi-common/pom.xml
View file @
a59aba76
...
@@ -171,6 +171,10 @@
...
@@ -171,6 +171,10 @@
<artifactId>
ant
</artifactId>
<artifactId>
ant
</artifactId>
<version>
1.10.5
</version>
<version>
1.10.5
</version>
</dependency>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
</dependencies>
</dependencies>
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/http/HttpUtils.java
View file @
a59aba76
package
com
.
ruoyi
.
common
.
utils
.
http
;
package
com
.
ruoyi
.
common
.
utils
.
http
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSONObject
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
...
@@ -17,6 +19,12 @@ import javax.net.ssl.SSLContext;
...
@@ -17,6 +19,12 @@ import javax.net.ssl.SSLContext;
import
javax.net.ssl.SSLSession
;
import
javax.net.ssl.SSLSession
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
javax.net.ssl.X509TrustManager
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.util.EntityUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.constant.Constants
;
...
@@ -189,6 +197,34 @@ public class HttpUtils
...
@@ -189,6 +197,34 @@ public class HttpUtils
return
result
.
toString
();
return
result
.
toString
();
}
}
public
static
String
sendJsonPost
(
String
url
,
JSONObject
param
)
{
JSONObject
result
=
new
JSONObject
();
//定义接收数据
HttpPost
httpPost
=
new
HttpPost
(
url
);
CloseableHttpClient
client
=
HttpClients
.
createDefault
();
//请求参数转JOSN字符串
StringEntity
entity
=
new
StringEntity
(
param
.
toString
(),
"UTF-8"
);
entity
.
setContentEncoding
(
"UTF-8"
);
entity
.
setContentType
(
"application/json"
);
httpPost
.
setEntity
(
entity
);
try
{
HttpResponse
response
=
client
.
execute
(
httpPost
);
if
(
response
.
getStatusLine
().
getStatusCode
()
==
200
)
{
result
=
JSON
.
parseObject
(
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
));
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
result
.
put
(
"error"
,
"连接错误!"
);
}
//关闭连接
try
{
client
.
close
();
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
getMessage
());
return
""
;
}
return
result
.
toString
();
}
public
static
String
sendSSLPost
(
String
url
,
String
param
)
public
static
String
sendSSLPost
(
String
url
,
String
param
)
{
{
StringBuilder
result
=
new
StringBuilder
();
StringBuilder
result
=
new
StringBuilder
();
...
...
smart-campus/src/main/java/yangtz/cs/liu/campus/util/VxTemlateSendApi.java
0 → 100644
View file @
a59aba76
package
yangtz
.
cs
.
liu
.
campus
.
util
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSONObject
;
import
com.core.domain.VerificationCodeParam
;
import
com.ruoyi.common.utils.http.HttpUtils
;
import
java.util.Date
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
yangtz.cs.liu.wechat.utils.CheckUtil
;
import
yangtz.cs.liu.wechat.controller.api.VxTemlateController
;
/**
* 调用模板发送信息
*/
@Service
public
class
VxTemlateSendApi
{
/**
* 发送模板信息
*/
/**
* 测试环境路径
*/
private
static
String
url
=
"http://urgb7d.natappfree.cc/houduan/vx/temlateses/sendTemlate"
;
/**
* 签名key
*/
private
static
String
ticketSecrets
=
"71_0xakqv3T3ORjyXPeP-s2rwRcAqDbMEmmmkfMQeeJJmXBM8g-W4p4oa5BKisL-FYVHMzLJLyzbhgFQUfOkBW8Ufr4SWTTgGpjGs-BmIi8V95ct5hAXtQ47xDetjoLSSiAFAXEE"
;
@Autowired
VxTemlateController
vxTemlateController
;
/**
*
* @param map
* toUserOpenId 微信用户id
* applyTime 申请时间
* remark 备注
* applyUser 用户名字
* content 内容
* first 标题
* @return
*/
private
static
String
sendVxTemlate
(
Map
<
String
,
Object
>
map
){
CheckUtil
checkUtil
=
new
CheckUtil
(
ticketSecrets
);
checkUtil
.
setMap
(
map
);
checkUtil
.
setValue
(
"timeStamp"
,
new
Date
().
getTime
()/
1000
);
VerificationCodeParam
verificationCodeParam
=
new
VerificationCodeParam
();
verificationCodeParam
.
setSign
(
checkUtil
.
makeSign
());
verificationCodeParam
.
setMap
(
map
);
verificationCodeParam
.
setTimeStamp
(
Long
.
valueOf
(
new
Date
().
getTime
()/
1000
));
String
jsonString
=
JSON
.
toJSONString
(
verificationCodeParam
);
JSONObject
jsonObject
=
JSONObject
.
parseObject
(
jsonString
);
String
post
=
HttpUtils
.
sendJsonPost
(
url
,
jsonObject
);
return
post
;
}
}
smart-campus/src/main/java/yangtz/cs/liu/wechat/controller/api/VxTemlateController.java
View file @
a59aba76
package
yangtz
.
cs
.
liu
.
wechat
.
controller
.
api
;
package
yangtz
.
cs
.
liu
.
wechat
.
controller
.
api
;
import
com.alibaba.fastjson2.JSON
;
import
com.alibaba.fastjson2.JSONObject
;
import
com.core.domain.VerificationCodeParam
;
import
com.core.domain.VerificationCodeParam
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
yangtz.cs.liu.campus.domain.temp.AuditoriumTemplate
;
import
yangtz.cs.liu.campus.domain.temp.AuditoriumTemplate
;
import
yangtz.cs.liu.wechat.service.api.IWxApiService
;
import
yangtz.cs.liu.wechat.service.api.IWxApiService
;
...
@@ -15,7 +22,8 @@ import yangtz.cs.liu.wechat.utils.TimestampUtil;
...
@@ -15,7 +22,8 @@ import yangtz.cs.liu.wechat.utils.TimestampUtil;
/**
/**
* 微信模板推送
* 微信模板推送
*/
*/
@RestController
(
"/vx/temlate"
)
@RestController
()
@RequestMapping
(
"/vx/temlateses"
)
public
class
VxTemlateController
{
public
class
VxTemlateController
{
@Autowired
@Autowired
...
@@ -31,7 +39,7 @@ public class VxTemlateController {
...
@@ -31,7 +39,7 @@ public class VxTemlateController {
* @return
* @return
*/
*/
@PostMapping
(
"/sendTemlate"
)
@PostMapping
(
"/sendTemlate"
)
private
AjaxResult
sendTemlate
(
VerificationCodeParam
param
){
private
AjaxResult
sendTemlate
(
@RequestBody
VerificationCodeParam
param
){
Boolean
flag
=
false
;
Boolean
flag
=
false
;
String
msg
=
""
;
String
msg
=
""
;
// 验证信息是否被篡改
// 验证信息是否被篡改
...
@@ -46,17 +54,26 @@ public class VxTemlateController {
...
@@ -46,17 +54,26 @@ public class VxTemlateController {
msg
=
"验证时间戳不合法"
;
msg
=
"验证时间戳不合法"
;
}
}
if
(
flag
){
if
(
flag
){
AjaxResult
.
error
(
msg
);
return
AjaxResult
.
error
(
msg
);
}
}
HashMap
<
String
,
Object
>
map
=
param
.
getMap
();
Map
<
String
,
Object
>
map
=
param
.
getMap
();
Date
date
=
null
;
String
applyTime
=
map
.
get
(
"applyTime"
).
toString
();
SimpleDateFormat
dateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
try
{
date
=
dateFormat
.
parse
(
applyTime
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
}
// 发送模板
// 发送模板
AuditoriumTemplate
auditoriumTemplate
=
new
AuditoriumTemplate
();
AuditoriumTemplate
auditoriumTemplate
=
new
AuditoriumTemplate
();
auditoriumTemplate
.
setApplyTime
(
(
Date
)
map
.
get
(
"applyTime"
)
);
auditoriumTemplate
.
setApplyTime
(
date
);
auditoriumTemplate
.
setRemark
(
map
.
get
(
"remark"
).
toString
());
auditoriumTemplate
.
setRemark
(
map
.
get
(
"remark"
).
toString
()
==
null
?
""
:
map
.
get
(
"remark"
).
toString
()
);
auditoriumTemplate
.
setContent
(
map
.
get
(
"content"
).
toString
());
auditoriumTemplate
.
setContent
(
map
.
get
(
"content"
).
toString
()
==
null
?
""
:
map
.
get
(
"content"
).
toString
()
);
auditoriumTemplate
.
setApplyUser
(
map
.
get
(
"applyUser"
).
toString
());
auditoriumTemplate
.
setApplyUser
(
map
.
get
(
"applyUser"
).
toString
()
==
null
?
""
:
map
.
get
(
"applyUser"
).
toString
()
);
auditoriumTemplate
.
setToUserOpenId
(
map
.
get
(
"toUserOpenId"
).
toString
());
auditoriumTemplate
.
setToUserOpenId
(
map
.
get
(
"toUserOpenId"
).
toString
()
==
null
?
""
:
map
.
get
(
"toUserOpenId"
).
toString
()
);
auditoriumTemplate
.
setFirst
(
map
.
get
(
"first"
).
toString
());
auditoriumTemplate
.
setFirst
(
map
.
get
(
"first"
).
toString
()
==
null
?
""
:
map
.
get
(
"first"
).
toString
()
);
String
s
=
iWxApiService
.
sendAuditoriumTemplate
(
auditoriumTemplate
);
String
s
=
iWxApiService
.
sendAuditoriumTemplate
(
auditoriumTemplate
);
return
AjaxResult
.
success
(
s
);
return
AjaxResult
.
success
(
s
);
}
}
...
...
smart-campus/src/main/java/yangtz/cs/liu/wechat/service/impl/api/WxApiServiceImpl.java
View file @
a59aba76
...
@@ -222,7 +222,7 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -222,7 +222,7 @@ public class WxApiServiceImpl implements IWxApiService {
msgTemplate
.
setTemplate_id
(
teacherLeaveTemplateId
);
msgTemplate
.
setTemplate_id
(
teacherLeaveTemplateId
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
t
emplate
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgT
emplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
...
@@ -250,7 +250,7 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -250,7 +250,7 @@ public class WxApiServiceImpl implements IWxApiService {
msgTemplate
.
setTemplate_id
(
leaveResultTemplateId
);
msgTemplate
.
setTemplate_id
(
leaveResultTemplateId
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
t
emplate
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgT
emplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
...
@@ -300,7 +300,7 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -300,7 +300,7 @@ public class WxApiServiceImpl implements IWxApiService {
msgTemplate
.
setTemplate_id
(
studentLeaveTemplateId
);
msgTemplate
.
setTemplate_id
(
studentLeaveTemplateId
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
t
emplate
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgT
emplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
...
@@ -331,7 +331,7 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -331,7 +331,7 @@ public class WxApiServiceImpl implements IWxApiService {
msgTemplate
.
setTemplate_id
(
purchaseTemplateId
);
msgTemplate
.
setTemplate_id
(
purchaseTemplateId
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
t
emplate
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgT
emplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
...
@@ -359,11 +359,13 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -359,11 +359,13 @@ public class WxApiServiceImpl implements IWxApiService {
MsgTemplate
msgTemplate
=
new
MsgTemplate
();
MsgTemplate
msgTemplate
=
new
MsgTemplate
();
msgTemplate
.
setData
(
data
);
msgTemplate
.
setData
(
data
);
msgTemplate
.
setTemplate_id
(
purchaseTemplateId
);
//正式
// msgTemplate.setTemplate_id(purchaseTemplateId);
//测试环境id
msgTemplate
.
setTemplate_id
(
"uR6Tta4qpv64ZGBByyjEkQ9N52HLMmNn9vHMESDdSF8"
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
template
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgTemplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
return
result
;
return
result
;
...
@@ -393,7 +395,7 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -393,7 +395,7 @@ public class WxApiServiceImpl implements IWxApiService {
msgTemplate
.
setTemplate_id
(
purchaseTemplateId
);
msgTemplate
.
setTemplate_id
(
purchaseTemplateId
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
t
emplate
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgT
emplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
...
@@ -425,7 +427,7 @@ public class WxApiServiceImpl implements IWxApiService {
...
@@ -425,7 +427,7 @@ public class WxApiServiceImpl implements IWxApiService {
msgTemplate
.
setTemplate_id
(
officialTemplateId
);
msgTemplate
.
setTemplate_id
(
officialTemplateId
);
// msgTemplate.setUrl("www.baidu.com");
// msgTemplate.setUrl("www.baidu.com");
msgTemplate
.
setTouser
(
toUserOpenId
);
msgTemplate
.
setTouser
(
toUserOpenId
);
String
jsonObject
=
JSONUtil
.
parseObj
(
t
emplate
).
toString
();
String
jsonObject
=
JSONUtil
.
parseObj
(
msgT
emplate
).
toString
();
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
sendUrl
=
"https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
+
accessToken
;
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
String
result
=
HttpUtils
.
sendPost
(
sendUrl
,
jsonObject
);
...
...
smart-campus/src/main/java/yangtz/cs/liu/wechat/service/impl/api/WxLoginServiceImpl.java
View file @
a59aba76
...
@@ -94,10 +94,8 @@ public class WxLoginServiceImpl implements IWxLoginService {
...
@@ -94,10 +94,8 @@ public class WxLoginServiceImpl implements IWxLoginService {
loginUser
.
setAvatar
(
user
.
getAvatar
());
loginUser
.
setAvatar
(
user
.
getAvatar
());
/** 更新老师openId */
/** 更新老师openId */
SchoolTeacher
teacher
=
new
SchoolTeacher
();
schoolTeacher
.
setOpenId
(
wxLoginBody
.
getOpenId
());
teacher
.
setId
(
schoolTeacher
.
getId
());
schoolTeacherMapper
.
updateById
(
schoolTeacher
);
teacher
.
setOpenId
(
wxLoginBody
.
getOpenId
());
schoolTeacherMapper
.
updateById
(
teacher
);
/** 更新用户表openId */
/** 更新用户表openId */
SysUser
sysUser
=
new
SysUser
();
SysUser
sysUser
=
new
SysUser
();
...
...
smart-campus/src/main/java/yangtz/cs/liu/wechat/utils/AccessTokenUtil.java
View file @
a59aba76
...
@@ -6,6 +6,9 @@ import cn.hutool.json.JSONUtil;
...
@@ -6,6 +6,9 @@ import cn.hutool.json.JSONUtil;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.core.redis.RedisCache
;
import
com.ruoyi.common.core.redis.RedisCache
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.http.HttpUtils
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
@@ -15,6 +18,7 @@ import org.springframework.data.redis.core.RedisTemplate;
...
@@ -15,6 +18,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
import
org.springframework.web.bind.annotation.GetMapping
;
/**
/**
* @author lyric
* @author lyric
...
@@ -37,18 +41,20 @@ public class AccessTokenUtil {
...
@@ -37,18 +41,20 @@ public class AccessTokenUtil {
String
token
=
redisCache
.
getCacheObject
(
ACCESS_TOKEN
);
String
token
=
redisCache
.
getCacheObject
(
ACCESS_TOKEN
);
if
(
StringUtils
.
isEmpty
(
token
))
{
if
(
StringUtils
.
isEmpty
(
token
))
{
try
{
try
{
String
url
=
accessTokenUri
;
//String url = accessTokenUri;
//测试环境
String
url
=
"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx765a55464b308d13&secret=aa6741b17f05203975b17f0a64458741"
;
// 利用hutool的http工具类请求获取access_token
// 利用hutool的http工具类请求获取access_token
String
result
=
HttpUtil
.
get
(
url
);
String
result
=
HttpUtil
.
get
(
url
);
// 将结果解析为json
// 将结果解析为json
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
result
);
JSONObject
jsonObject
=
JSONUtil
.
parseObj
(
result
);
// 获取access_token
// 获取access_token
String
accessToken
=
jsonObject
.
getStr
(
"access_token"
);
String
accessToken
=
(
String
)
jsonObject
.
get
(
"access_token"
);
if
(!
StringUtils
.
isEmpty
(
accessToken
))
{
if
(!
StringUtils
.
isEmpty
(
accessToken
))
{
token
=
accessToken
;
token
=
accessToken
;
log
.
info
(
accessToken
);
log
.
info
(
accessToken
);
// 将access_token存入redis
// 将access_token存入redis
redisCache
.
setCacheObject
(
"access_token"
,
accessToken
,
2
,
TimeUnit
.
HOUR
S
);
redisCache
.
setCacheObject
(
"access_token"
,
accessToken
,
5
,
TimeUnit
.
MINUTE
S
);
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
log
.
error
(
e
.
getMessage
(),
e
);
...
...
smart-campus/src/main/java/yangtz/cs/liu/wechat/utils/CheckUtil.java
View file @
a59aba76
...
@@ -23,6 +23,9 @@ public class CheckUtil {
...
@@ -23,6 +23,9 @@ public class CheckUtil {
public
void
setValue
(
String
key
,
Object
value
)
{
public
void
setValue
(
String
key
,
Object
value
)
{
map
.
put
(
key
,
value
);
map
.
put
(
key
,
value
);
}
}
public
void
setMap
(
Map
<
String
,
Object
>
maps
)
{
map
.
putAll
(
maps
);
}
/**
/**
* 检验签名是否正确
* 检验签名是否正确
...
...
smart-campus/src/main/java/yangtz/cs/liu/wechat/utils/SignUtil.java
View file @
a59aba76
...
@@ -8,6 +8,7 @@ public class SignUtil {
...
@@ -8,6 +8,7 @@ public class SignUtil {
public
static
boolean
validateMessage
(
VerificationCodeParam
param
,
String
secretKey
)
{
public
static
boolean
validateMessage
(
VerificationCodeParam
param
,
String
secretKey
)
{
CheckUtil
check
=
new
CheckUtil
(
secretKey
);
CheckUtil
check
=
new
CheckUtil
(
secretKey
);
check
.
setMap
(
param
.
getMap
());
check
.
setValue
(
"timeStamp"
,
param
.
getTimeStamp
());
check
.
setValue
(
"timeStamp"
,
param
.
getTimeStamp
());
boolean
result
=
check
.
checkSign
(
param
.
getSign
());
boolean
result
=
check
.
checkSign
(
param
.
getSign
());
return
result
;
return
result
;
...
...
smart-campus/src/main/resources/mapper/teacher/SchoolTeacherMapper.xml
View file @
a59aba76
...
@@ -201,7 +201,7 @@
...
@@ -201,7 +201,7 @@
<if
test=
"createTime != null"
>
create_time = #{createTime},
</if>
<if
test=
"createTime != null"
>
create_time = #{createTime},
</if>
<if
test=
"updateBy != null"
>
update_by = #{updateBy},
</if>
<if
test=
"updateBy != null"
>
update_by = #{updateBy},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime},
</if>
<if
test=
"updateTime != null"
>
update_time = #{updateTime},
</if>
<if
test=
"openId != null"
>
open_id = #{openId}
,
</if>
<if
test=
"openId != null"
>
open_id = #{openId}
</if>
</trim>
</trim>
where id = #{id}
where id = #{id}
</update>
</update>
...
...
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