public static function getEngine($strEngine = 'Ral') { if (defined('IS_ODP') && true === IS_ODP) { $strClassName = "Bd_Passport_Interact_Ral"; } else { $engine = Bd_Passport_Conf::getConfEx('engine', 'Ral'); $strEngine = ucfirst(strtolower($engine)); $strClassName = "Bd_Passport_Interact_{$strEngine}"; $filename = dirname(__FILE__) . "/interact/" . $strEngine . ".php"; if (file_exists($filename)) { require_once $filename; } else { Bd_Passport_Log::warning("{$filename} doesn't exist!", E_USER_ERROR); } } if (class_exists($strClassName)) { $instance = new $strClassName(); if (!$instance instanceof Bd_Passport_Interact_IEngine) { Bd_Passport_Log::warning("{$strClassName} isn't instanceof Bd_Passport_Interact_IEngine", E_USER_WARNING); } return $instance; } else { Bd_Passport_Log::warning("{$strClassName} Not Found!", E_USER_WARNING); } }
protected static function _initLog() { if (defined('IS_ODP') && true === IS_ODP) { self::$_cbLogNotice = array('Bd_Log', 'notice'); self::$_cbLogWarning = array('Bd_Log', 'warning'); self::$_cbLogDebug = array('Bd_Log', 'debug'); self::$_cbLogFatal = array('Bd_Log', 'fatal'); } else { /*非ODP环境日志回调函数*/ } self::$_isInit = true; }
/** * @brief 从URL中解密PSPTOKEN * @param string $psptoken 加密过的psptoken,根据配置文件中配置的tpl和key进行解密 * @return string psptoken * @return bool false On failure * @author fanmengzhe */ public static function decryptPSPToken($psptoken) { $tpl = Bd_Passport_Conf::getConfEx('tpl', false); if (!$tpl) { self::$_errno = -1; self::$_errmsg = 'TPL not found in passport.conf/Inc.php'; Bd_Passport_Log::warning(self::$_errmsg, self::$_errno); return false; } $key = Bd_Passport_Conf::getConfEx('psptoken_key_crypt', false); if (!$key) { self::$_errno = -1; self::$_errmsg = 'psptoken_key_crypt not found in passport.conf/Inc.php'; Bd_Passport_Log::warning(self::$_errmsg, self::$_errno); return false; } return Bd_Passport_Util_URLCrypt::url_decrypt($tpl, $key, $psptoken); }
/** * @brief * @param * @return * @author fanmengzhe * @date 2011/11/08 11:50:32 * @note */ protected function _send($fd, $strSend, $intTimeout) { $intLen = strlen($strSend); if ($intLen < 0) { Bd_Passport_Log::warning('null string found', -1); return false; } stream_set_blocking($fd, true); $intSecond = intval($intTimeout / 1000); $intMicroSecond = intval($intTimeout % 1000); stream_set_timeout($fd, $intSecond, $intMicroSecond); $intSent = fwrite($fd, $strSend, strlen($strSend)); return $intSent === $intLen ? $intSent : false; }
/** * @brief Talk With Passgate * @author fanmengzhe * @param string $strMethod [batget] * @param array $arrInput 输入数组 * @return */ protected static function _____($strMethod, $arrInput) { $ins = Bd_Passport_Interact::getEngine('Ral'); $retry = 1; while ($retry-- >= 0) { $ret = $ins->Call('passgate', $strMethod, $arrInput); // Return false when Ral Failed if (!is_array($ret)) { self::$_errno = -1; Bd_Passport_Log::warning('Communication with Passgate failed.', self::$_errno); continue; } if (isset($ret['header']['err_no'])) { self::$_errno = $ret['header']['err_no']; self::$_errmsg = $ret['header']['errno_info']; Bd_Passport_Log::warning("[Input :" . json_encode($arrInput) . "]", -1); Bd_Passport_Log::warning("[Output:" . json_encode($ret) . "]", self::$_errno); continue; } else { self::$_errno = 0; } if (!isset($ret['content'])) { Bd_Passport_Log::warning("[Input :" . json_encode($arrInput) . "]", -1); Bd_Passport_Log::warning("[Output:" . json_encode($ret) . "]", self::$_errno); continue; } foreach ($ret['content'] as &$content) { if (!isset($content['result_params'])) { Bd_Passport_Log::warning("[Input :" . json_encode($arrInput) . "]", -1); Bd_Passport_Log::warning("[Output:" . json_encode($ret) . "]", self::$_errno); continue; } foreach ($content['result_params'] as $key => &$val) { if (isset($val['taginfo'])) { $val['taginfo'] = self::_parseTagInfo($val['taginfo']); } if (isset($val['taginfo_ex'])) { $val['taginfo_ex'] = self::_parseTagInfoEx($val['taginfo_ex']); } } } return $ret; } //retry once return false; }
/** * @brief Talk With Session * */ protected static function _____($strMethod, $arrInput) { $ins = Bd_Passport_Interact::getEngine('Ral'); //Fix Clientip . NET-ORDER , Int32(Neither UInt32 nor Long) $arrInput['clientip'] = Bd_Passport_Util::ip2int(CLIENT_IP); //If @ORP , Need Pass(ie, Session Key) if (self::$_is_orp) { $arrInput['pass'] = self::$_pass; } //If the session server is busy , Just retry once. $retry = 1; while ($retry >= 0) { // Do Interaction CALL HERE !!! $ret = $ins->Call('session', $strMethod, $arrInput); if (is_array($ret) && isset($ret['status'])) { self::$_errno = $ret['status']; //if (self::$_errno != 0) { // Bd_Passport_Log::warning(self::$errmsgMap[self::$_errno], self::$_errno); //} if (self::RET_SSN2_SERVER_BUSY === $ret['status']) { Bd_Passport_Log::warning(self::$errmsgMap[self::$_errno], self::$_errno); --$retry; continue; } else { return $ret; } } else { //Let errno not defined , getMessage will return 'Unknown error'. Bd_Passport_Log::warning('Unknown Error', self::$_errno); self::$_errno = -1; return false; } } return false; }
public function getBDUSSBySSIDWithRAL($ssid) { ral_set_logid(LOG_ID); ral_set_pathinfo('passport/get_sid'); ral_set_querystring("ssid={$ssid}&plain=&version=2"); $res = ral('wappass', 'get', array(), 1); if ($res != null) { $res = json_decode($res, true); self::$_errno = !$res ? -1 : 0; self::$_errmsg = !$res ? "[Wappass][get_sid]Result json_decode failed." : ""; if (!$res) { Bd_Passport_Log::warning(self::$_errmsg, -1); } return is_array($res) ? $res : false; } else { self::$_errno = ral_get_errno(); self::$_errmsg = "[Wappass][get_sid]Talk with server failed. errmsg:" . ral_get_error(); Bd_Passport_Log::warning(self::$_errmsg, -1); return false; } }