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
742fe25c
Commit
742fe25c
authored
Jul 11, 2021
by
wuyang.zou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix New Feature: 有线网卡与无线网卡,自由切换后无需每次都重新签到; 请求报文中保护 PosIp
Version: 3.21.7.15
parent
a255e9bd
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
180 additions
and
73 deletions
+180
-73
sbkpay/DataProcess/cretopt.h
+26
-15
sbkpay/DataProcess/fmglobal.h
+1
-0
sbkpay/DataProcess/rollback.cpp
+8
-2
sbkpay/DataProcess/tools.h
+87
-9
sbkpay/control.cpp
+9
-9
sbkpay/control.h
+5
-1
sbkpay/version.h
+2
-3
tests/TestSimphony/tst_testsimphony.cpp
+42
-34
No files found.
sbkpay/DataProcess/cretopt.h
View file @
742fe25c
...
@@ -15,14 +15,17 @@ class CretOperate
...
@@ -15,14 +15,17 @@ class CretOperate
{
{
public
:
public
:
static
bool
GetDES3MAC
(
QJsonObject
&
json
,
const
int
region
,
QString
iv
)
static
bool
GetDES3MAC
AndIp
(
QJsonObject
&
json
,
const
int
region
,
QString
&
iv
,
QString
&
outPosIp
)
{
{
std
::
string
tmpmac
;
std
::
string
tmpMac
;
if
(
ToolS
::
GetMacByAdaptersAddresses
(
tmpmac
)
==
0
)
{
std
::
string
tmpIp
;
QLOG_ERROR
()
<<
"Get MAC Failed"
;
if
(
ToolS
::
GetMacIpByAdaptersAddresses
(
tmpMac
,
tmpIp
)
==
0
)
{
QLOG_ERROR
()
<<
"GetDES3MACAndIp:: Get Mac Or IP Failed"
;
return
false
;
return
false
;
}
}
QLOG_INFO
()
<<
tmpmac
.
data
();
outPosIp
=
QString
::
fromStdString
(
tmpIp
);
char
tmpiv
[
16
]
=
{
0
};
char
tmpiv
[
16
]
=
{
0
};
memcpy
(
tmpiv
,
iv
.
toUtf8
().
data
(),
iv
.
toUtf8
().
size
()
>
16
?
16
:
iv
.
toUtf8
().
size
());
memcpy
(
tmpiv
,
iv
.
toUtf8
().
data
(),
iv
.
toUtf8
().
size
()
>
16
?
16
:
iv
.
toUtf8
().
size
());
char
outmsg
[
4096
]
=
{
0
};
char
outmsg
[
4096
]
=
{
0
};
...
@@ -35,34 +38,42 @@ public:
...
@@ -35,34 +38,42 @@ public:
}
}
if
(
DataProcess
::
AESEncode
((
const
unsigned
char
*
)
aes_key
.
toUtf8
().
data
(),
(
unsigned
char
*
)
tmpiv
,
if
(
DataProcess
::
AESEncode
((
const
unsigned
char
*
)
aes_key
.
toUtf8
().
data
(),
(
unsigned
char
*
)
tmpiv
,
(
const
unsigned
char
*
)
tmp
mac
.
data
(),
strlen
(
tmpm
ac
.
data
()),
(
unsigned
char
*
)
outmsg
,
4096
)
==
0
)
(
const
unsigned
char
*
)
tmp
Mac
.
data
(),
strlen
(
tmpM
ac
.
data
()),
(
unsigned
char
*
)
outmsg
,
4096
)
==
0
)
{
{
QLOG_ERROR
()
<<
"
AES
MAC Failed"
;
QLOG_ERROR
()
<<
"
GetDES3MACAndIp:: AES Encode
MAC Failed"
;
return
false
;
return
false
;
}
}
QString
macAfterAES
=
QString
(
outmsg
);
QString
macAfterAES
=
QString
(
outmsg
);
json
.
insert
(
JSON_KEY_MAC
,
macAfterAES
);
json
.
insert
(
JSON_KEY_MAC
,
macAfterAES
);
QLOG_INFO
()
<<
macAfterAES
;
json
.
insert
(
JSON_KEY_IP
,
outPosIp
);
QLOG_INFO
()
<<
"GetDES3MACAndIp:: Mac AES Encode Finished: Mac: "
<<
tmpMac
.
data
()
<<
" macAfterAES: "
<<
macAfterAES
<<
" Ip: "
<<
tmpIp
.
data
();
return
true
;
return
true
;
}
}
static
bool
GetM
AC
(
QJsonObject
&
json
)
static
bool
GetM
acAndIp
(
QJsonObject
&
json
)
{
{
std
::
string
tmpmac
;
std
::
string
tmpMac
;
if
(
ToolS
::
GetMacByAdaptersAddresses
(
tmpmac
)
==
0
)
{
std
::
string
tmpIp
;
QLOG_ERROR
()
<<
"Get MAC Failed"
;
if
(
ToolS
::
GetMacIpByAdaptersAddresses
(
tmpMac
,
tmpIp
)
==
0
)
{
QLOG_ERROR
()
<<
"GetMacAndIp:: Get Mac Or Ip Failed"
;
return
false
;
return
false
;
}
}
QString
mac
=
QString
::
fromStdString
(
tmpmac
);
QString
mac
=
QString
::
fromStdString
(
tmpMac
);
QString
ip
=
QString
::
fromStdString
(
tmpIp
);
// 添加 Pos 机器 Mac地址 + IP地址集合
json
.
insert
(
JSON_KEY_MAC
,
mac
);
json
.
insert
(
JSON_KEY_MAC
,
mac
);
QLOG_INFO
()
<<
mac
;
json
.
insert
(
JSON_KEY_IP
,
ip
);
QLOG_INFO
()
<<
"GetMacAndIp:: Mac: "
<<
mac
<<
" Ip: "
<<
ip
;
return
true
;
return
true
;
}
}
static
bool
Get
Sign
(
QJsonObject
&
json
,
QString
iv
)
static
bool
Get
AddSignKeyData
(
QJsonObject
&
json
,
QString
iv
)
{
{
QString
serpbk
,
clipbk
;
QString
serpbk
,
clipbk
;
if
(
!
GetCret
(
iv
,
serpbk
,
clipbk
))
if
(
!
GetCret
(
iv
,
serpbk
,
clipbk
))
...
...
sbkpay/DataProcess/fmglobal.h
View file @
742fe25c
...
@@ -22,6 +22,7 @@
...
@@ -22,6 +22,7 @@
#define CRET_FILE_NAME "simphonyclient.p12"
#define CRET_FILE_NAME "simphonyclient.p12"
#define JSON_KEY_ONLY "partnerOrderId"
#define JSON_KEY_ONLY "partnerOrderId"
#define JSON_KEY_MAC "mac"
#define JSON_KEY_MAC "mac"
#define JSON_KEY_IP "posIp"
#define JSON_KEY_SIGN "sign"
#define JSON_KEY_SIGN "sign"
#define JSON_KEY_FMTEST "test"
#define JSON_KEY_FMTEST "test"
#define JSON_KEY_STATUS "statusCode"
#define JSON_KEY_STATUS "statusCode"
...
...
sbkpay/DataProcess/rollback.cpp
View file @
742fe25c
...
@@ -63,7 +63,7 @@ void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
...
@@ -63,7 +63,7 @@ void RollBack::RollWiteQuery(QSqlDatabase &_db, QSqlQuery &query)
QLOG_INFO
()
<<
"RollWiteQuery:: Get iv (partnerId+storeId+stationId): "
<<
iv
;
QLOG_INFO
()
<<
"RollWiteQuery:: Get iv (partnerId+storeId+stationId): "
<<
iv
;
if
(
!
CretOperate
::
Get
Sign
(
json
,
iv
))
{
if
(
!
CretOperate
::
Get
AddSignKeyData
(
json
,
iv
))
{
QLOG_ERROR
()
<<
"RollWiteQuery:: Get Sign Error"
;
QLOG_ERROR
()
<<
"RollWiteQuery:: Get Sign Error"
;
continue
;
continue
;
}
}
...
@@ -121,9 +121,15 @@ void RollBack::run()
...
@@ -121,9 +121,15 @@ void RollBack::run()
void
RollBack
::
InsertRollOrder
(
QSqlQuery
&
query
)
void
RollBack
::
InsertRollOrder
(
QSqlQuery
&
query
)
{
{
if
(
s_rollorder
.
count
()
)
{
QLOG_INFO
()
<<
"RollBack::InsertRollOrder Roll Order Map: "
<<
s_rollorder
;
}
else
{
return
;
}
QMap
<
QString
,
QString
>
tmporder
=
s_rollorder
;
QMap
<
QString
,
QString
>
tmporder
=
s_rollorder
;
QMap
<
QString
,
QString
>::
Iterator
it
;
QMap
<
QString
,
QString
>::
Iterator
it
;
QLOG_INFO
()
<<
"RollBack::InsertRollOrder Roll Order Map: "
<<
tmporder
;
for
(
it
=
tmporder
.
begin
();
it
!=
tmporder
.
end
();
++
it
)
{
for
(
it
=
tmporder
.
begin
();
it
!=
tmporder
.
end
();
++
it
)
{
if
(
!
it
.
key
().
isEmpty
())
{
if
(
!
it
.
key
().
isEmpty
())
{
...
...
sbkpay/DataProcess/tools.h
View file @
742fe25c
...
@@ -2,10 +2,15 @@
...
@@ -2,10 +2,15 @@
#define TOOLS
#define TOOLS
#include <winsock2.h>
#include <winsock2.h>
#include <WS2tcpip.h>
#include <iphlpapi.h>
#include <iphlpapi.h>
#include <Windows.h>
#include <Windows.h>
#include <string>
#include <string>
#include <QString>
#include <QString>
#include <QMap>
#include "QsLog.h"
#pragma comment(lib,"ws2_32.lib")
EXTERN_C
IMAGE_DOS_HEADER
__ImageBase
;
EXTERN_C
IMAGE_DOS_HEADER
__ImageBase
;
...
@@ -36,7 +41,7 @@ public:
...
@@ -36,7 +41,7 @@ public:
}
}
static
int
GetMac
ByAdaptersAddresses
(
std
::
string
&
mac
Out
)
static
int
GetMac
IpByAdaptersAddresses
(
std
::
string
&
macOut
,
std
::
string
&
ip
Out
)
{
{
bool
ret
=
0
;
bool
ret
=
0
;
...
@@ -56,22 +61,95 @@ public:
...
@@ -56,22 +61,95 @@ public:
if
(
GetAdaptersAddresses
(
AF_UNSPEC
,
0
,
NULL
,
pAddresses
,
&
outBufLen
)
==
NO_ERROR
)
if
(
GetAdaptersAddresses
(
AF_UNSPEC
,
0
,
NULL
,
pAddresses
,
&
outBufLen
)
==
NO_ERROR
)
{
{
char
buffIp
[
20
]
=
{
0
};
DWORD
buffIpLen
=
20
;
QString
tmpFirstMac
=
""
;
QString
tmpFirstIp
=
""
;
QString
tmpMac
=
""
;
QString
tmpIp
=
""
;
// If successful, output some information from the data we received
// 兼容特殊场景: MINI Pos (含无线网卡) 插在门店网线底座 签到 交易后, 门店需要将Pos移动作业 同时启用无线网卡, 在重新签到前 再次交易会报错( Mac地址异常).
for
(
PIP_ADAPTER_ADDRESSES
pCurrAddresses
=
pAddresses
;
pCurrAddresses
!=
NULL
;
pCurrAddresses
=
pCurrAddresses
->
Next
)
for
(
PIP_ADAPTER_ADDRESSES
pCurrAddresses
=
pAddresses
;
pCurrAddresses
!=
NULL
;
pCurrAddresses
=
pCurrAddresses
->
Next
)
{
{
if
(
pCurrAddresses
->
PhysicalAddressLength
!=
6
)
if
(
pCurrAddresses
->
PhysicalAddressLength
!=
6
)
continue
;
continue
;
char
acMAC
[
32
];
char
acMAC
[
32
];
sprintf
(
acMAC
,
"%02X-%02X-%02X-%02X-%02X-%02X"
,
sprintf
(
acMAC
,
"%02X-%02X-%02X-%02X-%02X-%02X"
,
int
(
pCurrAddresses
->
PhysicalAddress
[
0
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
0
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
1
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
1
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
2
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
2
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
3
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
3
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
4
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
4
]),
int
(
pCurrAddresses
->
PhysicalAddress
[
5
]));
int
(
pCurrAddresses
->
PhysicalAddress
[
5
]));
macOut
=
acMAC
;
tmpMac
=
acMAC
;
//pCurrAddresses->Dhcpv4Server // 通过 SOCKET_ADDRESS 地址进行 转换获取 准确的IPv4 地址;
PIP_ADAPTER_UNICAST_ADDRESS
pUnicast
=
pCurrAddresses
->
FirstUnicastAddress
;
if
(
pUnicast
!=
NULL
)
{
for
(
int
i
=
0
;
pUnicast
!=
NULL
;
i
++
)
{
if
(
pUnicast
->
Address
.
lpSockaddr
->
sa_family
==
AF_INET
)
{
sockaddr_in
*
sa_in
=
(
sockaddr_in
*
)
pUnicast
->
Address
.
lpSockaddr
;
//inet_ntop(AF_INET, &(sa_in->sin_addr), buffIp, buffIpLen); // inet_ntop Function Invalid In WS2tcpip.h ;
memcpy
(
buffIp
,
inet_ntoa
(
sa_in
->
sin_addr
),
buffIpLen
);
tmpIp
=
buffIp
;
}
else
if
(
pUnicast
->
Address
.
lpSockaddr
->
sa_family
==
AF_INET6
)
{
/*
sockaddr_in6 *sa_in6 = (sockaddr_in6 *)pUnicast->Address.lpSockaddr;
printf("\tIPV6:%s\n", inet_ntop(AF_INET6, &(sa_in6->sin6_addr), buffIp, bufflen));
*/
}
else
{
QLOG_INFO
()
<<
"GetMacIpByAdaptersAddresses sa_family UNSPEC"
;
tmpIp
=
"sa_family UNSPEC"
;
}
pUnicast
=
pUnicast
->
Next
;
}
}
else
{
QLOG_INFO
()
<<
" GetMacIpByAdaptersAddresses No Unicast Addresses"
;
tmpIp
=
"FirstUnicastAddress Is NULL"
;
}
// Get First Unicast IP Address From Adapter Finished;
// Record First Network Interface: Mac Address And Ip Address;
if
(
0
==
tmpFirstMac
.
length
()
)
{
tmpFirstMac
=
tmpMac
;
tmpFirstIp
=
tmpIp
;
}
/* QLOG_INFO() << " GetMacIpByAdaptersAddresses: :"<<" IfType: "<< pCurrAddresses->IfType // Network Interface Type : 6 -> Ethernet; 71 -> Wirless;
<<" OperStatus: "<< pCurrAddresses->OperStatus; // Network Interface: 1 -> up; 0 -> down;
*/
QLOG_INFO
()
<<
" GetMacIpByAdaptersAddresses:: Filter Valid One, Mac: "
<<
tmpMac
<<
" Ip: "
<<
tmpIp
<<
" IfType: "
<<
pCurrAddresses
->
IfType
;
// IEEE80211 标识网卡是无线网卡, 底层通信数据逻辑是特殊处理, 使用本机电脑进行验证过;
if
(
IF_TYPE_IEEE80211
==
pCurrAddresses
->
IfType
)
{
if
(
tmpMac
!=
tmpFirstMac
)
{
tmpFirstMac
=
tmpMac
;
}
break
;
}
}
if
(
tmpFirstMac
.
length
()
)
{
macOut
=
tmpFirstMac
.
toStdString
();
ipOut
=
tmpFirstIp
.
toStdString
();
ret
=
1
;
ret
=
1
;
break
;
}
}
//切换网络时(有线网卡就会不存在); tmpMac = "00-05-AE-01-B8-BB"; tmpIp = "10.73.194.245"; macIpMap.insert( tmpMac , tmpIp );
/* if ( macIpMap.count() ) {
macOut = macIpMap.firstKey().toStdString();
QMap< QString, QString>::iterator iter = macIpMap.begin();
while ( iter != macIpMap.end() ) {
ipOut.append( iter.value().toStdString() );
iter++;
if ( iter != macIpMap.end() ) { ipOut.append( "&" ); }
}
ret = 1;
}*/
}
}
free
(
pAddresses
);
free
(
pAddresses
);
...
...
sbkpay/control.cpp
View file @
742fe25c
...
@@ -256,8 +256,9 @@ bool Control::SendMessageBefore(const QJsonObject &json, QByteArray &outdata, QS
...
@@ -256,8 +256,9 @@ bool Control::SendMessageBefore(const QJsonObject &json, QByteArray &outdata, QS
if
(
!
tmpjson
.
contains
(
JSON_KEY_SERVER_URL
)
)
if
(
!
tmpjson
.
contains
(
JSON_KEY_SERVER_URL
)
)
tmpjson
.
insert
(
JSON_KEY_SERVER_URL
,
_setting
.
GetValue
(
VALUE_URL
,
""
).
toString
()
);
tmpjson
.
insert
(
JSON_KEY_SERVER_URL
,
_setting
.
GetValue
(
VALUE_URL
,
""
).
toString
()
);
CretOperate
::
GetMAC
(
tmpjson
);
// add json Key-Value: "mac": "**-**-**-**-**-**-**-**"
// 处理多网卡切换, 导致验签 / 加解密 失败.
CretOperate
::
GetSign
(
tmpjson
,
iv
);
// RSASign And add json Key-Value: "sign": "*"
CretOperate
::
GetMacAndIp
(
tmpjson
);
// add json Key-Value: "mac": "**-**-**-**-**-**-**-**" , "posIp": "**-**-**-**-**-**-**-**"
CretOperate
::
GetAddSignKeyData
(
tmpjson
,
iv
);
// RSASign And add json Key-Value: "sign": "*"
QLOG_INFO
()
<<
"Send Json Before: "
<<
tmpjson
;
QLOG_INFO
()
<<
"Send Json Before: "
<<
tmpjson
;
...
@@ -384,7 +385,7 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
...
@@ -384,7 +385,7 @@ bool Control::HttpPost(QString url, QByteArray &outdata, const QByteArray &indat
}
}
bool
Control
::
GetRSA
(
QString
&
error
)
bool
Control
::
GetRSA
SignIn
(
QString
&
error
)
{
{
QJsonObject
json
;
QJsonObject
json
;
QString
iv
;
QString
iv
;
...
@@ -404,11 +405,10 @@ bool Control::GetRSA(QString &error)
...
@@ -404,11 +405,10 @@ bool Control::GetRSA(QString &error)
QLOG_INFO
()
<<
"Get iv (partnerId+storeId+stationId): "
<<
iv
;
QLOG_INFO
()
<<
"Get iv (partnerId+storeId+stationId): "
<<
iv
;
CretOperate
::
GetDES3MAC
(
json
,
_posPartnerRegion
,
iv
);
CretOperate
::
GetDES3MACAndIp
(
json
,
_posPartnerRegion
,
iv
,
_posIp
);
QByteArray
array
;
QLOG_INFO
()
<<
"Get Request After Add DES3 Mac: "
<<
json
;
QLOG_INFO
()
<<
"Get Mac Sign Request: "
<<
json
;
QByteArray
array
;
QByteArray
data
=
QJsonDocument
(
json
).
toJson
(
QJsonDocument
::
Compact
);
QByteArray
data
=
QJsonDocument
(
json
).
toJson
(
QJsonDocument
::
Compact
);
if
(
!
Control
::
HttpPost
(
url
,
array
,
data
,
"application/json;charset=utf-8"
,
"application/json"
,
error
,
60
,
SIGN
))
if
(
!
Control
::
HttpPost
(
url
,
array
,
data
,
"application/json;charset=utf-8"
,
"application/json"
,
error
,
60
,
SIGN
))
...
@@ -429,7 +429,7 @@ bool Control::GetRSA(QString &error)
...
@@ -429,7 +429,7 @@ bool Control::GetRSA(QString &error)
void
Control
::
RequestSign
()
void
Control
::
RequestSign
()
{
{
QString
error
;
QString
error
;
bool
rlt
=
GetRSA
(
error
);
bool
rlt
=
GetRSA
SignIn
(
error
);
if
(
rlt
)
if
(
rlt
)
SetResponseWithMessage
(
"100"
,
QString
::
fromLocal8Bit
(
"签名成功"
));
SetResponseWithMessage
(
"100"
,
QString
::
fromLocal8Bit
(
"签名成功"
));
...
@@ -526,7 +526,7 @@ void Control::RequestBusinessAction(ReqType type, QStringList list)
...
@@ -526,7 +526,7 @@ void Control::RequestBusinessAction(ReqType type, QStringList list)
QJsonObject
tmpjson
=
json
;
QJsonObject
tmpjson
=
json
;
tmpjson
[
JSON_KEY_VER
]
=
DEFAULT_JSON_VER_VALUE
;
tmpjson
[
JSON_KEY_VER
]
=
DEFAULT_JSON_VER_VALUE
;
tmpjson
[
JSON_KEY_REQTYPE
]
=
3
;
tmpjson
[
JSON_KEY_REQTYPE
]
=
3
;
CretOperate
::
Get
Sign
(
tmpjson
,
iv
);
CretOperate
::
Get
AddSignKeyData
(
tmpjson
,
iv
);
QLOG_INFO
()
<<
"Send Reverse Json (rollback/wash): "
<<
tmpjson
;
QLOG_INFO
()
<<
"Send Reverse Json (rollback/wash): "
<<
tmpjson
;
QByteArray
tmpdata
=
QJsonDocument
(
tmpjson
).
toJson
(
QJsonDocument
::
Compact
);
QByteArray
tmpdata
=
QJsonDocument
(
tmpjson
).
toJson
(
QJsonDocument
::
Compact
);
...
...
sbkpay/control.h
View file @
742fe25c
...
@@ -46,7 +46,7 @@ private:
...
@@ -46,7 +46,7 @@ private:
void
RequestSign
();
void
RequestSign
();
bool
GetRSA
(
QString
&
error
);
bool
GetRSA
SignIn
(
QString
&
error
);
void
RequestBusinessAction
(
ReqType
type
,
QStringList
list
);
void
RequestBusinessAction
(
ReqType
type
,
QStringList
list
);
...
@@ -79,6 +79,10 @@ private:
...
@@ -79,6 +79,10 @@ private:
FMPSettings
_setting
;
FMPSettings
_setting
;
int
_posPartnerRegion
;
int
_posPartnerRegion
;
QString
_posMac
;
QString
_posIp
;
};
};
#endif // CONTROL_H
#endif // CONTROL_H
sbkpay/version.h
View file @
742fe25c
...
@@ -3,9 +3,8 @@
...
@@ -3,9 +3,8 @@
#define VER_MAJOR 3
#define VER_MAJOR 3
#define VER_MINOR 21
#define VER_MINOR 21
#define VER_REVISION 1
#define VER_REVISION 7
#define VER_BUILD 15
#define VER_BUILD 12
//! Convert version numbers to string
//! Convert version numbers to string
#define _STR(S) #S
#define _STR(S) #S
...
...
tests/TestSimphony/tst_testsimphony.cpp
View file @
742fe25c
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
#include "cretopt.h"
#include "cretopt.h"
#include "rollback.h"
#include "rollback.h"
#include <QDebug>
#include <QDebug>
#include "QsLog.h"
// add necessary includes here
// add necessary includes here
...
@@ -17,6 +18,43 @@ static QString CreatePartnerOrderId()
...
@@ -17,6 +18,43 @@ static QString CreatePartnerOrderId()
return
orderId
;
return
orderId
;
}
}
static
void
InitLogger
()
{
char
path
[
MAX_PATH
]
=
{
0
};
ToolS
::
GetProcPath
(
path
);
FMPSettings
setting
;
QString
logPath
=
setting
.
GetValue
(
CONFIG_LOG_PATH
,
QString
(
path
)
+
"/log"
).
toString
();
QString
logName
=
setting
.
GetValue
(
CONFIG_LOG_NAME
,
"testSbuxPay.txt"
).
toString
();
QsLogging
::
Level
logLevel
=
(
QsLogging
::
Level
)
setting
.
GetValue
(
CONFIG_LOG_LEVEL
,
0
).
toInt
();
if
(
logLevel
<
QsLogging
::
TraceLevel
||
logLevel
>
QsLogging
::
OffLevel
)
{
logLevel
=
QsLogging
::
TraceLevel
;
}
int
logSize
=
setting
.
GetValue
(
CONFIG_LOG_SIZE
,
1
).
toInt
();
int
logCount
=
setting
.
GetValue
(
CONFIG_LOG_COUNT
,
20
).
toInt
();
QDir
logDir
(
logPath
);
if
(
!
logDir
.
exists
())
{
logDir
.
mkpath
(
logDir
.
absolutePath
());
}
QString
logFilePath
=
logDir
.
absolutePath
()
+
'/'
+
logName
;
QsLogging
::
Logger
&
logger
=
QsLogging
::
Logger
::
instance
();
logger
.
setLoggingLevel
(
logLevel
);
/* 配置输出定向器 */
QsLogging
::
DestinationPtr
fileDestination
(
QsLogging
::
DestinationFactory
::
MakeFileDestination
(
logFilePath
,
QsLogging
::
EnableLogRotation
,
QsLogging
::
MaxSizeBytes
(
1024
*
1024
*
logSize
),
QsLogging
::
MaxOldLogCount
(
logCount
)));
logger
.
addDestination
(
fileDestination
);
QsLogging
::
DestinationPtr
consleDest
(
QsLogging
::
DestinationFactory
::
MakeDebugOutputDestination
());
logger
.
addDestination
(
consleDest
);
}
class
TestSimphony
:
public
QObject
class
TestSimphony
:
public
QObject
{
{
Q_OBJECT
Q_OBJECT
...
@@ -33,9 +71,6 @@ private slots:
...
@@ -33,9 +71,6 @@ private slots:
void
test_InitPOSReqJsonObj_data
();
void
test_InitPOSReqJsonObj_data
();
void
test_InitPOSReqJsonObj
();
void
test_InitPOSReqJsonObj
();
void
test_CreateOLTPXML_data
();
void
test_CreateOLTPXML
();
void
test_GetSign
();
void
test_GetSign
();
void
test_POSRequest_data
();
void
test_POSRequest_data
();
...
@@ -47,6 +82,7 @@ private slots:
...
@@ -47,6 +82,7 @@ private slots:
TestSimphony
::
TestSimphony
()
TestSimphony
::
TestSimphony
()
{
{
InitLogger
();
static
RollBack
rollback
;
static
RollBack
rollback
;
if
(
!
rollback
.
isRunning
())
if
(
!
rollback
.
isRunning
())
rollback
.
start
();
rollback
.
start
();
...
@@ -63,31 +99,6 @@ void TestSimphony::initTestCase()
...
@@ -63,31 +99,6 @@ void TestSimphony::initTestCase()
void
TestSimphony
::
cleanupTestCase
()
void
TestSimphony
::
cleanupTestCase
()
{
{
}
void
TestSimphony
::
test_CreateOLTPXML_data
()
{
QTest
::
addColumn
<
QJsonObject
>
(
"json"
);
QTest
::
addColumn
<
QByteArray
>
(
"result"
);
QJsonObject
json
;
json
[
JSON_KEY_TYPE
]
=
SIGN
;
json
[
JSON_KEY_STOREID
]
=
"17607"
;
json
[
JSON_KEY_STATIONID
]
=
"1"
;
QByteArray
signResult
(
"{
\"
stationId
\"
:
\"
1
\"
,
\"
storeId
\"
:
\"
17607
\"
,
\"
type
\"
: 0}"
);
QTest
::
newRow
(
"sign"
)
<<
json
<<
signResult
;
json
[
JSON_KEY_TYPE
]
=
PAY
;
QByteArray
payResult
(
"{
\"
stationId
\"
:
\"
1
\"
,
\"
storeId
\"
:
\"
17607
\"
,
\"
type
\"
: 2}"
);
QTest
::
newRow
(
"pay"
)
<<
json
<<
payResult
;
}
void
TestSimphony
::
test_CreateOLTPXML
()
{
QFETCH
(
QJsonObject
,
json
);
QFETCH
(
QByteArray
,
result
);
}
}
void
TestSimphony
::
test_InitPOSReqJsonObj_data
()
void
TestSimphony
::
test_InitPOSReqJsonObj_data
()
...
@@ -101,8 +112,6 @@ void TestSimphony::test_InitPOSReqJsonObj_data()
...
@@ -101,8 +112,6 @@ void TestSimphony::test_InitPOSReqJsonObj_data()
apiMaps
[
SIGN
]
=
"sign"
;
apiMaps
[
SIGN
]
=
"sign"
;
apiMaps
[
FINDS
]
=
"finds"
;
apiMaps
[
FINDS
]
=
"finds"
;
apiMaps
[
ENDDAY
]
=
"end"
;
apiMaps
[
ENDDAY
]
=
"end"
;
// apiMaps[pay] = "pay";
// apiMaps[refund] = "refund";
for
(
QMap
<
ReqType
,
QString
>::
ConstIterator
it
=
apiMaps
.
begin
();
it
!=
apiMaps
.
end
();
it
++
)
for
(
QMap
<
ReqType
,
QString
>::
ConstIterator
it
=
apiMaps
.
begin
();
it
!=
apiMaps
.
end
();
it
++
)
{
{
...
@@ -156,7 +165,7 @@ void TestSimphony::test_InitPOSReqJsonObj()
...
@@ -156,7 +165,7 @@ void TestSimphony::test_InitPOSReqJsonObj()
bool
isOk
=
false
;
bool
isOk
=
false
;
if
((
ReqType
)
reqType
==
SIGN
)
if
((
ReqType
)
reqType
==
SIGN
)
{
{
isOk
=
control
.
GetRSA
(
error
);
isOk
=
control
.
GetRSA
SignIn
(
error
);
if
(
isOk
)
{
if
(
isOk
)
{
control
.
SetResponseWithMessage
(
"100"
,
QString
::
fromUtf8
(
"签名成功"
));
control
.
SetResponseWithMessage
(
"100"
,
QString
::
fromUtf8
(
"签名成功"
));
}
else
{
}
else
{
...
@@ -197,15 +206,14 @@ void TestSimphony::test_GetSign()
...
@@ -197,15 +206,14 @@ void TestSimphony::test_GetSign()
json
[
JSON_KEY_VER
]
=
DEFAULT_JSON_VER_VALUE
;
json
[
JSON_KEY_VER
]
=
DEFAULT_JSON_VER_VALUE
;
QString
iv
=
json
[
JSON_KEY_RPARTNERID
].
toString
()
+
json
[
JSON_KEY_RSTOREID
].
toString
()
+
json
[
JSON_KEY_RSTATIONID
].
toString
();
QString
iv
=
json
[
JSON_KEY_RPARTNERID
].
toString
()
+
json
[
JSON_KEY_RSTOREID
].
toString
()
+
json
[
JSON_KEY_RSTATIONID
].
toString
();
QCOMPARE
(
CretOperate
::
GetSign
(
json
,
iv
),
true
);
QCOMPARE
(
CretOperate
::
GetAddSignKeyData
(
json
,
iv
),
true
);
}
}
void
TestSimphony
::
test_POSRequest_data
()
void
TestSimphony
::
test_POSRequest_data
()
{
{
QTest
::
addColumn
<
QByteArray
>
(
"ReqData"
);
QTest
::
addColumn
<
QByteArray
>
(
"ReqData"
);
QTest
::
newRow
(
"Manage"
)
<<
QString
(
"{
\"
reqType
\"
:351,
\"
storeId
\"
:
\"
16171
\"
,
\"
stationId
\"
:
\"
1
\"
,
\"
partnerId
\"
:1438}"
)
QTest
::
newRow
(
"Manage"
)
<<
QString
(
"{
\"
reqType
\"
:351,
\"
storeId
\"
:
\"
16171
\"
,
\"
stationId
\"
:
\"
1
\"
,
\"
partnerId
\"
:1438}"
).
toLocal8Bit
();
.
toLocal8Bit
();
int
amount
=
200
;
int
amount
=
200
;
QTest
::
newRow
(
"Pay"
)
<<
QString
(
"{ "
QTest
::
newRow
(
"Pay"
)
<<
QString
(
"{ "
...
...
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