mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 11:05:18 +08:00
update 0x31报文回复不足位数补零
This commit is contained in:
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.primitives.Bytes;
|
||||
import com.huifu.adapay.model.Refund;
|
||||
import com.jsowell.JsowellApplication;
|
||||
import com.jsowell.common.constant.CacheConstants;
|
||||
@@ -16,6 +17,7 @@ import com.jsowell.common.core.domain.ykc.LoginRequestData;
|
||||
import com.jsowell.common.core.domain.ykc.TransactionRecordsData;
|
||||
import com.jsowell.common.core.redis.RedisCache;
|
||||
import com.jsowell.common.enums.ykc.OrderStatusEnum;
|
||||
import com.jsowell.common.enums.ykc.StartModeEnum;
|
||||
import com.jsowell.common.exception.BusinessException;
|
||||
import com.jsowell.common.util.*;
|
||||
import com.jsowell.common.util.http.HttpUtils;
|
||||
@@ -145,6 +147,9 @@ public class SpringBootTestController {
|
||||
@Autowired
|
||||
private IMemberTransactionRecordService memberTransactionRecordService;
|
||||
|
||||
@Autowired
|
||||
private IMemberPlateNumberRelationService memberPlateNumberRelationService;
|
||||
|
||||
static final String MAC_KEY = "53TtFpc4gdVZbF3x";
|
||||
|
||||
static final String ALGORITHM_MAC = "HmacMD5";
|
||||
@@ -226,6 +231,117 @@ public class SpringBootTestController {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVinCode() {
|
||||
String msg = "880000000000210203000000000000000000000000000000000000000000000000004C5257594743454B584D43303437313434";
|
||||
// 获取消息体
|
||||
byte[] msgBody = BytesUtil.str2Bcd(msg);
|
||||
|
||||
int startIndex = 0;
|
||||
int length = 7;
|
||||
|
||||
// 桩编码
|
||||
byte[] pileSnByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String pileSn = BytesUtil.binary(pileSnByteArr, 16);
|
||||
|
||||
// 保存时间
|
||||
// saveLastTime(pileSn);
|
||||
|
||||
// 枪号
|
||||
startIndex += length;
|
||||
length = 1;
|
||||
byte[] connectorNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String connectorCode = BytesUtil.bcd2Str(connectorNumByteArr);
|
||||
|
||||
// 启动方式
|
||||
// 0x01 表示通过刷卡启动充电
|
||||
// 0x02 表求通过帐号启动充电 (暂不支持)
|
||||
// 0x03 表示vin码启动充电
|
||||
startIndex += length;
|
||||
byte[] startModeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String startMode = BytesUtil.bcd2Str(startModeByteArr);
|
||||
|
||||
// 是否需要密码 0x00 不需要 0x01 需要
|
||||
startIndex += length;
|
||||
byte[] needPasswordFlagByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String needPasswordFlag = BytesUtil.bcd2Str(needPasswordFlagByteArr);
|
||||
|
||||
// 物理卡号 不足 8 位补 0
|
||||
startIndex += length;
|
||||
length = 8;
|
||||
byte[] cardNumByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String physicsCard = BytesUtil.binary(cardNumByteArr, 16);
|
||||
|
||||
// 输入密码 对用户输入的密码进行16 位MD5 加密,采用小写上传
|
||||
startIndex += length;
|
||||
length = 16;
|
||||
byte[] inputPasswordByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
|
||||
// VIN码
|
||||
startIndex += length;
|
||||
length = 17;
|
||||
byte[] vinCodeByteArr = BytesUtil.copyBytes(msgBody, startIndex, length);
|
||||
String vinCode = BytesUtil.ascii2Str(vinCodeByteArr);
|
||||
System.out.println("桩号:" + pileSn +"申请充电VIN码:" + vinCode);
|
||||
|
||||
/**
|
||||
* 刷卡启动充电
|
||||
*/
|
||||
String logicCard = "";
|
||||
byte[] authenticationFlagByteArr = Constants.zeroByteArray; // 鉴权成功标识
|
||||
byte[] accountBalanceByteArr = Constants.zeroByteArray; // 账户余额
|
||||
String transactionCode = "";
|
||||
|
||||
try {
|
||||
/**
|
||||
* VIN码启动充电
|
||||
*/
|
||||
if (StringUtils.equals("03", startMode)) {
|
||||
// 通过vin码查询数据库绑定用户信息
|
||||
MemberPlateNumberRelation plateInfo = memberPlateNumberRelationService.getMemberPlateInfoByVinCode(vinCode);
|
||||
if (plateInfo == null) {
|
||||
throw new BusinessException("", "未查到绑定用户信息");
|
||||
}
|
||||
if (!StringUtils.equals("1", plateInfo.getVinStatus())) {
|
||||
// 1- 正常使用
|
||||
throw new BusinessException("", "vin状态不正确");
|
||||
}
|
||||
// vin码生成订单 vin启动充电
|
||||
GenerateOrderDTO dto = new GenerateOrderDTO();
|
||||
dto.setMemberPlateNumberRelation(plateInfo);
|
||||
dto.setPileSn(pileSn);
|
||||
dto.setConnectorCode(connectorCode);
|
||||
dto.setStartMode(StartModeEnum.VIN_CODE.getValue());
|
||||
Map<String, Object> map = orderBasicInfoService.generateOrderByCard(dto);
|
||||
if (map != null) {
|
||||
transactionCode = (String) map.get("transactionCode");
|
||||
accountBalanceByteArr = YKCUtils.getPriceByte(String.valueOf(map.get("accountBalance")), 2);
|
||||
// 鉴权成功标识 0x00 失败 0x01 成功
|
||||
authenticationFlagByteArr = Constants.oneByteArray;
|
||||
}
|
||||
}
|
||||
}catch (BusinessException e){
|
||||
System.out.println(e);
|
||||
// log.error("VIN码启动充电鉴权 error:{}, {}", e.getCode(), e.getMessage());
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
// log.error("VIN码启动充电鉴权 error", e);
|
||||
}
|
||||
byte[] serialNumByteArr = BytesUtil.str2Bcd(transactionCode);
|
||||
|
||||
byte[] defeatReasonByteArr = Constants.zeroByteArray;
|
||||
|
||||
// 不足位数的值补零
|
||||
cardNumByteArr = BytesUtil.checkLengthAndBehindAppendZero(cardNumByteArr, 16);
|
||||
serialNumByteArr = BytesUtil.checkLengthAndBehindAppendZero(serialNumByteArr, 32);
|
||||
pileSnByteArr = BytesUtil.checkLengthAndBehindAppendZero(pileSnByteArr, 14);
|
||||
accountBalanceByteArr = BytesUtil.checkLengthAndBehindAppendZero(accountBalanceByteArr, 8);
|
||||
|
||||
// 拼装消息体
|
||||
byte[] msgBodyByteArr = Bytes.concat(serialNumByteArr, pileSnByteArr, connectorNumByteArr, cardNumByteArr, accountBalanceByteArr,
|
||||
authenticationFlagByteArr, defeatReasonByteArr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateLianlianToken() throws UnsupportedEncodingException {
|
||||
String OperatorID = "425010765";
|
||||
|
||||
Reference in New Issue
Block a user