WIP: TEMU API
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
// ====== KONFIG ======
|
||||
$APP_KEY = '02cbeff8afd35247294810033b036cfe';
|
||||
$APP_SECRET = '8ecfa21b55cddf66c66043cbb80756efc4ba6596';
|
||||
$ACCESS_TOKEN = 'epld1qlfxtx9u9hfojczkqj7ez73jcqp3qiwy1aupqa5qcinxemkcja21dp';
|
||||
$BASE_URL = 'https://openapi-b-eu.temu.com/openapi/router'; // EU router
|
||||
$DATA_TYPE = 'JSON';
|
||||
|
||||
|
||||
// ==== HELPERY ====
|
||||
function json_stringify_no_outer_quotes($val)
|
||||
{
|
||||
$json = json_encode($val, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
if (is_string($val) && strlen($json) >= 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";
|
||||
@@ -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'])) {
|
||||
|
||||
Reference in New Issue
Block a user