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

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();
}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页