package com.dayu.recharge.card;
|
|
import com.dayu.recharge.dao.AppDatabase;
|
import com.dayu.recharge.dbBean.CardData;
|
import com.dayu.recharge.tools.HexUtil;
|
import com.dayu.recharge.utils.MyCommon;
|
import com.tencent.bugly.crashreport.CrashReport;
|
|
import java.io.Serializable;
|
|
/**
|
* Copyright (C), 2023,
|
* Author: zuo
|
* Date: 2023-11-07 20:52
|
* Description:所有卡结构的父类
|
*/
|
public class BaseCard implements Serializable {
|
public String cardData;//标识码
|
|
public void setCardData(AppDatabase baseDao, String cardType) {
|
try {
|
CardData cardDataBean = baseDao.cardDataDao().findFirst(cardType);
|
if (cardDataBean != null) {
|
cardData = cardDataBean.getCardIdentifying();
|
} else {
|
cardData=MyCommon.getDefaultCardData(cardType);
|
}
|
} catch (Exception e) {
|
CrashReport.postCatchedException(e);
|
}
|
}
|
|
|
/**
|
* 前15个字节算术累加和 不含进位
|
*
|
* @param data 源数据
|
* @return 16进制
|
*/
|
public byte getByteSum(byte[] data) {
|
if (data != null) {
|
int sum = 0;
|
for (byte b : data) {
|
sum += b & 0xFF; // & 0xFF 可以将字节扩展为正整数,避免符号位的影响
|
}
|
String hex = HexUtil.get10to16CompleteHex(sum);
|
hex = HexUtil.spaceHex(hex);
|
String[] hexArr = hex.split(" ");
|
return HexUtil.hexToByte(hexArr[hexArr.length - 1]);
|
}
|
return 0;
|
}
|
|
|
}
|