栓Q辅助工具心跳验证处理代码分析
该程序是一个栓Q辅助工具的心跳验证处理部分代码。在主函数中,首先通过发送请求获取应用信息,然后根据获取的应用信息提示用户输入授权码,并通过发送请求验证授权码。接着通过线程执行心跳循环验证和辅助逻辑。
'心跳验证'是指客户端和服务端之间保持连接状态的一种机制。在这个程序中,每隔一定时间,客户端就会向服务端发送一次心跳请求,以保证连接状态。如果客户端在规定时间内没有发送心跳请求,服务端就会认为客户端已经掉线。
在程序中,心跳验证的实现是通过一个while循环来实现的。首先通过Sleep函数让线程进入睡眠状态,等待一定时间,然后通过一个ShuanQApiClient对象来发送心跳请求。在发送请求之后,程序会对响应结果进行处理,判断是否出现异常情况。如果出现异常情况,程序会进行相应的处理。
在while循环中,程序还执行了一个'fuzruko'函数。这个函数的功能暂不清楚,需要进一步分析代码才能确定。
心跳验证处理函数(heartbeatHandle)
void heartbeatHandle()
{
while (true)
{
//Sleep(ShuanQ_HeartbeatFrequency);// * 多少就是多少秒
std::this_thread::sleep_for(std::chrono::milliseconds(ShuanQ_HeartbeatFrequency));
std::cout << std::endl << std::endl << "开始心跳检查" << std::endl;
ShuanQApiClient cardHeartbeatApi;//创建一个栓Q验证客户端接口实例对象
cardHeartbeatApi.setRequestApi("/api/card_app/get_card_info"); //设置接口请求地址
cardHeartbeatApi.addRequestParam("card", user_card); //增加一个参数
cardHeartbeatApi.addRequestParam("machine_code", machine_code); //增加一个参数
cardHeartbeatApi.addRequestParam("user_token", user_token); //增加一个参数
cardHeartbeatApi.addRequestParam("update_active", "1"); //增加一个参数
bool responseResult = cardHeartbeatApi.sendRequest();//发送请求(会自动帮您处理好必要参数、签名、参数加密等)
if (!responseResult) {//请求处理失败
std::cout << "请求失败" << std::endl;
//exit(-1);
}
try
{
cJSON* responseJson = cardHeartbeatApi.getResponseJsonObject();//获取响应json对象
int responseCode = cJSON_GetObjectItem(responseJson, "code")->valueint; //得到请求响应返回状态码
std::string responseMessage = cJSON_GetObjectItem(responseJson, "message")->valuestring; //得到请求响应返回信息
if (responseCode != 1) {//接口业务码响应非成功-将服务器返回信息提示
//std::cout << "接口业务码响应失败:" << responseMessage << std::endl;
//exit(-1);
}
if (!cardHeartbeatApi.requestDataSignatureVerify()) {//响应数据验签检测未通过
//std::cout << "响应数据验签失败" << std::endl;
//Sleep(5000);
//exit(-1);
}
if (!cardHeartbeatApi.requestSafeCodeVerify()) {//防劫持验证检测未通过
std::cout << "检测到数据被劫持篡改了" << std::endl;
Sleep(5000);
exit(-1);
}
if (!cardHeartbeatApi.requestDataTimeDifferenceVerify()) {//响应数据检测验证不通过
//std::cout << "响应数据异常,与服务器时差相差过多" << std::endl; // 刚刚是提示这个吗 没有任何提示 这个一般是电脑时间不对了提示的
//Sleep(5000);
//exit(-1);
}
int server_time = cJSON_GetObjectItem(responseJson, "timestamp")->valueint;
std::string dataJson = cardHeartbeatApi.getDecryptResponseData();//解密rc4和解十六进制得到原始未加密的dataJson数据
// 你拿张卡 登录然后封卡 我看看这里返回的啥
std::cout << "解密后的dataJson:" << dataJson << std::endl;
cJSON* responseDataJson = cardHeartbeatApi.getDataJsonObject();//获取解密后的data json对象
cJSON* moreOtherData = cJSON_GetObjectItem(responseDataJson, "moreOtherData");
std::string expireTimeStr = cJSON_GetObjectItem(responseDataJson, "expireTimeStr")->valuestring; //卡密到期时间字符串
cJSON* cardInfo = cJSON_GetObjectItem(responseDataJson, "cardInfo"); //获取cardInfo对象
cJSON* surplusTime = cJSON_GetObjectItem(responseDataJson, "surplusTime"); //获取surplusTime对象
int cardTimeType = cJSON_GetObjectItem(cardInfo, "time_type")->valueint; //得到卡密时长类型
int cardTimeValue = cJSON_GetObjectItem(cardInfo, "time_value")->valueint; //得到卡密时长值
double cardEndTime = cJSON_GetObjectItem(cardInfo, "endtime")->valuedouble; //得到卡密到期时间-时间戳10位
double surplusTimeSecond = cJSON_GetObjectItem(surplusTime, "second")->valuedouble; //得到卡密的总共剩余时间-秒
double surplusTimeMinute = cJSON_GetObjectItem(surplusTime, "minute")->valuedouble; //得到卡密的总共剩余时间-分钟
double surplusTimeHour = cJSON_GetObjectItem(surplusTime, "hour")->valuedouble; //得到卡密的总共剩余时间-小时
double surplusTimeDay = cJSON_GetObjectItem(surplusTime, "day")->valuedouble; //得到卡密的总共剩余时间-天
if (server_time > cardEndTime) {
std::cout << "卡密已到期" << std::endl;
Sleep(5000);
exit(-1);
}
}
catch (const std::exception& ex)//你 现在加壳试试看 会不会掉效果 好的
{
std::cout << "处理失败,出现异常" << std::endl;
Sleep(5000);
//exit(-1);
}
}
}
代码说明
- 心跳验证频率:
ShuanQ_HeartbeatFrequency变量控制心跳验证的频率,单位为毫秒。 - 创建栓Q验证客户端接口实例:
ShuanQApiClient cardHeartbeatApi用于发送心跳请求。 - 设置请求地址:
cardHeartbeatApi.setRequestApi("/api/card_app/get_card_info");指定心跳请求的接口地址。 - 添加请求参数:
cardHeartbeatApi.addRequestParam(...)向请求中添加必要参数,包括卡密、机器码、用户token等。 - 发送请求:
cardHeartbeatApi.sendRequest()发送心跳请求。 - 处理响应结果:
- 判断请求是否成功:
if (!responseResult) {...} - 获取响应json对象:
cJSON* responseJson = cardHeartbeatApi.getResponseJsonObject(); - 检查响应状态码:
if (responseCode != 1) {...} - 进行数据验签、防劫持验证、时间差验证:
cardHeartbeatApi.requestDataSignatureVerify(),cardHeartbeatApi.requestSafeCodeVerify(),cardHeartbeatApi.requestDataTimeDifferenceVerify()。 - 获取服务器时间:
int server_time = cJSON_GetObjectItem(responseJson, "timestamp")->valueint; - 解密响应数据:
std::string dataJson = cardHeartbeatApi.getDecryptResponseData(); - 获取解密后的data json对象:
cJSON* responseDataJson = cardHeartbeatApi.getDataJsonObject(); - 解析响应数据,获取卡密到期时间、剩余时间等信息。
- 判断卡密是否到期:
if (server_time > cardEndTime) {...}
- 判断请求是否成功:
- 异常处理:
catch (const std::exception& ex) {...}捕获异常,并进行相应的处理。
其他说明
- 程序中使用
cJSON库来解析json数据。 fuzruko函数的功能暂不清楚,需要进一步分析代码才能确定。getMachineCode函数用于获取机器码。WritePrivateProfileString函数用于将授权码写入配置文件。
总结
该程序通过心跳验证机制来保证客户端和服务端之间的连接状态,并通过解析响应数据来获取卡密相关信息,例如卡密到期时间、剩余时间等。程序中使用了线程来执行心跳循环验证和辅助逻辑。
原文地址: http://www.cveoy.top/t/topic/l5Cl 著作权归作者所有。请勿转载和采集!