the rules for the generation of unified social codes are formulated according to the national standard GB32100-2015 "coding rules for uniform Social Credit codes of legal Persons and other organizations".
Let"s start with a piece of code:
public static boolean validate18(String bizNo) {
String regex = "^([0-9ABCDEFGHJKLMNPQRTUWXY]{2})([0-9]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{10})$";
if (!bizNo.matches(regex)) {
return false;
}
String baseCode = "0123456789ABCDEFGHJKLMNPQRTUWXY";
char[] baseCodeArray = baseCode.toCharArray();
Map<Character, Integer> codes = new HashMap<Character, Integer>();
for (int i = 0; i < baseCode.length(); iPP) {
codes.put(baseCodeArray[i], i);
}
char[] businessCodeArray = bizNo.toCharArray();
Character check = businessCodeArray[17];
if (baseCode.indexOf(check) == -1) {
return false;
}
int[] ws = { 1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28 };
int sum = 0;
for (int i = 0; i < 17; iPP) {
Character key = businessCodeArray[i];
if (baseCode.indexOf(key) == -1) {
return false;
}
sum += (codes.get(key) * ws[i]);
}
int c18 = 31 - sum % 31;
if (c18 == 31) {
c18 = 0;
}
return c18 == codes.get(check);
from the point of view of the code, it should meet the national standards. In the process of practical application, it is found that there are many unsatisfactory situations. At present, it is mainly found that there are many unsatisfied situations in Fujian, for example: 91350211M0000XUF46, 9131000063159284XQ, etc.
do you have this kind of check?