cdek widget

https://confluence.cdek.ru/pages/viewpage.action?pageId=15616129

PHP обработчик данного виджета. Тестовые ключи универсальны для всех сайтов. Боевые надо получать у тех поддержки по адресу integrator@cdek.ru

<?


$ch = curl_init();

// боевой
// $account = '5x4zltRyfiRGUHt123kPOmrsd81wkoH';
// $secure = 'uOaYix0Rto54566GJcnL3TPMrvgl7h4';
// $url = 'https://integration.cdek.ru/new_orders.php';

$account_test = 'z9GRRu7FxmO53CQ9cFfI6qiy32wpfTkd';
$secure_test = 'w24JTCv4MnAcuRTx0oHjHLDtyt3I6IBq';
$url = 'https://integration.edu.cdek.ru/new_orders.php';

// отправитель
$sender_phone = $phone = '+7 (985) 727-88-81';
$sender_email = 'igorpodushkin@gmail.com';
$sender_name = 'Адитярова Екатерина Шавкятовна';
$sender_street = 'Алтуфьевское шоссе';
$sender_house = '95б';
$sender_flat = '103';
$sendcitycode = '44'; // мск

// получатель
$reccitycode = $_POST['city'];
$recipient_name = $_POST['name'];
$recipientemail = $_POST['email'];
$recipient_phone = $_POST['phone'];
$order_num = substr(md5($recipient_name . rand(1, 1000)),0, 5);

// товар
$good_comment = 'Комментарий к заказу';

// тариф
$TariffTypeCode = $_POST['tarif'];

file_put_contents(__DIR__.'/sdek.log', var_export($_POST, true));

if($_POST['PVZ'] != 'false'){
    $PvzCode = $_POST['id'];
    $courier = false;
}else{
    $courier = true;
    $recipient_street = $_POST['street'];
    $recipient_house = $_POST['house'];
    $recipient_flat = $_POST['flat'];
}

// Посылка
$common_weight = $_POST['weight_sum'];

$date = new DateTime();
$date_f = $date->format('Y-m-d H:i:s');

$date2 = new DateTime();
$date2->add(new DateInterval('P1D'));
$date_courier = $date2->format('Y-m-d H:i:s');

$data = '<?xml version="1.0" encoding="UTF-8"?>
<deliveryrequest 
            account="'.$account_test.'" 
            date="'.$date_f.'" 
            number="soOEl" 
            ordercount="1" 
            secure="'.$secure_test.'">';
/*if($courier == true){
$data .=    '<callcourier>
        <call comment="comment_soOEl1"
            date="'.$date_courier.'" lunchbeg="14:00"
            lunchend="14:30" sendcitycode="'.$sendcitycode.'" sendername="'.$sender_name.'"
            sendphone="'.$phone.'" timebeg="10:00" timeend="17:00" weight="'.$common_weight.'">
            <sendaddress flat="'.$recipient_flat.'" house="'.$recipient_house.'" street="'.$recipient_street.'"/>
        </call>
    </callcourier>';
}*/
$data .=    
    '<order 
        comment="'.$good_comment.'" 
        deliveryrecipientcost="0.0"
        deliveryrecipientvatrate="VATX" 
        deliveryrecipientvatsum="0.0"
        number="'.$order_num.'" 
        phone="'.$recipient_phone.'" 
        reccitycode="'.$reccitycode.'"
        recipientemail="'.$recipientemail.'" 
        recipientname="'.$recipient_name.'"
        sellername="seller-soOEl0" 
        sendcitycode="'.$sendcitycode.'" 
        tarifftypecode="'.$TariffTypeCode.'">';
if($courier == true){
    $data .= '<address flat="'.$recipient_flat.'" 
    house="'.$recipient_house.'" 
    street="'.$recipient_street.'"/>';
}else{
    $data .= '<address  PvzCode="'.$PvzCode.'"/>';
}        
$data .= '<sender 
            company="company-soOEl0" 
            name="'.$sender_name.'">
            <address 
                flat="'.$sender_flat.'" 
                house="'.$sender_house.'" 
                street="'.$sender_street.'"/>
            <emails>'.$sender_email.'</emails>
            <phone>'.$sender_phone.'</phone>
        </sender>
        <package 
            barcode="barcode-soOEl00" 
            number="soOEl00" 
            sizea="0"
            sizeb="0" 
            sizec="0" 
            weight="'.$common_weight.'">';
    foreach ($_POST['goods'] as $key => $value) {
        $data .='<item 
                amount="'.$value['count'].'" 
                comment="'.$value['name'].'" 
                cost="'.$value['price'].'"
                payment="'.$value['price'].'" 
                paymentvatrate="VATX" 
                paymentvatsum="0.0"
                warekey="warekey-soOEl000" 
                weight="'.$value['weight'].'"/>';
    }
$data .= '</package>';
$data .=        '<DeliveryRecipientCostAdv 
            Threshold="0" 
            Sum="0" 
            VATRate="VATX" 
            VATSum="0"/>
        <AddService ServiceCode="2"/>
        <schedule>
            <attempt date="'.$date_f.'" id="soOEl00"
                phone="123456789 987654321"
                recipientname="prozvon_recname" timebeg="11:00:00" timeend="13:00:00">
                <address flat="flat-prozvon_adr"
                    house="house-prozvon_adr" street="street-prozvon_adr"/>
            </attempt>
        </schedule>';
$data .= '</order>
</deliveryrequest>';

curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_URL, 'https://integration.cdek.ru/new_orders.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
// file_put_contents(__DIR__.'/sdek_request.log', var_export($data, true));
curl_setopt($ch, CURLOPT_POSTFIELDS, ['xml_request' => $data]);


$out = curl_exec($ch);

// print_r($out);
$arr = simplexml_load_string($out, "SimpleXMLElement", LIBXML_NOCDATA);
print_r(json_encode($arr));

curl_close($ch);

die();

Доки:

Leave a comment

Your email address will not be published.


*