华视CRV100-UC身份证阅读器

华视CRV100-UC身份证阅读器开发避坑
华视官网的64SDK开发包无法读取身份证照片!!!,查阅了很多开发人员的博客,他们的都无法使用64位的开发包读取到身份证照片.咨询了华视官方,告知不会给个人64位的sdk开发包,开发需要配合32位的jdk

public interface CardLibrary extends Library {
    CardLibrary INSTANCE = (CardLibrary) Native.loadLibrary("**\\***\\Termb.dll", CardLibrary.class);
    /**
     * 本函数用于PC与华视电子第二代居民身份证阅读器的连接
     * @param Port 连接串口(COM1~COM16)或USB口(1001~1016)
     * @return 1 正确 2 端口打开失败 0 动态库加载失败
     */
    int CVR_InitComm(int Port);

    /**
     * 本函数用于关闭PC到阅读器的连接。
     * @return 1 正确 0 错误
     */
    int CVR_CloseComm();

    /**
     * 本函数用于读卡器和卡片之间的合法身份确认。卡认证循环间隔大于300ms。 若卡片放置后发生认证错误时,应移走卡片重新放置。
     * @return 1 正确 卡片认证成功 2 错误 寻卡失败 3 错误 选卡失败 0 错误 初始化失败
     */
    int CVR_Authenticate();

    /**
     * 本函数用于通过阅读器从第二代居民身份证中读取相应信息。卡认证成功以后才可做读卡操作, 读卡完毕若继续读卡应移走二代证卡片重新放置做卡认证。
     * 读卡成功后在termb.dll文件所在路径下生成wz.txt(文字信息)和zp.bmp(照片信息) wz.txt内容示例如下: 张红叶 女 汉
     * 1988-11-18 河北省邯郸市临漳县称勾镇称勾东村复兴路25号 130423198811184328 临漳县公安局
     * 2011.03.30-2021.03.30 读各项文字信息到自定义内存缓冲
     * @param active 兼容以前版本,无实际意义, 1 读取基本信息,2 只读文字信息 ,3 只读最新住址信息,5 芯片管理
     * @return 1 正确 0 错误 99 异常
     */
    int CVR_Read_Content(int active);

