Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fmp_vip
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
fmp_vip
Commits
c255c6e5
Commit
c255c6e5
authored
Nov 03, 2017
by
NitefullWind
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 修复新签名算法Bug。
parent
d967b2ef
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
1 deletions
+98
-1
fmvip/task/fmtask.cpp
+40
-0
fmvip/task/fmtask.h
+6
-0
tests/testplugin/tst_testplugin.cpp
+51
-0
version.h
+1
-1
No files found.
fmvip/task/fmtask.cpp
View file @
c255c6e5
...
@@ -227,6 +227,46 @@ QString FMTask::sign() const
...
@@ -227,6 +227,46 @@ QString FMTask::sign() const
return
md5Bt
.
toHex
();
return
md5Bt
.
toHex
();
}
}
QByteArray
FMTask
::
JsonObjToMap
(
const
QJsonObject
&
jsonObj
,
QString
parentJson
)
{
parentJson
=
parentJson
.
isEmpty
()
?
""
:
parentJson
+
"."
;
QByteArray
signArray
;
foreach
(
const
QString
&
key
,
jsonObj
.
keys
())
{
switch
(
jsonObj
[
key
].
type
())
{
case
QJsonValue
:
:
Array
:
break
;
case
QJsonValue
:
:
Null
:
break
;
case
QJsonValue
:
:
Bool
:
signArray
.
append
(
QString
(
"%1:%2&"
).
arg
(
parentJson
+
key
).
arg
(
QString
::
number
(
jsonObj
[
key
].
toBool
())));
break
;
case
QJsonValue
:
:
Double
:
signArray
.
append
(
QString
(
"%1:%2&"
).
arg
(
parentJson
+
key
).
arg
(
QString
::
number
(
jsonObj
[
key
].
toDouble
())));
break
;
case
QJsonValue
:
:
String
:
signArray
.
append
(
QString
(
"%1:%2&"
).
arg
(
parentJson
+
key
).
arg
(
jsonObj
[
key
].
toString
()));
break
;
case
QJsonValue
:
:
Object
:
signArray
.
append
(
JsonObjToMap
(
jsonObj
[
key
].
toObject
(),
parentJson
+
key
));
break
;
default
:
break
;
}
}
if
(
parentJson
.
isEmpty
())
{
signArray
=
signArray
.
mid
(
0
,
signArray
.
length
()
-
1
);
}
return
signArray
;
}
QString
FMTask
::
Sign
(
const
QJsonObject
&
signJsonObj
)
{
QByteArray
signArray
=
JsonObjToMap
(
signJsonObj
);
FMP_INFO
()
<<
"Sign byte array:"
<<
JsonObjToMap
(
signJsonObj
);
QString
md5str
=
QCryptographicHash
::
hash
(
signArray
,
QCryptographicHash
::
Md5
).
toHex
();
return
md5str
;
}
bool
FMTask
::
checkReqJson
()
bool
FMTask
::
checkReqJson
()
{
{
bool
isOk
=
false
;
bool
isOk
=
false
;
...
...
fmvip/task/fmtask.h
View file @
c255c6e5
...
@@ -38,6 +38,10 @@ public:
...
@@ -38,6 +38,10 @@ public:
bool
checkReqJson
();
bool
checkReqJson
();
#ifdef FMTEST
friend
class
TestPlugin
;
#endif
protected
:
protected
:
// 从配置文件中拷贝数据信息
// 从配置文件中拷贝数据信息
void
copyPros
();
void
copyPros
();
...
@@ -66,6 +70,8 @@ protected:
...
@@ -66,6 +70,8 @@ protected:
private
:
private
:
QString
sign
()
const
;
QString
sign
()
const
;
static
QByteArray
JsonObjToMap
(
const
QJsonObject
&
jsonObj
,
QString
parentJson
=
""
);
static
QString
Sign
(
const
QJsonObject
&
signJsonObj
);
/**
/**
* @brief FMError
* @brief FMError
...
...
tests/testplugin/tst_testplugin.cpp
View file @
c255c6e5
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
#include <QMessageBox>
#include <QMessageBox>
#include "fmvipdispatcher.h"
#include "fmvipdispatcher.h"
#include "fmtask.h"
class
TestPlugin
:
public
QObject
class
TestPlugin
:
public
QObject
{
{
...
@@ -21,6 +22,12 @@ private slots:
...
@@ -21,6 +22,12 @@ private slots:
void
test_dotask_data
();
void
test_dotask_data
();
void
test_dotask
();
void
test_dotask
();
void
test_JsonObjToMap_data
();
void
test_JsonObjToMap
();
void
test_Sign_data
();
void
test_Sign
();
};
};
TestPlugin
::
TestPlugin
()
TestPlugin
::
TestPlugin
()
...
@@ -92,6 +99,50 @@ void TestPlugin::test_dotask()
...
@@ -92,6 +99,50 @@ void TestPlugin::test_dotask()
QMessageBox
::
information
(
nullptr
,
"Return to POS"
,
QString
(
rspData
));
QMessageBox
::
information
(
nullptr
,
"Return to POS"
,
QString
(
rspData
));
}
}
void
TestPlugin
::
test_JsonObjToMap_data
()
{
QTest
::
addColumn
<
QByteArray
>
(
"Json"
);
QTest
::
addColumn
<
QByteArray
>
(
"Map"
);
QByteArray
json
=
"{
\"
null
\"
:null,
\"
bool
\"
:0,
\"
int
\"
:100,
\"
double
\"
:66.6,
\"
string
\"
:
\"
string
\"
,
\"
array
\"
:[{
\"
a1
\"
:
\"
a1
\"
},{
\"
a2
\"
:
\"
a2
\"
}],
\"
object
\"
:{
\"
o1s
\"
:
\"
o1s
\"
,
\"
o2
\"
:[{
\"
o2a
\"
:
\"
o2a
\"
}],
\"
o3
\"
:{
\"
o3o
\"
:
\"
o3o
\"
}}}"
;
QByteArray
map
=
"bool:0&double:66.6&int:100&object.o1s:o1s&object.o3.o3o:o3o&string:string"
;
QTest
::
newRow
(
"Simple"
)
<<
json
<<
map
;
}
void
TestPlugin
::
test_JsonObjToMap
()
{
QFETCH
(
QByteArray
,
Json
);
QFETCH
(
QByteArray
,
Map
);
QJsonObject
obj
=
QJsonDocument
::
fromJson
(
Json
).
object
();
QCOMPARE
(
FMTask
::
JsonObjToMap
(
obj
),
Map
);
}
void
TestPlugin
::
test_Sign_data
()
{
QTest
::
addColumn
<
QString
>
(
"SignJson"
);
QTest
::
addColumn
<
QString
>
(
"SignStr"
);
QString
jsonStr1
=
"{
\"
amount
\"
:100,
\"
null
\"
:null,
\"
empty
\"
:
\"\"
,
\"
bool
\"
:true,
\"
data
\"
:{
\"
account
\"
:
\"
123123123
\"
,
\"
object
\"
:{
\"
string
\"
:
\"
string
\"
},
\"
products
\"
:[{
\"
name
\"
:
\"
p1
\"
,
\"
pid
\"
:
\"
1001
\"
},{
\"
name
\"
:
\"
p2
\"
,
\"
pid
\"
:
\"
1002
\"
},{
\"
name
\"
:
\"
p3
\"
,
\"
pid
\"
:
\"
1003
\"
}]}}"
;
QString
signStr
=
"1ec71402a014d24b9c0934a68e4e42c9"
;
QTest
::
newRow
(
"First"
)
<<
jsonStr1
<<
signStr
;
}
void
TestPlugin
::
test_Sign
()
{
QFETCH
(
QString
,
SignJson
);
QFETCH
(
QString
,
SignStr
);
QJsonParseError
error
;
QJsonObject
jsonObj1
=
QJsonDocument
::
fromJson
(
SignJson
.
toUtf8
(),
&
error
).
object
();
QVERIFY2
(
error
.
error
==
QJsonParseError
::
NoError
,
error
.
errorString
().
toStdString
().
data
());
QCOMPARE
(
FMTask
::
Sign
(
jsonObj1
),
SignStr
);
}
QTEST_MAIN
(
TestPlugin
)
QTEST_MAIN
(
TestPlugin
)
#include "tst_testplugin.moc"
#include "tst_testplugin.moc"
version.h
View file @
c255c6e5
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
#define VER_MINOR 1
#define VER_MINOR 1
#define VER_REVISION 0
#define VER_REVISION 0
#define VER_BUILD
18
#define VER_BUILD
21
//! Convert version numbers to string
//! Convert version numbers to string
#define _STR(S) #S
#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