From 2830cce39c0f3e677993bb19c031eb61b43659a3 Mon Sep 17 00:00:00 2001
From: ccy <3140717620@qq.com>
Date: 星期四, 21 五月 2026 10:25:23 +0800
Subject: [PATCH] 同步与CNNCSIM的加密解密的方式

---
 mainwindow.cpp |  495 ++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 402 insertions(+), 93 deletions(-)

diff --git a/mainwindow.cpp b/mainwindow.cpp
index 6b3d78a..1292e42 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1,25 +1,78 @@
 锘�#include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include "qaesencryption.h"
+#include "licensedata.h"
+#include "shortcrypto.h"
 
 #include <QClipboard>
 #include <QDateTime>
 #include <QDebug>
+#include <QDesktopServices>
 #include <QFileDialog>
 #include <QMessageBox>
 #include <QProcess>
-
+#include <qbytearray.h>
+#include "QtXlsx/xlsxdocument.h"
+#include "QtXlsx/xlsxworksheet.h"
+#include "QtXlsx/xlsxformat.h"
+using namespace QXlsx;
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent)
     , ui(new Ui::MainWindow)
 {
     ui->setupUi(this);
     setFixedSize(680, 600);
+    initUI();
 }
 
 MainWindow::~MainWindow()
 {
     delete ui;
+}
+
+void MainWindow::initUI()
+{
+    //灏嗘棫鐗堟湰鐨勬寜閽殣钘�
+    ui->pushButton_accreditall->setVisible(false);
+    ui->pushButton_accreditcell->setVisible(false);
+    ui->pushButton_accreditaquifer->setVisible(false);
+    ui->pushButton_deaccreditall->setVisible(false);
+    ui->pushButton_accreditpipe->setVisible(false);
+    ui->pushButton_accreditnetwork->setVisible(false);
+    ui->pushButton_dateset->setVisible(false);
+    ui->pushButton_adddate->setVisible(false);
+    ui->pushButton_reducedate->setVisible(false);
+    ui->lineEdit_basenum->setVisible(false);
+    ui->lineEdit_biosnum->setVisible(false);
+    ui->lineEdit_basenum_2->setVisible(false);
+    ui->lineEdit_biosnum_2->setVisible(false);
+    ui->label_basenum->setVisible(false);
+    ui->label_biosnum->setVisible(false);
+    ui->label_basenum_2->setVisible(false);
+    ui->label_biosnum_2->setVisible(false);
+    QTextOption opt = ui->textEdit_localid->document()->defaultTextOption();
+    opt.setWrapMode(QTextOption::WrapAnywhere);
+    ui->textEdit_localid->document()->setDefaultTextOption(opt);
+    QTextOption opt_lic = ui->textEdit_licensekey->document()->defaultTextOption();
+    opt_lic.setWrapMode(QTextOption::WrapAnywhere);
+    ui->textEdit_licensekey->document()->setDefaultTextOption(opt_lic);
+    //鍓嶄竷鏉℃槸绠�鍖栧姞瀵嗘暟鎹繀鐢ㄧ殑,鍦ㄨ繖閲岃瀹氬ソ鏂逛究瀵瑰簲
+    m_numToInfo.insert("1","Baseboard_Uuid");
+    m_numToInfo.insert("2","CPU_Processorid");
+    m_numToInfo.insert("3","Username");
+    m_numToInfo.insert("4","LicensedDuration_start");
+    m_numToInfo.insert("5","LicensedDuration_end");
+    m_numToInfo.insert("6","Productid");
+    m_numToInfo.insert("7","Versionid");
+    m_numToInfo.insert("8","ActiveState");
+    //鍚庤竟鐨勬槸鎺掗櫎鍚庝笉鍙備笌鍔犲瘑鐨勬暟鎹俊鎭�
+    m_numToInfo.insert("9","Bios_Serialnumber");
+    m_numToInfo.insert("10","IsEnabled_cell");
+    m_numToInfo.insert("11","IsEnabled_aquifer");
+    m_numToInfo.insert("12","IsEnabled_pipe");
+    m_numToInfo.insert("13","IsEnabled_network");
+    m_numToInfo.insert("14","Baseboard_Serialnumber");
+    changeUIstate();
 }
 
 QString MainWindow::toUpperAndLower(QString src)
@@ -81,6 +134,14 @@
     return QString::fromLatin1(QAESEncryption::RemovePadding(deBA, QAESEncryption::PKCS7));
 }
 
+QByteArray MainWindow::AES_decryption_byte(const QString &data, const QString &key)
+{
+    QAESEncryption encryption(QAESEncryption::AES_256, QAESEncryption::ECB, QAESEncryption::PKCS7);
+    QByteArray  enBA = QByteArray::fromBase64(data.toUtf8());
+    QByteArray deBA = encryption.decode(enBA, key.toUtf8());
+    return deBA;
+}
+
 QString MainWindow::getEncrypt(const QString &data, QString key)
 {
     QString str_encode_text;
@@ -100,6 +161,11 @@
     QString hashkey32 = EncryptData(hashkey64,QCryptographicHash::Md5);
     QString AESresult = AES_decryption(b64result,hashkey32);
     decodedText = DecodebyBase64(AESresult);
+    //娣诲姞瑙e帇缂╃殑鎿嶄綔
+    QByteArray text = decodedText.toLocal8Bit();
+    QByteArray jsonData = qUncompress(text.fromBase64(text));
+//    decodedText = DecodebyBase64(QString::fromLocal8Bit(jsonData));
+    decodedText = QString(jsonData);
     return decodedText;
 }
 
@@ -119,6 +185,9 @@
         ui->pushButton_setproid->setEnabled(false);
         ui->lineEdit_setversion->setEnabled(false);
         ui->lineEdit_setproid->setEnabled(false);
+        ui->pushButton_normal->setEnabled(false);
+        ui->pushButton_education->setEnabled(false);
+        ui->pushButton_profession->setEnabled(false);
 
         ui->lineEdit_basenum->setText("");
         ui->lineEdit_baseuuid->setText("");
@@ -148,6 +217,9 @@
         ui->pushButton_setproid->setEnabled(true);
         ui->lineEdit_setversion->setEnabled(true);
         ui->lineEdit_setproid->setEnabled(true);
+        ui->pushButton_normal->setEnabled(true);
+        ui->pushButton_education->setEnabled(true);
+        ui->pushButton_profession->setEnabled(true);
 
         ui->lineEdit_basenum->setText(localinfo.Baseboard_Serialnumber);
         ui->lineEdit_baseuuid->setText(localinfo.Baseboard_Uuid);
@@ -157,10 +229,15 @@
         ui->lineEdit_date->setText(localinfo.LicensedDuration_end);
         ui->lineEdit_version->setText(localinfo.Versionid);
         ui->lineEdit_proid->setText(localinfo.Productid);
