380 lines
17 KiB
C++
380 lines
17 KiB
C++
#include "LoginAndCheckAccountsTossScript.h"
|
||
|
||
#include <QRandomGenerator>
|
||
#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) {
|
||
|
||
if (true) {
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
auto accounts = xmlScreenParser.parseAccountsInfo();
|
||
if (!accounts.empty()) {
|
||
qDebug() << "--- Finish, amount: " << QString::number(accounts[0].amount);
|
||
}
|
||
return;
|
||
}
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
// находим первую кнопку Transfer
|
||
Node transferText = xmlScreenParser.findButtonNode("Transfer", false);
|
||
if (!transferText.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, transferText.x(), transferText.y());
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node enterAmount = xmlScreenParser.findEditText("Enter account number");
|
||
if (!enterAmount.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, enterAmount.x(), enterAmount.y());
|
||
QThread::msleep(200);
|
||
|
||
AdbUtils::inputText(m_deviceId, "51291082442507");
|
||
QThread::msleep(200);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node inputBank = xmlScreenParser.findNodeByClassName("android.widget.Spinner");
|
||
if (!inputBank.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, inputBank.x(), inputBank.y());
|
||
QThread::msleep(500);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
|
||
bool foundBank = false;
|
||
for (int i = 0; i < 5; ++i) {
|
||
Node bank = xmlScreenParser.findTextNode("Hana");
|
||
if (!bank.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, bank.x(), bank.y());
|
||
QThread::msleep(200);
|
||
foundBank = true;
|
||
break;
|
||
} else {
|
||
AdbUtils::makeSwipe(
|
||
m_deviceId,
|
||
device.screenWidth / 2, device.screenHeight / 4 * 3,
|
||
device.screenWidth / 2, device.screenHeight / 2
|
||
);
|
||
QThread::msleep(500);
|
||
}
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
}
|
||
|
||
if (!foundBank) {
|
||
m_error = "Bank not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node confirmTransfer = xmlScreenParser.findButtonNode("Confirm", false);
|
||
if (!confirmTransfer.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, confirmTransfer.x(), confirmTransfer.y());
|
||
QThread::msleep(3000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
|
||
bool enterAmountFound = false;
|
||
for (int i = 0; i < 10; ++i) {
|
||
Node enterAmountText = xmlScreenParser.findTextNode("Enter amount");
|
||
if (!enterAmountText.isEmpty()) {
|
||
// AdbUtils::makeTap(m_deviceId, enterAmountText.x(), enterAmountText.y());
|
||
// QThread::msleep(500);
|
||
enterAmountFound = true;
|
||
break;
|
||
}
|
||
|
||
QThread::msleep(1000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
}
|
||
|
||
if (!enterAmountFound) {
|
||
m_error = "Enter amount not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node closeBtn = xmlScreenParser.findButtonNode("확인", false);
|
||
if (!closeBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, closeBtn.x(), closeBtn.y());
|
||
QThread::msleep(200);
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
for (Node &number: xmlScreenParser.getNodeNumbers(4)) {
|
||
AdbUtils::makeTap(m_deviceId, number.x(), number.y());
|
||
QThread::msleep(QRandomGenerator::global()->bounded(200, 901));
|
||
}
|
||
|
||
// AdbUtils::inputText(m_deviceId, "2");
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node nextBtn = xmlScreenParser.findButtonNode("Next", false);
|
||
if (!nextBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, nextBtn.x(), nextBtn.y());
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node sendBtn = xmlScreenParser.findButtonNode("Send", false);
|
||
if (!sendBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, sendBtn.x(), sendBtn.y());
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(
|
||
AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node sendAgainBtn = xmlScreenParser.findButtonNode("Send", false);
|
||
if (!sendAgainBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, sendAgainBtn.x(), sendAgainBtn.y());
|
||
QThread::msleep(1000);
|
||
}
|
||
|
||
bool findAndInputPincode = false;
|
||
xmlScreenParser.parseAndSaveXml(
|
||
AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
if (const QList<Node> pincode = xmlScreenParser.findPinCodeNodes(app.pinCode);
|
||
pincode.size() == 6) {
|
||
for (const Node &node: pincode) {
|
||
AdbUtils::makeTap(m_deviceId, node.x(), node.y());
|
||
QThread::msleep(QRandomGenerator::global()->bounded(200, 901));
|
||
}
|
||
findAndInputPincode = true;
|
||
QThread::msleep(2000);
|
||
}
|
||
if (!findAndInputPincode) {
|
||
m_error = "Pincode not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(
|
||
AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
bool foundConfirmBtn = false;
|
||
for (int i = 0; i < 5; ++i) {
|
||
Node confirmBtn = xmlScreenParser.findButtonNode("Confirm", false);
|
||
if (!confirmBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, confirmBtn.x(), confirmBtn.y());
|
||
foundConfirmBtn = true;
|
||
break;
|
||
}
|
||
|
||
QThread::msleep(1000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
}
|
||
|
||
if (!foundConfirmBtn) {
|
||
m_error = "Last Confirm button not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
QThread::msleep(1000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
for (int i = 0; i < 10; ++i) {
|
||
Node lastBtn = xmlScreenParser.findTextNode("닫기");
|
||
Node lastBtn2 = xmlScreenParser.findTextNode("Close");
|
||
if (!lastBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, lastBtn.x(), lastBtn.y());
|
||
break;
|
||
}
|
||
if (!lastBtn2.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, lastBtn2.x(), lastBtn2.y());
|
||
break;
|
||
}
|
||
|
||
QThread::msleep(1000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
}
|
||
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
qDebug() << "--- Finish: " << xmlScreenParser.parseAccountAmount();
|
||
}
|
||
} else {
|
||
m_error = "Next button not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Confirm transfer button not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Input bank not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Enter account number not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Transfer button not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << 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);
|
||
}
|