    /**
     * 与 int CVR_Read_Content(int active);平级
     * 本函数用于通过阅读器从第二代居民身份证中读取相应信息。卡认证成功以后才可做读卡操作,读卡完毕若继续读卡应移走二代证卡片重新放置做卡认证。
     * 参数: 无
     *
     * */
    int CVR_Read_FPContent();
    /**
     * 获取各种信息
     * */
    int  GetPeopleName(byte[] strTmp, byte[] strLen);
    int  GetPeopleSex(byte[] strTmp, byte[] strLen);
    int  GetPeopleNation(byte[] strTmp, byte[] strLen);
    int  GetPeopleBirthday(byte[] strTmp, byte[] strLen);
    int  GetPeopleAddress(byte[] strTmp, byte[] strLen);
    int  GetPeopleIDCode(byte[] strTmp, byte[] strLen);
    int  GetDepartment(byte[] strTmp, byte[] strLen);
    int  GetStartDate(byte[] strTmp, byte[] strLen);
    int  GetEndDate(byte[] strTmp, byte[] strLen);
    int  GetBMPData(byte[] strTmp, IntByReference strLen);
    int  GetJpgData(byte[] strTmp, IntByReference strLen);
    int  CVR_GetSAMID(byte[] strTmp, byte[] strLen);
}
 /**
 * a参数在说明文档中确定了最大的长度
 * b参数是C++的int类型长度为4个字节
 * 方法中a参数返回查询到的值,b参数返回a的长度
 * java中数组在创建时就需要确定好长度,所以b参数没有意义
 */
 public class Card {

    @Resource
    private static RestTemplate restTemplate;

    /**
     * 得到姓名信息
     *
     * @return 姓名信息
     * @throws Exception
     */
    public static String GetPeopleName() throws Exception {
        try {
            byte[] a = new byte[30];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetPeopleName(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到性别信息
     *
     * @return 性别信息
     * @throws Exception
     */
    public static String GetPeopleSex() throws Exception {
        try {
            byte[] a = new byte[2];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetPeopleSex(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到民族信息
     *
     * @return 民族信息
     * @throws Exception
     */
    public static String GetPeopleNation() throws Exception {
        try {
            byte[] a = new byte[20];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetPeopleNation(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到出生日期信息
     *
     * @return 到出生日期信息
     * @throws Exception
     */
    public static String GetPeopleBirthday() throws Exception {
        try {
            byte[] a = new byte[16];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetPeopleBirthday(a, b) == 1 ? new String(a).trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到地址信息
     *
     * @return 地址信息
     * @throws Exception
     */
    public static String GetPeopleAddress() throws Exception {
        try {
            byte[] a = new byte[70];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetPeopleAddress(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到卡号信息
     *
     * @return 卡号信息
     * @throws Exception
     */
    public static String GetPeopleIDCode() throws Exception {
        try {
            byte[] a = new byte[36];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetPeopleIDCode(a, b) == 1 ? new String(a).trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到发证机关信息
     *
     * @return 发证机关信息
     * @throws Exception
     */
    public static String GetDepartment() throws Exception {
        try {
            byte[] a = new byte[30];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetDepartment(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到有效开始日期
     *
     * @return 有效开始日期
     * @throws Exception
     */
    public static String GetStartDate() throws Exception {
        try {
            byte[] a = new byte[16];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetStartDate(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到有效截止日期
     *
     * @return 有效截止日期
     * @throws Exception
     */
    public static String GetEndDate() throws Exception {
        try {
            byte[] a = new byte[16];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.GetEndDate(a, b) == 1 ? new String(a, "gb2312").trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 得到安全模块号码
     *
     * @return 安全模块号码
     * @throws Exception
     */
    public static String CVR_GetSAMID() throws Exception {
        try {
            byte[] a = new byte[4 * 10];
            byte[] b = new byte[4];
            return CardLibrary.INSTANCE.CVR_GetSAMID(a, b) == 1 ? new String(a).trim() : "";
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }

    /**
     * 获取照片,将图片写到指定路径
     *
     * @return 获取成功 boolean
     * @throws Exception
     */
    public static boolean GetBMPData() throws Exception {
        try {
            // 初始缓冲区(可根据实际需求调整大小)
            byte[] buffer = new byte[38862]; // 50KB
            IntByReference len = new IntByReference(buffer.length);

            // 第一次调用:获取实际数据长度
            int result = CardLibrary.INSTANCE.GetBMPData(buffer, len);
            if (result != 1) {
                System.err.println("获取 BMP 数据失败,错误码: " + result);
                return false;
            }

            // 检查返回长度是否超出缓冲区
            int actualLength = len.getValue();
            if (actualLength > buffer.length) {
                buffer = new byte[actualLength]; // 重新分配足够大的缓冲区
                len = new IntByReference(actualLength);
                result = CardLibrary.INSTANCE.GetBMPData(buffer, len);
                if (result != 1) {
                    System.err.println("第二次获取 BMP 数据失败");
                    return false;
                }
            }

            // 验证 BMP 文件头(可选)
            if (actualLength < 2 || buffer[0] != 'B' || buffer[1] != 'M') {
                System.err.println("警告:数据可能不是有效的 BMP 格式");
                // 可尝试手动添加文件头(需了解数据的具体格式)
            }

            // 写入文件
            try (FileOutputStream fos = new FileOutputStream("C:\\123.bmp")) {
                fos.write(buffer, 0, actualLength);
                System.out.println("BMP 保存成功,实际长度: " + actualLength + " 字节");
            }
            return true;
        } catch (Exception ex) {
            ex.printStackTrace();
            return false;
        }
    }

    /**
     * 获取照片,将图片写到指定路径
     *
     * @return 获取成功 boolean
     * @throws Exception
     */
    public static byte[] GetJpgData() throws Exception {
        try {
            byte[] a = new byte[38862]; // 假设最大长度为 38862 字节
            IntByReference len = new IntByReference();

            // 调用 DLL 方法获取 JPG 数据
            if (CardLibrary.INSTANCE.GetJpgData(a, len) == 1) {
                int actualLength = len.getValue(); // 获取实际数据长度
                return a;
            } else {
                System.err.println("获取 JPG 数据失败");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return null;
    }
}


public class CardDTO {

    // 个人信息
    private String peopleName;
    private String peopleSex;
    private String peopleNation;
    private Date peopleBirthday;
    private String peopleAddress;
    private String peopleIDCode;
    private String department;
    private Date startDate;
    private Date endDate;
    // 安全模块信息
    private String cvrSamId;
    private String imageUrl;
    private  byte[] bytes;

@Data
public class MgDriverInfo   {
    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     * 主键ID
     */
    private Long id;

    /**
     * 车牌号
     */
    private String licensePlate;

    /**
     * 姓名
     */
    private String name;

    /**
     * 性别
     */
    private String gender;

    /**
     * 头像
     */
    private String avatar;

    /**
     * 民族
     */
    private String nationality;

    /**
     * 出生日期
     */
    private Date birthDate;

    /**
     * 身份证号
     */
    private String idCard;

    /**
     * 联系电话
     */
    private String phoneNumber;

    /**
     * 地址
     */
    private String address;

    /**
     * 照片
     */
    private String photo;

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值