校验码算法描述如下:详细:http://wenku.baidu.com/link?url=CDvNJ1sLYOPzbbxjEy5R-oME95RlfTCUU5-I5M0bqUt0I32b0Xd0EKmI-HiFQHhY8OcB6ERTml7pUwXFseLl8GGvkuc7w0V2sFDxi2H0XGC
本例子以16位编号为例子,用PHP予以实现,代码如下:
$m = '';
$str = '440400131008309';
$str.= 'a';
/* 测试用例,最后一位为校验码
4404021110060840
4404001310083095
4404021150062404
*/
function p($str,$n)
{
if ($n == 1)
{
return 10;
}
else
{
$num = $str[$n-2];
$s = p($str,$n-1)%11 + $num;
return ($s%10==0?10:$s%10)*2;
}
}
$p = p($str,16);
for($i=0;$i<10;$i++){
if (($p%11 + $i)%10 == 1){
$m = $i;
break;
}
}
echo $m;