Commit efaf7dd9 authored by AfirSraftGarrier's avatar AfirSraftGarrier

修改连接测试

parent 8f2eacc9
...@@ -22,14 +22,30 @@ import java.util.Random; ...@@ -22,14 +22,30 @@ import java.util.Random;
*/ */
public class DeviceControllerTest { 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 @Test
void auth() { void auth() {
String appId = "ebsh71dp5t1ck948l5"; String appId = "ebsh71dp5t1ck948l5";
String sn = "ERE54S619LNYMPKVN9"; String sn = "ERE54S619LNYMPKVN9";
String snBind = "snabcd";
String appKey = "110801"; String appKey = "110801";
//byte[] baseKeyBytes = "nAOq38p4bGQyF4FG".getBytes(); //byte[] baseKeyBytes = "nAOq38p4bGQyF4FG".getBytes();
//System.out.println(baseKeyBytes.length); //System.out.println(baseKeyBytes.length);
byte[] allBytes = getAuthSendBytes(appId, sn, appKey); byte[] allBytes = getAuthSendBytes(appId, sn, snBind, appKey);
System.out.println(bytes2Hex(allBytes)); System.out.println(bytes2Hex(allBytes));
} }
...@@ -39,8 +55,9 @@ public class DeviceControllerTest { ...@@ -39,8 +55,9 @@ public class DeviceControllerTest {
int serverPort = 18889; int serverPort = 18889;
String appId = "ebsh71dp5t1ck948l5"; String appId = "ebsh71dp5t1ck948l5";
String sn = "ERE54S619LNYMPKVN9"; String sn = "ERE54S619LNYMPKVN9";
String snBind = "snabcd";
String appKey = "110801"; String appKey = "110801";
socket(serverIp, serverPort, appId, sn, appKey); socket(serverIp, serverPort, appId, sn, snBind, appKey);
} }
@Test @Test
...@@ -49,18 +66,19 @@ public class DeviceControllerTest { ...@@ -49,18 +66,19 @@ public class DeviceControllerTest {
int serverPort = 18889; int serverPort = 18889;
String appId = "mny3i9pgg0xxs520qf"; String appId = "mny3i9pgg0xxs520qf";
String sn = "IU23404BR1CQJOC63Q"; String sn = "IU23404BR1CQJOC63Q";
String snBind = "snabcd";
String appKey = "20221114"; String appKey = "20221114";
socket(serverIp, serverPort, appId, sn, appKey); socket(serverIp, serverPort, appId, sn, snBind, appKey);
} }
@SneakyThrows @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 socket = new Socket(serverIp, serverPort);
socket.setKeepAlive(true); socket.setKeepAlive(true);
System.out.println("connect success..."); System.out.println("connect success...");
// 事先组装好要发送的鉴权信息 // 事先组装好要发送的鉴权信息
byte[] authSendBytes = getAuthSendBytes(appId, sn, appKey); byte[] authSendBytes = getAuthSendBytes(appId, sn, snBind, appKey);
OutputStream outputStream = socket.getOutputStream(); OutputStream outputStream = socket.getOutputStream();
...@@ -103,7 +121,7 @@ public class DeviceControllerTest { ...@@ -103,7 +121,7 @@ public class DeviceControllerTest {
return requestBytes; 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}; byte[] stxBytes = {(byte) 0x55, (byte) 0xaa};
// 这部分生成内容 // 这部分生成内容
...@@ -118,7 +136,7 @@ public class DeviceControllerTest { ...@@ -118,7 +136,7 @@ public class DeviceControllerTest {
for (int i = 0; i < randomBytes.length; i++) { for (int i = 0; i < randomBytes.length; i++) {
sm4KeyBytes[i] = (byte) (randomBytes[i] ^ baseKeyBytes[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); String sign = HmacUtil.encrypt(string, appKey, HmacUtil.HMAC_SHA1);
// 组装 // 组装
AuthData authData = new AuthData(); AuthData authData = new AuthData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment