<?php

require_once(BASE_MOBILE_PATH . '/control/app_pay.php');
require_once (BASE_DATA_PATH . '/logic/delivery.logic.php');
require_once(BASE_ROOT_PATH . '/helper/kdn_helper.php');

$requestData = $_POST['RequestData'];  // 快递鸟数据
$deliver_info = json_decode(urldecode($requestData),true);

$success = true;
$reson = '';
//数据不正确, 记录并退出
if ($deliver_info === false || empty($deliver_info))
{
    $success = false;
    $reson = 'data is empty.';
    Log::record("kdniao_notify:cannot query delivery info from kuaidn.",Log::ERR);
}
else
{
    Log::record("start handle....",Log::DEBUG);
    $count = intval($deliver_info['Count']);
    if($count <= 0 || $deliver_info['EBusinessID'] != kdn_helper::cur_businessid()) {
        $success = false;
        $reson = "count={$count} or EBusinessID = {$deliver_info['EBusinessID']} != " . kdn_helper::cur_businessid();
    }
    else
    {
        foreach($deliver_info['Data'] as $item) {
            kdn_helper::onCallback($item);
        }
    }
}

echo (json_encode(array('EBusinessID' => kdn_helper::cur_businessid(),'UpdateTime' => strftime("%Y-%m-%d %H:%M:%S",time()), 'Success' => $success,'Reason' => $reson)));

?>