64 lines
2.3 KiB
PHP
64 lines
2.3 KiB
PHP
<?php
|
|||
|
|
|
||
|
|
namespace App\Console\Commands;
|
||
|
|
|
||
|
|
use App\Services\SmsBilling\SuperAdminSmsClient;
|
||
|
|
use Illuminate\Console\Command;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Smoke-test SuperAdmin SMS remote for this sold version.
|
||
|
|
*
|
||
|
|
* php artisan sms:superadmin-probe
|
||
|
|
*/
|
||
|
|
class SmsSuperAdminProbeCommand extends Command
|
||
|
|
{
|
||
|
|
protected $signature = 'sms:superadmin-probe';
|
||
|
|
|
||
|
|
protected $description = 'Probe SuperAdmin SMS remote (enabled flag, domain, balance/overview)';
|
||
|
|
|
||
|
|
public function handle(SuperAdminSmsClient $client): int
|
||
|
|
{
|
||
|
|
$base = (string) config('services.superadmin.sms_base_url', '');
|
||
|
|
$domain = (string) config('services.superadmin.sms_domain', '');
|
||
|
|
$appUrl = (string) config('app.url', '');
|
||
|
|
$secretSet = trim((string) config('services.superadmin.sms_shared_secret', '')) !== '';
|
||
|
|
$tokenSet = trim((string) config('services.superadmin.remote_token', '')) !== '';
|
||
|
|
|
||
|
|
$this->table(
|
||
|
|
['key', 'value'],
|
||
|
|
[
|
||
|
|
['enabled', $client->enabled() ? 'yes' : 'no'],
|
||
|
|
['sms_base_url', $base !== '' ? $base : '(empty)'],
|
||
|
|
['sms_domain_override', $domain !== '' ? $domain : '(empty → APP_URL host)'],
|
||
|
|
['app_url', $appUrl !== '' ? $appUrl : '(empty)'],
|
||
|
|
['shared_secret_set', $secretSet ? 'yes' : 'no'],
|
||
|
|
['remote_token_set', $tokenSet ? 'yes' : 'no'],
|
||
|
|
]
|
||
|
|
);
|
||
|
|
|
||
|
|
if (!$client->enabled()) {
|
||
|
|
$this->error('SuperAdmin SMS remote is disabled. Set SUPERADMIN_SMS_BASE_URL and secret/token.');
|
||
|
|
|
||
|
|
return self::FAILURE;
|
||
|
|
}
|
||
|
|
|
||
|
|
$balance = $client->balance();
|
||
|
|
if ($balance === null) {
|
||
|
|
$this->error('balance request failed (auth/domain/network). Check SUPERADMIN_SMS_DOMAIN vs SuperAdmin tenant.');
|
||
|
|
|
||
|
|
return self::FAILURE;
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->info('SuperAdmin SMS remote OK');
|
||
|
|
$this->line(json_encode([
|
||
|
|
'balance' => $balance['balance'] ?? $balance['balanceRials'] ?? null,
|
||
|
|
'price_per_part' => $balance['price_per_part'] ?? $balance['pricePerPartRials'] ?? null,
|
||
|
|
'is_blocked' => $balance['is_blocked'] ?? $balance['isBlocked'] ?? null,
|
||
|
|
'source' => $balance['source'] ?? null,
|
||
|
|
'raw_keys' => array_keys($balance),
|
||
|
|
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
|
||
|
|
|
||
|
|
return self::SUCCESS;
|
||
|
|
}
|
||
|
|
}
|