/** * @ 创建唯一码的入口 * @param $index * @param $code_length // 生成码的位数 * @return array */ public function encode($index, $code_length = 11) { if (!$this->initLength($code_length)) { return $this->returnArray(false, "Can not handle {$code_length}-character codes", []); } $this->_index = $index; $indexMsg = $this->getCodingMsgByIndex('create'); if ($indexMsg === false) { // 不存在解析出来的index return $this->returnArray(false, 'No such index', []); } // 编号超出最大存储范围 $this->_bin_numbering = $this->nuToBin($this->_numbering, $this->_numbering_bin_length); if (strlen($this->_bin_numbering) > $this->_numbering_bin_length) { return $this->returnArray(false, 'Numbering exceed the maximum', ['number' => $this->_numbering, 'code' => '']); } // 索引ID超出最大存储范围 $this->_bin_index = $this->nuToBin($this->_index, $this->_index_bin_length); if (strlen($this->_bin_index) > $this->_index_bin_length) { return $this->returnArray(false, 'Index exceed the maximum', ['number' => $this->_numbering, 'code' => '']); } $disruptedBin41 = $this->makeSignAndMixWithNumber(); $endMix = c_implodeBins($this->binNot($this->_bin_index), $disruptedBin41); //echo $disruptedBin41."\t"; return $this->returnArray(true, 'success', ['number' => $this->_numbering, 'code' => $this->binToStr($endMix)]); }
/** * @ 创建唯一码的入口 * @param $index * @param $code_length // 生成码的位数 * @return array */ public function encode($index, $code_length = 11, $count = 1) { if (!$this->initLength($code_length)) { return $this->returnArray(false, "Can not handle {$code_length}-character codes", []); } $this->_index = $index; $indexMsg = $this->callCoding('create', $count); $arrCodings = []; for ($i = 0; $i < $count; $i++) { if ($indexMsg === false) { // 不存在解析出来的index return $this->returnArray(false, 'Index message id not exist or not correct', []); } // 编号超出最大存储范围 $this->_bin_numbering = $this->nuToBin($this->_numbering, $this->_numbering_bin_length); if (strlen($this->_bin_numbering) > $this->_numbering_bin_length) { return $this->returnArray(false, 'Numbering exceed the maximum', []); } // 索引ID超出最大存储范围 $this->_bin_index = $this->nuToBin($this->_index, $this->_index_bin_length); if (strlen($this->_bin_index) > $this->_index_bin_length) { return $this->returnArray(false, 'Index exceed the maximum', []); } $disruptedBin41 = $this->makeSignAndMixWithNumber(); $endMix = c_implodeBins($this->binNot($this->_bin_index), $disruptedBin41); $arrCodings[] = $this->binToStr($endMix); $this->_numbering++; } return $this->returnArray(true, 'success', ['number' => ['start' => $this->_numbering - $count, 'end' => $this->_numbering - 1], 'code' => $arrCodings]); }