load( DIR.'config/contrast_table.inc.xml'); $roots = $this->getElementsByTagName('root'); foreach ($roots as $k) { $chars = $k->getElementsByTagName('key'); $values = $k->getElementsByTagName('value'); for($i=0; $i<64; $i++ ){ $key = $chars->item($i)->nodeValue; $value = $values->item($i)->nodeValue; $this->charcters[$key] = $value; $this->values[$value] = $key; } } } /** * 生成帖子ID * @param int $server_id 服务器ID * @param int $group_id 组ID * @param int $thread_id 帖子ID * @param string 返回生成的帖子ID */ function createThreadId( $server_id = 1,$group_id = 1,$thread_id = 1){ /* 先转换成二进制,然后按位补齐 */ $sid = $this->strpad( decbin(($server_id)),12 ); $gid = $this->strpad( decbin(($group_id)),16 ); $tid = $this->strpad( decbin(($thread_id)),16 ); //echo $sid.'0000'.$gid.$tid.''; /* 转换为数组 */ $aTemp = str_split( $sid.'0000'.$gid.$tid ); $len = count($aTemp); $res = array(); $temp = 0; /* 将48位的字符串切成8个子串 */ for($i=0;$i<$len;$i++){ if( ($i)%6 == 0 ){ $temp++; } $res[$temp].= $aTemp[$i]; } $len = count($res); /* 清空零时数组 */ $aTemp = array(); /* 将8个子串分别转换成进制数 */ for($i=1;$i<=$len;$i++){ $aTemp[$i] = bindec($res[$i]); } /* 对应到64进制表 */ foreach($aTemp AS $v ){ $this->result .= $this->values[$v]; } return $this->result; } /** * 获取原始ID信息 反解析 * @param type $str N6000g1D * @return array {"server_id"=>3142,"group_id"=>1,"thread_id"=>103} */ function getOriginalThreadId($str = ""){ $aTemp1 = str_split($str); $aTemp2 = array(); /* 找到对应64进制表中的值,并转换成二进制,同时按6位补齐 */ foreach( $aTemp1 as $v ) { $aTemp2[] = $this->strpad( decbin($this->charcters[$v]),6 ); } /* 得到48位的字符串 */ $x = implode($aTemp2); /* 分别计算 */ $result['server_id'] = bindec(substr($x, 0,12)); $result['group_id'] = bindec(substr($x, strlen($x)-32,16)); $result['thread_id'] = bindec(substr($x, strlen($x)-16)); return $result; } /** * 重写补位函数 * @param type $str 原始二进制串 * @param type $byte 需要补齐的位数 * @return string 补齐后的二进制串 */ private function strpad($str,$byte){ if( strlen($str)<$byte ){ return str_pad($str, $byte, '0',STR_PAD_LEFT); } return $str; } /** * * @param int $server_id * @param int $group_id * @return string 生成后的帖子ID */ function getBlogThreadId($server_id,$group_id){ $path = DIR.'filecache/thread_id_cache.php'; require_once ($path); $thread_id += 1; /* 计算12二进制位用于表示帖子ID 不能超过2^12 */ if( 65536 <= $thread_id ){ $group_id++; $thread_id = 0; } $data = " "; /* 将当前new帖子ID写入到缓存文件*/ $handle = @fopen($path, 'w+'); if ($handle) { fwrite($handle, $data); fclose($handle); } $returnValue = $this->createThreadId($server_id,$group_id,$thread_id); return $returnValue; } } ?>
0 E 1 F 2 G 3 H 4 I 5 J 6 K 7 L 8 M 9 N 10 a 11 b 12 c 13 d 14 e 15 f 16 g 17 h 18 i 19 j 20 O 21 P 22 Q 23 R 24 S 25 T 26 U 27 V 28 W 29 X 30 k 31 l 32 m 33 n 34 o 35 p 36 q 37 r 38 s 39 t 40 u 41 v 42 w 43 x 44 y 45 z 46 A 47 B 48 C 49 D 50 0 51 1 52 2 53 3 54 4 55 5 56 6 57 7 58 8 59 9 60 Y 61 Z 62 _ 63 $