package com.yeshi.location.app.aop;
|
|
import com.yeshi.location.app.entity.config.SystemConfigKey;
|
import com.yeshi.location.app.vo.AcceptData;
|
import net.sf.json.JSONObject;
|
import org.aspectj.lang.annotation.Aspect;
|
import org.springframework.core.annotation.Order;
|
import org.springframework.stereotype.Component;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.*;
|
|
//客户端接口签名验证
|
@Component
|
@Aspect
|
@Order(2)
|
public class SignValidate {
|
|
private String getHttpServletParams(HttpServletRequest request) {
|
if (request == null) {
|
return "";
|
}
|
Map map = request.getParameterMap();
|
if (map != null) {
|
Iterator<String> its = map.keySet().iterator();
|
JSONObject json = new JSONObject();
|
while (its.hasNext()) {
|
String next = its.next();
|
if (map.get(next) != null) {
|
Object[] objects = (Object[]) map.get(next);
|
if (objects != null && objects.length > 0) {
|
json.put(next, objects[0].toString());
|
}
|
}
|
}
|
return json.toString();
|
}
|
return "";
|
}
|
|
|
/**
|
* 判断签名的正确性 Android version>50
|
*
|
* @param request
|
* @return
|
*/
|
private boolean signIsRight(HttpServletRequest request, AcceptData acceptData) {
|
Map<String, String[]> map = request.getParameterMap();
|
Iterator<String> its = map.keySet().iterator();
|
List<String> list = new ArrayList<>();
|
|
while (its.hasNext()) {
|
String key = its.next();
|
if (key.equalsIgnoreCase("sign") || key.equalsIgnoreCase("callback") || key.equalsIgnoreCase("_")) {
|
continue;
|
}
|
String[] values = map.get(key);
|
list.add(key + "=" + values[0]);
|
}
|
Collections.sort(list);
|
String str = "";
|
for (String st : list) {
|
str += st + "&";
|
}
|
String key = systemConfigService.getValueCache(acceptData.getSystem(), SystemConfigKey.signKey);
|
String sign = StringUtil.Md5(str + key);
|
if (sign.equalsIgnoreCase(request.getParameter("sign") + "")) {
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
|
}
|