public class Main {


public static void main(String[] args) {
//企业中征码为 16位 后2位位验证码
String checkZZM = checkZZM( String.valueOf((int)(Math.random()*10+1)) + String.valueOf(System.currentTimeMillis()) );
System.out.println("企业中征码为:" + checkZZM);
}

//校验中征码
public static String checkZZM(String value) {
//判断中征码前14位
if (value.length()!=14) {
return "";
}
//前14位转化为char数组
char[] idCode = value.substring(0, 14).toCharArray();
//加权因子
int[] weight_factor = new int[]{1, 3, 5, 7, 11, 2, 13, 1, 1, 17, 19, 97, 23, 29};
int len = idCode.length;
int num = 0;
int temp = 0;
//循环取和
for (int i = 0; i < len; i++) {
//字母转数字
if (idCode[i] >= 'A' && idCode[i] <= 'Z') {
temp = (int) idCode[i] - 55;
} else {
temp = (int) idCode[i] - 48;
}
//求和
num = num + temp * weight_factor[i];
}
//取余+1
int resisue = num % 97 + 1;
System.out.println("生成2位验证码为:"+resisue);
//拼接验证码
value = value + resisue;
//判断中征码是否为16位
if (value.length()!=16) {
return "";
}
return value;
}
}