JAVA生成企业组织机构代码、营业执照代码、税务登记号码、统一社会信用代码并校验
生成代碼及校驗代碼如下:JAVA生成企業組織機構代碼、營業執照代碼、稅務登記號碼、統一社會信用代碼并校驗 - CodeAntenna
import java.util.HashMap; import java.util.Map; import java.util.Random;public class ProductData {//生成企業組織機構代碼public static String getORGANIZATION_CODE(){int [] in = { 3, 7, 9, 10, 5, 8, 4, 2 };String data = "";String yz = "";int a = 0;//隨機生成英文字母和數字for (int i = 0; i < in.length; i++){String word = getCharAndNumr(1,0).toUpperCase();if (word.matches("[A-Z]")) {a += in[i] * getAsc(word);}else{a += in[i] * Integer.parseInt(word);}data += word;}//確定序列int c9 = 11 - a % 11;//判斷c9大小,安裝 X 0 或者C9if (c9 == 10) {yz = "X";} else if (c9 == 11) {yz = "0";} else {yz = c9 + "";}data += "-"+yz;return data.toUpperCase();}//生成營業執照代碼public static String getBUSINESS_LISENSE_CODE(){String data = "";//隨機生成14位數字String number = getCharAndNumr(14,1);//獲取校驗后的第15位String yz = getBusinesslicenseCheckBit(number)+"";//拼湊data = number+yz;return data.toUpperCase();}//生成稅務登記號碼public static String getTAX_REGISTRATION_CODE(){String data = "";String first = "73"+getCharAndNumr(4,2);String end = getORGANIZATION_CODE();data= first+end;data =data.toUpperCase().replaceAll("-","");if (!test5(data.toUpperCase())) getTAX_REGISTRATION_CODE();return data;}//生成統一社會信用代碼public static String getSOCIAL_CREDIT_CODE(){String data = "";String first = "Y2"+getCharAndNumr(6,3)+getCharAndNumr(9,3);String end = String.valueOf(getUSCCCheckBit(first));data = first + end;if (!test4(data.toUpperCase())) getSOCIAL_CREDIT_CODE();return data.toUpperCase();}public static String getCharAndNumr(int length,int status) {Random random = new Random();StringBuffer valSb = new StringBuffer();String charStr = "0123456789abcdefghijklmnopqrstuvwxy";if (status == 1) charStr = "0123456789";if (status == 2) charStr = "0123456789";if (status == 3) charStr = "0123456789ABCDEFGHJKLMNPQRTUWXY";int charLength = charStr.length();for (int i = 0; i < length; i++) {int index = random.nextInt(charLength);if (status==1&&index==0){ index =3;}valSb.append(charStr.charAt(index));}return valSb.toString();}private static char getUSCCCheckBit(String businessCode) {if (("".equals(businessCode)) || businessCode.length() != 17) {return 0;}String baseCode = "0123456789ABCDEFGHJKLMNPQRTUWXY";char[] baseCodeArray = baseCode.toCharArray();Map<Character, Integer> codes = new HashMap<Character, Integer>();for (int i = 0; i < baseCode.length(); i++) {codes.put(baseCodeArray[i], i);}char[] businessCodeArray = businessCode.toCharArray();int[] wi = { 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; i++) {Character key = businessCodeArray[i];if (baseCode.indexOf(key) == -1) {return 0;}sum += (codes.get(key) * wi[i]);}int value = 31 - sum % 31;if(value == 31){value = 0;}return baseCodeArray[value];}public static int getAsc(String st) {byte[] gc = st.getBytes();int ascNum = (int) gc[0] - 55;return ascNum;}/*** 校驗 營業執照注冊號* @param businesslicense* @return*/public static int getBusinesslicenseCheckBit(String businesslicense){if(businesslicense.length() != 14){return 0;}char[] chars = businesslicense.toCharArray();int[] ints = new int[chars.length];for(int i=0; i<chars.length;i++){ints[i] = Integer.parseInt(String.valueOf(chars[i]));}return getCheckCode(ints);}/*** 獲取 營業執照注冊號的校驗碼* @param* @return bit*/private static int getCheckCode(int[] ints){if (null != ints && ints.length > 1) {int ti = 0;int si = 0;// pi|11+tiint cj = 0;// (si||10==0?10:si||10)*2int pj = 10;// pj=cj|11==0?10:cj|11for (int i=0;i<ints.length;i++) {ti = ints[i];pj = (cj % 11) == 0 ? 10 : (cj % 11);si = pj + ti;cj = (0 == si % 10 ? 10 : si % 10) * 2;if (i == ints.length-1) {pj = (cj % 11) == 0 ? 10 : (cj % 11);return pj == 1 ? 1 : 11 - pj;}}}return -1;}public static String getCheckBit(String code) {String yz = "";int[] in = { 3, 7, 9, 10, 5, 8, 4, 2 };int a = 0;for (int i = 0; i < in.length; i++) {if (code.substring(i, i + 1).matches("[A-Z]")) {a += in[i] * getAsc(code.substring(i, i + 1));}else{a += in[i] * Integer.parseInt(code.substring(i, i + 1));}}int c9 = 11 - a % 11;if (c9 == 10) {yz = "X";} else if (c9 == 11) {yz = "0";} else {yz = c9 + "";}return yz;}public static boolean test(String data){String code = data.replace("-","");return data.endsWith(getCheckBit(code.substring(0,code.length()-1)));}public static boolean test1(String data){return data.endsWith(String.valueOf(getBusinesslicenseCheckBit(data.substring(0,data.length()-1))));}public static boolean test2(String data){return data.endsWith(String.valueOf(getCheckBit(data.substring(6,data.length()-1))));}public static boolean test3(String data){return data.endsWith(String.valueOf(getUSCCCheckBit(data.substring(0,data.length()-1))));}public static boolean test4(String data){if(data==null) {return false;}if (data.length() != 18) {return false;}if(!data.matches("[a-zA-Z0-9]+")) {return false;}String regex = "^([159Y]{1})([1239]{1})([0-9ABCDEFGHJKLMNPQRTUWXY]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{9})([0-90-9ABCDEFGHJKLMNPQRTUWXY])$";if (!data.matches(regex)) {return false;}return true;}public static boolean test5(String data){String regex = "[1-8][1-6]\\d{4}[a-zA-Z0-9]{9}$";if (!data.matches(regex)) {return false;}elsereturn true;}public static void main(String[] args) throws Exception{// // String code1 = "91530622292785224"; // String code2 = "97028471650403700000"; // // SocialCreditCodeOperation object= new SocialCreditCodeOperation(20562);String code = getORGANIZATION_CODE();System.out.println(code);System.out.println(test(code));code = getBUSINESS_LISENSE_CODE();System.out.println(code);System.out.println(test1(code));code = getTAX_REGISTRATION_CODE();System.out.println(code);System.out.println(test2(code));System.out.println(test5(code));code = getSOCIAL_CREDIT_CODE();System.out.println(code);System.out.println(test3(code));System.out.println("test4: "+test4(code)); // System.out.println(object.dataVerify(code2)); // System.out.println("仿真:" + object.simulation(code2));// System.out.println("屏蔽:" + object.maskingOut(code2)); // System.out.println("替換:" + object.substitution(code2)); // System.out.println("仿真:" + object.simulation(code2)); // System.out.println("變形:" + object.variance(code2)); // System.out.println("加密:" + object.encrypt(code2));}}【Python實戰】生成虛擬的統一社會信用代碼 - 代碼先鋒網
【Python實戰】生成虛擬的統一社會信用代碼
技術標簽:?python??統一社會信用代碼
1、統一社會信用代碼設計為18位,使用阿拉伯數字或英文字母表示,由五個部分組成。
2、第一部分(第1位),為登記管理部門代碼。
3、第二部分(第2位),為企業等納稅人類別代碼。
4、第三部分(第3-8位),為登記管理機關行政區劃碼。
5、第四部分(第9-17位),為主體標識碼。
6、第五部分(第18位),為校驗碼,由系統自動生成。
一是預留前兩位給登記機關和機構類別,這樣統一社會信用代碼在應用中更加清晰高效,第一位便于登記機關管理,可以作為檢索條目,第二位可以準確給組織機構歸類,方便細化分管。
二是在組織機構代碼前增加行政區劃代碼,這個組合不難發現就是稅務登記證號碼。這樣就提高了統一社會代碼的兼容性,在過渡期內稅務機關可以利用這種嵌套規則更加便利地升級到新的信用代碼系統。
三是嵌入了組織機構代碼作為主體標識碼。通過組織機構代碼的唯一性確保社會信用代碼不會重碼。換言之,組織機構代碼的唯一性完美“遺傳”給統一社會信用代碼。
四是統一社會信用代碼的主體標識碼天生具有的大容量。通過數字字母組合,加上指數級增長,可以確保在很長一段時間內無需升位就可容納大量組織機構。
五是統一社會信用代碼位數為18位,和身份證的位數相同,這一巧妙設計在未來“兩碼管兩人”的應用中可以實現登記、檢索、填表等統一。
六是統一社會信用代碼中內嵌的主體標識碼具有校驗位,同時自身第十八位也是校驗位,與身份證號相比是雙校驗,確保了號碼準確性。
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??? 法人和其他組織統一社會信用代碼構成
| 代碼序號 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 代碼 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | x | x | x | x |
| 說明 | 登記管理部門代碼1位 | 機構類別代碼1位 | 登記管理機關行政區劃碼6位 | 主體標識碼(組織機構代碼)9位 | 校驗碼1位 | |||||||||||||
【Python實戰】生成虛擬的統一社會信用代碼 - 代碼先鋒網
總結
以上是生活随笔為你收集整理的JAVA生成企业组织机构代码、营业执照代码、税务登记号码、统一社会信用代码并校验的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一键生成 Android 录屏 gif
- 下一篇: labview混合编程学习