Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
efaf7dd9
Commit
efaf7dd9
authored
Nov 24, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改连接测试
parent
8f2eacc9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
+25
-7
DeviceControllerTest.java
.../iot/sixiang/license/controller/DeviceControllerTest.java
+25
-7
No files found.
license/src/test/java/iot/sixiang/license/controller/DeviceControllerTest.java
View file @
efaf7dd9
...
...
@@ -22,14 +22,30 @@ import java.util.Random;
*/
public
class
DeviceControllerTest
{
@Test
void
tokenSign
()
{
String
appId
=
"ebsh71dp5t1ck948l5"
;
String
sn
=
"ERE54S619LNYMPKVN9"
;
String
snBind
=
"snabcd"
;
String
appKey
=
"110801"
;
String
string
=
"app_id="
+
appId
+
"&sn="
+
sn
+
"&sn_bind="
+
snBind
;
String
sign
=
HmacUtil
.
encrypt
(
string
,
appKey
,
HmacUtil
.
HMAC_SHA1
);
System
.
out
.
println
(
"token appId:"
+
appId
);
System
.
out
.
println
(
"token sn:"
+
sn
);
System
.
out
.
println
(
"token sign:"
+
sign
);
}
@Test
void
auth
()
{
String
appId
=
"ebsh71dp5t1ck948l5"
;
String
sn
=
"ERE54S619LNYMPKVN9"
;
String
snBind
=
"snabcd"
;
String
appKey
=
"110801"
;
//byte[] baseKeyBytes = "nAOq38p4bGQyF4FG".getBytes();
//System.out.println(baseKeyBytes.length);
byte
[]
allBytes
=
getAuthSendBytes
(
appId
,
sn
,
appKey
);
byte
[]
allBytes
=
getAuthSendBytes
(
appId
,
sn
,
snBind
,
appKey
);
System
.
out
.
println
(
bytes2Hex
(
allBytes
));
}
...
...
@@ -39,8 +55,9 @@ public class DeviceControllerTest {
int
serverPort
=
18889
;
String
appId
=
"ebsh71dp5t1ck948l5"
;
String
sn
=
"ERE54S619LNYMPKVN9"
;
String
snBind
=
"snabcd"
;
String
appKey
=
"110801"
;
socket
(
serverIp
,
serverPort
,
appId
,
sn
,
appKey
);
socket
(
serverIp
,
serverPort
,
appId
,
sn
,
snBind
,
appKey
);
}
@Test
...
...
@@ -49,18 +66,19 @@ public class DeviceControllerTest {
int
serverPort
=
18889
;
String
appId
=
"mny3i9pgg0xxs520qf"
;
String
sn
=
"IU23404BR1CQJOC63Q"
;
String
snBind
=
"snabcd"
;
String
appKey
=
"20221114"
;
socket
(
serverIp
,
serverPort
,
appId
,
sn
,
appKey
);
socket
(
serverIp
,
serverPort
,
appId
,
sn
,
snBind
,
appKey
);
}
@SneakyThrows
void
socket
(
String
serverIp
,
int
serverPort
,
String
appId
,
String
sn
,
String
appKey
)
{
void
socket
(
String
serverIp
,
int
serverPort
,
String
appId
,
String
sn
,
String
snBind
,
String
appKey
)
{
Socket
socket
=
new
Socket
(
serverIp
,
serverPort
);
socket
.
setKeepAlive
(
true
);
System
.
out
.
println
(
"connect success..."
);
// 事先组装好要发送的鉴权信息
byte
[]
authSendBytes
=
getAuthSendBytes
(
appId
,
sn
,
appKey
);
byte
[]
authSendBytes
=
getAuthSendBytes
(
appId
,
sn
,
snBind
,
appKey
);
OutputStream
outputStream
=
socket
.
getOutputStream
();
...
...
@@ -103,7 +121,7 @@ public class DeviceControllerTest {
return
requestBytes
;
}
private
byte
[]
getAuthSendBytes
(
String
appId
,
String
sn
,
String
appKey
)
{
private
byte
[]
getAuthSendBytes
(
String
appId
,
String
sn
,
String
snBind
,
String
appKey
)
{
byte
[]
stxBytes
=
{(
byte
)
0x55
,
(
byte
)
0xaa
};
// 这部分生成内容
...
...
@@ -118,7 +136,7 @@ public class DeviceControllerTest {
for
(
int
i
=
0
;
i
<
randomBytes
.
length
;
i
++)
{
sm4KeyBytes
[
i
]
=
(
byte
)
(
randomBytes
[
i
]
^
baseKeyBytes
[
i
]);
}
String
string
=
"app_id="
+
appId
+
"&sn="
+
sn
;
String
string
=
"app_id="
+
appId
+
"&sn="
+
sn
+
"&sn_bind="
+
snBind
;
String
sign
=
HmacUtil
.
encrypt
(
string
,
appKey
,
HmacUtil
.
HMAC_SHA1
);
// 组装
AuthData
authData
=
new
AuthData
();
...
...
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