|
@@ -1,14 +1,19 @@
|
|
|
package thyyxxk.webserver.utils;
|
|
|
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
import org.springframework.http.converter.StringHttpMessageConverter;
|
|
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
|
|
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import java.nio.charset.Charset;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
public class HaiciHttpUtil {
|
|
|
private static final Charset thirdRequest = StandardCharsets.UTF_8;
|
|
@@ -21,7 +26,6 @@ public class HaiciHttpUtil {
|
|
|
|
|
|
public static RestTemplate restTemplate() {
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
-
|
|
|
// 处理请求中文乱码问题
|
|
|
List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
|
|
|
for (HttpMessageConverter<?> messageConverter : messageConverters) {
|
|
@@ -35,7 +39,23 @@ public class HaiciHttpUtil {
|
|
|
((AllEncompassingFormHttpMessageConverter) messageConverter).setCharset(thirdRequest);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
return restTemplate;
|
|
|
}
|
|
|
+
|
|
|
+ public static String getSign(Map<String, Object> map, String key) {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, Object> entry : map.entrySet())
|
|
|
+ if (null != entry.getValue() && !StringUtils.isEmpty(entry.getValue() + ""))
|
|
|
+ list.add(entry.getKey() + "=" + entry.getValue() + "&");
|
|
|
+ int size = list.size();
|
|
|
+ String[] arrayToSort = list.toArray(new String[size]);
|
|
|
+ Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (int i = 0; i < size; i++)
|
|
|
+ sb.append(arrayToSort[i]);
|
|
|
+ if (!StringUtils.isEmpty(key))
|
|
|
+ sb.append(key);
|
|
|
+ byte[] target = sb.toString().getBytes(StandardCharsets.UTF_8);
|
|
|
+ return DigestUtils.md5Hex(target).toUpperCase();
|
|
|
+ }
|
|
|
}
|