Commit ffcf864b by NitefullWind

1. 修正支付后崩溃问题(跨线程引用栈变量); 2. 乱码问题; 3. 导出接口去掉窗口句柄

parent fffc6402
...@@ -72,31 +72,35 @@ void Control::InitModel() ...@@ -72,31 +72,35 @@ void Control::InitModel()
bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error) bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata, QString &error)
{ {
char in[MAX_BUF_LEN] = {0};
char out[MAX_BUF_LEN] = {0};
QByteArray array = QJsonDocument(json).toJson(QJsonDocument::Compact);
QLibrary lib(qApp->applicationDirPath() + "/" + "FreemudWrapper.dll"); QLibrary lib(qApp->applicationDirPath() + "/" + "FreemudWrapper.dll");
outdata.clear();
strcpy(in, array);
if(lib.load()) if(lib.load())
{ {
GetValue getvalue = (GetValue)lib.resolve("_GetValue@8"); GetValue getvalue = (GetValue)lib.resolve("_GetValue@8");
if(getvalue != NULL) if(getvalue != NULL)
{ {
QEventLoop loop; QEventLoop loop;
QtConcurrent::run( [ this, &loop, &in, &out, getvalue]() QFuture<QByteArray> future = QtConcurrent::run( [ this, &loop, json, getvalue]() ->QByteArray
{ {
char in[MAX_BUF_LEN] = {0};
char out[MAX_BUF_LEN] = {0};
QByteArray array = QJsonDocument(json).toJson(QJsonDocument::Compact);
strcpy(in, array);
getvalue(in, out); getvalue(in, out);
loop.exit();
return QByteArray(out);
}); });
QFutureWatcher<QByteArray> watcher;
watcher.setFuture(future);
connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec(); loop.exec();
outdata = QByteArray(out); outdata = watcher.result();
return true; return true;
} }
else else
......
#ifndef CONTROL_H #ifndef CONTROL_H
#define CONTROL_H #define CONTROL_H
#include "requestmodel.h" #include "requestmodel.h"
......
#ifndef FMTOOL #ifndef FMTOOL
#define FMTOOL #define FMTOOL
#include <windows.h> #include <windows.h>
......
...@@ -211,7 +211,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message) ...@@ -211,7 +211,7 @@ void HostWidget::ShowWiteMGS(ReqType type, bool flag, QString message)
ui->label_pay_money->setVisible(true); ui->label_pay_money->setVisible(true);
ui->label_pay_money->setText(message); ui->label_pay_money->setText(message);
ui->btn_pay_exit->setVisible(true); ui->btn_pay_exit->setVisible(true);
ui->btn_pay_exit->setText("确认"); ui->btn_pay_exit->setText(QString::fromLocal8Bit("确认"));
if(flag) { if(flag) {
ui->label_pay_msg_time->setVisible(true); ui->label_pay_msg_time->setVisible(true);
......
#ifndef JSONFACTORY #ifndef JSONFACTORY
#define JSONFACTORY #define JSONFACTORY
#include "requestmodel.h" #include "requestmodel.h"
......
 #ifdef SBKDLL
#include <qwinwidget.h>
#include <QMessageBox>
#include <windows.h>
#include "control.h"
#include "global.h"
#include "QsLog.h"
#include "requestmodel.h"
#include "fmtool.h"
#include "rspfactory.h"
#include <QDir>
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )
{
static bool ownApplication = FALSE;
if ( dwReason == DLL_PROCESS_ATTACH )
ownApplication = QMfcApp::pluginInstance( hInstance );
if ( dwReason == DLL_PROCESS_DETACH && ownApplication )
delete qApp;
return TRUE;
}
extern "C" __declspec(dllexport) void Start(const char *indata, char *outdata)
{
HWND parent = GetDesktopWindow();
QWinWidget win( parent );
QString logDir = QString("%1/log").arg(QApplication::applicationDirPath());
QDir().mkdir(logDir);
QsLogging::Logger& logger = QsLogging::Logger::instance();
logger.setLoggingLevel(QsLogging::TraceLevel);
QString str = qApp->applicationDirPath() + "/log/sbuxpay.txt";
/* 配置输出定向器 */
QsLogging::DestinationPtr fileDestination(QsLogging::DestinationFactory::MakeFileDestination(
str,
QsLogging::EnableLogRotation, QsLogging::MaxSizeBytes(1024*1024),
QsLogging::MaxOldLogCount(5)));
logger.addDestination(fileDestination);
QsLogging::DestinationPtr consleDest(QsLogging::DestinationFactory::MakeDebugOutputDestination());
logger.addDestination(consleDest);
Control control(&win);
control.Start(indata, outdata);
}
#else
#ifdef FM_TEST #ifdef FM_TEST
#include "control.h" #include "control.h"
...@@ -101,7 +155,7 @@ int main(int argc, char *argv[]) ...@@ -101,7 +155,7 @@ int main(int argc, char *argv[])
AlipayRequest req; AlipayRequest req;
FMTool::SetString(req.BusinessDay, 8 , QString("20170908")); FMTool::SetString(req.BusinessDay, 8 , QString("20170908"));
FMTool::SetString(req.TransType, 2 , QString("10")); FMTool::SetString(req.TransType, 2 , QString("40"));
FMTool::SetString(req.Reserved1, 64 , QString("1443")); FMTool::SetString(req.Reserved1, 64 , QString("1443"));
FMTool::SetString(req.StoreNo, 20 , QString("17607")); FMTool::SetString(req.StoreNo, 20 , QString("17607"));
FMTool::SetString(req.DeviceNo, 6 , QString("1")); FMTool::SetString(req.DeviceNo, 6 , QString("1"));
...@@ -153,4 +207,6 @@ int main(int argc, char *argv[]) ...@@ -153,4 +207,6 @@ int main(int argc, char *argv[])
return a.exec(); return a.exec();
} }
#endif #endif //! FM_TEST
#endif //! #ifdef SBKDLL
#ifndef REQUESTMODEL #ifndef REQUESTMODEL
#define REQUESTMODEL #define REQUESTMODEL
typedef enum typedef enum
......
...@@ -12,7 +12,6 @@ TARGET = sbkpay ...@@ -12,7 +12,6 @@ TARGET = sbkpay
include("./QsLog/QsLog.pri") include("./QsLog/QsLog.pri")
DEFINES += FM_TEST
CONFIG += C++11 SBKDLL CONFIG += C++11 SBKDLL
...@@ -21,7 +20,8 @@ CONFIG += C++11 SBKDLL ...@@ -21,7 +20,8 @@ CONFIG += C++11 SBKDLL
include($$PWD/qtwinmigrate/src/qtwinmigrate.pri) include($$PWD/qtwinmigrate/src/qtwinmigrate.pri)
SBKDLL { SBKDLL {
TEMPLATE = lib TEMPLATE = lib
CONFIG += dll DEFINES += SBKDLL
CONFIG += dll
} else { } else {
TEMPLATE = app TEMPLATE = app
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment