xbeginagain / generator Goto Github PK
View Code? Open in Web Editor NEW编号生成器(测试用)
Home Page: https://xbeginagain.github.io/generator/
License: Apache License 2.0
编号生成器(测试用)
Home Page: https://xbeginagain.github.io/generator/
License: Apache License 2.0
统一社会信用代码校验,校验存在问题
例如: 12440600MB2C07549J
`
import java.util.HashMap;
import java.util.Map;
public class HelloWorld {
public static void main(String []args) {
HelloWorld helloWorld = new HelloWorld();
boolean b = helloWorld.validate18("12440600MB2C07549J");
System.out.println(b);
}
public 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(); i++) {
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; i++) {
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);
}
}
`
var str = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var wi =[1,3,9,27,19,26,16,17,20,29,25,13,8,24,10,30,28];
var sum = 0;
for (var i = 0; i < 17; i++) {
sum += str.indexOf(creditCode.charAt(i)) * wi[i];
}
str里面不能有I O Z S V
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.