diff --git a/connector-miravia/classes/shared/MiraviaSdk.php b/connector-miravia/classes/shared/MiraviaSdk.php index 072d83f..282f66e 100644 --- a/connector-miravia/classes/shared/MiraviaSdk.php +++ b/connector-miravia/classes/shared/MiraviaSdk.php @@ -28,7 +28,13 @@ class MiraviaSdk } if(!empty($this->app_key) && !empty($this->secret_key)) { - $this->client = new SimpleIopClient('https://api-sg.aliexpress.com/sync', $this->app_key, $this->secret_key); + // For personal tokens, use the global gateway instead of Singapore + $gateway_url = 'https://eco.aliexpress.com/sync'; + $this->client = new SimpleIopClient($gateway_url, $this->app_key, $this->secret_key); + + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: Using gateway: " . $gateway_url); + } } } @@ -268,7 +274,7 @@ class MiraviaSdk } /** - * Test API connection with different methods + * Test API connection with personal token approach */ public function testConnection() { @@ -277,28 +283,45 @@ class MiraviaSdk } try { - // Try a simpler API method first - get seller info - $request = new SimpleIopRequest('aliexpress.seller.info.query'); + // For personal tokens, try a basic category query instead + $request = new SimpleIopRequest('aliexpress.postproduct.redefining.categoryforecast'); + $request->addApiParam('subject', 'test'); if(class_exists('LOG')) { - LOG::add("DEBUG SDK: Testing connection with seller info query"); + LOG::add("DEBUG SDK: Testing personal token with category forecast"); } $response = $this->client->execute($request, $this->access_token); if(class_exists('LOG')) { - LOG::add("DEBUG SDK: Seller info response: " . json_encode($response)); + LOG::add("DEBUG SDK: Category forecast response: " . json_encode($response)); } + // Check for error response if(isset($response->error_response)) { - $error = $response->error_response->msg; - return ['success' => false, 'error' => $error]; - } else { - return ['success' => true, 'message' => 'Connection successful']; + $error = $response->error_response->msg ?? 'Unknown API error'; + $error_code = $response->error_response->code ?? 'NO_CODE'; + + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: API Error - Code: {$error_code}, Message: {$error}"); + } + + return ['success' => false, 'error' => "API Error ({$error_code}): {$error}"]; } + // Check for successful response structure + if(isset($response->aliexpress_postproduct_redefining_categoryforecast_response)) { + return ['success' => true, 'message' => 'Personal token connection successful']; + } + + // If we get here, the response format is unexpected but not an error + return ['success' => true, 'message' => 'Connection successful (unexpected response format)']; + } catch (Exception $e) { - return ['success' => false, 'error' => $e->getMessage()]; + if(class_exists('LOG')) { + LOG::add("DEBUG SDK: Exception during test: " . $e->getMessage()); + } + return ['success' => false, 'error' => 'Connection failed: ' . $e->getMessage()]; } } @@ -321,7 +344,8 @@ class MiraviaSdk 'has_token' => !empty($this->access_token), 'token_length' => strlen($this->access_token), 'token_prefix' => substr($this->access_token, 0, 20), - 'gateway_url' => 'https://api-sg.aliexpress.com/sync' + 'gateway_url' => 'https://eco.aliexpress.com/sync', + 'auth_method' => 'personal_token' ]; if(class_exists('LOG')) { diff --git a/connector-miravia/classes/shared/SimpleIopClient.php b/connector-miravia/classes/shared/SimpleIopClient.php index 1c7e02f..0f016a2 100644 --- a/connector-miravia/classes/shared/SimpleIopClient.php +++ b/connector-miravia/classes/shared/SimpleIopClient.php @@ -51,7 +51,8 @@ class SimpleIopClient ]; if ($accessToken) { - $sysParams["session"] = $accessToken; + // Personal tokens use access_token parameter instead of session + $sysParams["access_token"] = $accessToken; } $apiParams = $request->getApiParams();