统一社会信用代码c#校验函数

来源:互联网 发布:淘宝开店卖虚拟 编辑:程序博客网 时间:2024/04/29 04:02
public static bool CheckSocialCreditCode(string code){if (code == null || code.Length != 18) return false;code = code.ToUpper();int[] factor = { 1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28 };string str = "0123456789ABCDEFGHJKLMNPQRTUWXY";int total = factor.Select((p, i) => p * str.IndexOf(code[i])).Sum();int index = total % 31 == 0 ? 0 : (31 - total % 31);return str[index] == code.Last();}

1 0
原创粉丝点击