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
566f0949
Commit
566f0949
authored
Aug 19, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 实现签名功能。 2. 解析OLTP的返回。 3. 修改退款逻辑,由POS传fmId。4.日志打印文件名和行号。
parent
7f2d56e3
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
556 additions
and
74 deletions
+556
-74
sbkpay/QsLog/QsLog.pri
+1
-1
sbkpay/control.cpp
+198
-43
sbkpay/control.h
+2
-0
sbkpay/fmtool.h
+19
-0
sbkpay/hostwidget.cpp
+18
-6
sbkpay/hostwidget.h
+3
-0
sbkpay/jsonfactory.h
+12
-0
sbkpay/main.cpp
+1
-1
sbkpay/rspfactory.h
+54
-2
sbkpay/sbkpay.pro
+8
-4
sbkpay/sbkpay.pro.user
+78
-17
sbkpay/xmlreader.cpp
+122
-0
sbkpay/xmlreader.h
+40
-0
No files found.
sbkpay/QsLog/QsLog.pri
View file @
566f0949
INCLUDEPATH += $$PWD
#
DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message
DEFINES += QS_LOG_LINE_NUMBERS # automatically writes the file and line for each log message
#DEFINES += QS_LOG_DISABLE # logging code is replaced with a no-op
#DEFINES += QS_LOG_SEPARATE_THREAD # messages are queued and written from a separate thread
#DEFINES += QS_LOG_WIN_PRINTF_CONSOLE # Use fprintf instead of OutputDebugString on Windows
...
...
sbkpay/control.cpp
View file @
566f0949
...
...
@@ -5,6 +5,7 @@
#include "QsLog.h"
#include "jsonfactory.h"
#include "rspfactory.h"
#include "xmlreader.h"
#include <QtConcurrent>
#include <QSettings>
...
...
@@ -19,6 +20,9 @@ typedef int (__stdcall *GetValue) (char *, char *);
typedef
int
(
__stdcall
*
GetRSACret
)(
int
,
const
char
*
,
const
char
*
);
typedef
int
(
__stdcall
*
SKBAPISend
)(
const
char
*
indata
,
const
char
*
guid
,
char
*
outdata
,
char
*
errMsg
,
const
char
*
mode
);
typedef
int
(
__stdcall
*
AddSign
)(
char
*
,
char
*
);
typedef
int
(
__stdcall
*
GetMac
)(
char
*
);
typedef
int
(
__stdcall
*
GetRealMac
)(
char
*
);
typedef
int
(
__stdcall
*
SetRSACret
)(
char
*
);
void
Control
::
GetProcPath
(
char
*
pathBuf
)
{
...
...
@@ -50,8 +54,10 @@ void Control::Start(const char *indata, char *outdata)
if
(
_widget
==
NULL
)
_widget
=
new
HostWidget
();
QLOG_INFO
()
<<
"In data: "
<<
QString
::
fromUtf8
(
indata
);
QJsonParseError
parseError
;
QJsonDocument
inDataDoc
=
QJsonDocument
::
fromJson
(
QString
::
from
Local8Bit
(
indata
).
toUtf8
(),
&
parseError
);
QJsonDocument
inDataDoc
=
QJsonDocument
::
fromJson
(
QString
::
from
Utf8
(
indata
).
toUtf8
(),
&
parseError
);
if
(
parseError
.
error
==
QJsonParseError
::
NoError
)
{
_posReqJsonObj
=
inDataDoc
.
object
();
...
...
@@ -98,22 +104,29 @@ void Control::Start(const char *indata, char *outdata)
_widget
=
NULL
;
_lock
.
unlock
();
memcpy
(
outdata
,
(
char
*
)(
&
_response
),
sizeof
(
struct
AlipayResponse
));
outdata
[
sizeof
(
struct
AlipayResponse
)]
=
0
;
// memcpy(outdata, (char *)(&_response), sizeof(struct AlipayResponse));
// outdata[sizeof(struct AlipayResponse)] = 0;
QByteArray
responseArray
=
QJsonDocument
(
_responseJsonObj
).
toJson
(
QJsonDocument
::
Compact
);
memcpy
(
outdata
,
responseArray
.
data
(),
responseArray
.
size
());
QLOG_INFO
()
<<
"return data to pos : "
<<
outdata
;
}
void
Control
::
SetResPonseWithMessage
(
QString
code
,
const
QString
&
message
)
{
FMTool
::
SetString
(
_response
.
ResponseCode
,
3
,
code
);
FMTool
::
SetString
(
_response
.
ResponseMsg
,
40
,
message
);
// FMTool::SetString(_response.ResponseCode, 3, code);
// FMTool::SetString(_response.ResponseMsg, 40, message);
_responseJsonObj
[
JSON_KEY_STATUSCODE
]
=
code
;
_responseJsonObj
[
JSON_KEY_MESSAGE
]
=
message
;
}
void
Control
::
InitModel
()
{
memset
(
&
_request
,
' '
,
sizeof
(
struct
AlipayRequest
));
memset
(
&
_response
,
' '
,
sizeof
(
struct
AlipayResponse
));
// memset(&_request, ' ', sizeof(struct AlipayRequest));
// memset(&_response, ' ', sizeof(struct AlipayResponse));
_posReqJsonObj
=
QJsonObject
();
_responseJsonObj
=
QJsonObject
();
}
bool
Control
::
SendMessageToPayMent
(
const
QJsonObject
&
json
,
QByteArray
&
outdata
,
QString
&
error
)
...
...
@@ -210,24 +223,21 @@ bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata,
"</ns0:AP>"
"</ns0:OLTP>"
);
QString
nsTo
=
"CS00400004"
;
int
type
=
FMTool
::
GetJsonValue
(
_posReqJsonObj
,
JSON_KEY_REQTYPE
).
toInt
(
);
if
(
type
==
SPCC_sign
)
{
int
type
=
FMTool
::
GetJsonValue
(
json
,
JSON_KEY_REQTYPE
).
toInt
(
-
1
);
if
(
type
==
-
1
)
{
nsTo
=
"CS00400003"
;
}
QString
date
=
QDate
::
currentDate
().
toString
(
"yyMMdd"
);
QString
time
=
QTime
::
currentTime
().
toString
(
"hhmmss"
);
QString
storeId
=
FMTool
::
GetJsonValue
(
_posReqJsonObj
,
JSON_KEY_STOREID
).
toString
();
QString
posId
=
FMTool
::
GetJsonValue
(
_posReqJsonObj
,
JSON_KEY_STATIONID
).
toString
();
QString
storeId
=
FMTool
::
GetJsonValue
(
json
,
JSON_KEY_STOREID
).
toString
();
QString
posId
=
FMTool
::
GetJsonValue
(
json
,
JSON_KEY_STATIONID
).
toString
();
qsrand
(
QDateTime
::
currentMSecsSinceEpoch
());
QString
termino
=
QString
::
fromUtf8
(
"%1%2%3%4%5"
).
arg
(
date
).
arg
(
storeId
).
arg
(
posId
).
arg
(
qrand
()
%
90
+
10
).
arg
(
time
);
QString
termino
=
QString
::
fromUtf8
(
"%1%2%3%4%5"
).
arg
(
date
).
arg
(
storeId
,
6
,
'0'
).
arg
(
posId
,
6
,
'0'
).
arg
(
qrand
()
%
90
+
10
).
arg
(
time
);
QByteArray
jsonArray
=
QJsonDocument
(
json
).
toJson
(
QJsonDocument
::
Compact
);
char
signStr
[
MAX_BUF_LEN
]
=
{
0
};
GetSPCCSign
(
jsonArray
.
data
(),
signStr
);
QLOG_INFO
()
<<
"Sign str: "
<<
signStr
;
reqXmlStr
=
reqXmlStr
.
arg
(
termino
).
arg
(
nsTo
).
arg
(
date
).
arg
(
time
).
arg
(
QString
::
fromUtf8
(
jsonArray
));
reqXmlStr
=
reqXmlStr
.
arg
(
termino
).
arg
(
nsTo
).
arg
(
QDate
::
currentDate
().
toString
(
"yyyyMMdd"
)
).
arg
(
time
).
arg
(
QString
::
fromUtf8
(
jsonArray
));
char
in
[
MAX_BUF_LEN
]
=
{
0
};
char
out
[
MAX_BUF_LEN
]
=
{
0
};
...
...
@@ -238,14 +248,72 @@ bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata,
strcpy
(
in
,
reqXmlStr
.
toUtf8
().
data
());
QLOG_INFO
()
<<
"Request StarbucksAPI XML data: "
<<
in
;
#define SBKTEST
#ifdef SBKTEST
int
result
=
skbSend
(
in
,
guid
,
out
,
errMsg
,
mode
);
#else
QLOG_DEBUG
()
<<
"============ Read debug data. ==============="
;
QFile
f
(
qApp
->
applicationDirPath
()
+
"/test/1.txt"
);
f
.
open
(
QIODevice
::
ReadOnly
);
strcpy
(
out
,
f
.
readAll
().
data
());
int
result
=
0
;
#endif //! End def SBKTEST
QLOG_DEBUG
()
<<
"StarbucksAPI return to UTF-8: "
<<
QString
::
fromUtf8
(
out
);
QLOG_DEBUG
()
<<
"StarbucksAPI return to GBK: "
<<
QString
::
fromLocal8Bit
(
out
);
QString
outXMlString
=
QString
::
fromUtf8
(
out
);
QLOG_INFO
()
<<
"OLTP return: "
<<
result
<<
" data: "
<<
outXMlString
;
if
(
result
!=
0
)
{
error
=
QString
(
errMsg
);
QLOG_ERROR
()
<<
"SKBSend return: "
<<
result
<<
" errMsg: "
<<
errMsg
<<
" data: "
<<
out
;
error
=
"OLTP return error:
\n
"
+
QString
::
fromUtf8
(
errMsg
);
QLOG_ERROR
()
<<
error
;
return
QByteArray
();
}
else
{
QString
statcode
;
bool
isOk
=
FMTool
::
SearchXMLNodeString
(
outXMlString
,
"ns0:STATCODE"
,
statcode
);
if
(
!
isOk
)
{
error
=
"Can't find xml node: ns0:STATCODE"
;
QLOG_ERROR
()
<<
error
;
return
QByteArray
();
}
if
(
statcode
.
compare
(
"0000"
)
!=
0
)
{
error
=
"OLTP return STATCODE is: "
+
statcode
;
QLOG_ERROR
()
<<
error
;
return
QByteArray
();
}
QLOG_INFO
()
<<
"SKBSend return: "
<<
result
<<
" data: "
<<
out
;
QString
returnStr
;
isOk
=
FMTool
::
SearchXMLNodeString
(
outXMlString
,
"ns0:AP"
,
returnStr
);
if
(
!
isOk
)
{
error
=
"Can't find xml node: ns0:AP"
;
QLOG_ERROR
()
<<
error
;
return
QByteArray
();
}
return
returnStr
.
toUtf8
();
// XMLReader reader;
// if(!reader.parser(QString::fromUtf8(out))) {
// error = "OLTP return xml parser error: " + reader.errorString;
// QLOG_ERROR() << error;
// return QByteArray();
// } else {
// QList<QDomNode> outElements = reader.findElements("ns0:AP");
// if(outElements.length() != 1) {
// error = "OLTP return xml can't find ns0:AP";
// return QByteArray();
// } else {
// QDomNode node = outElements.first().firstChild();
// QString text = node.nodeValue();
// QLOG_INFO() << "OLTP JSON: " << text;
// return text.toUtf8();
// }
// }
}
return
QByteArray
(
out
);
});
...
...
@@ -278,6 +346,9 @@ bool Control::SendMessageToSBKAPI(const QJsonObject &json, QByteArray &outdata,
bool
Control
::
GetRSA
(
QString
&
error
)
{
QJsonObject
json
;
JsonFactory
::
GetJsonWithType
(
sign
,
json
,
_posReqJsonObj
,
QStringList
());
char
mod
[
MAX_PATH
]
=
{
0
};
GetProcPath
(
mod
);
...
...
@@ -289,31 +360,54 @@ bool Control::GetRSA(QString &error)
if
(
lib
.
load
())
{
json
[
"mac"
]
=
GetMacString
();
GetRSACret
getrsacret
=
(
GetRSACret
)
lib
.
resolve
(
"_GetRSACret@12"
);
if
(
getrsacret
!=
NULL
)
{
QEventLoop
loop
;
QtConcurrent
::
run
(
[
this
,
&
loop
,
&
rlt
,
&
error
,
getrsacret
]()
{
int
i
=
FMTool
::
GetString
(
_request
.
PlatNo
,
4
).
toInt
();
QString
storeID
=
FMTool
::
GetString
(
_request
.
StoreNo
,
20
);
QString
PosNO
=
FMTool
::
GetString
(
_request
.
DeviceNo
,
6
);
rlt
=
getrsacret
(
i
,
storeID
.
toLatin1
().
data
(),
PosNO
.
toLatin1
().
data
());
if
(
!
rlt
)
error
=
QString
::
fromLocal8Bit
(
"获取服务端返回数据失败"
);
loop
.
exit
();
});
QByteArray
out
;
if
(
!
SendMessageToSBKAPI
(
json
,
out
,
error
))
{
QLOG_ERROR
()
<<
"GetRSA error: "
<<
error
;
return
false
;
}
loop
.
exec
();
SetRSACret
setRsaCret
=
(
SetRSACret
)
lib
.
resolve
(
"SetRSACret"
);
if
(
setRsaCret
!=
NULL
)
{
if
(
setRsaCret
(
out
.
data
()))
{
QLOG_INFO
()
<<
"setRSACret return success. "
;
return
true
;
}
else
{
error
=
"setRSACret return error."
;
QLOG_ERROR
()
<<
error
;
return
false
;
}
else
{
QLOG_ERROR
()
<<
"get function (GetRSACret) failed"
;
}
else
{
QLOG_ERROR
()
<<
"get function (SetRSACret) failed"
;
error
=
QString
::
fromLocal8Bit
(
"加载基础组件(fun)失败"
);
}
// GetRSACret getrsacret = (GetRSACret)lib.resolve("_GetRSACret@12");
// if(getrsacret != NULL)
// {
// QEventLoop loop;
// QtConcurrent::run( [ this, &loop, &rlt, &error, getrsacret]()
// {
// int i = FMTool::GetString(_request.PlatNo, 4).toInt();
// QString storeID = FMTool::GetString(_request.StoreNo, 20);
// QString PosNO = FMTool::GetString(_request.DeviceNo, 6);
// rlt = getrsacret(i, storeID.toLatin1().data(), PosNO.toLatin1().data());
// if(!rlt)
// error = QString::fromLocal8Bit("获取服务端返回数据失败");
// loop.exit();
// });
// loop.exec();
// }
// else
// {
// QLOG_ERROR() << "get function (GetRSACret) failed";
// error = QString::fromLocal8Bit("加载基础组件(fun)失败");
// }
}
else
{
...
...
@@ -323,6 +417,55 @@ bool Control::GetRSA(QString &error)
return
rlt
;
}
QString
Control
::
GetMacString
(
bool
isSign
)
{
char
mod
[
MAX_PATH
]
=
{
0
};
GetProcPath
(
mod
);
QLibrary
lib
(
QString
(
mod
)
+
"
\\
"
+
"FreemudWrapper.dll"
);
if
(
lib
.
load
())
{
if
(
isSign
)
{
GetMac
getMac
=
(
GetMac
)
lib
.
resolve
(
"GetMac"
);
if
(
getMac
!=
NULL
)
{
char
mac
[
128
]
=
{
0
};
if
(
getMac
(
mac
)
==
1
)
{
QString
macStr
=
QString
::
fromUtf8
(
mac
);
QLOG_INFO
()
<<
"Get mac success: "
<<
macStr
;
return
macStr
;
}
else
{
QLOG_ERROR
()
<<
"Get mac failed."
;
}
}
else
{
QLOG_ERROR
()
<<
"get function (GetMac) failed"
;
}
}
else
{
GetRealMac
getMac
=
(
GetRealMac
)
lib
.
resolve
(
"GetRealMac"
);
if
(
getMac
!=
NULL
)
{
char
mac
[
128
]
=
{
0
};
if
(
getMac
(
mac
)
==
1
)
{
QString
macStr
=
QString
::
fromUtf8
(
mac
);
QLOG_INFO
()
<<
"Get mac success: "
<<
macStr
;
return
macStr
;
}
else
{
QLOG_ERROR
()
<<
"Get real mac failed."
;
}
}
else
{
QLOG_ERROR
()
<<
"get function (GetRealMac) failed"
;
}
}
}
else
{
QLOG_ERROR
()
<<
"load dll failed"
;
}
return
""
;
}
void
Control
::
RequestSign
()
{
QString
error
;
...
...
@@ -341,18 +484,20 @@ void Control::RequestSign()
bool
Control
::
GetJson
(
ReqType
type
,
QJsonObject
&
json
,
const
QByteArray
array
,
QString
&
error
)
{
QJsonDocument
jsonDocument
=
QJsonDocument
::
fromJson
(
array
.
data
());
QJsonParseError
parseError
;
QJsonDocument
jsonDocument
=
QJsonDocument
::
fromJson
(
array
.
data
(),
&
parseError
);
if
(
jsonDocument
.
isNull
()
)
{
QLOG_ERROR
()
<<
"server return not json"
;
QLOG_ERROR
()
<<
"server return not json"
<<
parseError
.
errorString
()
;
error
=
QString
::
fromLocal8Bit
(
"服务端返回数据异常"
);
return
false
;
}
json
=
jsonDocument
.
object
();
RspFactory
::
GetResPonseJson
(
type
,
_response
,
json
);
// RspFactory::GetResPonseJson(type, _response, json);
RspFactory
::
GetResPonseJson
(
type
,
_responseJsonObj
,
json
);
if
(
json
.
contains
(
JSON_KEY_MESSAGE
))
error
=
json
[
JSON_KEY_MESSAGE
].
toString
();
...
...
@@ -373,12 +518,22 @@ void Control::Request(ReqType type, QStringList list)
// bool rlt = SendMessageToPayMent(json, outdata, error);
JsonFactory
::
GetJsonWithType
(
type
,
json
,
_posReqJsonObj
,
list
);
json
[
"ver"
]
=
1
;
json
[
"mac"
]
=
GetMacString
(
false
);
QByteArray
jsonArray
=
QJsonDocument
(
json
).
toJson
(
QJsonDocument
::
Compact
);
char
signStr
[
MAX_BUF_LEN
]
=
{
0
};
GetSPCCSign
(
jsonArray
.
data
(),
signStr
);
json
[
"sign"
]
=
QString
::
fromLocal8Bit
(
signStr
);
QLOG_INFO
()
<<
"Sign str: "
<<
signStr
;
bool
rlt
=
SendMessageToSBKAPI
(
json
,
outdata
,
error
);
if
(
rlt
)
rlt
=
Control
::
GetJson
(
type
,
rtjson
,
outdata
,
error
);
else
if
(
!
rlt
)
SetResPonseWithMessage
(
"23"
,
error
);
...
...
sbkpay/control.h
View file @
566f0949
...
...
@@ -48,6 +48,8 @@ private:
void
GetSPCCSign
(
char
*
in
,
char
*
out
);
QString
GetMacString
(
bool
isSign
=
true
);
public
slots
:
void
RequestWithType
(
ReqType
type
,
QStringList
list
);
...
...
sbkpay/fmtool.h
View file @
566f0949
...
...
@@ -163,6 +163,25 @@ public:
}
return
QJsonValue
();
}
static
bool
SearchXMLNodeString
(
const
QString
&
xmlStr
,
const
QString
&
nodeName
,
QString
&
nodeStr
)
{
QRegularExpression
regExp
(
QString
(
"<%1>([
\\
s
\\
S]+)</%1>"
).
arg
(
nodeName
));
int
index
=
0
;
QRegularExpressionMatch
match
;
do
{
match
=
regExp
.
match
(
xmlStr
,
index
);
if
(
match
.
hasMatch
())
{
index
=
match
.
capturedEnd
();
nodeStr
=
match
.
captured
(
1
).
trimmed
();
return
true
;
}
else
{
break
;
}
}
while
(
index
<
xmlStr
.
length
());
return
false
;
}
};
...
...
sbkpay/hostwidget.cpp
View file @
566f0949
...
...
@@ -86,6 +86,16 @@ void HostWidget::keyPressEvent(QKeyEvent *ke)
{
if
(
ke
->
key
()
==
Qt
::
Key_Return
&&
_curr_show_widget
==
ui
->
pay
)
{
ShowPayWidget
();
}
else
{
FMPWindow
::
keyPressEvent
(
ke
);
}
}
void
HostWidget
::
ShowPayWidget
()
{
if
(
!
_need_exit
)
{
ui
->
btn_pay_exit
->
hide
();
...
...
@@ -110,11 +120,6 @@ void HostWidget::keyPressEvent(QKeyEvent *ke)
}
else
emit
Exits
();
}
else
{
FMPWindow
::
keyPressEvent
(
ke
);
}
}
void
HostWidget
::
ShowWithRequest
(
AlipayRequest
request
)
...
...
@@ -157,6 +162,8 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
{
int
reqtype
=
FMTool
::
GetJsonValue
(
requestObj
,
JSON_KEY_REQTYPE
).
toInt
();
_posReqJsonObj
=
requestObj
;
switch
(
reqtype
)
{
case
manage
:
{
...
...
@@ -188,6 +195,7 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
case
SPCC_sign
:
{
ShowWidget
(
ui
->
Manager
);
_curr_show_widget
=
ui
->
Manager
;
on_btn_mananger_register_clicked
();
break
;
}
case
SPCC_manage
:
{
...
...
@@ -210,9 +218,12 @@ void HostWidget::ShowWithRequest(QJsonObject requestObj)
ShowWidget
(
ui
->
pay
);
_curr_show_widget
=
ui
->
pay
;
double
Amount
=
FMTool
::
GetJsonValue
(
requestObj
,
JSON_KEY_TRANSAMOUNT
).
toInt
()
/
100.0
;
QString
FmId
=
FMTool
::
GetJsonValue
(
requestObj
,
JSON_KEY_FMID
).
toString
();
ui
->
label_pay_title
->
setText
(
QString
::
fromLocal8Bit
(
"请扫描退款凭证号"
));
ui
->
btn_pay_exit
->
setText
(
QString
::
fromLocal8Bit
(
"取消退款"
));
ui
->
label_pay_money
->
setText
(
QString
::
fromLocal8Bit
(
"退款 ¥ %1"
).
arg
(
Amount
));
ui
->
lineEdit_pay_code
->
setText
(
FmId
);
ShowPayWidget
();
break
;
}
default
:
...
...
@@ -298,7 +309,8 @@ void HostWidget::on_btn_mananger_register_clicked()
ui
->
btn_sign_sign
->
hide
();
ui
->
label_sign_title
->
setText
(
QString
::
fromLocal8Bit
(
"签到中..."
));
ui
->
label_sign_msg
->
setText
(
""
);
ui
->
label_sign_storeid
->
setText
(
FMTool
::
GetString
(
_data
.
StoreNo
,
20
));
// ui->label_sign_storeid->setText(FMTool::GetString(_data.StoreNo, 20));
ui
->
label_sign_storeid
->
setText
(
FMTool
::
GetJsonValue
(
_posReqJsonObj
,
JSON_KEY_STOREID
).
toString
());
emit
RequestWithType
(
sign
,
list
);
}
...
...
sbkpay/hostwidget.h
View file @
566f0949
...
...
@@ -64,6 +64,8 @@ private:
void
InitWidget
();
void
ShowPayWidget
();
private
:
Ui
::
HostWidget
*
ui
;
...
...
@@ -72,6 +74,7 @@ private:
QWidget
*
_curr_show_widget
;
AlipayRequest
_data
;
QJsonObject
_posReqJsonObj
;
LabelsTimer
*
_label_pay_timer
;
...
...
sbkpay/jsonfactory.h
View file @
566f0949
...
...
@@ -32,11 +32,14 @@ public:
static
bool
GetJsonWithType
(
ReqType
type
,
QJsonObject
&
json
,
const
QJsonObject
&
reqJson
,
QStringList
list
)
{
switch
(
type
)
{
case
sign
:
return
GetSignJson
(
json
,
reqJson
,
list
);
case
pay
:
return
GetPayJson
(
json
,
reqJson
,
list
);
case
refund
:
return
GetRefundJosn
(
json
,
reqJson
,
list
);
default
:
json
=
reqJson
;
break
;
}
}
...
...
@@ -65,6 +68,15 @@ public:
}
private
:
static
bool
GetSignJson
(
QJsonObject
&
json
,
const
QJsonObject
&
reqJson
,
QStringList
l
)
{
json
[
JSON_KEY_VER
]
=
reqJson
[
JSON_KEY_VER
];
json
[
JSON_KEY_PARTNERID
]
=
reqJson
[
JSON_KEY_PARTNERID
];
json
[
JSON_KEY_STOREID
]
=
reqJson
[
JSON_KEY_STOREID
];
json
[
JSON_KEY_STATIONID
]
=
reqJson
[
JSON_KEY_STATIONID
];
return
true
;
}
//支付
static
bool
GetPayJson
(
QJsonObject
&
json
,
const
AlipayRequest
&
request
,
QStringList
list
)
{
...
...
sbkpay/main.cpp
View file @
566f0949
...
...
@@ -288,7 +288,7 @@ int main(int argc, char *argv[])
// control.Start(as, b);
char
spccIn
[
MAX_BUF_LEN
]
=
"{
\"
reqType
\"
:353,
\"
storeId
\"
:
\"
1713
\"
,
\"
stationId
\"
:
\"
1
\"
,
\"
partnerId
\"
:1443,
\"
operatorId
\"
:
\"
sssaw
\"
,
\"
transId
\"
:
\"
52342342323806
\"
,
\"
transAmount
\"
:8000,
\"
partnerOrderId
\"
:
\"
909911039993720192019
\"
,
\"
businessDate
\"
:
\"
20170508
\"
,
\"
products
\"
:[{
\"
pid
\"
:
\"
123
\"
,
\"
name
\"
:
\"
中杯拿铁
\"
,
\"
price
\"
:321,
\"
salesType
\"
:
\"
NORMAL
\"
}]}"
;
char
spccIn
[
MAX_BUF_LEN
]
=
"{
\"
fmId
\"
:
\"
0123456789012345678
\"
,
\"
reqType
\"
:353,
\"
storeId
\"
:
\"
1713
\"
,
\"
stationId
\"
:
\"
1
\"
,
\"
partnerId
\"
:1443,
\"
operatorId
\"
:
\"
sssaw
\"
,
\"
transId
\"
:
\"
52342342323806
\"
,
\"
transAmount
\"
:8000,
\"
partnerOrderId
\"
:
\"
909911039993720192019
\"
,
\"
businessDate
\"
:
\"
20170508
\"
,
\"
products
\"
:[{
\"
pid
\"
:
\"
123
\"
,
\"
name
\"
:
\"
中杯拿铁
\"
,
\"
price
\"
:321,
\"
salesType
\"
:
\"
NORMAL
\"
}]}"
;
control
.
Start
(
spccIn
,
b
);
return
a
.
exec
();
...
...
sbkpay/rspfactory.h
View file @
566f0949
...
...
@@ -33,6 +33,23 @@ public:
return
false
;
}
static
bool
GetResPonseJson
(
ReqType
type
,
QJsonObject
&
response
,
const
QJsonObject
&
json
)
{
if
(
json
.
isEmpty
())
return
false
;
if
(
type
==
sign
)
return
GetSignResponse
(
response
,
json
);
if
(
type
==
pay
)
return
GetPayResponse
(
response
,
json
);
if
(
type
==
refund
)
return
GetRefundResponse
(
response
,
json
);
return
false
;
}
static
bool
GetResPonseWithError
(
AlipayResponse
&
response
,
QString
errorcode
,
QString
message
)
{
if
(
errorcode
.
isEmpty
()
||
message
.
isEmpty
())
...
...
@@ -50,6 +67,12 @@ public:
private
:
#endif
static
bool
GetSignResponse
(
QJsonObject
&
response
,
const
QJsonObject
&
json
)
{
response
=
json
;
return
true
;
}
static
bool
GetPayResponse
(
AlipayResponse
&
response
,
const
QJsonObject
&
json
)
{
FMTool
::
SetString
(
response
.
ResponseCode
,
3
,
QString
::
number
(
json
[
JSON_KEY_STATUSCODE
].
toInt
()));
...
...
@@ -62,6 +85,20 @@ private:
return
true
;
}
static
bool
GetPayResponse
(
QJsonObject
&
response
,
const
QJsonObject
&
json
)
{
response
=
json
;
// FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
// FMTool::SetString(response.ResponseMsg, 40, json[JSON_KEY_MESSAGE].toString());
// FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
// FMTool::SetString(response.NeedPrint, 2, QString("01"));
// if(json[JSON_KEY_STATUSCODE].toInt() == 100)
// return SetPinter(response, json);
return
true
;
}
static
bool
GetRefundResponse
(
AlipayResponse
&
response
,
const
QJsonObject
&
json
)
{
FMTool
::
SetString
(
response
.
ResponseCode
,
3
,
QString
::
number
(
json
[
JSON_KEY_STATUSCODE
].
toInt
()));
...
...
@@ -69,12 +106,27 @@ private:
FMTool
::
SetString
(
response
.
CardTraceNo
,
40
,
json
[
JSON_KEY_FMID
].
toString
());
FMTool
::
SetString
(
response
.
NeedPrint
,
2
,
QString
(
"01"
));
if
(
json
[
JSON_KEY_STATUSCODE
].
toInt
()
==
100
)
return
SetPinter
(
response
,
json
);
//
if(json[JSON_KEY_STATUSCODE].toInt() == 100)
//
return SetPinter(response, json);
return
true
;
}
static
bool
GetRefundResponse
(
QJsonObject
&
response
,
const
QJsonObject
&
json
)
{
response
=
json
;
// FMTool::SetString(response.ResponseCode, 3, QString::number(json[JSON_KEY_STATUSCODE].toInt()));
// FMTool::SetString(response.ResponseMsg, 40, json[JSON_KEY_MESSAGE].toString());
// FMTool::SetString(response.CardTraceNo, 40, json[JSON_KEY_FMID].toString());
// FMTool::SetString(response.NeedPrint, 2, QString("01"));
// if(json[JSON_KEY_STATUSCODE].toInt() == 100)
// return SetPinter(response, json);
return
true
;
}
static
bool
GetDayEndResponse
(
AlipayResponse
&
response
,
const
QJsonObject
&
json
)
{
FMTool
::
SetString
(
response
.
ResponseCode
,
3
,
QString
::
number
(
json
[
JSON_KEY_STATUSCODE
].
toInt
()));
...
...
sbkpay/sbkpay.pro
View file @
566f0949
...
...
@@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT
+=
core
gui
concurrent
QT
+=
core
gui
concurrent
xml
greaterThan
(
QT_MAJOR_VERSION
,
4
)
:
QT
+=
widgets
...
...
@@ -13,7 +13,9 @@ TARGET = sbkpay
include
(
"./QsLog/QsLog.pri"
)
CONFIG
+=
C
++
11
SBKDLL
CONFIG
+=
C
++
11
#CONFIG += SBKTEST
#CONFIG += SBKDLL
include
(
$$
PWD
/
qtwinmigrate
/
src
/
qtwinmigrate
.
pri
)
...
...
@@ -35,7 +37,8 @@ release {
SOURCES
+=
main
.
cpp
\
hostwidget
.
cpp
\
control
.
cpp
\
labelstimer
.
cpp
labelstimer
.
cpp
\
xmlreader
.
cpp
HEADERS
+=
hostwidget
.
h
\
fmp_window
.
h
\
...
...
@@ -48,7 +51,8 @@ HEADERS += hostwidget.h \
jsonfactory
.
h
\
labelstimer
.
h
\
rspfactory
.
h
\
reqfactory
.
h
reqfactory
.
h
\
xmlreader
.
h
FORMS
+=
hostwidget
.
ui
...
...
sbkpay/sbkpay.pro.user
View file @
566f0949
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator
3.5.1, 2017-08-14T12:31:22
. -->
<!-- Written by QtCreator
4.3.1, 2017-08-19T15:59:53
. -->
<qtcreator>
<data>
<variable>
EnvironmentId
</variable>
<value
type=
"QByteArray"
>
{
45ff7264-c067-4213-ad04-937bad1dfb10
}
</value>
<value
type=
"QByteArray"
>
{
ca824a60-ba93-49e5-b668-ae93bbb68724
}
</value>
</data>
<data>
<variable>
ProjectExplorer.Project.ActiveTarget
</variable>
...
...
@@ -40,6 +40,7 @@
<value
type=
"bool"
key=
"EditorConfiguration.ScrollWheelZooming"
>
true
</value>
<value
type=
"bool"
key=
"EditorConfiguration.ShowMargin"
>
false
</value>
<value
type=
"int"
key=
"EditorConfiguration.SmartBackspaceBehavior"
>
0
</value>
<value
type=
"bool"
key=
"EditorConfiguration.SmartSelectionChanging"
>
true
</value>
<value
type=
"bool"
key=
"EditorConfiguration.SpacesForTabs"
>
true
</value>
<value
type=
"int"
key=
"EditorConfiguration.TabKeyBehavior"
>
0
</value>
<value
type=
"int"
key=
"EditorConfiguration.TabSize"
>
8
</value>
...
...
@@ -58,22 +59,21 @@
<data>
<variable>
ProjectExplorer.Project.Target.0
</variable>
<valuemap
type=
"QVariantMap"
>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
Desktop Qt 5.5.1 MSVC2010 32bit
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
>
Desktop Qt 5.5.1 MSVC2010 32bit
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
qt.55.win32_msvc2010_kit
</value>
<value
type=
"int"
key=
"ProjectExplorer.Target.ActiveBuildConfiguration"
>
1
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
Qt5.5.1 MSVC2010
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
>
Qt5.5.1 MSVC2010
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
{373b91dc-3ee0-4b8c-ab5f-13bc6628cb59}
</value>
<value
type=
"int"
key=
"ProjectExplorer.Target.ActiveBuildConfiguration"
>
0
</value>
<value
type=
"int"
key=
"ProjectExplorer.Target.ActiveDeployConfiguration"
>
0
</value>
<value
type=
"int"
key=
"ProjectExplorer.Target.ActiveRunConfiguration"
>
0
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.Target.BuildConfiguration.0"
>
<value
type=
"QString"
key=
"ProjectExplorer.BuildConfiguration.BuildDirectory"
>
D:/gitcode/sbkpay/build-sbkpay-Desktop_Qt_5_5_1_MSVC2010_32bit
-Debug
</value>
<value
type=
"QString"
key=
"ProjectExplorer.BuildConfiguration.BuildDirectory"
>
E:/Qt/sbkpay/build-sbkpay-Qt5_5_1_MSVC2010
-Debug
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildConfiguration.BuildStepList.0"
>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildStepList.Step.0"
>
<value
type=
"bool"
key=
"ProjectExplorer.BuildStep.Enabled"
>
true
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
qmake
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
QtProjectManager.QMakeBuildStep
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary"
>
false
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto"
>
true
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary"
>
true
</value>
<value
type=
"QString"
key=
"QtProjectManager.QMakeBuildStep.QMakeArguments"
></value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.QMakeForced"
>
false
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.SeparateDebugInfo"
>
false
</value>
...
...
@@ -120,7 +120,7 @@
<value
type=
"bool"
key=
"Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild"
>
true
</value>
</valuemap>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.Target.BuildConfiguration.1"
>
<value
type=
"QString"
key=
"ProjectExplorer.BuildConfiguration.BuildDirectory"
>
D:/gitcode/sbkpay/build-sbkpay-Desktop_Qt_5_5_1_MSVC2010_32bit
-Release
</value>
<value
type=
"QString"
key=
"ProjectExplorer.BuildConfiguration.BuildDirectory"
>
E:/Qt/sbkpay/build-sbkpay-Qt5_5_1_MSVC2010
-Release
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildConfiguration.BuildStepList.0"
>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildStepList.Step.0"
>
<value
type=
"bool"
key=
"ProjectExplorer.BuildStep.Enabled"
>
true
</value>
...
...
@@ -128,7 +128,6 @@
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
QtProjectManager.QMakeBuildStep
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary"
>
false
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto"
>
true
</value>
<value
type=
"QString"
key=
"QtProjectManager.QMakeBuildStep.QMakeArguments"
></value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.QMakeForced"
>
false
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.SeparateDebugInfo"
>
false
</value>
...
...
@@ -174,7 +173,61 @@
<value
type=
"int"
key=
"Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration"
>
0
</value>
<value
type=
"bool"
key=
"Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild"
>
true
</value>
</valuemap>
<value
type=
"int"
key=
"ProjectExplorer.Target.BuildConfigurationCount"
>
2
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.Target.BuildConfiguration.2"
>
<value
type=
"QString"
key=
"ProjectExplorer.BuildConfiguration.BuildDirectory"
>
E:/Qt/sbkpay/build-sbkpay-Qt5_5_1_MSVC2010-Profile
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildConfiguration.BuildStepList.0"
>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildStepList.Step.0"
>
<value
type=
"bool"
key=
"ProjectExplorer.BuildStep.Enabled"
>
true
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
qmake
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
QtProjectManager.QMakeBuildStep
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary"
>
true
</value>
<value
type=
"QString"
key=
"QtProjectManager.QMakeBuildStep.QMakeArguments"
></value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.QMakeForced"
>
false
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.SeparateDebugInfo"
>
true
</value>
<value
type=
"bool"
key=
"QtProjectManager.QMakeBuildStep.UseQtQuickCompiler"
>
false
</value>
</valuemap>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildStepList.Step.1"
>
<value
type=
"bool"
key=
"ProjectExplorer.BuildStep.Enabled"
>
true
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
Make
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
Qt4ProjectManager.MakeStep
</value>
<valuelist
type=
"QVariantList"
key=
"Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"
/>
<value
type=
"bool"
key=
"Qt4ProjectManager.MakeStep.Clean"
>
false
</value>
<value
type=
"QString"
key=
"Qt4ProjectManager.MakeStep.MakeArguments"
></value>
<value
type=
"QString"
key=
"Qt4ProjectManager.MakeStep.MakeCommand"
></value>
</valuemap>
<value
type=
"int"
key=
"ProjectExplorer.BuildStepList.StepsCount"
>
2
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
构建
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
ProjectExplorer.BuildSteps.Build
</value>
</valuemap>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildConfiguration.BuildStepList.1"
>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildStepList.Step.0"
>
<value
type=
"bool"
key=
"ProjectExplorer.BuildStep.Enabled"
>
true
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
Make
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
Qt4ProjectManager.MakeStep
</value>
<valuelist
type=
"QVariantList"
key=
"Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments"
/>
<value
type=
"bool"
key=
"Qt4ProjectManager.MakeStep.Clean"
>
true
</value>
<value
type=
"QString"
key=
"Qt4ProjectManager.MakeStep.MakeArguments"
>
clean
</value>
<value
type=
"QString"
key=
"Qt4ProjectManager.MakeStep.MakeCommand"
></value>
</valuemap>
<value
type=
"int"
key=
"ProjectExplorer.BuildStepList.StepsCount"
>
1
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
清理
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
ProjectExplorer.BuildSteps.Clean
</value>
</valuemap>
<value
type=
"int"
key=
"ProjectExplorer.BuildConfiguration.BuildStepListCount"
>
2
</value>
<value
type=
"bool"
key=
"ProjectExplorer.BuildConfiguration.ClearSystemEnvironment"
>
false
</value>
<valuelist
type=
"QVariantList"
key=
"ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"
/>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
Profile
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
Qt4ProjectManager.Qt4BuildConfiguration
</value>
<value
type=
"int"
key=
"Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration"
>
0
</value>
<value
type=
"bool"
key=
"Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild"
>
true
</value>
</valuemap>
<value
type=
"int"
key=
"ProjectExplorer.Target.BuildConfigurationCount"
>
3
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.Target.DeployConfiguration.0"
>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.BuildConfiguration.BuildStepList.0"
>
<value
type=
"int"
key=
"ProjectExplorer.BuildStepList.StepsCount"
>
0
</value>
...
...
@@ -190,6 +243,11 @@
<value
type=
"int"
key=
"ProjectExplorer.Target.DeployConfigurationCount"
>
1
</value>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.Target.PluginSettings"
/>
<valuemap
type=
"QVariantMap"
key=
"ProjectExplorer.Target.RunConfiguration.0"
>
<value
type=
"bool"
key=
"Analyzer.QmlProfiler.AggregateTraces"
>
false
</value>
<value
type=
"bool"
key=
"Analyzer.QmlProfiler.FlushEnabled"
>
false
</value>
<value
type=
"uint"
key=
"Analyzer.QmlProfiler.FlushInterval"
>
1000
</value>
<value
type=
"QString"
key=
"Analyzer.QmlProfiler.LastTraceFile"
></value>
<value
type=
"bool"
key=
"Analyzer.QmlProfiler.Settings.UseGlobalSettings"
>
true
</value>
<valuelist
type=
"QVariantList"
key=
"Analyzer.Valgrind.AddedSuppressionFiles"
/>
<value
type=
"bool"
key=
"Analyzer.Valgrind.Callgrind.CollectBusEvents"
>
false
</value>
<value
type=
"bool"
key=
"Analyzer.Valgrind.Callgrind.CollectSystime"
>
false
</value>
...
...
@@ -226,12 +284,15 @@
</valuelist>
<value
type=
"int"
key=
"PE.EnvironmentAspect.Base"
>
2
</value>
<valuelist
type=
"QVariantList"
key=
"PE.EnvironmentAspect.Changes"
/>
<value
type=
"QString"
key=
"ProjectExplorer.CustomExecutableRunConfiguration.Arguments"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.CustomExecutableRunConfiguration.Executable"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory"
>
%{buildDir}
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
自定义执行档
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DefaultDisplayName"
>
sbkpay
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.DisplayName"
></value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
ProjectExplorer.CustomExecutableRunConfiguration
</value>
<value
type=
"QString"
key=
"ProjectExplorer.ProjectConfiguration.Id"
>
Qt4ProjectManager.Qt4RunConfiguration:E:/Qt/sbkpay/sbkpay/sbkpay.pro
</value>
<value
type=
"bool"
key=
"QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath"
>
true
</value>
<value
type=
"QString"
key=
"Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"
></value>
<value
type=
"QString"
key=
"Qt4ProjectManager.Qt4RunConfiguration.ProFile"
>
sbkpay.pro
</value>
<value
type=
"bool"
key=
"Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix"
>
false
</value>
<value
type=
"QString"
key=
"Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"
></value>
<value
type=
"QString"
key=
"Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"
>
E:/Qt/sbkpay/build-sbkpay-Qt5_5_1_MSVC2010-Debug
</value>
<value
type=
"uint"
key=
"RunConfiguration.QmlDebugServerPort"
>
3768
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseCppDebugger"
>
false
</value>
<value
type=
"bool"
key=
"RunConfiguration.UseCppDebuggerAuto"
>
true
</value>
...
...
sbkpay/xmlreader.cpp
0 → 100644
View file @
566f0949
#include "xmlreader.h"
#include <QDebug>
#include <QFile>
#include <QDomNodeList>
XMLReader
::
XMLReader
(
QObject
*
parent
)
:
QObject
(
parent
)
{
}
XMLReader
::~
XMLReader
()
{
}
bool
XMLReader
::
parserFile
(
const
QString
&
xmlFile
,
QDomNode
&
root
)
{
QFile
f
(
xmlFile
);
if
(
!
f
.
open
(
QIODevice
::
ReadOnly
))
{
errorString
=
QString
(
"Open file: %1 failed.
\n
%2"
).
arg
(
xmlFile
).
arg
(
f
.
errorString
());
return
false
;
}
int
errorLine
,
errorColumn
;
if
(
!
xmlDoc
.
setContent
(
&
f
,
&
errorString
,
&
errorLine
,
&
errorColumn
))
{
errorString
+=
QString
(
" Line: %1, Column: %2"
).
arg
(
errorLine
).
arg
(
errorColumn
);
return
false
;
}
root
=
xmlDoc
.
firstChild
();
return
true
;
}
bool
XMLReader
::
parser
(
const
QString
&
xmlString
)
{
int
errorLine
,
errorColumn
;
if
(
!
xmlDoc
.
setContent
(
xmlString
,
&
errorString
,
&
errorLine
,
&
errorColumn
))
{
errorString
+=
QString
(
" Line: %1, Column: %2"
).
arg
(
errorLine
).
arg
(
errorColumn
);
return
false
;
}
return
true
;
}
QList
<
QDomNode
>
XMLReader
::
findElements
(
const
QString
&
name
)
{
QList
<
QDomNode
>
nodeList
;
QDomNodeList
domNodeList
=
xmlDoc
.
elementsByTagName
(
name
);
for
(
int
i
=
0
;
i
<
domNodeList
.
length
();
i
++
)
{
nodeList
.
append
(
domNodeList
.
at
(
i
));
}
return
nodeList
;
}
QList
<
QDomNode
>
XMLReader
::
findElementsByAttr
(
const
QString
&
name
,
const
Attributes
&
attr
)
{
QList
<
QDomNode
>
nodeList
=
findElements
(
name
);
foreach
(
QDomNode
node
,
nodeList
)
{
foreach
(
QString
attrName
,
attr
.
keys
())
{
QString
attrValue
=
attr
[
attrName
];
if
(
!
checkAttributeValue
(
node
,
attrName
,
attrValue
))
{
nodeList
.
removeOne
(
node
);
break
;
}
}
}
return
nodeList
;
}
QMap
<
QString
,
QList
<
QDomNode
>
>
XMLReader
::
groupElementsByAttr
(
const
QString
&
nodeName
,
const
QString
&
attrName
)
{
QMap
<
QString
,
QList
<
QDomNode
>
>
nodeMap
;
QList
<
QDomNode
>
nodeList
=
findElements
(
nodeName
);
foreach
(
QDomNode
node
,
nodeList
)
{
QString
attrValue
=
getAttributeValue
(
node
,
attrName
);
if
(
nodeMap
.
contains
(
attrValue
))
{
nodeMap
[
attrValue
].
append
(
node
);
}
else
{
QList
<
QDomNode
>
tempNodeList
;
tempNodeList
.
append
(
node
);
nodeMap
[
attrValue
]
=
tempNodeList
;
}
}
return
nodeMap
;
}
Attributes
XMLReader
::
getAttributes
(
const
QDomNode
&
node
)
{
Attributes
attrs
;
QDomNamedNodeMap
attrNodeMap
=
node
.
attributes
();
for
(
int
i
=
0
;
i
<
attrNodeMap
.
length
();
i
++
)
{
QDomNode
attrNode
=
attrNodeMap
.
item
(
i
);
if
(
attrNode
.
isAttr
())
{
attrs
[
attrNode
.
nodeName
()]
=
attrNode
.
nodeValue
();
}
}
return
attrs
;
}
QString
XMLReader
::
getAttributeValue
(
const
QDomNode
&
node
,
const
QString
&
attrName
)
{
QString
value
;
if
(
!
node
.
hasAttributes
())
{
errorString
=
QString
(
"Node: %1 don't has any attrs."
).
arg
(
node
.
nodeName
());;
}
else
{
QDomNamedNodeMap
attrs
=
node
.
attributes
();
if
(
!
attrs
.
contains
(
attrName
))
{
errorString
=
QString
(
"Node: %1 don't has attr: %2."
).
arg
(
node
.
nodeName
()).
arg
(
attrName
);
}
else
{
QDomNode
attr
=
attrs
.
namedItem
(
attrName
);
value
=
attr
.
toAttr
().
value
();
}
}
return
value
;
}
bool
XMLReader
::
checkAttributeValue
(
const
QDomNode
&
node
,
const
QString
&
attrName
,
const
QString
&
attrValue
)
{
QString
value
=
getAttributeValue
(
node
,
attrName
);
return
(
value
==
attrValue
);
}
sbkpay/xmlreader.h
0 → 100644
View file @
566f0949
#ifndef XMLREADER_H
#define XMLREADER_H
#include <QObject>
#include <QDomDocument>
#include <QDomElement>
typedef
QMap
<
QString
,
QString
>
Attributes
;
class
XMLReader
:
public
QObject
{
Q_OBJECT
public
:
explicit
XMLReader
(
QObject
*
parent
=
nullptr
);
~
XMLReader
();
bool
parser
(
const
QString
&
xmlString
);
bool
parserFile
(
const
QString
&
xmlFile
,
QDomNode
&
root
);
QList
<
QDomNode
>
findElements
(
const
QString
&
name
);
QList
<
QDomNode
>
findElementsByAttr
(
const
QString
&
name
,
const
Attributes
&
attr
);
QMap
<
QString
,
QList
<
QDomNode
>>
groupElementsByAttr
(
const
QString
&
nodeName
,
const
QString
&
attrName
);
Attributes
getAttributes
(
const
QDomNode
&
node
);
QString
getAttributeValue
(
const
QDomNode
&
node
,
const
QString
&
attrName
);
bool
checkAttributeValue
(
const
QDomNode
&
node
,
const
QString
&
attrName
,
const
QString
&
attrValue
);
QString
errorString
;
QDomDocument
xmlDoc
;
signals
:
public
slots
:
private
:
};
#endif // XMLREADER_H
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