-        ui->label_iscell->setText(localinfo.IsEnabled_cell==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
-        ui->label_isaquifer->setText(localinfo.IsEnabled_aquifer==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
-        ui->label_ispipe->setText(localinfo.IsEnabled_pipe==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
-        ui->label_isnetwork->setText(localinfo.IsEnabled_network==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_iscell->setText(localinfo.IsEnabled_cell==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_isaquifer->setText(localinfo.IsEnabled_aquifer==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_ispipe->setText(localinfo.IsEnabled_pipe==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_isnetwork->setText(localinfo.IsEnabled_network==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        //褰撳墠鎺堟潈鏄粺涓�鐨勶紝鍙渶瑕佸垽鏂竴涓槸鍚︽縺娲荤殑鍙傛暟灏辫
+        ui->label_iscell->setText(localinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_isaquifer->setText(localinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_ispipe->setText(localinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_isnetwork->setText(localinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
     }
     if(licenseinfo.Username==""){
         ui->lineEdit_basenum_2->setText("");
@@ -186,58 +263,87 @@
         ui->lineEdit_setversion->setText(licenseinfo.Versionid);
         ui->lineEdit_proid_2->setText(licenseinfo.Productid);
         ui->lineEdit_setproid->setText(licenseinfo.Productid);
-        ui->label_iscell_2->setText(licenseinfo.IsEnabled_cell==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
-        ui->label_isaquifer_2->setText(licenseinfo.IsEnabled_aquifer==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
-        ui->label_ispipe_2->setText(licenseinfo.IsEnabled_pipe==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
-        ui->label_isnetwork_2->setText(licenseinfo.IsEnabled_network==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_iscell_2->setText(licenseinfo.IsEnabled_cell==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_isaquifer_2->setText(licenseinfo.IsEnabled_aquifer==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_ispipe_2->setText(licenseinfo.IsEnabled_pipe==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+//        ui->label_isnetwork_2->setText(licenseinfo.IsEnabled_network==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_iscell_2->setText(licenseinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_isaquifer_2->setText(licenseinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_ispipe_2->setText(licenseinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
+        ui->label_isnetwork_2->setText(licenseinfo.ActiveState==0?QStringLiteral("鏈縺娲�"):QStringLiteral("宸叉縺娲�"));
     }
 }
 
 void MainWindow::on_pushButton_decrypt_clicked()
 {
     QString encryptlocalid = ui->textEdit_localid->toPlainText();
-    QString localid = getDecrypt(encryptlocalid,key);
-    QByteArray localidbyte = localid.toLocal8Bit();
-    QJsonParseError err_rpt;
-    QJsonDocument localidjsondoc(QJsonDocument::fromJson(localidbyte, &err_rpt));//瀛楃涓叉牸寮忓寲涓篔SON
-    if(err_rpt.error != QJsonParseError::NoError)
-    {
-        localinfo = LicenseInfo();
-        licenseinfo = LicenseInfo();
-        workingjsondoc = QJsonDocument();
-        ui->textEdit_licensekey->setPlainText("");
-        changeUIstate();
-        qDebug() << QStringLiteral("localid JSON鏍煎紡閿欒");
-        QMessageBox msgbox(QMessageBox::Information,QStringLiteral(""),QStringLiteral("瑙f瀽澶辫触锛屼笉鏄竴涓纭殑璁惧ID搴忓垪"),QMessageBox::Ok);
-        msgbox.setButtonText(QMessageBox::Ok,QStringLiteral("纭畾"));
-        msgbox.exec();
-    }
-    else    //JSON鏍煎紡姝g‘
-    {
-        QMessageBox msgbox(QMessageBox::Information,QStringLiteral(""),QStringLiteral("瑙f瀽鎴愬姛"),QMessageBox::Ok);
-        msgbox.setButtonText(QMessageBox::Ok,QStringLiteral("纭畾"));
-        msgbox.exec();
-        ui->textEdit_licensekey->setPlainText(ui->textEdit_localid->toPlainText());
-        workingjsondoc = QJsonDocument(QJsonDocument::fromJson(localidbyte));
+    // 涓�閿В瀵�
+    lic2.fromBinary(ShortCrypto::decrypt(encryptlocalid, key));
+    qDebug()<<"on_pushButton_decrypt_clicked"<<lic2.toDebugString();
+    //涓庝箣鍓嶇殑鍔犲瘑瀵瑰簲,涓斿幓鎺夊啑浣欎俊鎭�
+    localinfo.Baseboard_Uuid = LicenseData::uuidBinaryToString(lic2.boardUuid);
+    localinfo.CPU_Processorid = LicenseData::binaryToHexString(lic2.cpuSerial);
+    localinfo.Username = lic2.userName;
+    localinfo.LicensedDuration_end = lic2.expireDate.toString("yyyy-MM-dd");
+//    localinfo.LicensedDuration_start = localid_Obj.value(m_numToInfo.key("LicensedDuration_start")).toString();
+    localinfo.Productid = QString::number(lic2.productId);
+    localinfo.Versionid = QString::number(lic2.verMajor)+"."+QString::number(lic2.verMinor);
+    localinfo.ActiveState = static_cast<int>(lic2.activeState);
+    licenseinfo = LicenseInfo(localinfo);
+    ui->textEdit_licensekey->setPlainText(ui->textEdit_localid->toPlainText());
+    changeUIstate();
 
-        QJsonObject localid_Obj = localidjsondoc.object();
-        localinfo.Baseboard_Serialnumber = localid_Obj.value("Baseboard_Serialnumber").toString();
-        localinfo.Baseboard_Uuid = localid_Obj.value("Baseboard_Uuid").toString();
-        localinfo.Bios_Serialnumber = localid_Obj.value("Bios_Serialnumber").toString();
-        localinfo.CPU_Processorid = localid_Obj.value("CPU_Processorid").toString();
-        localinfo.Username = localid_Obj.value("Username").toString();
-        localinfo.IsEnabled_cell = localid_Obj.value("IsEnabled_cell").toInt();
-        localinfo.IsEnabled_aquifer = localid_Obj.value("IsEnabled_aquifer").toInt();
-        localinfo.IsEnabled_pipe = localid_Obj.value("IsEnabled_pipe").toInt();
-        localinfo.IsEnabled_network = localid_Obj.value("IsEnabled_network").toInt();
-        localinfo.LicensedDuration_end = localid_Obj.value("LicensedDuration_end").toString();
-        localinfo.LicensedDuration_start = localid_Obj.value("LicensedDuration_start").toString();
-        localinfo.Productid = localid_Obj.value("Productid").toString();
-        localinfo.Versionid = localid_Obj.value("Versionid").toString();
+//    QString localid = getDecrypt(encryptlocalid,key);
+//    QByteArray localidbyte = localid.toLocal8Bit();
+//    QJsonParseError err_rpt;
+//    QJsonDocument localidjsondoc(QJsonDocument::fromJson(localid.toUtf8(), &err_rpt));//瀛楃涓叉牸寮忓寲涓篔SON
+//    if(err_rpt.error != QJsonParseError::NoError)
+//    {
+//        localinfo = LicenseInfo();
+//        licenseinfo = LicenseInfo();
+//        workingjsondoc = QJsonDocument();
+//        ui->textEdit_licensekey->setPlainText("");
+//        changeUIstate();
+//        qDebug() << QStringLiteral("localid JSON鏍煎紡閿欒");
+//        QMessageBox msgbox(QMessageBox::Information,QStringLiteral(""),QStringLiteral("瑙f瀽澶辫触锛屼笉鏄竴涓纭殑璁惧ID搴忓垪"),QMessageBox::Ok);
+//        msgbox.setButtonText(QMessageBox::Ok,QStringLiteral("纭畾"));
+//        msgbox.exec();
+//    }
+//    else    //JSON鏍煎紡姝g‘
+//    {
+//        QMessageBox msgbox(QMessageBox::Information,QStringLiteral(""),QStringLiteral("瑙f瀽鎴愬姛"),QMessageBox::Ok);
+//        msgbox.setButtonText(QMessageBox::Ok,QStringLiteral("纭畾"));
+//        msgbox.exec();
+//        ui->textEdit_licensekey->setPlainText(ui->textEdit_localid->toPlainText());
+//        workingjsondoc = QJsonDocument(QJsonDocument::fromJson(localidbyte));
 
-        licenseinfo = LicenseInfo(localinfo);
-        changeUIstate();
-    }
+//        QJsonObject localid_Obj = localidjsondoc.object();
+////        localinfo.Baseboard_Serialnumber = localid_Obj.value("Baseboard_Serialnumber").toString();
+////        localinfo.Baseboard_Uuid = localid_Obj.value("Baseboard_Uuid").toString();
+////        localinfo.Bios_Serialnumber = localid_Obj.value("Bios_Serialnumber").toString();
+////        localinfo.CPU_Processorid = localid_Obj.value("CPU_Processorid").toString();
+////        localinfo.Username = localid_Obj.value("Username").toString();
+////        localinfo.IsEnabled_cell = localid_Obj.value("IsEnabled_cell").toInt();
+////        localinfo.IsEnabled_aquifer = localid_Obj.value("IsEnabled_aquifer").toInt();
+////        localinfo.IsEnabled_pipe = localid_Obj.value("IsEnabled_pipe").toInt();
+////        localinfo.IsEnabled_network = localid_Obj.value("IsEnabled_network").toInt();
+////        localinfo.LicensedDuration_end = localid_Obj.value("LicensedDuration_end").toString();
+////        localinfo.LicensedDuration_start = localid_Obj.value("LicensedDuration_start").toString();
+////        localinfo.Productid = localid_Obj.value("Productid").toString();
+////        localinfo.Versionid = localid_Obj.value("Versionid").toString();
+
+//        //涓庝箣鍓嶇殑鍔犲瘑瀵瑰簲,涓斿幓鎺夊啑浣欎俊鎭�
+//        localinfo.Baseboard_Uuid = localid_Obj.value(m_numToInfo.key("Baseboard_Uuid")).toString();
+//        localinfo.CPU_Processorid = localid_Obj.value(m_numToInfo.key("CPU_Processorid")).toString();
+//        localinfo.Username = localid_Obj.value(m_numToInfo.key("Username")).toString();
+//        localinfo.LicensedDuration_end = localid_Obj.value(m_numToInfo.key("LicensedDuration_end")).toString();
+//        localinfo.LicensedDuration_start = localid_Obj.value(m_numToInfo.key("LicensedDuration_start")).toString();
+//        localinfo.Productid = localid_Obj.value(m_numToInfo.key("Productid")).toString();
+//        localinfo.Versionid = localid_Obj.value(m_numToInfo.key("Versionid")).toString();
+//        localinfo.ActiveState = localid_Obj.value(m_numToInfo.key("ActiveState")).toInt();
+//        licenseinfo = LicenseInfo(localinfo);
+//        changeUIstate();
+//    }
 }
 
 void MainWindow::on_pushButton_accreditall_clicked()
@@ -278,7 +384,8 @@
 void MainWindow::on_pushButton_accreditpipe_clicked()
 {
     QJsonObject licensekey_Obj = workingjsondoc.object();
-    licensekey_Obj["IsEnabled_pipe"] = 1;
+//    licensekey_Obj["IsEnabled_pipe"] = 1;
+    licensekey_Obj["8"] = 1;
     workingjsondoc.setObject(licensekey_Obj);
     QByteArray jsonbytearray = workingjsondoc.toJson();
     ui->textEdit_licensekey->setPlainText("");
@@ -333,19 +440,20 @@
 
 void MainWindow::setLicenseinfo(const QJsonObject licensekey_Obj)
 {
-    licenseinfo.Baseboard_Serialnumber = licensekey_Obj.value("Baseboard_Serialnumber").toString();
-    licenseinfo.Baseboard_Uuid = licensekey_Obj.value("Baseboard_Uuid").toString();
-    licenseinfo.Bios_Serialnumber = licensekey_Obj.value("Bios_Serialnumber").toString();
-    licenseinfo.CPU_Processorid = licensekey_Obj.value("CPU_Processorid").toString();
-    licenseinfo.Username = licensekey_Obj.value("Username").toString();
-    licenseinfo.IsEnabled_cell = licensekey_Obj.value("IsEnabled_cell").toInt();
-    licenseinfo.IsEnabled_aquifer = licensekey_Obj.value("IsEnabled_aquifer").toInt();
-    licenseinfo.IsEnabled_pipe = licensekey_Obj.value("IsEnabled_pipe").toInt();
-    licenseinfo.IsEnabled_network = licensekey_Obj.value("IsEnabled_network").toInt();
-    licenseinfo.LicensedDuration_end = licensekey_Obj.value("LicensedDuration_end").toString();
-    licenseinfo.LicensedDuration_start = licensekey_Obj.value("LicensedDuration_start").toString();
-    licenseinfo.Productid = licensekey_Obj.value("Productid").toString();
-    licenseinfo.Versionid = licensekey_Obj.value("Versionid").toString();
+    licenseinfo.Baseboard_Serialnumber = licensekey_Obj.value(m_numToInfo.key("Baseboard_Serialnumber")).toString();
+    licenseinfo.Baseboard_Uuid = licensekey_Obj.value(m_numToInfo.key("Baseboard_Uuid")).toString();
+    licenseinfo.Bios_Serialnumber = licensekey_Obj.value(m_numToInfo.key("Bios_Serialnumber")).toString();
+    licenseinfo.CPU_Processorid = licensekey_Obj.value(m_numToInfo.key("CPU_Processorid")).toString();
+    licenseinfo.Username = licensekey_Obj.value(m_numToInfo.key("Username")).toString();
+    licenseinfo.IsEnabled_cell = licensekey_Obj.value(m_numToInfo.key("IsEnabled_cell")).toInt();
+    licenseinfo.IsEnabled_aquifer = licensekey_Obj.value(m_numToInfo.key("IsEnabled_aquifer")).toInt();
+    licenseinfo.IsEnabled_pipe = licensekey_Obj.value(m_numToInfo.key("IsEnabled_pipe")).toInt();
+    licenseinfo.IsEnabled_network = licensekey_Obj.value(m_numToInfo.key("IsEnabled_network")).toInt();
+    licenseinfo.LicensedDuration_end = licensekey_Obj.value(m_numToInfo.key("LicensedDuration_end")).toString();
+    licenseinfo.LicensedDuration_start = licensekey_Obj.value(m_numToInfo.key("LicensedDuration_start")).toString();
+    licenseinfo.Productid = licensekey_Obj.value(m_numToInfo.key("Productid")).toString();
+    licenseinfo.Versionid = licensekey_Obj.value(m_numToInfo.key("Versionid")).toString();
+    licenseinfo.ActiveState = licensekey_Obj.value(m_numToInfo.key("ActiveState")).toInt();
     changeUIstate();
 }
 
@@ -368,22 +476,38 @@
 
     QJsonDocument json_doc;//鍒涘缓json鏂囦欢
     QJsonObject json_obj;//鍒涘缓json瀵硅薄
-    json_obj.insert("Username",localinfo.Username);
-    json_obj.insert("CPU_Processorid",localinfo.CPU_Processorid);
-    json_obj.insert("Bios_Serialnumber",localinfo.Bios_Serialnumber);
-    json_obj.insert("Baseboard_Serialnumber",localinfo.Baseboard_Serialnumber);
-    json_obj.insert("Baseboard_Uuid",localinfo.Baseboard_Uuid);
-    json_obj.insert("IsEnabled_cell",localinfo.IsEnabled_cell);
-    json_obj.insert("IsEnabled_aquifer",localinfo.IsEnabled_aquifer);
-    json_obj.insert("IsEnabled_pipe",localinfo.IsEnabled_pipe);
-    json_obj.insert("IsEnabled_network",localinfo.IsEnabled_network);
-    json_obj.insert("LicensedDuration_start",localinfo.LicensedDuration_start);
-    json_obj.insert("LicensedDuration_end",localinfo.LicensedDuration_end);
-    json_obj.insert("Productid",localinfo.Productid);
-    json_obj.insert("Versionid",localinfo.Versionid);
-    json_doc.setObject(json_obj);//灏唈son瀵硅薄杞负json鏂囦欢
-    QByteArray jsonbytearray = json_doc.toJson();
-    localid = QString(jsonbytearray);
+//    json_obj.insert("Username",localinfo.Username);
+//    json_obj.insert("CPU_Processorid",localinfo.CPU_Processorid);
+//    json_obj.insert("Bios_Serialnumber",localinfo.Bios_Serialnumber);
+//    json_obj.insert("Baseboard_Serialnumber",localinfo.Baseboard_Serialnumber);
+//    json_obj.insert("Baseboard_Uuid",localinfo.Baseboard_Uuid);
+//    json_obj.insert("IsEnabled_cell",localinfo.IsEnabled_cell);
+//    json_obj.insert("IsEnabled_aquifer",localinfo.IsEnabled_aquifer);
+//    json_obj.insert("IsEnabled_pipe",localinfo.IsEnabled_pipe);
+//    json_obj.insert("IsEnabled_network",localinfo.IsEnabled_network);
+//    json_obj.insert("LicensedDuration_start",localinfo.LicensedDuration_start);
+//    json_obj.insert("LicensedDuration_end",localinfo.LicensedDuration_end);
+//    json_obj.insert("Productid",localinfo.Productid);
+//    json_obj.insert("Versionid",localinfo.Versionid);
+//    json_doc.setObject(json_obj);//灏唈son瀵硅薄杞负json鏂囦欢
+//    QByteArray jsonbytearray = json_doc.toJson();
+//    localid = QString(jsonbytearray);
+
+    //鍏跺疄涓昏鍔犲瘑鐨勬暟鎹槸value(鐢佃剳鐨勫叿浣撳弬鏁颁俊鎭級锛屽墠杈圭殑鎻忚堪鏄彲浠ョ畝鍐欑殑锛屾寜鐓ц瀹氬ソ鐨勮鍒欙紝鍙瓨鍌ㄧ畝鍗曠殑key鍊�
+    //杩欓噷鍙幏鍙栨垜浠紭鍖栧悗瑕侀�夋嫨鍔犲瘑鐨勬暟鎹�
+    json_obj.insert(m_numToInfo.key("Username"),localinfo.Username);
+    json_obj.insert(m_numToInfo.key("CPU_Processorid"),localinfo.CPU_Processorid);
+    json_obj.insert(m_numToInfo.key("Baseboard_Uuid"),localinfo.Baseboard_Uuid);
+    json_obj.insert(m_numToInfo.key("LicensedDuration_start"),localinfo.LicensedDuration_start);
+    json_obj.insert(m_numToInfo.key("LicensedDuration_end"),localinfo.LicensedDuration_end);
+    json_obj.insert(m_numToInfo.key("Productid"),localinfo.Productid);
+    json_obj.insert(m_numToInfo.key("Versionid"),localinfo.Versionid);
+    json_obj.insert(m_numToInfo.key("ActiveState"),localinfo.ActiveState);
+
+    QByteArray compressedArray = QJsonDocument(json_obj).toJson(QJsonDocument::Compact);
+    QByteArray jsonbytearray = qCompress(compressedArray,9);
+    localid = jsonbytearray.toBase64();
+
     return localid;
 }
 
@@ -403,11 +527,146 @@
     return result;
 }
 
+void MainWindow::giveLicense(int time)
+{
+    //鐜板湪鐐瑰嚮鎺堟潈鏄粠褰撳墠鐨勬椂闂村姞鎺堟潈鏃堕棿
+    QDateTime licensedate = QDateTime::currentDateTime();
+    QDateTime newlicensedate = licensedate.addMonths(time);
+    QString licensedatestr = newlicensedate.toString("yyyy-MM-dd");
+    lic2.expireDate = QDate::fromString(licensedatestr,"yyyy-MM-dd");
+//    lic2.expireDate = lic2.expireDate.addMonths(time);
+    lic2.activeState = 1;
+    QString cipher = ShortCrypto::encrypt(lic2.toBinary(), key);
+    ui->textEdit_licensekey->clear();
+    ui->textEdit_licensekey->setPlainText(cipher);
+    // 涓�閿В瀵�
+    LicenseData lic3;
+    lic3.fromBinary(ShortCrypto::decrypt(cipher, key));
+    qDebug()<<"change"<<cipher<<lic3.toDebugString()<<cipher.size();
+    //鏇存柊licenseinfo锛屽彧闇�瑕佹洿鏂癓icensedDuration_end銆丩icensedDuration_start銆丄ctiveState
+    licenseinfo.LicensedDuration_end = newlicensedate.toString("yyyy-MM-dd");
+    licenseinfo.LicensedDuration_start = licensedate.toString("yyyy-MM-dd");
+    licenseinfo.ActiveState = 1;
+    changeUIstate();
+    //灏嗘巿鏉冧俊鎭褰曞埌excel琛ㄤ腑
+    QString edition ="";
+    if(time == 3){
+        edition = QStringLiteral("鏅�氱増");
+    }else if(time == 6){
+        edition = QStringLiteral("鏁欒偛鐗�");
+    }else if(time == 12){
+        edition = QStringLiteral("涓撲笟鐗�");
+    }
+    ActiveRecord(lic2,edition,ui->textEdit_licensekey->toPlainText());
+}
+
+void MainWindow::ActiveRecord(LicenseData lic,QString edition, QString licenseKey)
+{
+    QString Baseboard_Uuid = LicenseData::uuidBinaryToString(lic.boardUuid);
+    QString src = QApplication::applicationDirPath();
+    QDir dir(src);
+    QString file_name(QStringLiteral("瀹夊叏璇勪环杞欢鎺堟潈浜烘暟缁熻琛�.xlsx"));
+    QString filepath=dir.path()+"/"+file_name;
+    if(!dir.exists(file_name)){
+        Document xlsx;
+        // 璁剧疆鍒楁爣棰�
+        QStringList headers = {
+            "id",
+            QStringLiteral("涓绘澘鍞竴鏍囪瘑"),
+            QStringLiteral("鐗堟湰"),
+            QStringLiteral("璁稿彲璧峰鏃堕棿"),
+            QStringLiteral("璁稿彲鎴鏃堕棿"),
+            QStringLiteral("浜у搧鍙�"),
+            QStringLiteral("鐗堟湰鍙�"),
+            QStringLiteral("璁稿彲瀵嗛挜")
+        };
+        // 鍐欏叆鏍囬琛�
+        for (int col = 1; col <= headers.size(); ++col) {
+            xlsx.write(1, col, headers[col - 1]);
+        }
+        xlsx.saveAs(filepath);
+    }
+
+    QXlsx::Document xlsx(filepath);
+    int uuidColumn = -1;
+    //鍏堟煡鎵炬槸鍚﹀凡缁忓瓨鍦ㄨ椤硅褰�
+    for(int i = 2; i <= xlsx.dimension().rowCount(); i++){
+        QXlsx::Cell* headerCell = xlsx.cellAt(i, 2);
+        if (headerCell) {
+            QString headerValue = headerCell->value().toString();
+            if (headerValue.compare(Baseboard_Uuid, Qt::CaseInsensitive) == 0) {
+                uuidColumn = i;
+                break;
+            }
+        }
+    }
+    if(uuidColumn == -1){
+        //濡傛灉娌℃湁杩欐潯璁板綍灏卞啓鍏ユ柊鐨�
+        int rowCount = xlsx.dimension().rowCount()+1;
+        int id = xlsx.read(rowCount-1,1).toInt();
+        xlsx.write(rowCount, 1, id+1);
+        xlsx.write(rowCount, 2, LicenseData::uuidBinaryToString(lic.boardUuid));
+        xlsx.write(rowCount, 3, edition);
+        xlsx.write(rowCount, 4, QDate::currentDate().toString("yyyy-MM-dd"));
+        xlsx.write(rowCount, 5, lic.expireDate.toString("yyyy-MM-dd"));
+        xlsx.write(rowCount, 6, QString::number(lic2.productId));
+        xlsx.write(rowCount, 7, QString::number(lic2.verMajor)+"."+QString::number(lic2.verMinor));
+        xlsx.write(rowCount, 8, licenseKey);
+    }else{
+        //濡傛灉瀛樺湪杩欐潯璁板綍灏辨洿鏂版暟鎹俊鎭�
+        xlsx.write(uuidColumn, 2, LicenseData::uuidBinaryToString(lic.boardUuid));
+        xlsx.write(uuidColumn, 3, edition);
+        xlsx.write(uuidColumn, 4, QDate::currentDate().toString("yyyy-MM-dd"));
+        xlsx.write(uuidColumn, 5, lic.expireDate.toString("yyyy-MM-dd"));
+        xlsx.write(uuidColumn, 6, QString::number(lic2.productId));
+        xlsx.write(uuidColumn, 7, QString::number(lic2.verMajor)+"."+QString::number(lic2.verMinor));
+        xlsx.write(uuidColumn, 8, licenseKey);
+    }
+    xlsx.save();
+}
+
+QString MainWindow::getEncrypt_New()
+{
+    QString localid = "";
+    LicenseInfo localinfo;
+    //鏌ヨ绯荤粺鐢ㄦ埛鍚�
+    localinfo.Username = qgetenv("USER"); // Linux绯荤粺
+    if (localinfo.Username.isEmpty())
+        localinfo.Username = qgetenv("USERNAME"); // Windows绯荤粺
+    //鏌ヨCPU搴忓垪鍙�
+    localinfo.CPU_Processorid = getWindowsInfo("wmic cpu get processorid");
+    //鏌ヨ涓绘澘搴忓垪鍙�
+    localinfo.Baseboard_Serialnumber = getWindowsInfo("wmic baseboard get serialnumber");
+    //鏌ヨBIOS搴忓垪鍙�
+    localinfo.Bios_Serialnumber = getWindowsInfo("wmic bios get serialnumber");
+    //鏌ヨ涓绘澘鍞竴鏍囪瘑
+    localinfo.Baseboard_Uuid = getWindowsInfo("wmic csproduct get uuid");
+
+    //灏濊瘯鏂扮殑鍔犲瘑鏂规硶
+    LicenseData lic;
+    lic.boardUuid  = LicenseData::hexStringToBinary(localinfo.Baseboard_Uuid);
+    lic.cpuSerial  = LicenseData::hexStringToBinary(localinfo.CPU_Processorid);
+    lic.userName   = localinfo.Username;
+    lic.expireDate = QDate::fromString(localinfo.LicensedDuration_end,"yyyy-MM-dd");
+    lic.productId  = localinfo.Productid.toUInt();
+    QString version = localinfo.Versionid;
+    lic.verMajor   = version.split(".").at(0).toUInt();
+    lic.verMinor   = version.split(".").at(1).toUInt();
+    lic.activeState = localinfo.ActiveState;
+    // 涓�閿姞瀵�
+    QString cipher = ShortCrypto::encrypt(lic.toBinary(), key);
+//    ui->textEdit_localid->setText(cipher);
+    return  cipher;
+}
+
 
 void MainWindow::on_pushButton_getId_clicked()
 {
     QString localid = getLocalID();
     QString encryptid = getEncrypt(localid,key);
+
+    //鏂扮殑鍔犲瘑鏂规硶
+    encryptid = getEncrypt_New();
     ui->textEdit_localid->setText(encryptid);
 
     localinfo = LicenseInfo();
@@ -521,22 +780,72 @@
 
 void MainWindow::on_pushButton_setproid_clicked()
 {
-    QJsonObject licensekey_Obj = workingjsondoc.object();
-    licensekey_Obj["Productid"] = ui->lineEdit_setproid->text();
-    workingjsondoc.setObject(licensekey_Obj);
-    QByteArray jsonbytearray = workingjsondoc.toJson();
-    ui->textEdit_licensekey->setPlainText("");
-    ui->textEdit_licensekey->setPlainText(getEncrypt(QString(jsonbytearray),key));
-    setLicenseinfo(licensekey_Obj);
+//    QJsonObject licensekey_Obj = workingjsondoc.object();
+//    licensekey_Obj[m_numToInfo.key("Productid")] = ui->lineEdit_setproid->text();
+//    workingjsondoc.setObject(licensekey_Obj);
+
+//    QByteArray compressedArray = QJsonDocument(licensekey_Obj).toJson(QJsonDocument::Compact);
+//    QByteArray jsonbytearray = qCompress(compressedArray,9);
+//    QString testid = jsonbytearray.toBase64();
+//    ui->textEdit_licensekey->setPlainText("");
+//    ui->textEdit_licensekey->setPlainText(getEncrypt(QString(testid),key));
+
+    lic2.productId = ui->lineEdit_setproid->text().toUInt();
+    QString cipher = ShortCrypto::encrypt(lic2.toBinary(), key);
+    ui->textEdit_licensekey->setPlainText(cipher);
+//    setLicenseinfo(licensekey_Obj);
+
+    //閫欒!涔熷彧闇�瑕佹洿鏂皃roductId
+    licenseinfo.Productid = ui->lineEdit_setproid->text();
+    changeUIstate();
+
 }
 
 void MainWindow::on_pushButton_setversion_clicked()
 {
-    QJsonObject licensekey_Obj = workingjsondoc.object();
-    licensekey_Obj["Versionid"] = ui->lineEdit_setversion->text();
-    workingjsondoc.setObject(licensekey_Obj);
-    QByteArray jsonbytearray = workingjsondoc.toJson();
-    ui->textEdit_licensekey->setPlainText("");
-    ui->textEdit_licensekey->setPlainText(getEncrypt(QString(jsonbytearray),key));
-    setLicenseinfo(licensekey_Obj);
+//    QJsonObject licensekey_Obj = workingjsondoc.object();
+//    licensekey_Obj[m_numToInfo.key("Versionid")] = ui->lineEdit_setversion->text();
+//    workingjsondoc.setObject(licensekey_Obj);
+
+//    QByteArray compressedArray = QJsonDocument(licensekey_Obj).toJson(QJsonDocument::Compact);
+//    QByteArray jsonbytearray = qCompress(compressedArray,9);
+//    QString testid = jsonbytearray.toBase64();
+//    ui->textEdit_licensekey->setPlainText("");
+//    ui->textEdit_licensekey->setPlainText(getEncrypt(QString(testid),key));
+
+//    setLicenseinfo(licensekey_Obj);
+    QString version = ui->lineEdit_setversion->text();
+    lic2.verMajor = version.split(".").at(0).toUInt();
+    lic2.verMinor = version.split(".").at(1).toUInt();
+    QString cipher = ShortCrypto::encrypt(lic2.toBinary(), key);
+    ui->textEdit_licensekey->setPlainText(cipher);
+    //閫欒!涔熷彧闇�瑕佹洿鏂癡ersionid
+    licenseinfo.Versionid = ui->lineEdit_setversion->text();
+    changeUIstate();
+}
+
+void MainWindow::on_pushButton_normal_clicked()
+{
+    giveLicense(3);
+
+}
+
+void MainWindow::on_pushButton_education_clicked()
+{
+    giveLicense(6);
+}
+
+void MainWindow::on_pushButton_profession_clicked()
+{
+    giveLicense(12);
+}
+
+void MainWindow::on_pushButton_viewUsers_clicked()
+{
+    QString excelPath = QApplication::applicationDirPath()+QStringLiteral("/瀹夊叏璇勪环杞欢鎺堟潈浜烘暟缁熻琛�.xlsx");
+
+    QUrl fileUrl = QUrl::fromLocalFile(excelPath);
+
+    // 2. 璋冪敤绯荤粺鏈嶅姟鎵撳紑鏂囦欢绠$悊鍣ㄥ苟閫変腑鏂囦欢
+    QDesktopServices::openUrl(fileUrl);
 }

--
Gitblit v1.9.1