openx2.6 (2.8也有新的api) .提供的一个功能。
示例代码:
// 1. 设置环境 if (!@include('xmlrpc/XML/RPC.php')) { die('Error: cannot load the PEAR XML_RPC class'); } $xmlRpcHost = 'localhost'; $xmlRpcPort = '8080'; $webXmlRpcDir = '/www/api/v1/xmlrpc'; $username = 'myname'; $password = 'xxx';
$logonXmlRpcWebServiceUrl = $webXmlRpcDir . '/LogonXmlRpcService.php'; $bannerWebServiceUrl = $webXmlRpcDir . '/ZoneXmlRpcService.php';
// 2. 登录且返回sessionID $aParams = array( new XML_RPC_Value($username, 'string'), new XML_RPC_Value($password, 'string') ); $oMessage = new XML_RPC_Message('logon', $aParams); $oClient = new XML_RPC_Client($logonXmlRpcWebServiceUrl, $xmlRpcHost, $xmlRpcPort); $oResponse = $oClient->send($oMessage); if (!$oResponse) { die('Communication error: ' . $oClient->errstr); } $sessionId = returnXmlRpcResponseData($oResponse);
/// another call 取得一个特定zone 信息 foreach (range(1,4) as $v) { $aParams = array( new XML_RPC_Value($sessionId, 'string'), new XML_RPC_Value($v,'int'), ); $oMessage = new XML_RPC_Message('getZone', $aParams); $oClient = new XML_RPC_Client($bannerWebServiceUrl, $xmlRpcHost, $xmlRpcPort); $oResponse = $oClient->send($oMessage); $result = returnXmlRpcResponseData($oResponse); print_r($result); } $aParams = array( new XML_RPC_Value($sessionId, 'string'), new XML_RPC_Value(1,'int'), ); $oMessage = new XML_RPC_Message('getZoneListByPublisherId', $aParams); $oClient = new XML_RPC_Client($bannerWebServiceUrl, $xmlRpcHost, $xmlRpcPort); $oResponse = $oClient->send($oMessage); $result = returnXmlRpcResponseData($oResponse); print_r($result);
/// 取得一个特定zone 所生成的code $lastParams = new XML_RPC_Value( array( 'target' => new XML_RPC_Value('_blank', 'string'), 'source' => new XML_RPC_Value('', 'string'), 'refresh' => new XML_RPC_Value('', 'string'), 'resize' => new XML_RPC_Value(0, 'int'), 'transparent' => new XML_RPC_Value( 0, 'int'), 'ilayer' => new XML_RPC_Value( 0, 'int'), 'iframetracking' => new XML_RPC_Value( 1, 'int'), 'thirdpartytrack' => new XML_RPC_Value( 0, 'int'), 'cachebuster' => new XML_RPC_Value( 1, 'int'), 'comments' => new XML_RPC_Value( 0, 'int'), ), 'struct' ); $aParams = array( new XML_RPC_Value($sessionId, 'string'), new XML_RPC_Value(1,'int'), new XML_RPC_Value("adframe",'string'), $lastParams ); $oMessage = new XML_RPC_Message('generateTags', $aParams); $oClient = new XML_RPC_Client($bannerWebServiceUrl, $xmlRpcHost, $xmlRpcPort); //$oClient->setDebug(1); $oResponse = $oClient->send($oMessage); $result = returnXmlRpcResponseData($oResponse);//输入广告的adframe代码形式
// 4. 登录注销 $aParams = array(new XML_RPC_Value($sessionId, 'string')); $oMessage = new XML_RPC_Message('logoff', $aParams); $oClient = new XML_RPC_Client($logonXmlRpcWebServiceUrl, $xmlRpcHost, $xmlRpcPort); $oResponse = $oClient->send($oMessage);
function returnXmlRpcResponseData($oResponse) { if (!$oResponse->faultCode()) { $oVal = $oResponse->value(); $data = XML_RPC_decode($oVal); return $data; } else { die('Fault Code: ' . $oResponse->faultCode() . "\n" . 'Fault Reason: ' . $oResponse->faultString() . "\n"); } }