beautybaby 2009-05-25 13:02
<?php
class OpsAdManage {
var $ptotal;
var $presult;
var $pcount;
var $statistic;
var $aid;
var $serviceid;
var $pid;
var $pw;
function OpsAdManage($pid='10849159',$pw='qXsuaCg=')
{
$this->presult = array();
$this->pcount=0;
$this->ptotal = 0;
$this->statistic = array();
$this->pid = $pid;
$this->pw = $pw;
$this->aid = '';
$this->serviceid = '';
global $OPSCNF;
if($OPSCNF['pw'] != '')
$this->pw = $OPSCNF['pw'];
if($OPSCNF['pid'] != '')
$this->pid = $OPSCNF['pid'];
}
function opsparser($data)
{
$resarr =array();
preg_match("/<PTOTAL>(.*?)<\/PTOTAL>/is",$data,$tmpout);
$resarr['ptotal'] = intval($tmpout[1]);
$this->ptotal = $resarr['ptotal'];
unset($tmpout);
preg_match_all("/<PRESULT>\s*<PRICE>(.*?)<\/PRICE>\s*<TOTALCOST>(.*?)<\/TOTALCOST>\s*<MEMBERID>(.*?)<\/MEMBERID>\s*<CLICKINFO>(.*?)<\/CLICKINFO>\s*<COMMISIONRATE>(.*?)<\/COMMISIONRATE>\s*<TOTALCLICK>(.*?)<\/TOTALCLICK>\s*<RESOURCEPATH>(.*?)<\/RESOURCEPATH>\s*<CATNAME>(.*?)<\/CATNAME>\s*<RANK_SCORE>(.*?)<\/RANK_SCORE>\s*<ALT>(.*?)<\/ALT>\s*<EURL>(.*?)<\/EURL>\s*<SERVICEID>(.*?)<\/SERVICEID>\s*<DETAIL_URL>(.*?)<\/DETAIL_URL>\s*<COMMISION>(.*?)<\/COMMISION>\s*<TAOBAO_INFO>(.*?)<\/TAOBAO_INFO>\s*<ORITYPE>(.*?)<\/ORITYPE>\s*<CATID>(.*?)<\/CATID>\s*<CONTACT>(.*?)<\/CONTACT>\s*<ORIMEMBERID>(.*?)<\/ORIMEMBERID>\s*<TOTALACTION>(.*?)<\/TOTALACTION>\s*<DESC>(.*?)<\/DESC>\s*<ORIOBJID>(.*?)<\/ORIOBJID>\s*<SHOPCOMMISIONRATE>(.*?)<\/SHOPCOMMISIONRATE>\s*<UPDATETIME>(.*?)<\/UPDATETIME>\s*<TITLE>(.*?)<\/TITLE>\s*<\/PRESULT>/is",$data,$out);
$tmptotal = count($out[0]);
$tmpd = array();
for($i=0; $i < $tmptotal; $i ++){
$tmpd[$i] = array();
$tmpd[$i]['price'] = $out[1][$i];
$tmpd[$i]['totalcost'] = $out[2][$i];
$tmpd[$i]['memberid'] = $out[3][$i];
$tmpd[$i]['clickinfo'] = $out[4][$i];
$tmpd[$i]['commisionrate'] = $out[5][$i];
$tmpd[$i]['totalclick'] = $out[6][$i];
$tmpd[$i]['resourcepath'] = $out[7][$i];
$tmpd[$i]['catname'] = $out[8][$i];
$tmpd[$i]['rank_score'] = $out[9][$i];
$tmpd[$i]['alt'] = $out[10][$i];
$tmpd[$i]['eurl'] = $out[11][$i];
$tmpd[$i]['serviceid'] = $out[12][$i];
$tmpd[$i]['detail_url'] = $out[13][$i];
$tmpd[$i]['commision'] = $out[14][$i];
$tmpd[$i]['taobao_info'] = $out[15][$i];
$tmpd[$i]['oritype'] = $out[16][$i];
$tmpd[$i]['catid'] = $out[17][$i];
$tmpd[$i]['contact'] = $out[18][$i];
$tmpd[$i]['orimemberid'] = $out[19][$i];
$tmpd[$i]['totalaction'] = $out[20][$i];
$tmpd[$i]['desc'] = $out[21][$i];
$tmpd[$i]['oriobjid'] = $out[22][$i];
$tmpd[$i]['shopcommisionrate'] = $out[23][$i];
$tmpd[$i]['updatetime'] = $out[24][$i];
$tmpd[$i]['title'] = $out[25][$i];
}
$resarr['presult'] = $tmpd;
$this->presult = $tmpd;
$this->pcount = count($tmpd);
unset($tmpd,$out);
preg_match("/<STATISTIC>\s*<PAIR>\s*<CATID>(.*?)<\/CATID>\s*<CATNAME>\s*<\/CATNAME>\s*<CATCOUNT>(.*?)<\/CATCOUNT>\s*<\/PAIR>\s*<\/STATISTIC>/is",$data,$out);
$tmpd = array();
if(count($out) > 0){
$tmpd['catid'] = $out[1];
$tmpd['catname'] = $out[2];
$tmpd['catcount'] = $out[3];
}
$resarr['statistic'] = $tmpd;
unset($tmpd,$out);
return $resarr;
}
function opsget($url,$method='fopen',$ebytes=1024,$port=80,$timeout=300)
{
extract(parse_url($url));
if($method == 'fopen'){
$fp = fopen($url,'r');
if(!$fp){
echo "\nCannot open the url: $url\n<br>";
return false;
}
}
else if($method == 'fsockopen'){
$fp = fsockopen($host,$port,$errstr,$errno,$timeout);
if(!$fp){
echo "\nRequest Error $errno : $errstr\n<br>";
return false;
}
$reqstr = $path.'?'.$query;
$tmpout = "GET $reqstr HTTP/1.1\r\n";
$tmpout .= "Host: $host\r\n";
$tmpout .= "Connection: Close\r\n\r\n";
fwrite($fp,$tmpout);
}
else{
echo "Bad http method or not support!<br>\n";
return false;
}
$tmptext = '';
while( false == feof($fp) ){
$tmptext .= fread($fp,$ebytes);
}
return $tmptext;
}
function get_clickurl($str)
{
preg_match("/<RESULT>(.*?)<\/RESULT>/is",$str,$tmpout);
if(!strstr($tmpout[1],'') )
return false;
return $tmpout[1];
}
function parse_catinfo($data)
{
$catarr = explode("\n\t",$data);
$tmpres = array();
$len = count($catarr);
$index = explode(",",$catarr[0]);
$lindex = count($index);
$tmpres[0] = $index ;
for($i=1; $i < $len ; $i ++){
$tmparr = explode(",",$catarr[$i]);
$tmpres[$i] = array();
for($j=0;$j < $lindex;$j++){
$tmpres[$i][$index[$j]] = $tmparr[$j] ;
}
}
return $tmpres;
}
// [url=http://taoke.alimama.com/rpc/searchAuctionByRpc.do?pw=[pw]&rowoffset=[rowoffset]&rowcount=[rowcount]&catid=[catid]&keyword=[keyword]&mid=[mid]&sr=[sr]?pw=[pw]&rowoffset=[rowoffset]&rowcount=[rowcount]&catid=[catid]&keyword=[keyword]&mid=[mid]&sr=[sr[/url]]
// [url=http://taoke.alimama.com/rpc/auctionCata.do?pw=[pw]?pw=[pw[/url]]
// [url=http://taoke.alimama.com/rpc/genCodeByRpc.do?pw=[pw]&aid=[aid]&pid=[pid]?pw=[pw]&aid=[aid]&pid=[pid[/url]]
// [url=http://taoke.alimama.com/rpc/getAuctionByRpc.do?pw=[pw]&serviceid=[serviceid]?pw=[pw]&serviceid=[serviceid[/url]]
function make_url($type,$vars=array())
{
$types = array('searchAuctionByRpc','genCodeByRpc','getAuctionByRpc','auctionCata');
$base_url = '' . $types[$type] . '.do?pw='.$this->pw;
$resurl = '';
if($type == 0 ){
if(empty($vars['keyword']))
return '';
if(empty($vars['catid']))
$vars['catid'] = 0;
if(empty($vars['rowoffset']))
$vars['rowoffset'] = 1;
if(empty($vars['rowcount']))
$vars['rowcount'] = 10;
if(empty($vars['mid']))
$vars['mid'] = 0;
if(empty($vars['sr']) || intval($vars['sr']) < 1)
$vars['sr'] = 1;
$resurl .= $base_url.'&rowoffset='.$vars['rowoffset'].'&rowcount='.$vars['rowcount'].'&catid='.$vars['catid'].'&keyword='.$vars['keyword'].'&mid='.$vars['mid'].'&sr='.$vars['sr'];
}
else if($type == 1){
if(empty($vars['aid']))
$vars['aid'] = $this->aid;
$resurl .= $base_url.'&aid='.$vars['aid'].'&pid='.$this->pid;
}
else if($type == 2){
if(empty($vars['serviceid']))
$vars['serviceid'] = $this->serviceid;
$resurl .= $base_url.'&serviceid='.$vars['serviceid'];
}
else if($type == 3){
$resurl = $base_url ;
}
return $resurl;
}
}
?>