Пример #1
0
 * */
$arrEncode = $objCodesEncode->encode($index, $code_length = 11, $count = 11120);
echo "生成成功:\n";
var_dump($arrEncode);
$arrEncode = $objCodesEncode->encode($index, $code_length = 15);
echo "支持生成10-15位码:\n";
var_dump($arrEncode);
$index = 20000;
$arrEncode = $objCodesEncode->encode($index, 11);
echo "index值溢出:\n";
var_dump($arrEncode);
$index = 10000;
$arrEncode = $objCodesEncode->encode($index, 16);
echo "不支持16位的码:\n";
var_dump($arrEncode);
echo "\n\n\n";
// ...
// 校验码的对象
$objCodesDecode = new myCodes();
$arrDecode = $objCodesDecode->decode("H6YRZR75K7T");
echo "验证成功:\n";
var_dump($arrDecode);
$arrDecode = $objCodesDecode->decode("UCYVQARJM6P57NF");
echo "验证成功:\n";
var_dump($arrDecode);
$arrDecode = $objCodesDecode->decode("FHM3RJZRHZF");
echo "验证失败:\n";
var_dump($arrDecode);
$arrDecode = $objCodesDecode->decode("FHM3RJZRHZFRHZFF");
echo "不支持16位:\n";
var_dump($arrDecode);
Пример #2
0
         *     [
         *         (int)    'current'=> '当前创建码的个数',
         *         (string) 'salt'=> '秘钥',
         *         (int)    'interference'=> '参与计算的乱序随机数',
         *     ]
         */
        $arrReturn = ['current' => $this->current, 'salt' => 'hG#cGzBW*PxVskFP$4*a', 'interference' => '14162'];
        // * 如果$autoincreament为true,current的值加1存库
        if ($autoincreament) {
            $this->current++;
        }
        return $arrReturn;
    }
}
$objCodesEncode = new myCodes();
$objCodesDecode = new myCodes();
$index = 1;
echo "index:{$index}\n";
$t_s = microtime(true);
for ($i = 0; $i < 10; $i++) {
    $t_st = microtime(true);
    $arrEncode = $objCodesEncode->encode($index, 11);
    if (!$arrEncode['success']) {
        echo $arrEncode['msg'] . "\n";
        continue;
    }
    $t_mt = microtime(true);
    // echo $arrEncode['data']['code']."\t";
    $arrDecode = $objCodesDecode->decode($arrEncode['data']['code']);
    $t_et = microtime(true);
    // echo $arrDecode['data']['index']."\t";