publicstaticStringgetSign(Mapmap, StringappSecret) throwsNoSuchAlgorithmException {
StringBuffersignOri=newStringBuffer();
Setset=map.entrySet();
Iteratorit=set .iterator();
while (it.hasNext()) {
Map.Entryentry= (Map.Entry) it.next();
Stringk= (String) entry.getKey();
Objectv=entry.getValue();
if (null!=v&&!"".equals(v)) {
signOri.append(k+"="+v+"&");
}
}
signOri=signOri.append("appSecret="+appSecret);
System.out.println(signOri);
Stringsign=encodeByMD5(signOri.toString()).toUpperCase();
returnsign;
}
publicstaticStringencodeByMD5(Stringstr) throwsNoSuchAlgorithmException {
MessageDigestmd=MessageDigest.getInstance("MD5");
byte[] digest=md.digest(str.getBytes());
StringhexString=bytesToHex(digest);
returnhexString;
}
publicstaticStringbytesToHex(byte[] bytes) {
StringBuilderhexString=newStringBuilder();
for (byteb : bytes) {
Stringhex=Integer.toHexString(0xff&b);
if (hex.length() ==1) {
hexString.append('0');
}
hexString.append(hex);
}
returnhexString.toString();
}