mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 电单车协议
This commit is contained in:
@@ -55,6 +55,7 @@ public class PileChannelEntity {
|
||||
* @return
|
||||
*/
|
||||
public static ChannelHandlerContext getChannelByPileSn(String pileSn) {
|
||||
output();
|
||||
return manager.get(pileSn);
|
||||
}
|
||||
|
||||
@@ -78,7 +79,7 @@ public class PileChannelEntity {
|
||||
public static void output() {
|
||||
for (HashMap.Entry<String, ChannelHandlerContext> entry : manager.entrySet()) {
|
||||
System.out.println("pileSn:" + entry.getKey() +
|
||||
",ChannelId:" + entry.getValue().channel().id().asLongText());
|
||||
",ChannelId:" + entry.getValue().channel().id().asShortText());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -272,6 +272,55 @@ public class BytesUtil {
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串转换为指定长度的16进制字节数组。
|
||||
*
|
||||
* @param str 需要转换的字符串
|
||||
* @param targetLength 目标字节数组的长度
|
||||
* @return 对应的16进制字节数组
|
||||
*/
|
||||
public static byte[] stringToHexBytes(String str, int targetLength) {
|
||||
if (str == null) {
|
||||
throw new IllegalArgumentException("字符串不能为null");
|
||||
}
|
||||
|
||||
int strLength = str.length();
|
||||
if (targetLength < strLength) {
|
||||
throw new IllegalArgumentException("目标字节数组长度必须大于等于字符串长度");
|
||||
}
|
||||
|
||||
byte[] hexBytes = new byte[targetLength];
|
||||
for (int i = 0; i < strLength; i++) {
|
||||
char c = str.charAt(i);
|
||||
hexBytes[i] = (byte) c;
|
||||
}
|
||||
|
||||
// 剩余部分用0填充
|
||||
for (int i = strLength; i < targetLength; i++) {
|
||||
hexBytes[i] = 0;
|
||||
}
|
||||
|
||||
return hexBytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字节数组转换为十六进制字符串,用于打印查看。
|
||||
*
|
||||
* @param bytes 字节数组
|
||||
* @return 十六进制字符串
|
||||
*/
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
String hex = Integer.toHexString(0xFF & b);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @函数功能: 10进制串转为BCD码
|
||||
* @输入参数: 10进制串
|
||||
@@ -326,12 +375,14 @@ public class BytesUtil {
|
||||
return revert(temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
byte[] length = new byte[] {0x09, 0x00};
|
||||
int i = BytesUtil.bytesToIntLittle(length);
|
||||
System.out.println(i);
|
||||
// byte[] length = new byte[] {0x09, 0x00};
|
||||
// int i = BytesUtil.bytesToIntLittle(length);
|
||||
// System.out.println(i);
|
||||
|
||||
String testStr = "DNY";
|
||||
byte[] hexBytes = stringToHexBytes(testStr, 3);
|
||||
System.out.println("Hex Bytes: " + bytesToHex(hexBytes));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Set;
|
||||
public class RandomUtil {
|
||||
private static final String SYMBOLS_NUM = "0123456789"; // 纯数字
|
||||
//如果需加入字母就改成0123456789abcdefg...........
|
||||
private static final String SYMBOLS_NUM_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
// private static final String SYMBOLS_NUM_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
private static final Random RANDOM = new SecureRandom();
|
||||
|
||||
@@ -24,7 +24,7 @@ public class RandomUtil {
|
||||
* @return 随机数字
|
||||
*/
|
||||
public static String getSMSVerificationCode() {
|
||||
return getRandomNumber(6);
|
||||
return getRandomNumberStr(6);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ public class RandomUtil {
|
||||
* @param length 需要的长度
|
||||
* @return 随机数
|
||||
*/
|
||||
public static String getRandomNumber(int length) {
|
||||
public static String getRandomNumberStr(int length) {
|
||||
char[] nonceChars = new char[length]; //指定长度,自己可以设置
|
||||
for (int index = 0; index < nonceChars.length; ++index) {
|
||||
nonceChars[index] = SYMBOLS_NUM.charAt(RANDOM.nextInt(SYMBOLS_NUM.length()));
|
||||
@@ -41,6 +41,10 @@ public class RandomUtil {
|
||||
return new String(nonceChars);
|
||||
}
|
||||
|
||||
public static int getRandomNumber(int length) {
|
||||
return Integer.parseInt(getRandomNumberStr(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一组不重复的6位数随机数
|
||||
*
|
||||
|
||||
@@ -87,7 +87,7 @@ public class IdUtils {
|
||||
public static String generateTransactionCode(String pileConnectorCode) {
|
||||
String timeNow = DateUtils.dateTimeNow(DateUtils.YYMMDDHHMMSS);
|
||||
// 随机生成一个四位整数
|
||||
String randomNumber = RandomUtil.getRandomNumber(4);
|
||||
String randomNumber = RandomUtil.getRandomNumberStr(4);
|
||||
return pileConnectorCode + timeNow + randomNumber;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user