File "tracking.php"

Full path: /home/kosmetik/public_html/api/bookurier/tracking.php
File size: 2.27 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

header('Content-type:application/json');
function test_api()
{
    $url = 'http://www.bookurier.ro/colete/serv/get_stat.php';
    $ch = curl_init();
    $msgstr = "<msg>\r\n\t\t\t<cmd>\r\n\t\t\t<awb>" . $_REQUEST['awb_id'] . "</awb>\r\n\t\t    </cmd>\r\n\t\t    </msg>";
    $msgstr = str_replace(array("\r", "\n", "\r\n", "\t"), '', $msgstr);
    $user_id = $_REQUEST['username'];
    $pwd = $_REQUEST['password'];
    $fields = array('userid' => $user_id, 'pwd' => $pwd, 'msg' => urlencode($msgstr));
    $fields_string = '';
    foreach ($fields as $key => $value) {
        $fields_string .= $key . '=' . $value . '&';
    }
    rtrim($fields_string, '&');
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, count($fields));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    return curl_exec($ch);
}
function doom_dbx()
{
    $html = test_api();
    $doc = new \DOMDocument();
    $doc->loadHTML($html);
    $awb = $doc->getElementsByTagName("awb");
    if (count($awb)) {
        foreach ($awb as $item) {
            $awb1 = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }
        $statusid = $doc->getElementsByTagName("status_id");
        foreach ($statusid as $item) {
            $status_id = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }
        $statusdesc = $doc->getElementsByTagName("status_desc");
        foreach ($statusdesc as $item) {
            $status_desc = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }
        $unq = $doc->getElementsByTagName("unq");
        foreach ($unq as $item) {
            $nr_comanda = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
        }
        $date_awb = array('id_awb' => $awb1, 'nr_comanda' => $nr_comanda, 'status_id' => $status_id, 'status_desc' => $status_desc);
        $data = json_encode($date_awb);
        return $data;
    } else {
        echo 'Eroare: Date incomplete';
    }
}
if ($_SERVER["REQUEST_METHOD"] == "POST" && $_SERVER["CONTENT_TYPE"] == "application/json") {
    $data = trim(file_get_contents("php://input"));
    $json = json_decode($data, true);
    if (is_array($json)) {
        $_REQUEST = $json + $_REQUEST;
    }
    echo doom_dbx();
} else {
    http_response_code(405);
}