Ejemplo n.º 1
0
date_default_timezone_set('UTC');
ini_set('default_charset', 'UTF-8');
mb_internal_encoding('UTF-8');
require_once __DIR__ . '/../vendor/autoload.php';
try {
    $exampleResponse = file_get_contents(__DIR__ . '/example_responses/sticky_ads_example_1.txt');
    $bidResponse = new \openrtb\BidResponse();
    $bidResponse->hydrate($exampleResponse);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}
try {
    $exampleRequest = file_get_contents(__DIR__ . '/example_requests/sticky_ads_example_2.txt');
    $bidRequest = new \openrtb\BidRequest();
    $bidRequest->hydrate($exampleRequest);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}
// $bidResponse = new \openrtb\BidResponse();
// $bidResponse->set('id','ABC123');
// $bid = new \openrtb\models\Bid();
// $bid->set('id','ABC123');
// $bid->set('impid','ABC123');
// $bid->set('price',1.2);
// $seatBid = new \openrtb\models\SeatBid();
// $seatBid->set('bid',array(
//   $bid
// ));
// $bidResponse->set('seatbid',$seatBid);
// var_dump($bidResponse->getDataAsJson());
Ejemplo n.º 2
0
    usleep($delay);
}
function getBidderUrl()
{
    $protocol = $_SERVER['SERVER_PORT'] === '80' ? 'http://' : 'https://';
    return $protocol . $_SERVER['HTTP_HOST'] . '/';
}
//Get BidRequestsa
try {
    if ($_SERVER['REQUEST_METHOD'] === 'POST') {
        $jsonData = file_get_contents('php://input');
    } else {
        $jsonData = file_get_contents(__DIR__ . '/example_requests/sticky_ads_example_2.txt');
    }
    $bidRequest = new \openrtb\BidRequest();
    $bidRequest->hydrate($jsonData);
} catch (\Exception $e) {
    var_dump($e->getMessage());
}
addDelay();
//Get impression(s) info
$imp = $bidRequest->get('imp');
$noImp = !isset($imp[0]);
//Constructing BidResponse
$bidResponse = new \openrtb\BidResponse();
$bidResponse->set('id', $bidRequest->get('id'));
//Randomly generate a no bid response for 0.5% of BidRequests
if (rand(1, 200) === 1 || $noImp) {
    $bidResponse->set('seatbid', []);
    $nbr = $noImp ? 2 : rand(0, 8);
    $bidResponse->set('nbr', $nbr);