1
0
forked from BRT/arc
arc/android/toss/LoginAndCheckAccountsTossScript.cpp
2025-07-31 11:32:52 +05:00

209 lines
7.6 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "LoginAndCheckAccountsTossScript.h"
#include <QThread>
#include "adb/AdbUtils.h"
#include "dao/AccountDAO.h"
#include "dao/ApplicationDAO.h"
#include "dao/DeviceDAO.h"
#include "dao/TransactionDAO.h"
#include "time/DateUtils.h"
LoginAndCheckAccountsTossScript::LoginAndCheckAccountsTossScript(
QString deviceId,
QString appCode,
QObject *parent
) : CommonTossScript(parent),
m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)) {
}
LoginAndCheckAccountsTossScript::~LoginAndCheckAccountsTossScript() = default;
/**
NongHyup
KakaoBank
Kookmin
Toss Bank
Shinhan
Woori
IBK
Hana
MG
Busan Bank
iM Bank(Daegu)
Kbank
Credit Union
Postal Sav.
SC
Kyongnam
Kwangju
Suhyup
Jeonbuk
Savings Banks
Jeju Bank
Jeonbuk
Savings Banks
Jeju Bank
Citibank
KDB
NFCF
SBI Sav.
BOA
Bank of China
HSBC
ICBC
Deutsche
JPMorgan
BNP Paribas
CCB
*/
void LoginAndCheckAccountsTossScript::doStart() {
const DeviceInfo device = DeviceDAO::getDeviceById(m_deviceId);
const ApplicationInfo app = ApplicationDAO::getApplication(m_deviceId, m_appCode);
if (true) {
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
// искать Transfer кнопку
// Node transferText = xmlScreenParser.findTextContainsNode("토스뱅크 통장");
// if (transferText.isEmpty()) {
// }
Node transferText = xmlScreenParser.findFirstAccountLine();
if (!transferText.isEmpty()) {
AdbUtils::makeTap(device.id, transferText.x(), transferText.y());
QThread::msleep(3000);
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
bool historyFound = false;
for (int i = 0; i < 5; ++i) {
Node topUpBtn = xmlScreenParser.findButtonNode("Top up", false);
Node sendBtn = xmlScreenParser.findButtonNode("Send", false);
if (!topUpBtn.isEmpty() && !sendBtn.isEmpty()) {
// подгрузка истории идет
QThread::msleep(2000);
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
QList<TransactionInfo> transactions = xmlScreenParser.parsePositiveTransactions();
for (auto &transaction: transactions) {
qDebug().noquote().nospace() << convertTransactionToString(transaction);
}
historyFound = true;
break;
}
QThread::msleep(1000);
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
}
if (!historyFound) {
m_error = "Top up or send button not found: " + m_deviceId + " " + m_appCode;
qWarning() << m_error;
emit finishedWithResult(m_error);
return;
}
} else {
m_error = "Card not found: " + m_deviceId + " " + m_appCode;
qWarning() << m_error;
emit finishedWithResult(m_error);
return;
}
} else {
// "Maraqlı deyil" - не интересно
if (device.id.isEmpty() || app.id == -1) {
m_error = "Device or app not found: " + m_deviceId + " " + m_appCode;
qCritical() << m_error;
emit finishedWithResult(m_error);
return;
}
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
if (!runAppAndGoToHomeScreen(device.id, app.package, app.pinCode, device.screenWidth, device.screenHeight)) {
m_error = "Cant open the home screen: " + m_deviceId + " " + m_appCode;
qWarning() << m_error;
if (!ApplicationDAO::updatePinCodeStatus(app.id, "no", "Не прошла проверка [дата]")) {
qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode;
}
AdbUtils::tryToKillApplication(m_deviceId, app.package);
emit finishedWithResult(m_error);
return;
} else {
if (!ApplicationDAO::updatePinCodeStatus(app.id, "yes", "")) {
qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode;
}
Node mainAccount = xmlScreenParser.findTextContainsNode("Main account");
if (!mainAccount.isEmpty()) {
// AdbUtils::makeTap(device.id, mainAccount.x(), mainAccount.y());
// QThread::msleep(1000);
// for (int i = 0; i < 5; ++i) {
// xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_account.deviceId, ++m_counter));
// Node mainAccount = xmlScreenParser.findTextContainsNode("Main account");
// if (!byDayTitle.isEmpty()) {
// qWarning() << "--- beforeYesterdayTitle found!";
// break;
// }
// AdbUtils::makeSwipe(
// m_account.deviceId,
// device.screenWidth / 2, device.screenHeight / 4 * 3,
// device.screenWidth / 2, device.screenHeight / 4
// );
// QThread::msleep(1000);
//
// }
}
QThread::msleep(2000);
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
QList<AccountInfo> oldAccounts = AccountDAO::getAccounts(m_deviceId, m_appCode);
QMap<QString, AccountInfo> accountMap;
for (AccountInfo &oldAccount: oldAccounts) {
if (oldAccount.status == AccountStatus::Active) {
accountMap.insert(oldAccount.lastNumbers, oldAccount);
}
}
QList<AccountInfo> accounts = xmlScreenParser.parseAccountsInfo();
if (accounts.length() == 1 && accountMap.size() == 1) {
AccountInfo account = accounts[0];
account.deviceId = m_deviceId;
account.appCode = m_appCode;
account.lastNumbers = accountMap.first().lastNumbers;
account.description = accountMap.first().description;
account.currency = accountMap.first().currency;
account.description = accountMap.first().description;
account.status = AccountStatus::Active;
if (!AccountDAO::upsertAccount(account)) {
m_error = "Not updated: " + account.lastNumbers;
qCritical() << m_error;
}
}
// for (auto account: accounts) {
// if (accountMap.contains(account.lastNumbers)) {
// account.deviceId = m_deviceId;
// account.appCode = m_appCode;
// account.currency = accountMap[account.lastNumbers].currency;
// account.description = accountMap[account.lastNumbers].description;
// account.status = AccountStatus::Active;
// if (!AccountDAO::upsertAccount(account)) {
// m_error = "Not updated: " + account.lastNumbers;
// qCritical() << m_error;
// }
// }
// }
QList<AccountInfo> savedAccounts = AccountDAO::getAccounts(m_deviceId, m_appCode);
postAccountsData(savedAccounts);
}
AdbUtils::tryToKillApplication(m_deviceId, app.package);
}
emit finishedWithResult(m_error);
}