Exemple #1
0
 private static function pid2UrlRal($reqArr)
 {
     ral_set_logid(time() + mt_rand());
     $array = array("cmd_no" => 1012, "reqs" => $reqArr);
     $ret = ral('urlCrypt', 'nothing', $array, rand());
     if ($ret === false) {
         Bd_Pic_Log::warning(ral_get_error(), ral_get_errno());
         return false;
     }
     return $ret;
 }
Exemple #2
0
 public function queryFromSug(&$arrData)
 {
     //sug接口wiki:http://wiki.babel.baidu.com/twiki/bin/view/Ps/Rank/InterActionTopic/OpensugInterfaceIntroduction
     //json=1表示返回标准的json格式数据
     //cb=空 表示返回的数据中没有“window.baidu.sug”回调
     $arrUrlParams = array();
     $strReferWord = '';
     if (!empty($arrData['uiData']['queryinfo']['refer'])) {
         $strUrlParams = parse_url($arrData['uiData']['queryinfo']['refer'], PHP_URL_QUERY);
         if (!empty($strUrlParams)) {
             parse_str($strUrlParams, $arrUrlParams);
             if (!empty($arrUrlParams)) {
                 $strReferWord = isset($arrUrlParams['wd']) ? $arrUrlParams['wd'] : (isset($arrUrlParams['word']) ? $arrUrlParams['word'] : (isset($arrUrlParams['w']) ? $arrUrlParams['w'] : ''));
             }
         }
     }
     $arrHeader['pathinfo'] = 'su';
     $arrHeader['querystring'] = 'wd=' . $arrData['uiData']['queryInfo']['queryWord'] . "&ie=utf-8&json=2&cb=";
     $arrHeader['Referer'] = $_SERVER['HTTP_REFERER'];
     $arrHeader['Cookie'] = $_SERVER['HTTP_COOKIE'];
     $arrData['uiData']['queryInfo']['isParams']['sug_status'] = SUG_STATUS_NORMAL;
     $arrSugInfo = array();
     if (!isset($_ENV['HHVM'])) {
         ral_set_logid(CLog::logId());
         $ret = ral('sug', 'get', '', Volatile::rand(), $arrHeader);
     } else {
         $ral = new RalClass();
         $ral->ral_set_logid(CLog::logId());
         $ret = $ral->ral_curl_sug('sug', '', $arrHeader);
     }
     //ral请求失败
     if ($ret === false) {
         $arrData['uiData']['queryInfo']['isParams']['sug_status'] = SUG_STATUS_RAL_ERROR;
         return $arrSugInfo;
     }
     $arrRst = json_decode($ret, true);
     //json_decode失败
     if ($arrRst === false) {
         $arrData['uiData']['queryInfo']['isParams']['sug_status'] = SUG_STATUS_JSON_FAIL;
         return $arrSugInfo;
     }
     if (empty($arrRst['q'])) {
         $arrData['uiData']['queryInfo']['isParams']['sug_status'] = SUG_STATUS_ERROR_REQ;
         return $arrSugInfo;
     }
     //sug为空
     if (empty($arrRst['s']) || !is_array($arrRst['s'])) {
         $arrData['uiData']['queryInfo']['isParams']['sug_status'] = SUG_STATUS_NO_SUG;
         return $arrSugInfo;
     }
     $arrSugInfo = $arrRst['s'];
     return $arrSugInfo;
 }
Exemple #3
0
 public static function create($service, $extra = null)
 {
     //set logid
     if (defined('LOG_ID')) {
         ral_set_logid(LOG_ID);
     }
     if (!is_array($extra)) {
         $extra = self::$extra;
     } else {
         $extra = array_merge(self::$extra, $extra);
     }
     self::$err_msg = '';
     if (strpos($service, '_') === false) {
         $classname = 'Ak_Service_' . $service;
     } else {
         $classname = $service;
     }
     $ret = new $classname();
     if ($ret->_init($service, $extra)) {
         return $ret;
     }
     self::$err_msg = $ret->get_error();
     return null;
 }
