function ValidateEnterpriseCode(EnterpriseCode: string): Boolean; var i, sum, code, weight: Integer; begin Result := False; // 企业信用代码长度校验 if Length(EnterpriseCode) <> 18 then Exit; // 企业信用代码权重因子 const factor: array[1..17] of Integer = (1, 3, 9, 27, 19, 26, 16, 17, 20, 29, 25, 13, 8, 24, 10, 30, 28); // 计算企业信用代码前17位的加权和 sum := 0; for i := 1 to 17 do begin code := Ord(EnterpriseCode[i]) - Ord('0'); weight := factor[i]; sum := sum + code * weight; end; // 计算校验码 code := 31 - sum mod 31; // 校验企业信用代码最后一位校验码 if code = 31 then code := 0; if code <> Ord(EnterpriseCode[18]) - Ord('0') then Exit; Result := True; end;
标签:code,17,sum,校验,企业信用,GPT,Ord,EnterpriseCode From: https://www.cnblogs.com/kinglandsoft/p/17853331.html