当前位置:   article > 正文

JAVA生成企业组织机构代码、营业执照代码、税务登记号码、统一社会信用代码并校验_组织机构代码生成器在线

组织机构代码生成器在线

生成代码及校验代码如下:JAVA生成企业组织机构代码、营业执照代码、税务登记号码、统一社会信用代码并校验 - CodeAntenna

  1. import java.util.HashMap;
  2. import java.util.Map;
  3. import java.util.Random;
  4. public class ProductData {
  5. //生成企业组织机构代码
  6. public static String getORGANIZATION_CODE(){
  7. int [] in = { 3, 7, 9, 10, 5, 8, 4, 2 };
  8. String data = "";
  9. String yz = "";
  10. int a = 0;
  11. //随机生成英文字母和数字
  12. for (int i = 0; i < in.length; i++){
  13. String word = getCharAndNumr(1,0).toUpperCase();
  14. if (word.matches("[A-Z]")) {
  15. a += in[i] * getAsc(word);
  16. }else{
  17. a += in[i] * Integer.parseInt(word);
  18. }
  19. data += word;
  20. }
  21. //确定序列
  22. int c9 = 11 - a % 11;
  23. //判断c9大小,安装 X 0 或者C9
  24. if (c9 == 10) {
  25. yz = "X";
  26. } else if (c9 == 11) {
  27. yz = "0";
  28. } else {
  29. yz = c9 + "";
  30. }
  31. data += "-"+yz;
  32. return data.toUpperCase();
  33. }
  34. //生成营业执照代码
  35. public static String getBUSINESS_LISENSE_CODE(){
  36. String data = "";
  37. //随机生成14位数字
  38. String number = getCharAndNumr(14,1);
  39. //获取校验后的第15
  40. String yz = getBusinesslicenseCheckBit(number)+"";
  41. //拼凑
  42. data = number+yz;
  43. return data.toUpperCase();
  44. }
  45. //生成税务登记号码
  46. public static String getTAX_REGISTRATION_CODE(){
  47. String data = "";
  48. String first = "73"+getCharAndNumr(4,2);
  49. String end = getORGANIZATION_CODE();
  50. data= first+end;
  51. data =data.toUpperCase().replaceAll("-","");
  52. if (!test5(data.toUpperCase())) getTAX_REGISTRATION_CODE();
  53. return data;
  54. }
  55. //生成统一社会信用代码
  56. public static String getSOCIAL_CREDIT_CODE(){
  57. String data = "";
  58. String first = "Y2"+getCharAndNumr(6,3)+getCharAndNumr(9,3);
  59. String end = String.valueOf(getUSCCCheckBit(first));
  60. data = first + end;
  61. if (!test4(data.toUpperCase())) getSOCIAL_CREDIT_CODE();
  62. return data.toUpperCase();
  63. }
  64. public static String getCharAndNumr(int length,int status) {
  65. Random random = new Random();
  66. StringBuffer valSb = new StringBuffer();
  67. String charStr = "0123456789abcdefghijklmnopqrstuvwxy";
  68. if (status == 1) charStr = "0123456789";
  69. if (status == 2) charStr = "0123456789";
  70. if (status == 3) charStr = "0123456789ABCDEFGHJKLMNPQRTUWXY";
  71. int charLength = charStr.length();
  72. for (int i = 0; i < length; i++) {
  73. int index = random.nextInt(charLength);
  74. if (status==1&&index==0){ index =3;}
  75. valSb.append(charStr.charAt(index));
  76. }
  77. return valSb.toString();
  78. }
  79. private static char getUSCCCheckBit(String businessCode) {
  80. if (("".equals(businessCode)) || businessCode.length() != 17) {
  81. return 0;
  82. }
  83. String baseCode = "0123456789ABCDEFGHJKLMNPQRTUWXY";
  84. char[] baseCodeArray = baseCode.toCharArray();
  85. Map<Character, Integer> codes = new HashMap<Character, Integer>();
  86. for (int i = 0; i < baseCode.length(); i++) {
  87. codes.put(baseCodeArray[i], i);
  88. }
  89. char[] businessCodeArray = businessCode.toCharArray();
  90. int[] wi = { 1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28 };
  91. int sum = 0;
  92. for (int i = 0; i < 17; i++) {
  93. Character key = businessCodeArray[i];
  94. if (baseCode.indexOf(key) == -1) {
  95. return 0;
  96. }
  97. sum += (codes.get(key) * wi[i]);
  98. }
  99. int value = 31 - sum % 31;
  100. if(value == 31){
  101. value = 0;
  102. }
  103. return baseCodeArray[value];
  104. }
  105. public static int getAsc(String st) {
  106. byte[] gc = st.getBytes();
  107. int ascNum = (int) gc[0] - 55;
  108. return ascNum;
  109. }
  110. /**
  111. * 校验 营业执照注册号
  112. * @param businesslicense
  113. * @return
  114. */
  115. public static int getBusinesslicenseCheckBit(String businesslicense){
  116. if(businesslicense.length() != 14){
  117. return 0;
  118. }
  119. char[] chars = businesslicense.toCharArray();
  120. int[] ints = new int[chars.length];
  121. for(int i=0; i<chars.length;i++){
  122. ints[i] = Integer.parseInt(String.valueOf(chars[i]));
  123. }
  124. return getCheckCode(ints);
  125. }
  126. /**
  127. * 获取 营业执照注册号的校验码
  128. * @param
  129. * @return bit
  130. */
  131. private static int getCheckCode(int[] ints){
  132. if (null != ints && ints.length > 1) {
  133. int ti = 0;
  134. int si = 0;// pi|11+ti
  135. int cj = 0;// (si||10==010:si||10*2
  136. int pj = 10;// pj=cj|11==0?10:cj|11
  137. for (int i=0;i<ints.length;i++) {
  138. ti = ints[i];
  139. pj = (cj % 11) == 0 ? 10 : (cj % 11);
  140. si = pj + ti;
  141. cj = (0 == si % 10 ? 10 : si % 10) * 2;
  142. if (i == ints.length-1) {
  143. pj = (cj % 11) == 0 ? 10 : (cj % 11);
  144. return pj == 1 ? 1 : 11 - pj;
  145. }
  146. }
  147. }
  148. return -1;
  149. }
  150. public static String getCheckBit(String code) {
  151. String yz = "";
  152. int[] in = { 3, 7, 9, 10, 5, 8, 4, 2 };
  153. int a = 0;
  154. for (int i = 0; i < in.length; i++) {
  155. if (code.substring(i, i + 1).matches("[A-Z]")) {
  156. a += in[i] * getAsc(code.substring(i, i + 1));
  157. }else{
  158. a += in[i] * Integer.parseInt(code.substring(i, i + 1));
  159. }
  160. }
  161. int c9 = 11 - a % 11;
  162. if (c9 == 10) {
  163. yz = "X";
  164. } else if (c9 == 11) {
  165. yz = "0";
  166. } else {
  167. yz = c9 + "";
  168. }
  169. return yz;
  170. }
  171. public static boolean test(String data){
  172. String code = data.replace("-","");
  173. return data.endsWith(getCheckBit(code.substring(0,code.length()-1)));
  174. }
  175. public static boolean test1(String data){
  176. return data.endsWith(String.valueOf(getBusinesslicenseCheckBit(data.substring(0,data.length()-1))));
  177. }
  178. public static boolean test2(String data){
  179. return data.endsWith(String.valueOf(getCheckBit(data.substring(6,data.length()-1))));
  180. }
  181. public static boolean test3(String data){
  182. return data.endsWith(String.valueOf(getUSCCCheckBit(data.substring(0,data.length()-1))));
  183. }
  184. public static boolean test4(String data){
  185. if(data==null) {
  186. return false;
  187. }
  188. if (data.length() != 18) {
  189. return false;
  190. }
  191. if(!data.matches("[a-zA-Z0-9]+")) {
  192. return false;
  193. }
  194. String regex = "^([159Y]{1})([1239]{1})([0-9ABCDEFGHJKLMNPQRTUWXY]{6})([0-9ABCDEFGHJKLMNPQRTUWXY]{9})([0-90-9ABCDEFGHJKLMNPQRTUWXY])$";
  195. if (!data.matches(regex)) {
  196. return false;
  197. }
  198. return true;
  199. }
  200. public static boolean test5(String data){
  201. String regex = "[1-8][1-6]\\d{4}[a-zA-Z0-9]{9}$";
  202. if (!data.matches(regex)) {
  203. return false;
  204. }else
  205. return true;
  206. }
  207. public static void main(String[] args) throws Exception
  208. {
  209. //
  210. // String code1 = "91530622292785224";
  211. // String code2 = "97028471650403700000";
  212. //
  213. // SocialCreditCodeOperation object= new SocialCreditCodeOperation(20562);
  214. String code = getORGANIZATION_CODE();
  215. System.out.println(code);
  216. System.out.println(test(code));
  217. code = getBUSINESS_LISENSE_CODE();
  218. System.out.println(code);
  219. System.out.println(test1(code));
  220. code = getTAX_REGISTRATION_CODE();
  221. System.out.println(code);
  222. System.out.println(test2(code));
  223. System.out.println(test5(code));
  224. code = getSOCIAL_CREDIT_CODE();
  225. System.out.println(code);
  226. System.out.println(test3(code));
  227. System.out.println("test4: "+test4(code));
  228. // System.out.println(object.dataVerify(code2));
  229. // System.out.println("仿真:" + object.simulation(code2));
  230. // System.out.println("屏蔽:" + object.maskingOut(code2));
  231. // System.out.println("替换:" + object.substitution(code2));
  232. // System.out.println("仿真:" + object.simulation(code2));
  233. // System.out.println("变形:" + object.variance(code2));
  234. // System.out.println("加密:" + object.encrypt(code2));
  235. }
  236. }

