Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sbkpay
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhenfei.zhang
sbkpay
Commits
ec1ef79f
Commit
ec1ef79f
authored
Sep 18, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 整合onedatabase分支 [
5f164e4d
] 代码。 修复一个冲正时数据库的Bug。
parent
08b78a0f
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
122 additions
and
50 deletions
+122
-50
sbkpay/DataProcess/fmnetwork.cpp
+0
-1
sbkpay/DataProcess/rollback.cpp
+63
-6
sbkpay/DataProcess/rollback.h
+11
-1
sbkpay/control.cpp
+42
-39
sbkpay/control.h
+2
-2
sbkpay/sbkpay.pro
+3
-0
sbkpay/version.h
+1
-1
No files found.
sbkpay/DataProcess/fmnetwork.cpp
View file @
ec1ef79f
...
...
@@ -17,7 +17,6 @@
#include <QtConcurrent>
#include <QLibrary>
typedef
int
(
__stdcall
*
SKBAPISend
)(
const
char
*
indata
,
const
char
*
guid
,
char
*
outdata
,
char
*
errMsg
,
const
char
*
mode
,
const
char
*
operation
);
FMNetWork
::
FMNetWork
(
QObject
*
parent
)
:
QObject
(
parent
)
{
...
...
sbkpay/DataProcess/rollback.cpp
View file @
ec1ef79f
...
...
@@ -8,6 +8,7 @@
#include <QJsonObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QMap>
#include <QSqlError>
#include "tools.h"
#include "QsLog.h"
...
...
@@ -15,9 +16,12 @@
#include "fmnetwork.h"
#include <QtConcurrent>
QMap
<
QString
,
QString
>
RollBack
::
s_rollorder
;
QMutex
RollBack
::
s_rollorder_lock
;
RollBack
::
RollBack
(
QObject
*
parent
)
:
QThread
(
parent
)
{
//_db = new FMPDataBase(path + DB_ORDER, QString("rollback"));
}
RollBack
::~
RollBack
()
...
...
@@ -56,11 +60,11 @@ void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
if
(
!
CretOperate
::
GetSign
(
json
))
{
QLOG_ERROR
()
<<
"get sign error"
;
QLOG_ERROR
()
<<
"
rollback : "
<<
"
get sign error"
;
continue
;
}
QLOG_INFO
()
<<
json
;
QLOG_INFO
()
<<
"rollback : "
<<
json
;
QByteArray
array
;
...
...
@@ -93,7 +97,7 @@ void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
}
QLOG_WARN
()
<<
"rollback resulte "
<<
QThread
::
currentThreadId
()
<<
":"
<<
array
;
QLOG_WARN
()
<<
"rollback
: "
<<
"rollback
resulte "
<<
QThread
::
currentThreadId
()
<<
":"
<<
array
;
}
}
...
...
@@ -115,13 +119,15 @@ void RollBack::run()
_db
.
open
();
QSqlQuery
query
(
_db
);
InsertRollOrder
(
query
);
query
.
clear
();
QLOG_WARN
()
<<
"find sql : "
<<
"select * from orderlist"
;
QLOG_WARN
()
<<
"
rollback : "
<<
"
find sql : "
<<
"select * from orderlist"
;
bool
flag
=
query
.
exec
(
"select * from orderlist"
);
if
(
!
flag
)
QLOG_WARN
()
<<
query
.
lastError
();
QLOG_WARN
()
<<
"rollback : "
<<
query
.
lastError
();
RollWiteQuery
(
_db
,
query
);
...
...
@@ -138,3 +144,54 @@ void RollBack::run()
loop
.
exec
();
}
}
void
RollBack
::
InsertRollOrder
(
QSqlQuery
&
query
)
{
QMap
<
QString
,
QString
>
tmporder
=
s_rollorder
;
QMap
<
QString
,
QString
>::
Iterator
it
;
QLOG_INFO
()
<<
"rollback : "
<<
"roll order map "
<<
tmporder
;
for
(
it
=
tmporder
.
begin
();
it
!=
tmporder
.
end
();
++
it
)
{
if
(
!
it
.
key
().
isEmpty
())
{
QString
sql
=
QString
(
"insert into %1 ( 'orderid', 'content') values ('%2', '%3')"
).
arg
(
DB_TABLE_NAME
).
arg
(
it
.
key
()).
arg
(
it
.
value
());
QLOG_INFO
()
<<
"rollback : "
<<
"insert sql "
<<
sql
;
if
(
!
query
.
exec
(
sql
))
{
QLOG_ERROR
()
<<
"rollback : "
<<
query
.
lastError
()
<<
query
.
lastError
().
text
();
}
else
{
s_rollorder_lock
.
lock
();
s_rollorder
.
remove
(
it
.
key
());
s_rollorder_lock
.
unlock
();
}
}
else
{
QLOG_ERROR
()
<<
"rollback : "
<<
"rollorder error "
<<
it
.
key
()
<<
it
.
value
();
}
}
s_rollorder_lock
.
lock
();
if
(
s_rollorder
.
size
()
>
300
)
{
QLOG_WARN
()
<<
"rollback : "
<<
"map size big clean : "
<<
s_rollorder
.
size
();
s_rollorder
.
clear
();
}
s_rollorder_lock
.
unlock
();
}
void
RollBack
::
SetRollOrder
(
QString
orderid
,
QString
request
)
{
QLOG_INFO
()
<<
"rollback : "
<<
"new roll order "
<<
orderid
<<
request
;
s_rollorder_lock
.
lock
();
s_rollorder
.
insert
(
orderid
,
request
);
s_rollorder_lock
.
unlock
();
}
sbkpay/DataProcess/rollback.h
View file @
ec1ef79f
#ifndef ROLLBACK_H
#define ROLLBACK_H
#include <QString>
#include <QMAp>
#include <QMutex>
#include <QThread>
#include <QPointer>
#include <QSemaphore>
...
...
@@ -20,9 +23,16 @@ public:
void
run
();
static
void
SetRollOrder
(
QString
orderid
,
QString
request
);
private
:
void
InsertRollOrder
(
QSqlQuery
&
query
);
private
:
//FMPDataBase *_db;
QSemaphore
_spr
;
//QSemaphore _spr;
static
QMap
<
QString
,
QString
>
s_rollorder
;
static
QMutex
s_rollorder_lock
;
FMPSettings
_setting
;
};
...
...
sbkpay/control.cpp
View file @
ec1ef79f
...
...
@@ -13,6 +13,8 @@
#include <QFont>
#include <QFontDatabase>
#include <QApplication>
#include <QSqlError>
#include <QSqlQuery>
#include <QSslSocket>
#include <QSslConfiguration>
#include <QNetworkAccessManager>
...
...
@@ -20,43 +22,54 @@
#include <QNetworkRequest>
#include <QJsonDocument>
#include <Windows.h>
#include "DataProcess/rollback.h"
#include "DataProcess/tools.h"
#include "DataProcess/cretopt.h"
#include "DataProcess/fmnetwork.h"
#include <QUuid>
EXTERN_C
IMAGE_DOS_HEADER
__ImageBase
;
typedef
int
(
__stdcall
*
SKBAPISend
)(
const
char
*
indata
,
const
char
*
guid
,
char
*
outdata
,
char
*
errMsg
,
const
char
*
mode
,
const
char
*
operation
);
Control
::
Control
(
QObject
*
parent
)
:
QObject
(
parent
),
_widget
(
NULL
)
{
QString
path
;
ToolS
::
GetPath
(
path
);
QSqlDatabase
db
=
QSqlDatabase
::
addDatabase
(
"QSQLITE"
,
QString
(
"creat"
));
db
.
setDatabaseName
(
path
+
DB_ORDER
);
db
.
open
();
_isinterrupt
=
false
;
_db
=
new
FMPDataBase
(
path
+
DB_ORDER
,
QString
(
"writeorder"
));
if
(
db
.
isOpen
())
{
QSqlQuery
query
(
db
);
QString
sql
=
QString
(
"create table "
)
+
DB_TABLE_NAME
+
" ("
"orderid varchar(60) primary key, "
"content text"
")"
;
QLOG_INFO
()
<<
"creat table : "
<<
sql
;
bool
flag
=
query
.
exec
(
sql
);
if
(
!
flag
)
QLOG_WARN
()
<<
query
.
lastError
();
db
.
close
();
}
else
{
QLOG_ERROR
()
<<
"----"
<<
db
.
open
();
QLOG_ERROR
()
<<
db
.
lastError
().
type
()
<<
db
.
lastError
().
text
();
}
_db
->
Init
();
_db
->
creat
(
sql
);
_isinterrupt
=
false
;
InitModel
();
}
Control
::~
Control
()
{
if
(
_db
!=
NULL
)
{
delete
_db
;
_db
=
NULL
;
}
//
if(_db != NULL)
//
{
//
delete _db;
//
_db = NULL;
//
}
}
void
Control
::
Start
(
const
char
*
indata
,
char
*
outdata
)
...
...
@@ -73,8 +86,7 @@ void Control::Start(const char *indata, char *outdata)
QFont
ft
(
"Microsoft YaHei UI Light"
);
qApp
->
setFont
(
ft
);
QLOG_INFO
()
<<
"Openssl support:"
<<
QSslSocket
::
supportsSsl
();
qDebug
()
<<
"Openssl support:"
<<
QSslSocket
::
supportsSsl
()
<<
QApplication
::
libraryPaths
();
QLOG_INFO
()
<<
"Openssl support:"
<<
QSslSocket
::
supportsSsl
()
<<
QApplication
::
libraryPaths
();
QEventLoop
loop
;
...
...
@@ -183,8 +195,7 @@ bool Control::SendMessageToServer(const QJsonObject &json, QByteArray &outdata,
CretOperate
::
GetMAC
(
tmpjson
);
CretOperate
::
GetSign
(
tmpjson
);
QLOG_INFO
()
<<
"send json to payment: "
<<
tmpjson
;
qDebug
()
<<
"send json to payment: "
<<
tmpjson
;
QLOG_INFO
()
<<
"send json to server: "
<<
tmpjson
;
bool
isOk
=
false
;
if
(
_posType
==
SPCC
)
{
...
...
@@ -198,14 +209,15 @@ bool Control::SendMessageToServer(const QJsonObject &json, QByteArray &outdata,
//如果没有点击取消支付按钮直接写数据库异步冲正
if
(
tmpjson
.
contains
(
JSON_KEY_REQTYPE
)
&&
tmpjson
[
JSON_KEY_REQTYPE
].
toInt
()
==
72
)
{
QByteArray
data
=
QJsonDocument
(
tmpjson
).
toJson
(
QJsonDocument
::
Compact
);
QVariantHash
hash
;
// QVariantHash hash;
hash
.
insert
(
SQL_KEY_ORDERID
,
tmp
json
[
JSON_KEY_PARTORDERID
].
toString
());
hash
.
insert
(
SQL_KET_CONTENT
,
QString
(
data
));
// hash.insert(SQL_KEY_ORDERID,
json[JSON_KEY_PARTORDERID].toString());
//
hash.insert(SQL_KET_CONTENT, QString(data));
// _db->insert(DB_TABLE_NAME, hash);
_db
->
insert
(
DB_TABLE_NAME
,
hash
);
QByteArray
data
=
QJsonDocument
(
tmpjson
).
toJson
(
QJsonDocument
::
Compact
);
RollBack
::
SetRollOrder
(
json
[
JSON_KEY_PARTORDERID
].
toString
(),
QString
(
data
));
}
return
false
;
}
...
...
@@ -245,17 +257,6 @@ bool Control::SendMessageToPayMent(const QJsonObject &json, QByteArray &outdata,
#else
if
(
!
Control
::
HttpPost
(
url
,
array
,
data
,
"application/json;charset=utf-8"
,
"application/json"
,
error
,
60
))
{
// if(json.contains(JSON_KEY_PARTORDERID) && !json[JSON_KEY_PARTORDERID].toString().isEmpty())
// {
// QVariantHash hash;
// hash.insert(SQL_KEY_ORDERID, json[JSON_KEY_PARTORDERID].toString());
// hash.insert(SQL_KET_CONTENT, QString(data));
// _db->insert(DB_TABLE_NAME, hash);
// }
return
false
;
}
#endif
...
...
@@ -617,15 +618,17 @@ void Control::Request(ReqType type, QStringList list)
SetResPonseWithMessage
(
"23"
,
error
);
else
{
// QVariantHash hash;
// hash.insert(SQL_KEY_ORDERID, json[JSON_KEY_PARTORDERID].toString());
// hash.insert(SQL_KET_CONTENT, QString(tmpdata));
QVariantHash
hash
;
// QLOG_ERROR() << "roll back faile , move request to database : " << json
;
hash
.
insert
(
SQL_KEY_ORDERID
,
json
[
JSON_KEY_PARTORDERID
].
toString
());
hash
.
insert
(
SQL_KET_CONTENT
,
QString
(
tmpdata
));
// _db->insert(DB_TABLE_NAME, hash);
QLOG_ERROR
()
<<
"roll back faile , move request to database : "
<<
json
;
RollBack
::
SetRollOrder
(
json
[
JSON_KEY_PARTORDERID
].
toString
(),
QString
(
tmpdata
))
;
_db
->
insert
(
DB_TABLE_NAME
,
hash
);
SetResPonseWithMessage
(
"23"
,
error
);
}
...
...
sbkpay/control.h
View file @
ec1ef79f
...
...
@@ -3,7 +3,7 @@
#include "requestmodel.h"
#include "hostwidget.h"
#include "DataProcess/fmp_database.h"
//
#include "DataProcess/fmp_database.h"
#include "fmp_settings.h"
#include <QObject>
#include <QApplication>
...
...
@@ -83,7 +83,7 @@ private:
bool
_isinterrupt
;
FMPDataBase
*
_db
;
//
FMPDataBase *_db;
FMPSettings
_setting
;
POSType
_posType
;
...
...
sbkpay/sbkpay.pro
View file @
ec1ef79f
...
...
@@ -45,3 +45,6 @@ RESOURCES += \
res
.
qrc
RC_FILE
=
res
/
sbkpay
.
rc
HEADERS
+=
\
version
.
h
sbkpay/version.h
View file @
ec1ef79f
...
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_REVISION 1
#define VER_BUILD
1
#define VER_BUILD
2
//! Convert version numbers to string
#define _STR(S) #S
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment