public static boolean check(Http
ServletRequest request){
Map<String, String[]> map = request.getParameterMap();
Set<Entry<String, String[]>> set = map.entrySet();
Iterator<Entry<String, String[]>> it = set.iterator();
String sign = "";
Map<String,String> pras = new HashMap<String, String>();
List<String> keys = new ArrayList<String>();
while (it.
hasNext()) {
Entry<String, String[]> entry = it.next();
String key = entry.getKey().trim();
String value = entry.getValue()[0];
if(!"sign".equals(key)){
if(value==null) value = "";
keys.add(key);
pras.put(key, value.trim());
}
if("sign".equals(key)) sign = value;
}
Collections.sort(keys);
StringBuffer bf = new StringBuffer();
for(int i=0;i<keys.size();i++){
bf.append(keys.get(i)).append("=");
try {
bf.append(URLEncoder.encode(pras.get(keys.get(i)),"utf-8")+"&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
bf.append("key=").append(Global.getConfig("httpMD5Key").trim());
logger.info("待签名字符串:"+bf.toString()+" sign:"+sign + " MD5:"+MD5.GetMD5Code(bf.toString()));
if(sign.equals(MD5.GetMD5Code(bf.toString()))){
return true;
}
return false;
}