【Python实战】生成虚拟的统一社会信用代码 - 代码先锋网

【Python实战】生成虚拟的统一社会信用代码

技术标签: python  统一社会信用代码

1、统一社会信用代码设计为18位,使用阿拉伯数字或英文字母表示,由五个部分组成。
2、第一部分(第1位),为登记管理部门代码。
3、第二部分(第2位),为企业等纳税人类别代码。
4、第三部分(第3-8位),为登记管理机关行政区划码。
5、第四部分(第9-17位),为主体标识码。
6、第五部分(第18位),为校验码,由系统自动生成。

一是预留前两位给登记机关和机构类别,这样统一社会信用代码在应用中更加清晰高效,第一位便于登记机关管理,可以作为检索条目,第二位可以准确给组织机构归类,方便细化分管。
二是在组织机构代码前增加行政区划代码,这个组合不难发现就是税务登记证号码。这样就提高了统一社会代码的兼容性,在过渡期内税务机关可以利用这种嵌套规则更加便利地升级到新的信用代码系统。
三是嵌入了组织机构代码作为主体标识码。通过组织机构代码的唯一性确保社会信用代码不会重码。换言之,组织机构代码的唯一性完美“遗传”给统一社会信用代码。
四是统一社会信用代码的主体标识码天生具有的大容量。通过数字字母组合,加上指数级增长,可以确保在很长一段时间内无需升位就可容纳大量组织机构。
五是统一社会信用代码位数为18位,和身份证的位数相同,这一巧妙设计在未来“两码管两人”的应用中可以实现登记、检索、填表等统一。
六是统一社会信用代码中内嵌的主体标识码具有校验位,同时自身第十八位也是校验位,与身份证号相比是双校验,确保了号码准确性。

                                                                    法人和其他组织统一社会信用代码构成

代码序号123456789101112131415161718
代码xxxxxxxxxxxxxxxxxx
说明登记管理部门代码1位机构类别代码1位登记管理机关行政区划码6位主体标识码(组织机构代码)9位校验码1位

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

【Python实战】生成虚拟的统一社会信用代码 - 代码先锋网

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/336767
推荐阅读
相关标签
  

闽ICP备14008679号