-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Expand file tree
/
Copy pathDataUtils.java
More file actions
27 lines (25 loc) · 823 Bytes
/
Copy pathDataUtils.java
File metadata and controls
27 lines (25 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package me.chanjar.weixin.common.util;
import org.apache.commons.lang3.RegExUtils;
import org.apache.commons.lang3.StringUtils;
/**
* <pre>
* 数据处理工具类
* Created by BinaryWang on 2018/5/8.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
public class DataUtils {
/**
* 将数据中包含的secret字符使用星号替换,防止日志打印时被输出
*/
public static <E> E handleDataWithSecret(E data) {
E dataForLog = data;
if (data instanceof String) {
String stringData = (String) data;
stringData = RegExUtils.replaceAll(stringData, "(^|[?&])secret=[^&]*", "$1secret=******");
dataForLog = (E) RegExUtils.replaceAll(stringData, "(\\\"openid\\\"\\s*:\\s*\\\")[^\\\"]*(\\\")", "$1******$2");
}
return dataForLog;
}
}