public static function getDbNo($identifier) { $sign = $identifier; is_numeric($identifier) || ($sign = Sign::sign64($identifier)); $tag = intval(Sign::mod($sign, AppConf::$dbConf['db_num'] * AppConf::$dbConf['tb_num']) / AppConf::$dbConf['tb_num']); return $tag; }
private function genRequestId() { if (isset($_SERVER['HTTP_CLIENTAPPID'])) { return intval($_SERVER['HTTP_CLIENTAPPID']); } $reqip = App::getClientIp(); $time = gettimeofday(); $time = $time['sec'] * 100 + $time['usec']; $ip = ip2long($reqip); $id = ($time ^ $ip) & 0xffffffff; $id = Sign::sign64($id . '_' . rand(1, 800000000)); return $id; }
public static function checkRetriPassParam($db, $euid, $code, $timestamp, $jump = 'reject') { $now = time(); if ($timestamp + AppConf::$emailRetriPassExpire < $now) { if (is_string($jump)) { throw new Exception("param {$jump} time expired [ now: {$now}, timestamp: " . "{$timestamp}, expire time: " . AppConf::$emailRetriPassExpire . ' ].', 1); } throw new Exception("param time expired [ now: {$now}, timestamp: " . "{$timestamp}, expire time: " . AppConf::$emailRetriPassExpire . ' ].'); } $uid = Uc_Com_Utils::decodeUserId($euid); $sql = "SELECT uid, account, password, email, phone, qq, regist_time FROM uc_user_info WHERE uid = {$uid}"; $dbRet = $db->query($sql, is_string($jump) ? 'error' : true); if (count($dbRet) <= 0) { if (is_string($jump)) { throw new Exception("nouser {$jump} such user does not exists [ uid: " . $uid . ' ].', 1); } throw new Exception('nouser such user does not exists [ uid: ' . $uid . ' ].'); } $uInfo = $dbRet[0]; $orgStr = AppConf::$emailVeriPrefix . '_' . $euid . '_' . $uInfo['account'] . '_' . $uInfo['password'] . '_' . $uInfo['email'] . '_' . $uInfo['phone'] . '_' . $uInfo['qq'] . '_' . date('Y-m-d H:i:s', $uInfo['regist_time']) . '_' . date('Y-m-d H:i:s', $timestamp); $str = md5(base64_encode($orgStr)); $dbCode = Sign::sign64($str); if ($dbCode != $code) { if (is_string($jump)) { throw new Exception("param {$jump} invalid code [ uid: {$uid}, code: {$code}, db code: {$dbCode}, str: {$orgStr} ]", 1); } throw new Exception("param invalid code [ uid: {$uid}, code: {$code}, db code: {$dbCode}, str: {$orgStr} ]"); } KC_LOG_DEBUG("check retrieve password params succ [ euid: {$euid}, uid: {$uid}, code: {$code}, str: {$orgStr} ]."); }