Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation
This project
Loading...
Sign in
李苗
/
Vion-DevOps
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 376f6542
authored
Aug 28, 2024
by
HlQ
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
[fix] 修复调用钉钉接口因为 urlEncoded 引起的问题
1 parent
ee7a696c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
src/main/java/vion/config/RestClientConfig.java
src/main/java/vion/third/DingMod.java
src/main/java/vion/config/RestClientConfig.java
View file @
376f654
...
...
@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.web.client.RestClient
;
import
org.springframework.web.util.DefaultUriBuilderFactory
;
/**
* @author HlQ
...
...
@@ -22,8 +23,12 @@ public class RestClientConfig {
@Bean
(
name
=
"oDingRestClient"
)
public
RestClient
getODingRestClient
()
{
// disable url encoding
// 在对 + 号进行处理时,默认对该字符不出力
var
uriBuilderFactory
=
new
DefaultUriBuilderFactory
(
"https://oapi.dingtalk.com"
);
uriBuilderFactory
.
setEncodingMode
(
DefaultUriBuilderFactory
.
EncodingMode
.
NONE
);
return
RestClient
.
builder
()
.
baseUrl
(
"https://oapi.dingtalk.com"
)
.
uriBuilderFactory
(
uriBuilderFactory
)
.
build
();
}
...
...
src/main/java/vion/third/DingMod.java
View file @
376f654
...
...
@@ -30,6 +30,8 @@ import vion.vo.RoleVO;
import
vion.vo.UserVO
;
import
java.io.IOException
;
import
java.net.URLEncoder
;
import
java.nio.charset.StandardCharsets
;
import
java.time.Duration
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -435,7 +437,9 @@ public class DingMod {
HMac
hMac
=
SecureUtil
.
hmacSha256
(
appSecret
);
byte
[]
signBytes
=
hMac
.
digest
(
timestamp
);
String
sign
=
Base64
.
encode
(
signBytes
);
return
StrUtil
.
format
(
"/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo×tamp={}&signature={}"
,
timestamp
,
sign
);
String
encode
=
URLEncoder
.
encode
(
sign
,
StandardCharsets
.
UTF_8
);
String
encodeSign
=
encode
.
replace
(
"+"
,
"%20"
).
replace
(
"*"
,
"%2A"
).
replace
(
"~"
,
"%7E"
).
replace
(
"/"
,
"%2F"
);
return
StrUtil
.
format
(
"/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo×tamp={}&signature={}"
,
timestamp
,
encodeSign
);
}
public
String
robotPush
(
String
accessToken
,
String
body
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment