赞
踩
生成代码及校验代码如下: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 或者C9
- if (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+ti
- int cj = 0;// (si||10==0?10:si||10)*2
- int pj = 10;// pj=cj|11==0?10:cj|11
- for (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;
- }else
- return 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实战】生成虚拟的统一社会信用代码 - 代码先锋网
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位 |
- # -!- coding: utf-8 -!-
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- #作者:cacho_37967865
- #博客:https://blog.csdn.net/sinat_37967865
- #文件:deal_company_code.py
- #日期:2019-12-02
- #备注:生成虚拟的企业:组织机构代码(八位数字(或大写拉丁字母)本体代码和一位数字(或大写拉丁字母)校验码组成)
- 三证合一和一证一码是指工商营业执照,税务登记证,组织机构代码证合并为一张加载统一社会信用代码的营业执照。
- 统一社会信用代码:(登记管理部门代码(1位)、机构类别代码(1位)、登记管理机关行政区划码(6位)、主体标识码(组织机构代码)(9位)和校验码(1位)5个部分组成)
- '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
-
- import random
-
- # 统一社会信用代码最后一位:代码字符集
- check_dict = {
- "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9,
- "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "G": 16, "H": 17, "J": 18, "K": 19, "L": 20, "M": 21,
- "N": 22, "P": 23, "Q": 24, "R": 25, "T": 26, "U": 27, "W": 28, "X": 29, "Y": 30
- }
- dict_check = {value: key for key, value in check_dict.items()}
-
-
- # 组织机构代码 9位
- def create_organization():
- weight_code = [3,7,9,10,5,8,4,2] # Wi 代表第i位上的加权因子=pow(3,i-1)%31
- org_code = [] # 组织机构代码列表
- sum = 0
- for i in range(8):
- org_code.append(dict_check[random.randint(0,30)]) # 前八位本体代码:0~9 + A~Z 31个
- sum = sum + check_dict[org_code[i]]*weight_code[i]
- C9 = 11-sum % 11 # 代表校验码:11-MOD(∑Ci(i=1→8)×Wi,11)-->前8位加权后与11取余,然后用11减
- if C9 == 10:
- last_code = 'X'
- elif C9 == 11:
- last_code = '0'
- else:
- last_code = str(C9)
-
- code = ''.join(org_code) + '-' +last_code # 组织机构代码
- #print(code)
- return (code)
-
-
- # 统一社会信用代码 18位
- def create_social_credit():
- manage_code = [9] # 登记管理部门代码:9-工商
- type_code = [1,2,3,9] # 9-1-企业,9-2-个体工商户,9-3-农民专业合作社,9-9-其他
- area_code = '100000' # 登记管理机关行政区划码:100000-国家用
- org_code = create_organization().replace('-','') # 组织机构代码
- sum = 0
- weight_code = [1, 3, 9, 27, 19, 26, 16, 17,20,29,25,13,8,24,10,30,28] # Wi 代表第i位上的加权因子=pow(3,i-1)%31
- code = str(random.choice(manage_code)) + str(random.choice(type_code)) + area_code + org_code
- for i in range(17):
- sum = sum + check_dict[code[i:i+1]]*weight_code[i]
- C18 = dict_check[31-sum % 31]
- social_code = code + C18
- print(social_code)
- return social_code
-
-
- if __name__ == '__main__':
- #create_organization()
- create_social_credit()

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。