Exemple #4
0
 public function queryFromUs($arrData)
 {
     $arrQueryInfo = $arrData['uiData']['queryInfo'];
     $arrSessionInfo = $arrData['uiData']['passport'];
     $arrControlInfo = $arrData['uiControl'];
     // 传递给us的数据结构
     $objQuery = new QueryUSInfo();
     $objQuery->time = time();
     $objQuery->word = $arrQueryInfo['queryWord'];
     $objQuery->wordNoSyntax = $arrQueryInfo['wordNoSyntax'];
     $objQuery->otherResultQuery = $arrQueryInfo['otherResultQuery'];
     $objQuery->ip = $arrQueryInfo['ip'];
     if ($arrQueryInfo['interPage'] > 0) {
         $objQuery->isInterPage = 1;
     } else {
         $objQuery->isInterPage = 0;
     }
     if ($arrQueryInfo['bwsRetry'] > 0) {
         $objQuery->isBwsRetry = 1;
     } else {
         $objQuery->isBwsRetry = 0;
     }
     $objQuery->preference = $arrQueryInfo['preference'];
     $objQuery->passportUserName = $arrSessionInfo['passportUserName'];
     if (!empty($arrQueryInfo['JpAlaPre'])) {
         $objQuery->JpAlaPre = $arrQueryInfo['JpAlaPre'];
     }
     $objQuery->codeType = $arrQueryInfo['originCodeType'] & ~(DICT_SEARCH_BIT | MON_BIT | NEWS_SEARCH_BIT | BAIDU_REFER_BIT | TITLE_SEARCH_BIT | AUTHOR_SEARCH_BIT);
     if (($arrQueryInfo['isDebug'] && intval($arrData['uiData']['templateConfig']['debug'])) > 0) {
         $objQuery->isDebug = 1;
     } else {
         $objQuery->isDebug = 0;
     }
     $objQuery->strategyName = $arrQueryInfo['strategyName'];
     $objQuery->siteName = $arrQueryInfo['siteName'];
     $objQuery->lastModified = $arrQueryInfo['lastModified'];
     $strTemplateNameMod = null;
     if (!empty($arrControlInfo['templateName']) && $arrControlInfo['platform'] !== $GLOBALS['DEFAULT_PLATFORM']) {
         $strTemplateNameMod = 'baidu' . $arrQueryInfo['dspName'];
     }
     if (empty($strTemplateNameMod)) {
         $objQuery->templateName = $arrControlInfo['templateName'];
     } else {
         $objQuery->templateName = $strTemplateNameMod;
     }
     $objQuery->sid = $arrQueryInfo['samplingId'];
     $objQuery->cookie = $arrQueryInfo['baiduId'];
     $objQuery->needsp = $arrQueryInfo['needSp'];
     $objQuery->pageNo = $arrQueryInfo['pageNo'];
     $objQuery->queryId = $arrQueryInfo['queryIdInt'];
     $objQuery->beforeQueryId = $arrQueryInfo['beforeQueryId'];
     $objQuery->beforeUrl = $arrQueryInfo['beforeUrl'];
     $objQuery->accountName = $arrQueryInfo['accountName'];
     $objQuery->isContCluster = $arrQueryInfo['isContMirror'];
     $objQuery->isSiteCluster = $arrQueryInfo['isSiteCluster'];
     $intPageNum = 0;
     if ($arrQueryInfo['pageNo'] == 1 || $arrQueryInfo['pageNo'] == 2 && $arrQueryInfo['resNum'] == 10) {
         $intPageNum = $arrQueryInfo['pageNum'];
     } else {
         $intPageNum = $arrQueryInfo['pageNum'] - $arrQueryInfo['usm'];
     }
     if ($intPageNum < 0) {
         $intPageNum = 0;
     }
     if ($intPageNum >= MAX_OUTPUT_NUM) {
         $intPageNum = 750;
     }
     $objQuery->pageNum = $intPageNum;
     $objQuery->resNum = $arrQueryInfo['resNum'];
     $objQuery->resultLang = $arrQueryInfo['resultLang'];
     $objQuery->resultLocale = $arrQueryInfo['resultLocale'];
     $strUrlParam = self::filterParamFromUrl($arrQueryInfo['urlParam'], WENKU_WAP_PC_KEY);
     if (!empty($strUrlParam) && !empty($arrQueryInfo['wenkuUrlPara'])) {
         $strUrlParam .= '&' . $arrQueryInfo['wenkuUrlPara'];
     }
     $objQuery->urlParam = $strUrlParam;
     $objQuery->requestCode = $arrQueryInfo['requestCode'];
     $objQuery->usm = $arrQueryInfo['usm'];
     $objQuery->UrlParaPack = self::packUrlParam($strUrlParam, $arrQueryInfo['postData'], $strTemplateNameMod, $arrQueryInfo['cookieInfo']);
     if (PROTECTPP_SWITCH_OPEN == $arrQueryInfo['resLimitSwitch']) {
         $objQuery->enalbeModifyUsm = 1;
     } else {
         $objQuery->enalbeModifyUsm = 0;
     }
     $intCommand = 0;
     for ($intI = 0; $intI < DA_RES_COUNT; $intI++) {
         $intCommand |= $arrQueryInfo['daResource'][$intI];
     }
     $objQuery->template_rsse_command = $intCommand;
     $objQuery->need_open_disphilight = $arrQueryInfo['need_open_disphilight'];
     $objQuery->need_RsSE_result = $arrQueryInfo['needRsSeResult'];
     $objQuery->need_ers_result = $arrQueryInfo['needERSResult'];
     $objQuery->need_asp_result = $arrQueryInfo['needASPResult'];
     $objQuery->need_as_result = $arrQueryInfo['need_as_result'];
     $objQuery->preQueryWord = $arrQueryInfo['preQueryWord'];
     $objQuery->querySource = $arrQueryInfo['querySource'];
     $objQuery->isInternalFlow = $arrQueryInfo['isInternalFlow'];
     $objQuery->srcId = $arrQueryInfo['srcId'];
     $objQuery->templateForRs = $arrQueryInfo['templateForRs'];
     $objQuery->beforeQueryId = $arrQueryInfo['beforeQueryId'];
     $objQuery->noscript = $arrQueryInfo['noscript'];
     $objQuery->cookieNoscript = $arrQueryInfo['cookieNoscript'];
     $objQuery->channel = $arrQueryInfo['channel'];
     $objQuery->rsPos = $arrQueryInfo['rsPos'];
     $objQuery->platformName = $arrControlInfo['platform'];
     $objQuery->is_bws_re = $arrQueryInfo['is_bws_re'];
     $objQuery->useragent_full = $arrQueryInfo['useragent_full'];
     $objQuery->confuse_Switch = $arrQueryInfo['confuse_Switch'];
     $objQuery->protectNum = $arrQueryInfo['protectNum'];
     $objQuery->ec_src = $arrQueryInfo['ec_src'];
     $objQuery->php_default_platform = $GLOBALS['DEFAULT_PLATFORM'];
     $objQuery->dspName = $arrQueryInfo['dspName'];
     $objQuery->ipv6Address = $arrQueryInfo['ipv6Address'];
     $objQuery->refer = $arrQueryInfo['refer'];
     $objQuery->needProtect = $arrQueryInfo['needProtect'];
     $objQuery->protectPPSwitch = $arrQueryInfo['protectPPSwitch'];
     $objQuery->nojc = $arrQueryInfo['nojc'];
     $objQuery->super_se_flag = $arrQueryInfo['superSeFlag'];
     $objQuery->isContainPunc = $arrQueryInfo['isContainPunc'];
     $objQuery->wordNoPunc = $arrQueryInfo['wordNoPunc'];
     $objQuery->clusterMod = $arrQueryInfo['clusterMod'];
     $objQuery->wordEnc = $arrQueryInfo['wordEnc'];
     $objQuery->extraStr = $arrQueryInfo['extraStr'];
     $objQuery->strategy_state = $arrQueryInfo['strategyState'];
     $objQuery->prompt_flag = $arrQueryInfo['promptUsOpen'];
     $objQuery->passport_user_id = $arrSessionInfo['passportUserId'];
     $objQuery->need_interleaving = $arrQueryInfo['need_interleaving'];
     $objQuery->comeFrom = $arrQueryInfo['comeFrom'];
     if (!empty($arrQueryInfo['country'])) {
         $objQuery->country_str = $arrQueryInfo['country'];
     }
     $objQuery->is_sample_template = isset($arrQueryInfo['is_sample_template']) ? intval($arrQueryInfo['is_sample_template']) : 0;
     $objQuery->superseSwitch = isset($arrQueryInfo['superseSwitch']) ? intval($arrQueryInfo['superseSwitch']) : 1;
     $objQuery->query_lang = $arrQueryInfo['query_lang'];
     $objQuery->displayLang = $arrControlInfo['language'];
     if (isset($arrQueryInfo['isParams'])) {
         if ($arrQueryInfo['isParams']['mod'] === IS_PRE_DICT_REQ) {
             if (!empty($arrQueryInfo['isParams']['hsug'])) {
                 $objQuery->hsug = $arrQueryInfo['isParams']['hsug'];
             }
             if (!empty($arrQueryInfo['isParams']['sug'])) {
                 $objQuery->sug = $arrQueryInfo['isParams']['sug'];
             }
             if (!empty($arrQueryInfo['isParams']['clist'])) {
                 $objQuery->clist = $arrQueryInfo['isParams']['clist'];
             }
         }
         $objQuery->mod = $arrQueryInfo['isParams']['mod'];
         $objQuery->cqid = empty($arrQueryInfo['isParams']['cqid']) ? '0' : $arrQueryInfo['isParams']['cqid'];
         $objQuery->isid = empty($arrQueryInfo['isParams']['isid']) ? '0' : $arrQueryInfo['isParams']['isid'];
         $objQuery->chk = empty($arrQueryInfo['isParams']['chk']) ? '0' : $arrQueryInfo['isParams']['chk'];
         if (in_array($objQuery->mod, array(IS_PRE_REQ, IS_PRE_DICT_REQ)) && in_array($objQuery->word, array('baidu', '百度'))) {
             $objQuery->f4s = 1;
         } else {
             $objQuery->f4s = $arrQueryInfo['isParams']['f4s'];
         }
         $objQuery->isbd = $arrQueryInfo['isParams']['isbd'];
         $objQuery->csq = intval($arrQueryInfo['isParams']['csq']);
         $objQuery->pstg = intval($arrQueryInfo['isParams']['pstg']);
         $objQuery->isDebugSwitch = intval($arrQueryInfo['isDebugSwitch']);
     }
     // User Agent相关字段, by chenjinsheng@baidu.com, 2013-07-08
     if (!empty($arrQueryInfo['userAgent'])) {
         list($resx, $resy) = @explode('x', $arrQueryInfo['userAgent']['resolution']);
         $arrUaInfo = array('ua_os' => $arrQueryInfo['userAgent']['os'], 'ua_browser' => $arrQueryInfo['userAgent']['browser'], 'ua_modal' => $arrQueryInfo['userAgent']['modal'], 'ua_measure' => $arrQueryInfo['userAgent']['measure'], 'ua_res_x' => $resx, 'ua_res_y' => $resy);
         $arrExpFields = Bd_Conf::getConf('tpl_uaadaptation/UA_DICT_EXPLICIT');
         $arrExpFields = array_keys($arrExpFields);
         foreach ($arrExpFields as $filed) {
             unset($arrQueryInfo['userAgent'][$filed]);
         }
         if (!empty($arrQueryInfo['userAgent'])) {
             $objUaFields = Util::mcpack_normal($arrQueryInfo['userAgent']);
             $strUaFields = mc_pack_array2pack($objUaFields);
             $arrUaInfo['ua_ext'] = $strUaFields;
         }
         $objQuery->uaInfo = $arrUaInfo;
     }
     $arrQuery = $objQuery->toArray();
     $arrQuery = Util::mcpack_normal($arrQuery);
     foreach ($arrQuery as $key => $value) {
         if (in_array($key, array('cookie', 'beforeUrl', 'UrlParaPack', 'JpAlaPre'))) {
             $arrQuery['(raw)' . $key] = $value;
             unset($arrQuery[$key]);
         }
     }
     if (!isset($_ENV['HHVM'])) {
         ral_set_logid(CLog::logId());
         $ret = ral('us', 'us', $arrQuery, Volatile::rand());
         if ($ret === false) {
             $intErrno = ral_get_errno();
             CLog::fatal('Fail to connect us, errNo:' . $intErrno, $GLOBALS['logArr']);
         }
     } else {
         $ral = new RalClass();
         $ral->ral_set_logid(CLog::logId());
         $ret = $ral->ral('us', 'us', $arrQuery, Volatile::rand());
         if ($ret === false) {
             $intErrno = $ral->ral_get_errno();
             $strErrmsg = $ral->ral_get_error($intErrno);
             CLog::fatal('Fail to connect us, errNo:' . $intErrno . 'errMsg: ' . $strErrmsg, $GLOBALS['logArr']);
         }
     }
     return $ret;
 }
Exemple #5
0
 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;
     }
 }
Exemple #6
0
 public function Call($strServer, $strMethod, $arrInput)
 {
     ral_set_logid(LOG_ID);
     return ral($strServer, $strMethod, $arrInput, 1);
 }