if ($autoincreament) { // $arrReturn->current += $count; // $arrReturn->save(); $current += $count; } return $arrReturn; } } // 生成码的对象 $objCodesEncode = new myCodes(); $index = 10000; /** * $code_length 码位数 * $count 生成数量 * */ $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"; // ...
* (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"; echo $arrEncode['data']['code'] . "\t" . number_format($t_mt - $t_st, 7) . "\t| " . ($arrDecode['success'] ? $arrDecode['data']['index'] . '-' . $arrDecode['data']['number'] : $arrDecode['msg']) . "\t" . number_format($t_et - $t_mt, 7) . "\n"; } echo "total:{$i}, time:" . number_format($t_et - $t_s, 7) . "\n";