From 351e9af67de599c76a78cb7dd759016cbccf4483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Zieli=C5=84ski?= Date: Tue, 21 Oct 2025 19:18:31 +0200 Subject: [PATCH] WIP: TEMU API --- .../importTEMUInvoices.php | 82 +++++++++++++++++++ modules/EcmInvoiceOuts/ecommerce.php | 2 + 2 files changed, 84 insertions(+) create mode 100644 modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importTEMUInvoices.php diff --git a/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importTEMUInvoices.php b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importTEMUInvoices.php new file mode 100644 index 00000000..a25b4b0c --- /dev/null +++ b/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importTEMUInvoices.php @@ -0,0 +1,82 @@ += 2 && $json[0] === '"' && substr($json, -1) === '"') return substr($json, 1, -1); + return $json; +} + +function temu_sign_md5(array $params, $secret) +{ + ksort($params, SORT_STRING); + $buf = $secret; + foreach ($params as $k => $v) { + if ($v !== '' && $v !== null) { + $buf .= $k . json_stringify_no_outer_quotes($v); + } + } + $buf .= $secret; + return strtoupper(md5($buf)); +} + +function http_post_json_diag($url, array $body) +{ + $ch = curl_init(); + $payload = json_encode($body, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); + curl_setopt_array($ch, [ + CURLOPT_URL => $url, // <— jawnie ustawiamy URL (by uniknąć „malformed”) + CURLOPT_RETURNTRANSFER => true, + CURLOPT_POST => true, + CURLOPT_HTTPHEADER => ['Content-Type: application/json'], + CURLOPT_POSTFIELDS => $payload, // JSON body jak w Postmanie + CURLOPT_CONNECTTIMEOUT => 30, + CURLOPT_TIMEOUT => 60, + CURLOPT_SSL_VERIFYPEER => true, + CURLOPT_SSL_VERIFYHOST => 2, + CURLOPT_IPRESOLVE => CURL_IPRESOLVE_V4, + ]); + $resp = curl_exec($ch); + if ($resp === false) { + $errno = curl_errno($ch); + $err = curl_error($ch); + curl_close($ch); + die("cURL error: #$errno $err\nURL: $url\nBODY: $payload\n"); + } + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + return [$code, $resp]; +} + +// ==== REQUEST: najpierw lista v2 (tak jak wcześniej) ==== +$biz = [ + 'type' => 'bg.order.list.v2.get', + 'parentOrderStatus' => 0, + 'regionId' => 211, + 'pageNumber' => 1, // jeśli router zgłosi błąd paramów, zamień na 'pageNo' + 'pageSize' => 1, +]; + +// common wg Twojego pre-request +$common = [ + 'app_key' => $APP_KEY, + 'access_token' => $ACCESS_TOKEN, + 'data_type' => $DATA_TYPE, + 'timestamp' => (int)floor(microtime(true)), +]; + +$req = $biz + $common; +$req['sign'] = temu_sign_md5($req, $APP_SECRET); + +list($http, $raw) = http_post_json_diag($BASE_URL, $req); + +echo "HTTP $http\n=== REQUEST BODY ===\n", json_encode($req, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n"; +echo "=== RAW RESPONSE ===\n$raw\n"; \ No newline at end of file diff --git a/modules/EcmInvoiceOuts/ecommerce.php b/modules/EcmInvoiceOuts/ecommerce.php index 52c47525..0d97e174 100644 --- a/modules/EcmInvoiceOuts/ecommerce.php +++ b/modules/EcmInvoiceOuts/ecommerce.php @@ -19,6 +19,8 @@ if (isset($_REQUEST['import_baselinker'])) { include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/amazonWDT/amazonWZ.php'); } else if (isset($_REQUEST['import_apilo'])) { include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importApiloInvoices.php'); +} else if (isset($_REQUEST['import_temu'])) { + include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/importTEMUInvoices.php'); } else if (isset($_REQUEST['apilo_details'])) { include_once(getcwd() . '/modules/EcmInvoiceOuts/BimIT-eCommerceInvoices/apiloInvoiceDetails.php'); } else if (isset($_REQUEST['baselinker_details'])) {