...
|
...
|
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
import com.google.common.collect.ImmutableList;
|
|
|
import com.yohoufo.common.exception.SignatureNotMatchException;
|
|
|
import com.yohoufo.common.utils.MD5Utils;
|
|
|
import com.yohoufo.common.utils.SignUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -82,7 +83,7 @@ public class BodySignatureCheckInterceptor implements HandlerInterceptor { |
|
|
throw new SignatureNotMatchException();
|
|
|
}
|
|
|
|
|
|
String cacuSign = this.getSign(bodyParam, privateKey);
|
|
|
String cacuSign = SignUtils.getSign(bodyParam, privateKey);
|
|
|
if(!cacuSign.equalsIgnoreCase(signParam))
|
|
|
{
|
|
|
logger.warn("sign not match. request:{}, caculate:{}", signParam, cacuSign );
|
...
|
...
|
@@ -112,46 +113,6 @@ public class BodySignatureCheckInterceptor implements HandlerInterceptor { |
|
|
return objectMapper.readValue(request.getInputStream(), Map.class);
|
|
|
}
|
|
|
|
|
|
private String getSign(Map<String, Object> bodyParam, String privateKey)throws SignatureNotMatchException
|
|
|
{
|
|
|
//remove some headers
|
|
|
ImmutableList list = ImmutableList.of("sign","business_type");
|
|
|
SortedMap<String,Object> filtedMap = new TreeMap<>();
|
|
|
for(Map.Entry<String,Object> entry : bodyParam.entrySet())
|
|
|
{
|
|
|
String k = entry.getKey();
|
|
|
if(!list.contains(k)){
|
|
|
filtedMap.put(k,entry.getValue());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//string: k1=v1&k2=v2
|
|
|
List<String> array = new LinkedList<>();
|
|
|
for(Map.Entry<String,Object> entry : filtedMap.entrySet())
|
|
|
{
|
|
|
|
|
|
if (entry.getValue() instanceof ArrayList){
|
|
|
array.add(StringUtils.trim(entry.getKey() + "=" + JSON.toJSONString(entry.getValue())));
|
|
|
}else {
|
|
|
array.add(StringUtils.trim(entry.getKey() + "=" + entry.getValue()));
|
|
|
}
|
|
|
|
|
|
}
|
|
|
String signStr = String.join("&", array);
|
|
|
|
|
|
String sign = "";
|
|
|
try {
|
|
|
sign = MD5Utils.signMd5(signStr + privateKey, "utf-8");
|
|
|
logger.info("signBeforeStr is {}, sign is {}", signStr, sign);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("body param sign failed: {}", e);
|
|
|
throw new SignatureNotMatchException();
|
|
|
}
|
|
|
//sign md5
|
|
|
return sign;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setIsDebugEnable(boolean isDebugEnable) {
|
...
|
...
|
|