微信公众号 设置与开发-基本配置-服务器配置
明文模式校验
public static void main(String[] args) {
// 微信加密签名
final String signature = "74b2aa660dcdbfc2f27c201ac2cdf4cf24a1bd1e";
// 时间戳
final String timestamp = "1681989320";
// 随机数
final String nonce = "1743502518";
// 随机字符串
final String echoStr = "8305999631672647420";
//此处token应与公众号用于验签的token相同
String[] sortStr = {timestamp, nonce, WECHAT_SERVER_TOKEN};
sortStr = Arrays.stream(sortStr).sorted().toArray(String[]::new);
StringBuilder tmpStr = new StringBuilder();
for (int i = 0; i < sortStr.length; i++) {
tmpStr.append(sortStr[i]);
}
String sha1_0 = sha1(String.valueOf(tmpStr));
System.out.println("======================" + sha1_0);
}
public static String sha1(String text) {
String mySignature;
try {
MessageDigest md = MessageDigest.getInstance("SHA1");
md.update(text.getBytes());
byte[] digest = md.digest();
StringBuilder hexstr = new StringBuilder();
String shaHex;
for (int i = 0; i < digest.length; i++) {
shaHex = Integer.toHexString(digest[i] & 0xFF);
if (shaHex.length() < 2) {
hexstr.append(0);
}
hexstr.append(shaHex);
}
mySignature = hexstr.toString();
} catch (NoSuchAlgorithmException e) {
return "签名错误";
}
return mySignature;
}
(未完待续…)