164 lines
6.1 KiB
PHP
164 lines
6.1 KiB
PHP
<?php
|
|
|
|
$APP_KEY = '02cbeff8afd35247294810033b036cfe';
|
|
$APP_SECRET = '8ecfa21b55cddf66c66043cbb80756efc4ba6596';
|
|
$ACCESS_TOKEN = 'eplugtijmiyppv7ctra6iu7sjbgbvnlixcunsrigd918tl5awdl3ugmxno7';
|
|
$BASE_URL = 'https://openapi-b-eu.temu.com/openapi/router';
|
|
|
|
$dateFromStr = '2025-10-01';
|
|
$dateToStr = '2025-10-31';
|
|
$parentOrderStatus = 4;
|
|
$pageSize = 50;
|
|
|
|
function noquote($v){
|
|
$j = json_encode($v, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
|
return (is_string($v) && $j[0]==='"' && substr($j,-1)==='"') ? substr($j,1,-1) : $j;
|
|
}
|
|
function sign_md5($p, $secret){
|
|
ksort($p, SORT_STRING);
|
|
$s = $secret;
|
|
foreach($p as $k=>$v){ if($v!=='' && $v!==null) $s .= $k . noquote($v); }
|
|
$s .= $secret;
|
|
return strtoupper(md5($s));
|
|
}
|
|
function parse_date_to_ts_start($s){
|
|
$s = trim($s);
|
|
$fmts = array('Y-m-d','d.m.Y','Y/m/d','d-m-Y','d/m/Y');
|
|
foreach ($fmts as $f){
|
|
$dt = DateTime::createFromFormat($f, $s);
|
|
if ($dt && $dt->format($f) === $s){
|
|
$dt->setTime(0,0,0);
|
|
return (int)$dt->format('U');
|
|
}
|
|
}
|
|
// fallback
|
|
$t = strtotime($s);
|
|
if ($t !== false){ return (int)strtotime(date('Y-m-d 00:00:00', $t)); }
|
|
return null;
|
|
}
|
|
function parse_date_to_ts_end($s){
|
|
$ts = parse_date_to_ts_start($s);
|
|
if ($ts === null) return null;
|
|
return $ts + 86399; // 23:59:59
|
|
}
|
|
|
|
$fromTs = parse_date_to_ts_start($dateFromStr);
|
|
$toTs = parse_date_to_ts_end($dateToStr);
|
|
|
|
if ($fromTs === null || $toTs === null){
|
|
die('<pre>Błędny format daty od/do</pre>');
|
|
}
|
|
|
|
$totalMatched = 0;
|
|
$page = 1;
|
|
$maxPages = 500; // bezpiecznik
|
|
|
|
echo '<div style="font-family:monospace; font-size:13px">';
|
|
|
|
while ($page <= $maxPages) {
|
|
// 1) request listy
|
|
$biz = array(
|
|
"type" => "bg.order.list.v2.get",
|
|
//"regionId" => 162,
|
|
"pageNumber" => $page,
|
|
"pageSize" => $pageSize,
|
|
// "parentOrderStatus" => $parentOrderStatus
|
|
);
|
|
$common = array(
|
|
'app_key' => $APP_KEY,
|
|
'access_token' => $ACCESS_TOKEN,
|
|
'data_type' => 'JSON',
|
|
'timestamp' => (int)floor(microtime(true)),
|
|
);
|
|
$req = $biz + $common;
|
|
$req['sign'] = sign_md5($req, $APP_SECRET);
|
|
$payload = json_encode($req, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
|
|
|
$ch = curl_init();
|
|
curl_setopt_array($ch, array(
|
|
CURLOPT_URL => $BASE_URL,
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_POST => true,
|
|
CURLOPT_HTTPHEADER => array('Content-Type: application/json'),
|
|
CURLOPT_POSTFIELDS => $payload
|
|
));
|
|
$resp = curl_exec($ch);
|
|
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
$cerr = curl_error($ch);
|
|
curl_close($ch);
|
|
|
|
var_dump($resp);
|
|
|
|
if ($resp === false) {
|
|
echo "<pre>cURL error: " . htmlspecialchars($cerr, ENT_QUOTES, 'UTF-8') . "</pre>";
|
|
break;
|
|
}
|
|
|
|
$data = json_decode($resp, true);
|
|
if (!is_array($data) || !isset($data['result']['pageItems']) || !is_array($data['result']['pageItems'])) {
|
|
break;
|
|
}
|
|
|
|
$items = $data['result']['pageItems'];
|
|
if (!count($items)) {
|
|
break;
|
|
}
|
|
|
|
usort($items, function($a, $b){
|
|
$ta = isset($a['parentOrderMap']['parentOrderTime']) ? (int)$a['parentOrderMap']['parentOrderTime'] : 0;
|
|
$tb = isset($b['parentOrderMap']['parentOrderTime']) ? (int)$b['parentOrderMap']['parentOrderTime'] : 0;
|
|
if ($ta == $tb) return 0;
|
|
return ($ta > $tb) ? -1 : 1;
|
|
});
|
|
|
|
$minTsOnPage = null;
|
|
foreach ($items as $row) {
|
|
if (!isset($row['parentOrderMap']['parentOrderSn'])) continue;
|
|
$parentOrderSn = $row['parentOrderMap']['parentOrderSn'];
|
|
$orderTs = isset($row['parentOrderMap']['parentOrderTime']) ? (int)$row['parentOrderMap']['parentOrderTime'] : 0;
|
|
|
|
if ($minTsOnPage === null || $orderTs < $minTsOnPage) $minTsOnPage = $orderTs;
|
|
|
|
if ($orderTs >= $fromTs && $orderTs <= $toTs) {
|
|
// trafienie — drukujemy wybrane pola
|
|
$issueHuman = $orderTs ? date('Y-m-d H:i:s', $orderTs) : '(brak)';
|
|
|
|
echo '<hr style="margin:16px 0;border:0;border-top:2px solid #999;">';
|
|
echo '<div><b>Numer zamówienia:</b> ' . htmlspecialchars($parentOrderSn, ENT_QUOTES, 'UTF-8') . '</div>';
|
|
echo '<div><b>Status:</b> ' . htmlspecialchars($row['parentOrderMap']['parentOrderStatus'], ENT_QUOTES, 'UTF-8') . '</div>';
|
|
echo '<div><b>Data wystawienia:</b> ' . htmlspecialchars($issueHuman, ENT_QUOTES, 'UTF-8')
|
|
. ' <span style="color:#888">(epoch: ' . (int)$orderTs . ')</span></div>';
|
|
|
|
echo '<div style="margin-top:6px;"><b>Produkty (extCode, soldFactor):</b></div>';
|
|
if (isset($row['orderList']) && is_array($row['orderList']) && count($row['orderList'])>0) {
|
|
echo '<ul style="margin:4px 0 10px 20px; padding:0;">';
|
|
foreach ($row['orderList'] as $ol) {
|
|
if (!isset($ol['productList']) || !is_array($ol['productList'])) continue;
|
|
foreach ($ol['productList'] as $p) {
|
|
$extCode = isset($p['extCode']) ? $p['extCode'] : '';
|
|
$soldFactor = isset($p['soldFactor']) ? $p['soldFactor'] : '';
|
|
echo '<li>extCode: <code>' . htmlspecialchars($extCode, ENT_QUOTES, 'UTF-8') . '</code>'
|
|
. ', soldFactor: <code>' . htmlspecialchars($soldFactor, ENT_QUOTES, 'UTF-8') . '</code></li>';
|
|
}
|
|
}
|
|
echo '</ul>';
|
|
} else {
|
|
echo '<div style="color:#b00">brak productList w orderList</div>';
|
|
}
|
|
|
|
$totalMatched++;
|
|
}
|
|
}
|
|
|
|
if ($minTsOnPage !== null && $minTsOnPage < $fromTs) {
|
|
break;
|
|
}
|
|
|
|
$page++;
|
|
}
|
|
|
|
echo '<hr style="margin:16px 0;border:0;border-top:2px solid #999;">';
|
|
echo '<div><b>Łącznie dopasowanych zamówień:</b> ' . (int)$totalMatched . '</div>';
|
|
echo '<div><b>Zakres dat:</b> ' . htmlspecialchars(date('Y-m-d H:i:s', $fromTs), ENT_QUOTES, 'UTF-8')
|
|
. ' — ' . htmlspecialchars(date('Y-m-d H:i:s', $toTs), ENT_QUOTES, 'UTF-8') . '</div>';
|
|
echo '</div>'; |