void LogHelper::CookieEmptyCheck(UserProfile& upf){ int userid = upf.id(); if(!upf.id()){ upf.set_id(888); } if(upf.age() > 100 || upf.age() < 15){ upf.set_age(20 + AdMatchManagerI::instance().ServerIndex()); } if(upf.ip_area().empty() || "0000000000000000" == upf.ip_area()){ upf.set_ip_area("0086110000000000"); } if(!upf.stage()){ upf.set_stage(4); } if(!upf.ip()){ upf.set_ip(975044608); } if(upf.current_area().empty()){ upf.set_current_area("0086110000000000"); } /////////////////////////// //if(!upf.home_area().empty()) { // upf.set_ip_area(upf.home_area()); //for test only //} /////////////////////////// }
void CookieEmptyCheck(UserProfile& upf) { if (!upf.id()) { upf.set_id(8); } if (upf.ip_area().empty() || "0000000000000000" == upf.ip_area()) { upf.set_ip_area("0086110000000000"); // 北京 } if (!upf.stage()) { upf.set_stage(4); } if (!upf.ip()) { upf.set_ip(975044608); // 北京的一个随机IP } if (upf.current_area().empty()) { upf.set_current_area("0086110000000000"); // 北京 } }
AdResultMap AdMatchManagerI::GetAdsTest(::Ice::Int uid, ::Ice::Int stage, ::Ice::Int gender, ::Ice::Int age, const ::std::string& currentArea, const ::std::string& ipArea, ::Ice::Long school, ::Ice::Int grade, int count, const string & referer, int rotate_index, const Ice::Current& current) { AdInfoSeq out; string serialized; if (uid > 0) { bool b = UserProfileClient::instance().GetSerialized(uid, &serialized); if (!b) { MCE_INFO("profile not found in memcache. id=" << uid); /*try { serialized = AdUserCacheLoaderAdapter::instance().GetById(uid); } catch(Ice::Exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e << " uid=" << _login_uid); } catch(std::exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e.what() << " uid=" << _login_uid); }*/ } } UserProfile profile; profile.ParseFromString(serialized); /*UserProfile profile; profile.set_age(age); profile.set_id(uid); profile.set_gender(gender); profile.set_stage(stage); profile.set_current_area(currentArea); profile.set_ip_area(ipArea); profile.set_school(school); profile.set_grade(grade);*/ profile.set_ip(1896477159); string tmp; UserProfileClient::instance().Serialize(profile, &tmp); string tmpref = referer; return AdMatchManagerI::GetAds(tmp, tmpref, rotate_index); }
void CookieEmptyCheck(UserProfile& upf) { MCE_DEBUG("id=" << upf.id() << ",iparea=" << upf.ip_area() << ",stage=" << upf.stage() << ",current_area=" << upf.current_area()); if (!upf.id()) { upf.set_id(0); } if (upf.ip_area().empty() || "0000000000000000" == upf.ip_area()) { upf.set_ip_area("0086110000000000"); // 北京 } if (!upf.stage()) { upf.set_stage(4); } if (!upf.ip()) { upf.set_ip(975044608); // 北京的一个随机IP } if (upf.current_area().empty()) { upf.set_current_area("0086110000000000"); // 北京 } //测试代码,设置ip 10.2.17.35 (彭贺庭)和10.2.19.216(邢永涛)为国外 /*if (upf.ip() == (10*256*256*256+2*256*256+17*256+35) || upf.ip() == (10*256*256*256+2*256*256+19*256+216)) { MCE_DEBUG("10.2.17.35 set to 0087110000000000, uid = " << upf.id()); upf.set_current_area("0087110000000000"); upf.set_ip_area("0087110000000000"); // 北京 }*/ }
/************************TEST********************************/ AdResultMap AdMatchManagerI::GetAdsTest(::Ice::Int uid, ::Ice::Int stage, ::Ice::Int gender, ::Ice::Int age, const ::std::string& currentArea, const ::std::string& ipArea, ::Ice::Long school, ::Ice::Int grade, int count, const string & referer, int rotate_index, const Ice::Current& current) { AdInfoSeq out; UserProfile profile; profile.set_age(age); profile.set_id(uid); profile.set_gender(gender); profile.set_stage(stage); profile.set_current_area(currentArea); profile.set_ip_area(ipArea); profile.set_school(school); profile.set_grade(grade); profile.set_ip(1896477159); string tmp; UserProfileClient::instance().Serialize(profile, &tmp); string tmpref = referer; return AdMatchManagerI::GetAds(tmp, tmpref, rotate_index); }
bool AdNewGetRequest::response() { timeval start; gettimeofday(&start, NULL); if (!_fcgi_out) { MCE_WARN("remove notify fcgi_out null"); return false; } _login_uid = 2; string uid = getProperty("uid"); if (_cookies.find("id") != _cookies.end()) { uid = _cookies["id"]; } if (!uid.empty()) { try { _login_uid = boost::lexical_cast<int>(uid); } catch (...) { MCE_WARN("lexical_cast cookie id error : " << uid); } } string serialized; if (_login_uid > 0) { bool b = false; try { StatFunc stat("memc GetSerialized"); b = UserProfileClient::instance().GetSerialized(_login_uid, &serialized); } catch (std::exception& e) { MCE_WARN("UserProfileClient error : " << e.what() << " uid=" << _login_uid); } if (!b) { MCE_INFO("profile not found in memcache. id=" << _login_uid); try { StatFunc stat("memc AdUserCacheLoader"); serialized = AdUserCacheLoaderAdapter::instance().GetById(_login_uid); } catch (Ice::Exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e << " uid=" << _login_uid); } catch (std::exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e.what() << " uid=" << _login_uid); } } } // FCGX_PutS("Content-type: application/x-javascript; charset=utf-8\r\n\r\n{}", _fcgi_out); // return true; UserProfile profile; if (serialized.empty()) { profile.set_stage(4); profile.set_gender(0); profile.set_age(25); profile.set_school(0); profile.set_major(0); profile.set_grade(0); profile.set_home_area(""); profile.set_current_area(""); } else { profile.ParseFromString(serialized); } unsigned int ip = ntohl(inet_addr(GetRemoteAddr().c_str())); profile.set_id(_login_uid); profile.set_ip(ip); profile.set_ip_area(IpAreaCache::instance().GetIpArea(ip)); profile.SerializeToString(&serialized); int rotate_slot = GetCookieInt("an_slot", rand()); rotate_slot %= 10000; AdResultMap ads; AdZone2Creatives final_ads; string referer = getProperty("ref"); //MCE_DEBUG("[UrlMaping] ref = " << referer); if (referer.empty() || referer.find("http://") == string::npos) { referer = getProperty("r"); if (referer.empty() || referer.find("http://") == string::npos) { referer = GetParamFix("HTTP_REFERER"); //MCE_DEBUG("[UrlMaping] HTTP_REFERER = " << referer); } } bool err_flag = false; bool hide = false; string isvip = getProperty("isvip"); string hideads = getProperty("hideads"); if(isvip.compare("true")==0 && hideads.compare("true")==0) { hide = true; } stringstream log_url; try { char sep = '&'; if (referer.find_first_of('?') == string::npos) { sep = '?'; } int refresh_source = getPropertyInt("refresh_source", 0); int refresh_idx = getPropertyInt("refresh_idx", 0); log_url << referer << sep << "refresh_source=" << refresh_source << "&refresh_idx=" << refresh_idx; stringstream stat_desc; stat_desc << _login_uid << " GetAds"; StatFunc stat(stat_desc.str()); } catch (Ice::Exception& e) { MCE_WARN("AdGetRequest::response error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdGetRequest::response : " << e.what() << " uid=" << _login_uid); err_flag = true; } // string emtag = "M"; MCE_DEBUG("debug 001"); try { ads = AdEngineBAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, hide); MCE_DEBUG("EngineB size=" << ads.size()); AdGateI::instance().translate(ads,final_ads); MCE_DEBUG("EngineB size=" << final_ads.size()); // emtag = "M"; } catch (Ice::Exception& e) { MCE_WARN("AdEngineBAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineBAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } MCE_DEBUG("debug 002"); bool tw_flag = false; string tag, photo; map<long, EngineTypes> self_zones; // 需要中小自助广告广告位id for(AdResultMap::iterator it = ads.begin(); it != ads.end(); it++) { if(!it->second.empty() && (it->second.at(0).groupid == -1)) { //台湾分尾号流量切分 //MCE_INFO("Get Ads from AdEngine/AdTw"); MCE_DEBUG("debug 003"); if(_login_uid%10 < 2 || _login_uid == 287341024) { self_zones[it->first] = TW; tw_flag = true; } else { self_zones[it->first] = ENGINE; } } else if(!it->second.empty() && (it->second.at(0).groupid == -2)) { //余量,不分给台湾 self_zones[it->first] = ENGINE; tag = "rr_REMAIN_1"; } else if(!it->second.empty() && (it->second.at(0).groupid == -3)) { //余量,不分给台湾 self_zones[it->first] = ENGINE; tag = "rr_REMAIN_2"; photo = "true"; MCE_DEBUG("photo = true"); } } MCE_DEBUG("debug 004"); if (!self_zones.empty()) { try { AdResultMap e_ads_; AdZone2Creatives e_ads; MCE_DEBUG("debug 005"); //台湾分尾号流量切分 if((_login_uid%10 < 2 || _login_uid == 287341024) && tw_flag) { MCE_DEBUG("debug 006"); MCE_DEBUG("[TW_DEBUG] AdGetRequest::response --> enter to request Tw"); e_ads_ = AdTwAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); AdGateI::instance().translate(ads,final_ads); } else { MCE_DEBUG("debug 007"); MCE_DEBUG("AdGetRequest::response --> from AdEngine rotate_slot = " << rotate_slot); UserAndAction ua; ua.id = profile.id(); ua.stage = profile.stage(); ua.gender = profile.gender(); ua.age = profile.age(); ua.school = profile.school(); ua.userMajor = profile.major(); ua.grade = profile.grade(); ua.homeArea = profile.home_area(); ua.currentArea = profile.current_area(); ua.ip = profile.ip(); ua.ipArea = profile.ip_area(); ua.actionType = ActionType::PAGEVIEW; AdRequest ad_request; ad_request.userAndAction = ua; ad_request.referer = referer; //url_mapping // set<Ice::Long> zone_ids; for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { long z_key = (*zit).first; if( photo == "true" && z_key == 100000000072 ) { ad_request.zoneDict[z_key] = 2; }else{ ad_request.zoneDict[z_key] = 0; } ad_request.attributes[boost::lexical_cast<string>(z_key)]=tag; } // AdUrlMaping::instance().GetAdZone(referer, ua.stage, zone_ids); //AdCreativeCache::instance().GetZoneDict(zone_ids, ad_request.zoneDict); MCE_DEBUG("AdGetRequest::response --> enter to request JavaServer"); e_ads_=AdEngineJAdapter::instance().Request(ad_request); AdGateI::instance().translate(e_ads_,e_ads); //e_ads = AdEngineUAdapter::instance().GetAdsByZone(serialized, log_url.str(), rotate_slot, _login_uid, tag); //e_ads_ = AdEngineUAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, _login_uid, tag, photo); } if (e_ads.empty()) { MCE_DEBUG("AdGetRequest::response --> from AdEngineJ empty "); } else { for(AdZone2Creatives::iterator xxit = e_ads.begin(); xxit != e_ads.end(); xxit++) { MCE_DEBUG("AdGetRequest::response --> from AdEngineJ" << xxit->second.size()); } } for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { AdZone2Creatives::iterator eit = e_ads.find(zit->first); if (eit != e_ads.end()) { //eads[zit->first] = eit->second; //在相册页面,如果广告位wb1成功展示自助,则去掉wb2位置的广告 /*if(100000000072 == zit->first) { ads[100000000073] = AdInfoSeq(); }*/ } else { ads[zit->first] = AdInfoSeq(); } } for(AdZone2Creatives::const_iterator ad_x_it = e_ads.begin() ; ad_x_it != e_ads.end() ; ad_x_it ++ ){ final_ads[ad_x_it->first] = ad_x_it->second; MCE_DEBUG("AdGetRequest::response --> from AdEngineJ " << ad_x_it->first <<" " <<ad_x_it->second.size()); if( ad_x_it->second.size() > 0 ) { for( int vi =0 ; vi < ad_x_it->second.size() ;vi ++ ) { MCE_DEBUG("widgetis = " << ad_x_it->second[vi].widgetid); } } } } catch (Ice::Exception& e) { MCE_WARN("AdEngineUAdapter/AdTwAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineUAdapter/AdTwAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } } if (err_flag) { stringstream stat_desc; stat_desc << _login_uid << " PushDefault"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().PushDefault(_login_uid, profile.stage(), GetRemoteAddr(), referer, &ads); AdGateI::instance().translate(ads,final_ads); } stringstream ad_header; string ad_body; if (render_ == RT_HTML) { ad_header << "Content-type: text/html; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; AdCreativeCache::instance().Get(final_ads, &ad_body); MCE_INFO("final ad size : "<< final_ads.size()); } else if (render_ == RT_JSON) { ad_header << "Content-type: application/x-javascript; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; stringstream stat_desc; stat_desc << _login_uid << " GetJson"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().GetJson(referer, getPropertyInt( "refresh_source", 0), getPropertyInt("refresh_idx", 0), self_zones, final_ads, &ad_body); MCE_INFO("final ad size(json) : "<< final_ads.size()); } FCGX_PutS(ad_header.str().c_str(), _fcgi_out); FCGX_PutS(ad_body.c_str(), _fcgi_out); timeval end; gettimeofday(&end, NULL); AdGateI::instance().ping_sender_.Send("GetAds", 1000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec)/1000); return true; }
bool AdGetRequest::response() { timeval start; gettimeofday(&start, NULL); if (!_fcgi_out) { MCE_WARN("remove notify fcgi_out null"); return false; } _login_uid = 2; string uid = getProperty("uid"); if (_cookies.find("id") != _cookies.end()) { uid = _cookies["id"]; } if (!uid.empty()) { try { _login_uid = boost::lexical_cast<int>(uid); } catch (...) { MCE_WARN("lexical_cast cookie id error : " << uid); } } string serialized; if (_login_uid > 0) { bool b = false; try { StatFunc stat("memc GetSerialized"); b = UserProfileClient::instance().GetSerialized(_login_uid, &serialized); } catch (std::exception& e) { MCE_WARN("UserProfileClient error : " << e.what() << " uid=" << _login_uid); } if (!b) { MCE_INFO("profile not found in memcache. id=" << _login_uid); try { StatFunc stat("memc AdUserCacheLoader"); serialized = AdUserCacheLoaderAdapter::instance().GetById(_login_uid); } catch (Ice::Exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e << " uid=" << _login_uid); } catch (std::exception& e) { MCE_WARN("AdUserCacheLoaderAdapter GetById error : " << e.what() << " uid=" << _login_uid); } } } // FCGX_PutS("Content-type: application/x-javascript; charset=utf-8\r\n\r\n{}", _fcgi_out); // return true; UserProfile profile; if (serialized.empty()) { profile.set_stage(4); profile.set_gender(0); profile.set_age(25); profile.set_school(0); profile.set_major(0); profile.set_grade(0); profile.set_home_area(""); profile.set_current_area(""); } else { profile.ParseFromString(serialized); } unsigned int ip = ntohl(inet_addr(GetRemoteAddr().c_str())); profile.set_id(_login_uid); profile.set_ip(ip); profile.set_ip_area(IpAreaCache::instance().GetIpArea(ip)); profile.SerializeToString(&serialized); int rotate_slot = GetCookieInt("an_slot", rand()); rotate_slot %= 10000; string referer = getProperty("ref"); if (referer.empty() || referer.find("http://") == string::npos) { referer = getProperty("r"); if (referer.empty() || referer.find("http://") == string::npos) { referer = GetParamFix("HTTP_REFERER"); } } bool err_flag = false; stringstream log_url; try { char sep = '&'; if (referer.find_first_of('?') == string::npos) { sep = '?'; } int refresh_source = getPropertyInt("refresh_source", 0); int refresh_idx = getPropertyInt("refresh_idx", 0); log_url << referer << sep << "refresh_source=" << refresh_source << "&refresh_idx=" << refresh_idx; stringstream stat_desc; stat_desc << _login_uid << " GetAds"; StatFunc stat(stat_desc.str()); } catch (Ice::Exception& e) { MCE_WARN("AdGetRequest::response error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdGetRequest::response : " << e.what() << " uid=" << _login_uid); err_flag = true; } AdResultMap ads; AdZone2Creatives final_ads; try { ads = AdEngineBAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); //AdGateI::instance().translate(ads,final_ads); } catch (Ice::Exception& e) { MCE_WARN("AdEngineBAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineBAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } bool tw_flag = false; string tag, photo; map<long, EngineTypes> self_zones; // 需要中小自助广告广告位id for(AdResultMap::iterator it = ads.begin(); it != ads.end(); it++) { if(!it->second.empty() && (it->second.at(0).groupid == -1)) { //台湾分尾号流量切分 //MCE_INFO("Get Ads from AdEngine/AdTw"); if(_login_uid%10 < 2 || _login_uid == 287341024) { self_zones[it->first] = TW; tw_flag = true; } else { self_zones[it->first] = ENGINE; } } else if(!it->second.empty() && (it->second.at(0).groupid == -2)) { //余量,不分给台湾 self_zones[it->first] = ENGINE; tag = "rr_REMAIN_1"; } else if(!it->second.empty() && (it->second.at(0).groupid == -3)) { //余量,不分给台湾 self_zones[it->first] = ENGINE; tag = "rr_REMAIN_2"; photo = "true"; MCE_DEBUG("photo = true"); } } if (!self_zones.empty()) { try { //台湾分尾号流量切分 if((_login_uid%10 < 2 || _login_uid == 287341024) && tw_flag) { try { AdResultMap e_ads; MCE_DEBUG("[TW_DEBUG] AdGetRequest::response --> enter to request Tw"); e_ads = AdTwAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); if (e_ads.empty()) { MCE_INFO("AdGetRequest::response --> from AdTwS empty "); } else { for(AdResultMap::iterator xxit = e_ads.begin(); xxit != e_ads.end(); xxit++) { MCE_DEBUG("AdGetRequest::response --> from AdTwS " << xxit->second.size()); } } for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { AdResultMap::iterator eit = e_ads.find(zit->first); if (eit != e_ads.end()) { ads[zit->first] = eit->second; } else { ads[zit->first] = AdInfoSeq(); } } AdGateI::instance().translate(ads,final_ads); } catch (Ice::Exception& e) { MCE_WARN("AdTwAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdTwAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } } else { try { MCE_DEBUG("AdGetRequest::response --> from AdEngine rotate_slot = " << rotate_slot); //e_ads = AdEngineUAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, _login_uid, tag, photo); AdZone2Creatives e_ads; e_ads = AdEngineUAdapter::instance().GetAdsByZone(serialized, log_url.str(), rotate_slot, _login_uid, tag, photo); if (e_ads.empty()) { MCE_INFO("AdGetRequest::response --> from AdEngineU empty: uid = " << _login_uid << ", referer = " << log_url.str() << ", tag = " << tag << ", photo = " << photo); } else { for(AdZone2Creatives::iterator xxit = e_ads.begin(); xxit != e_ads.end(); xxit++) { MCE_DEBUG("AdGetRequest::response --> from AdEngineU " << xxit->second.size()); } } AdGateI::instance().translate(ads,final_ads); for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { AdZone2Creatives::iterator eit = e_ads.find(zit->first); if (eit != e_ads.end()) { final_ads[zit->first] = eit->second; } else { final_ads[zit->first] = AdCreativeSeq(); } } } catch (Ice::Exception& e) { MCE_WARN("AdEngineUAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineUAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } } } catch (Ice::Exception& e) { MCE_WARN("AdEngineUAdapter/AdTwAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineUAdapter/AdTwAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } } else { AdGateI::instance().translate(ads,final_ads); } if (err_flag) { stringstream stat_desc; stat_desc << _login_uid << " PushDefault"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().PushDefault(_login_uid, profile.stage(), GetRemoteAddr(), referer, &ads); AdGateI::instance().translate(ads,final_ads); } stringstream ad_header; string ad_body; if (render_ == RT_HTML) { ad_header << "Content-type: text/html; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; //AdCreativeCache::instance().Get(ads, &ad_body); AdCreativeCache::instance().Get(final_ads, &ad_body); } else if (render_ == RT_JSON) { ad_header << "Content-type: application/x-javascript; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; stringstream stat_desc; stat_desc << _login_uid << " GetJson"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().GetJson(referer, getPropertyInt("refresh_source", 0), getPropertyInt("refresh_idx", 0), self_zones, final_ads, &ad_body); } FCGX_PutS(ad_header.str().c_str(), _fcgi_out); FCGX_PutS(ad_body.c_str(), _fcgi_out); timeval end; gettimeofday(&end, NULL); AdGateI::instance().ping_sender_.Send("GetAds", 1000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec)/1000); return true; }
string AdGateMI::GetAds(int uid, Ice::Long zoneid, const string& ip_str, const Ice::Current&) { MCE_INFO("AdGateMI::GetAds() --> uid = " << uid << ", zone_id = " << zoneid << ", ip = " << ip_str); ostringstream oss; oss << "http://3g.renren.com/" << zoneid; string referer = oss.str(); string serialized; if (uid > 0) { bool b = false; try { StatFunc stat("memc GetSerialized"); b = UserProfileClient::instance().GetSerialized(uid, &serialized); } catch (std::exception& e) { MCE_WARN("UserProfileClient error : " << e.what() << " uid=" << uid); } if (!b) { MCE_INFO("profile not found in memcache. id=" << uid); try { StatFunc stat("memc AdUserCacheLoader"); serialized = AdUserCacheLoaderReplicaAdapter::instance().GetById(uid); } catch (Ice::Exception& e) { MCE_WARN("AdUserCacheLoaderReplicaAdapter GetById error : " << e << " uid=" << uid); } catch (std::exception& e) { MCE_WARN("AdUserCacheLoaderReplicaAdapter GetById error : " << e.what() << " uid=" << uid); } } } UserProfile profile; if (serialized.empty()) { profile.set_stage(4); profile.set_gender(0); profile.set_age(25); profile.set_school(0); profile.set_major(0); profile.set_grade(0); profile.set_home_area(""); profile.set_current_area(""); } else { profile.ParseFromString(serialized); } unsigned int ip = ntohl(inet_addr(ip_str.c_str())); profile.set_id(uid); profile.set_ip(ip); profile.set_ip_area(IpAreaCache::instance().GetIpArea(ip)); profile.SerializeToString(&serialized); // int rotate_slot = (an_slot == 0) ? rand(): an_slot; // rotate_slot %= 10000; int rotate_slot = GetRotateSlot(uid); bool err_flag = false; AdResultMap ads; stringstream log_url; try { char sep = '&'; if (referer.find_first_of('?') == string::npos) { sep = '?'; } int refresh_source = 0;//getPropertyInt("refresh_source", 0); int refresh_idx = 0;//getPropertyInt("refresh_idx", 0); log_url << referer << sep << "refresh_source=" << refresh_source << "&refresh_idx=" << refresh_idx; stringstream stat_desc; stat_desc << uid << " GetAds"; StatFunc stat(stat_desc.str()); } catch (Ice::Exception& e) { MCE_WARN("AdGetRequest::response error : " << e << " uid=" << uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdGetRequest::response : " << e.what() << " uid=" << uid); err_flag = true; } bool hide = false; try { ads = AdEngineBReplicaAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, hide); } catch (Ice::Exception& e) { MCE_WARN("AdEngineBReplicaAdapter::GetAds error : " << e << " uid=" << uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineBReplicaAdapter::GetAds error : " << e.what() << " uid=" << uid); err_flag = true; } if (err_flag) { stringstream stat_desc; stat_desc << uid << " PushDefault"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().PushDefault(uid, ip_str, referer, &ads); } for(AdResultMap::const_iterator it = ads.begin(); it != ads.end(); ++it) { MCE_INFO("AdEngineBReplicaAdapter::GetAds add default ad : " << it->first << '/' << it->second.size()); } string ad_body; AdCreativeCache::instance().GetHtml(referer, ads, ad_body); return ad_body; }
bool AdGetRequest::response() { if (!_fcgi_out) { MCE_WARN("remove notify fcgi_out null"); return false; } string uid = getProperty("uid"); if (_cookies.find("id") != _cookies.end()) { uid = _cookies["id"]; } if (!uid.empty()) { try { _login_uid = boost::lexical_cast<int>(uid); } catch (...) { MCE_WARN("lexical_cast cookie id error : " << uid); } } string serialized; if (_login_uid > 0) { bool b = false; try { StatFunc stat("memc GetSerialized"); b = UserProfileClient::instance().GetSerialized(_login_uid, &serialized); } catch (std::exception& e) { MCE_WARN("UserProfileClient error : " << e.what() << " uid=" << _login_uid); } if (!b) { MCE_INFO("profile not found in memcache. id=" << _login_uid); try { StatFunc stat("memc AdUserCacheLoader"); serialized = AdUserCacheLoaderReplicaAdapter::instance().GetById(_login_uid); } catch (Ice::Exception& e) { MCE_WARN("AdUserCacheLoaderReplicaAdapter GetById error : " << e << " uid=" << _login_uid); } catch (std::exception& e) { MCE_WARN("AdUserCacheLoaderReplicaAdapter GetById error : " << e.what() << " uid=" << _login_uid); } } } // FCGX_PutS("Content-type: application/x-javascript; charset=utf-8\r\n\r\n{}", _fcgi_out); // return true; UserProfile profile; if (serialized.empty()) { profile.set_stage(4); profile.set_gender(0); profile.set_age(25); profile.set_school(0); profile.set_major(0); profile.set_grade(0); profile.set_home_area(""); profile.set_current_area(""); } else { profile.ParseFromString(serialized); } unsigned int ip = ntohl(inet_addr(GetRemoteAddr().c_str())); profile.set_id(_login_uid); profile.set_ip(ip); profile.set_ip_area(IpAreaCache::instance().GetIpArea(ip)); profile.SerializeToString(&serialized); int rotate_slot = GetCookieInt("an_slot", rand()); rotate_slot %= 10000; AdResultMap ads; string referer = getProperty("ref"); //MCE_DEBUG("[UrlMaping] ref = " << referer); if (referer.empty() || referer.find("http://") == string::npos) { referer = getProperty("r"); if (referer.empty() || referer.find("http://") == string::npos) { referer = GetParamFix("HTTP_REFERER"); //MCE_DEBUG("[UrlMaping] HTTP_REFERER = " << referer); } } bool err_flag = false; bool hide = false; string isvip = getProperty("isvip"); string hideads = getProperty("hideads"); if(isvip.compare("true")==0 && hideads.compare("true")==0) { hide = true; } stringstream log_url; try { char sep = '&'; if (referer.find_first_of('?') == string::npos) { sep = '?'; } int refresh_source = getPropertyInt("refresh_source", 0); int refresh_idx = getPropertyInt("refresh_idx", 0); log_url << referer << sep << "refresh_source=" << refresh_source << "&refresh_idx=" << refresh_idx; stringstream stat_desc; stat_desc << _login_uid << " GetAds"; StatFunc stat(stat_desc.str()); } catch (Ice::Exception& e) { MCE_WARN("AdGetRequest::response error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdGetRequest::response : " << e.what() << " uid=" << _login_uid); err_flag = true; } // string emtag = "M"; try { ads = AdEngineBReplicaAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot, hide); // emtag = "M"; } catch (Ice::Exception& e) { MCE_WARN("AdEngineBReplicaAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineBReplicaAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } map<long, EngineTypes> self_zones; // 需要中小自助广告广告位id for(AdResultMap::iterator it = ads.begin(); it != ads.end(); it++) { if(!it->second.empty() && (it->second.at(0).groupid == -1)) { //台湾分尾号流量切分 MCE_INFO("Get Ads from AdEngine/AdTw"); if(_login_uid%10>4) { self_zones[it->first] = ENGINE; } else { self_zones[it->first] = TW; } } } if (!self_zones.empty()) { try { AdResultMap e_ads; //台湾分尾号流量切分 if(_login_uid%10>4) { MCE_DEBUG("AdGetRequest::response --> from AdEngine rotate_slot = " << rotate_slot); if (_login_uid % 10 == 8) { e_ads = AdEngineUAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); } else { e_ads = AdEngineAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); } } else { MCE_DEBUG("[TW_DEBUG] AdGetRequest::response --> enter to request Tw"); e_ads = AdTwAdapter::instance().GetAds(serialized, log_url.str(), rotate_slot); } if (e_ads.empty()) { MCE_DEBUG("AdGetRequest::response --> from AdEngine/Tw empty "); } else { for(AdResultMap::iterator xxit = e_ads.begin(); xxit != e_ads.end(); xxit++) { MCE_DEBUG("AdGetRequest::response --> from AdEngine/Tw " << xxit->second.size()); } } for (map<long, EngineTypes>::iterator zit = self_zones.begin(); zit != self_zones.end(); zit++) { AdResultMap::iterator eit = e_ads.find(zit->first); if (eit != e_ads.end()) { ads[zit->first] = eit->second; } else { ads[zit->first] = AdInfoSeq(); } } } catch (Ice::Exception& e) { MCE_WARN("AdEngineAdapter::GetAds error : " << e << " uid=" << _login_uid); err_flag = true; } catch (std::exception& e) { MCE_WARN("AdEngineAdapter::GetAds error : " << e.what() << " uid=" << _login_uid); err_flag = true; } } // AdResultMap eads; // AdResultMap::iterator tagit = ads.find(9999963); // if (tagit != ads.end() && ads.find(100000000063) != ads.end()) { // ads.earse(tagit); // try { // MCE_INFO("AdGetRequest::response --> from AdEngine rotate_slot = " // << rotate_slot); // eads = AdEngineAdapter::instance().GetAds(serialized, log_url.str(), // rotate_slot); // AdResultMap::iterator it = eads.find(100000000063); // if (it != eads.end()) { // ads[100000000063] = it->second; // } // emtag = "E"; // } catch (Ice::Exception& e) { // MCE_WARN("AdEngineAdapter::GetAds error : " << e << " uid=" << _login_uid); // err_flag = true; // } catch (std::exception& e) { // MCE_WARN("AdEngineAdapter::GetAds error : " << e.what() << " uid=" // << _login_uid); // err_flag = true; // } // } //MCE_INFO("GetAds size=" << ads.size() << " uid=" << _login_uid << " stage=" // << profile.stage() << " ip_area=" << profile.ip_area()); if (err_flag) { stringstream stat_desc; stat_desc << _login_uid << " PushDefault"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().PushDefault(_login_uid, GetRemoteAddr(), referer, &ads); } stringstream ad_header; string ad_body; if (render_ == RT_HTML) { ad_header << "Content-type: text/html; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; AdCreativeCache::instance().Get(ads, &ad_body); } else if (render_ == RT_JSON) { ad_header << "Content-type: application/x-javascript; charset=utf-8\r\nSet-Cookie: an_slot=" << ++rotate_slot << "; path=/ebpn\r\n\r\n"; stringstream stat_desc; stat_desc << _login_uid << " GetJson"; StatFunc stat(stat_desc.str()); AdCreativeCache::instance().GetJson(referer, getPropertyInt( "refresh_source", 0), getPropertyInt("refresh_idx", 0), self_zones, ads, &ad_body); } FCGX_PutS(ad_header.str().c_str(), _fcgi_out); FCGX_PutS(ad_body.c_str(), _fcgi_out); return true; }
AdZone2Creatives AdMatchManagerI::GetAdsByZoneInfo(const string& userProfile, const string& append_para, int rotate_index, const ZoneInfoMap &zone_info_map, const ::Ice::Current& current){ timeval start; gettimeofday(&start, NULL); AdResultMap ans; AdZone2Creatives res; UserProfile profile; UserProfileClient::instance().Deserialize(userProfile, &profile); if(!init_ok_){ MCE_INFO("AdMatchNManagerI::GetAds() --> initing......."); return res; } CookieEmptyCheck(profile); if(profile.id() == 287726637 || profile.id() == 287726711) { unsigned int ip = ntohl(inet_addr("14.201.79.46")); profile.set_ip(ip); profile.set_ip_area("0001000000000000"); MCE_DEBUG("Modify user ip" << ip << ",userid:" << profile.id()); } MatchHandlerParamter para(profile, append_para); //AdZoneDict zone_dict = AdZonePool::instance().GetAdZoneOrdered(para.referer_, profile, false); AdZoneDict zone_dict = AdZonePool::instance().GetAdZoneOrdered(zone_info_map, profile); if(zone_dict.empty()){ MCE_INFO("AdMatchNManagerI::GetAdsByZoneInfo GetAdZoneOrdered() empty. referer=" << para.referer_); return res; } MCE_INFO("[MAIN_PROCESS] AdMatchNManagerI::GetAdsByZoneInfo --> AdZoneDict->size = " << zone_dict.size()<<",uid = " << para.userProfile_.id()); FilterBindUser(zone_dict, ans, profile.id()); /*string tag; Ice::Context::const_iterator i = current.ctx.find("tag"); if (i != current.ctx.end() && !i->second.empty()) { tag = i->second; } if(!tag.empty()) { para.tag_ = tag; }*/ Ice::Context::const_iterator i = current.ctx.find("photo"); if (i != current.ctx.end() && i->second == "true") { para.photo_ = true; } i = current.ctx.find("count"); if (i != current.ctx.end() && !i->second.empty()) { try{ para.count_ = boost::lexical_cast<int>(i->second); }catch(std::exception e) { MCE_WARN("AdMatchManagerI::GetAdsByZoneInfo--err:" << e.what()); }catch(...) { MCE_WARN("AdMatchManagerI::GetAdsByZoneInfo--unknow err:" ); } } MCE_DEBUG("AdMatchManagerI::GetAdsByZoneInfo --> para.count_ = " << para.count_); bool hide_flag = false; for(AdZoneDict::iterator it = zone_dict.begin(); it != zone_dict.end(); ++it){ para.adzone_ = it->second; para.style_ = AdStyleDispatcher::instance().Dispatch(para.adzone_->id(),para.userProfile_); MCE_DEBUG("after dispatch: user_id = " << para.userProfile_.id() << ", adzone_id = " <<para.adzone_->id() << ", style_id = " << para.style_); if(100000000073 == para.adzone_->id() && hide_flag) { continue; } int rotate_size = it->second->GetRotateSize(); if (rotate_size) { para.rotate_index_ = rotate_index % rotate_size; } para.zone_selected_groups_.clear(); ZoneInfoMap::const_iterator itz = zone_info_map.find(para.adzone_->id()); if(itz != zone_info_map.end()) { para.tag_ = itz->second.tag; } else { para.tag_ = ""; } for(size_t i = 0; i < ad_match_handler_list_.size(); ++i) { if (!ad_match_handler_list_[i]->handle(para, ans)) { //如果是相册页wb1(72)展示自助广告,则不展示wb2广告位(73) if((100000000072 == para.adzone_->id()) && (!ans[100000000072].empty())) { MCE_DEBUG("hide_flag = true"); hide_flag = true; } break; } } AdInfoSeq ad_seq = ans[para.adzone_->id()]; AdCreativeSeq ac_seq; int abs_pos =0 ; for(AdInfoSeq::const_iterator ad_it = ad_seq.begin() ; ad_it != ad_seq.end() ; ++ ad_it){ AdCreativeInfo ac ; ac.creativeid = ad_it->creativeid; ac.groupid = ad_it->groupid; string atts = ad_it->text; vector<string> para_strs; boost::algorithm::split_regex( para_strs, atts,regex( "\\^C" ) ) ; ac.widgetid = boost::lexical_cast<Ice::Long>(para_strs[1]); ac.text = atts; if(ad_it->updateTime == -1) { ac.extra = "style_test"; } else { ac.extra = ""; } ac.position = ++abs_pos; ac_seq.push_back(ac); } res[para.adzone_->id()] = ac_seq; } for(AdZone2Creatives::const_iterator it = res.begin(); it != res.end(); ++it) { MCE_DEBUG("Ads : " << it->first << '/' << it->second.size()); if( it->second.size() > 0 ) { for( int vi = 0 ; vi < it->second.size() ; vi ++ ) { MCE_DEBUG("widgetid = " << it->second[vi].widgetid); } } } timeval end; gettimeofday(&end, NULL); AdMatchManagerI::instance().ping_sender_.Send("GetAds", 1000*(end.tv_sec-start.tv_sec)+(end.tv_usec-start.tv_usec)/1000); return res; }