Commit 376f6542 by HlQ

[fix] 修复调用钉钉接口因为 urlEncoded 引起的问题

1 parent ee7a696c
...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient; import org.springframework.web.client.RestClient;
import org.springframework.web.util.DefaultUriBuilderFactory;
/** /**
* @author HlQ * @author HlQ
...@@ -22,8 +23,12 @@ public class RestClientConfig { ...@@ -22,8 +23,12 @@ public class RestClientConfig {
@Bean(name = "oDingRestClient") @Bean(name = "oDingRestClient")
public RestClient getODingRestClient() { public RestClient getODingRestClient() {
// disable url encoding
// 在对 + 号进行处理时,默认对该字符不出力
var uriBuilderFactory = new DefaultUriBuilderFactory("https://oapi.dingtalk.com");
uriBuilderFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
return RestClient.builder() return RestClient.builder()
.baseUrl("https://oapi.dingtalk.com") .uriBuilderFactory(uriBuilderFactory)
.build(); .build();
} }
......
...@@ -30,6 +30,8 @@ import vion.vo.RoleVO; ...@@ -30,6 +30,8 @@ import vion.vo.RoleVO;
import vion.vo.UserVO; import vion.vo.UserVO;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration; import java.time.Duration;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -435,7 +437,9 @@ public class DingMod { ...@@ -435,7 +437,9 @@ public class DingMod {
HMac hMac = SecureUtil.hmacSha256(appSecret); HMac hMac = SecureUtil.hmacSha256(appSecret);
byte[] signBytes = hMac.digest(timestamp); byte[] signBytes = hMac.digest(timestamp);
String sign = Base64.encode(signBytes); String sign = Base64.encode(signBytes);
return StrUtil.format("/sns/getuserinfo_bycode?accessKey=dingkrzwks0jpi2di3uo&timestamp={}&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&timestamp={}&signature={}", timestamp, encodeSign);
} }
public String robotPush(String accessToken, String body) { public String robotPush(String accessToken, String body) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!