fix: PhoneSync usa company_endpoints en vez de api_base_url
api_base_url guarda el Graph API de WhatsApp (lo fija el propio seed), asi que el cron armaba https://graph.facebook.com/v22.0/php/controller/... y recibia 401 cada 5 minutos desde siempre. El endpoint numeros_dn ya estaba registrado con la URL absoluta correcta; ahora la sincronizacion lo usa como el resto de llamadas al ERP. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
0e89258f67
commit
1b797df2f0
+13
-5
@@ -3,6 +3,9 @@ declare(strict_types=1);
|
||||
|
||||
class PhoneSync
|
||||
{
|
||||
/** Endpoint registrado en company_endpoints que devuelve los números habilitados */
|
||||
private const ENDPOINT_KEY = 'numeros_dn';
|
||||
|
||||
public static function syncAll(): array
|
||||
{
|
||||
$companies = CompanyRepository::findAll();
|
||||
@@ -19,14 +22,19 @@ class PhoneSync
|
||||
{
|
||||
$companyId = (int)$company['id'];
|
||||
$name = $company['name'] ?? "company {$companyId}";
|
||||
$baseUrl = rtrim($company['api_base_url'] ?? '', '/');
|
||||
$apiKey = $company['api_key'] ?? '';
|
||||
|
||||
if ($baseUrl === '') {
|
||||
return ['company' => $name, 'status' => 'skip', 'reason' => 'sin api_base_url'];
|
||||
}
|
||||
// La URL sale de company_endpoints, igual que el resto de llamadas al ERP.
|
||||
// api_base_url no sirve acá: guarda el Graph API de WhatsApp, no el ERP.
|
||||
$stmt = db()->prepare(
|
||||
"SELECT url FROM company_endpoints WHERE company_id = ? AND endpoint_key = ? AND is_active = 1 LIMIT 1"
|
||||
);
|
||||
$stmt->execute([$companyId, self::ENDPOINT_KEY]);
|
||||
$url = (string)($stmt->fetchColumn() ?: '');
|
||||
|
||||
$url = $baseUrl . '/php/controller/controller_api_externa.php?peticion=whatsapp_numeros';
|
||||
if ($url === '') {
|
||||
return ['company' => $name, 'status' => 'skip', 'reason' => 'sin endpoint ' . self::ENDPOINT_KEY];
|
||||
}
|
||||
|
||||
$ch = curl_init($url);
|
||||
curl_setopt_array($ch, [
|
||||
|
||||
Reference in New Issue
Block a user