Files
admin aa59132330 Rewrite Update module and update client/server sources
Update: drop Qt dependency, rewrite as pure Win32 using v142 toolset. Replace Update.ui/qrc and miniz-based Zip with Api/Crypto/Http/Json/Unzip/UpdateWindow modules.

CrownClient/CrownServer: update Verify and main sources, retarget x64 configs to v142 (VS2019) with SDK 10.0.19041.0, fix VMProtect SDK paths.
2026-10-17 16:31:54 +08:00

118 lines
3.8 KiB
C++
Raw Permalink 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.
#pragma once
#include <QString>
#include <QDebug>
#include <QTime>
#include <QDateTime>
#include <QCryptographicHash>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QEventLoop>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonDocument>
#include <QUuid>
// 服务端「应用 -> 加密方式」,改后台配置时这里要跟着改
// 0 = 不加密 1 = RC4 2 = AES-256-GCM
#define VERIFY_ENCRYPT_TYPE 2
// 订单推送写进哪个云端变量。后台要先建一个 var_type=stream、
// 写权限包含 app_user 的变量,key 填这里
#define VERIFY_PUSH_VARIABLE_KEY "order_push"
// 永久授权 / 点数计费拿不到真实到期日,用这个占位,保证主程序的到期判断永远不触发
#define VERIFY_NO_EXPIRY_DATE QDate(2999, 12, 31)
class Verify :public QObject
{
Q_OBJECT
public:
Verify(QString Url, QString AppKey, QString CommKey, QString Verison);
~Verify();
private:
// 获取机器码
QString GetCPUID();
int GetRandom(int Min, int Max);
QString GetRandom(int Length);
unsigned int Crc32(const void* Buffer, unsigned short Length);
QString Md5(QByteArray Data);
QByteArray RC4(QByteArray Data, QString Key);
private:
QString ParamEncrypt(QString Param);
QString ParamDecrypt(QString Param);
// AES-256-GCM,布局与后端 crypto.encryptAES 一致:nonce(12) || 密文 || tag(16)
QByteArray AesGcmEncrypt(const QByteArray& Plain, bool& Ok);
QByteArray AesGcmDecrypt(const QByteArray& Cipher, bool& Ok);
// 按后台配置的加密方式处理请求体 / 响应体,输入输出都是 base64
QString EncryptBody(const QString& Plain, bool& Ok);
QString DecryptBody(const QString& Cipher, bool& Ok);
// 发一个 /api/v1/app/{appKey} 请求,成功时 Data 是业务 data(可能是对象也可能是数组)
bool Request(const QString& Path, const QJsonObject& Body, QJsonValue& Data, QString& Result,
bool WithToken = true, const QString& Method = "POST");
// 登录和心跳返回同一套计费字段,统一解析
void ParseBilling(const QJsonObject& Data);
public:
// 登录
bool Login(QString Username, QString Password, QString& result);
// 心跳
bool Heartbeat(QString& result);
// 检查更新(主程序的更新已交给 Update.exe,这里只在需要时做补充判断)
bool checkUpdate();
// 软件登录账号
QString Username();
// 到期时间;永久授权和点数计费没有到期日,返回 2999-12-31
QDateTime GetDueTime();
// 是否永久授权
bool IsPermanent();
// 剩余点数,非点数计费时无意义
double Balance();
// 计费模式:permanent / subscription / balance / free,未登录时为空
QString BillingMode();
// 界面上的到期文案,把三种计费模式合并成一句话
QString DueTimeText();
// 修改密码
bool ChangePassword(QString OldPassword, QString NewPassword, QString& result);
// 已绑定的设备列表
bool Devices(QJsonArray& list, QString& result);
// 解绑设备
bool UnbindDevice(QString DeviceId, QString& result);
public slots:
// 推送消息
bool push_msg(QString type, QString app, QString account, QMap<QString, QString> order);
private:
// 随机密码字符串 非十六进制
QString m_randomeKey;
// 应用密钥(verify 后台的 AppKey)
QString m_appId;
// 通信密钥(verify 后台的 EncryptKey)
QString m_commKey;
// 服务地址
QString m_webApi;
// 机器码
QString m_machineCode;
// 版本
QString m_version;
// 账号
QString m_username;
// 密码
QString m_password;
// 登录拿到的 JWT,心跳和云端接口都要带
QString m_token;
// 实例ID,同一台机器多开时区分进程
QString m_instanceId;
private:
// 到期时间
QDateTime m_dueTime;
// 是否永久授权
bool m_permanent;
// 剩余点数
double m_balance;
// 计费模式
QString m_billingMode;
};