162 lines
7.1 KiB
C++
162 lines
7.1 KiB
C++
#include "LoginAndCheckAccountsBirbankScript.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"
|
||
|
||
LoginAndCheckAccountsBirbankScript::LoginAndCheckAccountsBirbankScript(
|
||
QString deviceId,
|
||
QString appCode,
|
||
QObject *parent
|
||
) : CommonBirbankScript(parent),
|
||
m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)) {
|
||
}
|
||
|
||
LoginAndCheckAccountsBirbankScript::~LoginAndCheckAccountsBirbankScript() = default;
|
||
|
||
|
||
void LoginAndCheckAccountsBirbankScript::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));
|
||
// if (!xmlScreenParser.isHomeScreen()) {
|
||
// if (!runAppAndGoToHomeScreen(device.id, app.package, app.pinCode, device.screenWidth, device.screenHeight)) {
|
||
// m_error = "Не смогли дойти до домашней страницы";
|
||
// qCritical() << m_error;
|
||
// emit finishedWithResult(m_error);
|
||
// return;
|
||
// }
|
||
// }
|
||
//
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
|
||
Node closeBannerNode = xmlScreenParser.findButtonNode("Maraqlı deyil", false);
|
||
if (!closeBannerNode.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, closeBannerNode.x(), closeBannerNode.y());
|
||
QThread::msleep(1000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
}
|
||
|
||
if (xmlScreenParser.isHomeScreen()) {
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node cardText = xmlScreenParser.findTextNode("2480");
|
||
if (!cardText.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, cardText.x(), cardText.y());
|
||
QThread::msleep(2000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node payBtn = xmlScreenParser.findTextNode("Перевести");
|
||
if (!payBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, payBtn.x(), payBtn.y());
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node payByCardBtn = xmlScreenParser.findTextNode("На карту любого банка");
|
||
if (!payByCardBtn.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, payByCardBtn.x(), payByCardBtn.y());
|
||
QThread::msleep(1000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node cardEditText = xmlScreenParser.findEditText("Номер карты");
|
||
Node amountEditText = xmlScreenParser.findEditText("Сумма");
|
||
if (!cardEditText.isEmpty() && !amountEditText.isEmpty()) {
|
||
AdbUtils::makeTap(m_deviceId, cardEditText.x(), cardEditText.y());
|
||
QThread::msleep(200);
|
||
AdbUtils::inputText(m_deviceId, "1111222233334444");
|
||
|
||
AdbUtils::hideKeyboard(m_deviceId);
|
||
|
||
AdbUtils::makeTap(m_deviceId, amountEditText.x(), amountEditText.y());
|
||
QThread::msleep(200);
|
||
AdbUtils::inputText(m_deviceId, "10");
|
||
|
||
AdbUtils::hideKeyboard(m_deviceId);
|
||
|
||
|
||
// дальше оплата, но хз как
|
||
}
|
||
|
||
} else {
|
||
m_error = "Pay by card button not found: " + m_deviceId + " " + m_appCode;
|
||
qWarning() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Pay button 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;
|
||
}
|
||
|
||
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();
|
||
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);
|
||
}
|