Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
I
ims-ci-test
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
test-ci
ims-ci-test
Commits
1171fd8b
提交
1171fd8b
authored
7月 13, 2023
作者:
xiaowang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
消息推送token验证
上级
26e06f54
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
114 行增加
和
1 行删除
+114
-1
WXMsgPushUtils.java
.../main/java/com/mmc/csf/common/util/wx/WXMsgPushUtils.java
+48
-0
WxApiController.java
.../java/com/mmc/csf/release/controller/WxApiController.java
+34
-0
WxApiService.java
...c/main/java/com/mmc/csf/release/service/WxApiService.java
+6
-1
WxApiServiceImpl.java
...va/com/mmc/csf/release/service/impl/WxApiServiceImpl.java
+25
-0
not-check.yml
release-service/src/main/resources/not-check.yml
+1
-0
没有找到文件。
csf-common/csf-common-util/src/main/java/com/mmc/csf/common/util/wx/WXMsgPushUtils.java
0 → 100644
浏览文件 @
1171fd8b
package
com
.
mmc
.
csf
.
common
.
util
.
wx
;
import
java.security.MessageDigest
;
import
java.util.Arrays
;
public
class
WXMsgPushUtils
{
/**
* 用SHA1算法生成安全签名
*/
public
static
String
getSHA1
(
String
...
values
)
throws
Exception
{
try
{
String
[]
array
=
new
String
[
values
.
length
];
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
array
[
i
]
=
values
[
i
];
}
StringBuffer
sb
=
new
StringBuffer
();
// 字符串排序
Arrays
.
sort
(
array
);
for
(
int
i
=
0
;
i
<
values
.
length
;
i
++)
{
sb
.
append
(
array
[
i
]);
}
String
str
=
sb
.
toString
();
// SHA1签名生成
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-1"
);
md
.
update
(
str
.
getBytes
());
byte
[]
digest
=
md
.
digest
();
StringBuffer
hexstr
=
new
StringBuffer
();
String
shaHex
=
""
;
for
(
int
i
=
0
;
i
<
digest
.
length
;
i
++)
{
shaHex
=
Integer
.
toHexString
(
digest
[
i
]
&
0xFF
);
if
(
shaHex
.
length
()
<
2
)
{
hexstr
.
append
(
0
);
}
hexstr
.
append
(
shaHex
);
}
return
hexstr
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
Exception
(
"SHA1加密失败"
);
}
}
}
\ No newline at end of file
release-service/src/main/java/com/mmc/csf/release/controller/WxApiController.java
0 → 100644
浏览文件 @
1171fd8b
package
com
.
mmc
.
csf
.
release
.
controller
;
import
com.mmc.csf.release.service.WxApiService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.annotation.Resource
;
import
java.util.Map
;
/**
* @Author LW
* @date 2023/7/12 17:32
* 概要:
*/
@Api
(
tags
=
{
"wx-api"
})
@RestController
@RequestMapping
(
"/wechat"
)
public
class
WxApiController
{
@Resource
WxApiService
wxApiService
;
/**
* 正确响应微信发送的Token验证,注意 这里是 get请求
*/
@GetMapping
(
"/checkSignature"
)
@ApiOperation
(
value
=
"校验签名"
)
public
String
verifyUrl
(
@RequestParam
Map
<
String
,
String
>
params
)
throws
Exception
{
return
wxApiService
.
checkSignature
(
params
);
}
}
release-service/src/main/java/com/mmc/csf/release/service/WxApiService.java
浏览文件 @
1171fd8b
...
@@ -2,17 +2,22 @@ package com.mmc.csf.release.service;
...
@@ -2,17 +2,22 @@ package com.mmc.csf.release.service;
import
com.mmc.csf.common.util.web.ResultBody
;
import
com.mmc.csf.common.util.web.ResultBody
;
import
java.util.Map
;
/**
/**
* @Author LW
* @Author LW
* @date 2023/7/12 13:44
* @date 2023/7/12 13:44
* 概要:
* 概要:
*/
*/
public
interface
WxApiService
{
public
interface
WxApiService
{
ResultBody
msgSecCheck
(
String
openid
,
String
content
);
ResultBody
msgSecCheck
(
String
openid
,
String
content
);
/**
/**
* 获取稳定AccessToken
* 获取稳定AccessToken
*
* @return
* @return
*/
*/
String
getStableAccessToken
()
throws
Exception
;
String
getStableAccessToken
()
throws
Exception
;
String
checkSignature
(
Map
<
String
,
String
>
params
)
throws
Exception
;
}
}
release-service/src/main/java/com/mmc/csf/release/service/impl/WxApiServiceImpl.java
浏览文件 @
1171fd8b
...
@@ -5,6 +5,7 @@ import com.mmc.csf.common.util.web.HttpHelper;
...
@@ -5,6 +5,7 @@ import com.mmc.csf.common.util.web.HttpHelper;
import
com.mmc.csf.common.util.web.HttpsRequestUtil
;
import
com.mmc.csf.common.util.web.HttpsRequestUtil
;
import
com.mmc.csf.common.util.web.ResultBody
;
import
com.mmc.csf.common.util.web.ResultBody
;
import
com.mmc.csf.common.util.web.ResultEnum
;
import
com.mmc.csf.common.util.web.ResultEnum
;
import
com.mmc.csf.common.util.wx.WXMsgPushUtils
;
import
com.mmc.csf.release.constant.UserSystemConstant
;
import
com.mmc.csf.release.constant.UserSystemConstant
;
import
com.mmc.csf.release.constant.WxConstant
;
import
com.mmc.csf.release.constant.WxConstant
;
import
com.mmc.csf.release.service.WxApiService
;
import
com.mmc.csf.release.service.WxApiService
;
...
@@ -80,4 +81,28 @@ public class WxApiServiceImpl implements WxApiService {
...
@@ -80,4 +81,28 @@ public class WxApiServiceImpl implements WxApiService {
}
}
return
accessToken
;
return
accessToken
;
}
}
@Override
public
String
checkSignature
(
Map
<
String
,
String
>
params
)
throws
Exception
{
// 微信发送的请求中 会有四个参数
// 微信加密签名,signature结合了开发者填写的 token 参数和请求中的 timestamp 参数、nonce参数。
String
signature
=
params
.
get
(
"signature"
);
// 随机字符串
String
echostr
=
params
.
get
(
"echostr"
);
// 时间戳
String
timestamp
=
params
.
get
(
"timestamp"
);
// 随机数
String
nonce
=
params
.
get
(
"nonce"
);
// 消息推送配置中的 Token(令牌)
String
token
=
"IUAVKBTMMC"
;
// 验证
String
msgSignature
=
WXMsgPushUtils
.
getSHA1
(
token
,
timestamp
,
nonce
);
// 验证失败
if
(!
signature
.
equals
(
msgSignature
))
{
return
"false"
;
}
// 验证成功 将 echostr 原格式返回 ,即可完成验证
return
echostr
;
}
}
}
release-service/src/main/resources/not-check.yml
浏览文件 @
1171fd8b
...
@@ -33,3 +33,4 @@ data-filter:
...
@@ -33,3 +33,4 @@ data-filter:
-
/release/tender/info
-
/release/tender/info
-
/release/actuator/health/readiness
-
/release/actuator/health/readiness
-
/release/tender/infoById
-
/release/tender/infoById
-
release/wechat/checkSignature
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论