左晓为主开发手持机充值管理机
zuoxiao
2024-07-29 fc1ec55e6ad56dc92737657750bcca7ed49f53eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.dayu.qiheonlinelibrary.card;
 
import com.dayu.baselibrary.tools.HexUtil;
 
import com.dayu.qiheonlinelibrary.dao.QHOnLineAppDatabase;
import com.dayu.qiheonlinelibrary.dbBean.CardData;
import com.dayu.qiheonlinelibrary.utils.CardCommon;
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(QHOnLineAppDatabase baseDao, String cardType) {
        try {
            CardData cardDataBean = baseDao.cardDataDao().findFirst(cardType);
            if (cardDataBean != null) {
                cardData = cardDataBean.getCardIdentifying();
            } else {
                cardData= CardCommon.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;
    }
 
 
}