身份证读卡器Qt语言实现Linux系统开发集成

Linux系统用Qt开发身份证读卡器示例,后面是C++demo源码:


编译平台:
麒麟V10(SP1),amd构架,Intel i7-10700 CPU

Qt版本:
Qt Creator 4.11.0,Based on Qt 5.12.12(GCC 9.3.0,64bit)

donseeTest:项目源码
build-donseeTest-unknown-Release:Release
build-donseeTest-unknown-Debug:Debug
双击Release或者Debug文件夹里面的donseeTest,即可运行测试。

读卡器USB接口,支持广东东信身份证读卡器EST-100、EST-J13X、EST-100M(HID)等免驱机型。

其他平台,请替换以下2个库文件,然后重新编译。
libdonsee.so
libwlt2021.so


身份证读卡器Qt语言实现Linux系统开发集成_第1张图片

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "donsee.h"

//静态调用EST-100身份证读卡器

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);


    m_isOpen = false ;
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_btnOpen_clicked()
{

    long t_nHandle = -99;
    int i = 0;
    char pszError[128];
    unsigned char Response[1024] = {0};
    long t_nRe;


//    ui->textEdit->append("Hello World !") ;
    t_nHandle = Donsee_Open("USB");
    if (t_nHandle != 0)
    {
        ui->textEdit->append("连接EST-100身份证读卡器失败") ;
        printf("连接EST-100身份证读卡器失败,t_nRe = %ld\n", t_nHandle);
        m_isOpen = false ;
        //        return -1;
    }
    else {
        Donsee_Beep();
        ui->textEdit->append("连接EST-100身份证读卡器成功") ;
         m_isOpen = true ;
    }



}

void MainWindow::on_btnClose_clicked()
{

    long t_nRe = Donsee_Close();
    if (t_nRe != 0)
    {
        ui->textEdit->append("关闭EST-100身份证读卡器失败") ;

    }
    else {
        ui->textEdit->append("关闭EST-100身份证读卡器成功") ;
    }

    m_isOpen = false ;
}

void MainWindow::on_btnVersion_clicked()
{
    if(m_isOpen == false)
    {
        ui->textEdit->append("EST-100身份证读卡器端口未打开") ;
        return  ;
    }


    unsigned char Response[1024] = {0};
    long t_nRe;
    char t_szMsg[256] = "" ;

    t_nRe = Donsee_Version(Response);
    if (t_nRe != 0)
    {
        ui->textEdit->append("EST-100身份证读卡器读取设备版本号失败") ;

    }
    else {
        Donsee_Beep();
        sprintf(t_szMsg,"设备版本号:%s", Response) ;
        ui->textEdit->append(t_szMsg) ;
    }

    //    printf("设备版本号:%s\n", Response);
}

void MainWindow::on_btnClear_clicked()
{
    ui->textEdit->clear() ;
}

void MainWindow::on_btnICard_clicked()
{
    if(m_isOpen == false)
    {
        ui->textEdit->append("读卡器端口未打开") ;
        return  ;
    }    if(m_isOpen == false)


    char t_arrDataRe[32] = {0};
    char t_arrDataUID[8] = {0};
    char t_szMsg[256] = "" ;

    long t_nSet = Donsee_SetTypeA();
    if (t_nSet != 0)
    {
        printf("TypeA 设置失败\n") ;
        ui->textEdit->append("IC卡 设置失败") ;
        return ;
    }

    long t_nReq = Donsee_ICRequest();
    if (t_nReq != 0)
    {
        printf("TypeA 请求失败\n") ;
        ui->textEdit->append("IC卡 请求失败") ;
        return ;
    }

    long t_nAtl = Donsee_ICAnticoll(t_arrDataUID);
    if (t_nAtl != 0)
    {
        printf("TypeA 防碰撞失败\n") ;
        ui->textEdit->append("IC卡 防碰撞失败") ;
        return ;
    }

    //printf("IC卡 卡号:%s\n", t_arrDataUID);
    //sprintf(t_szMsg,"IC卡 卡号:%s", t_arrDataUID) ;
    QString t_strCard;
    t_strCard = t_arrDataUID;
    ui->textEdit->append("IC卡 卡号:"+t_strCard) ;
    Donsee_Beep();
    long t_nSel = Donsee_ICSelect(0x41);
    if (t_nSel != 0)
    {
        printf("TypeA 选卡失败\n") ;
        ui->textEdit->append("IC卡 选卡失败") ;
        return ;
    }


    char t_pszAtr[256] = "" ;
    long t_nRe = Donsee_PowerOnTypeA(t_pszAtr);
    if (t_nRe != 0)
    {
        printf("TypeA 上电失败") ;
        ui->textEdit->append("IC卡 上电失败") ;
        return ;
    }


}

void MainWindow::on_btnBankCard_clicked()
{
    if(m_isOpen == false)
    {
        ui->textEdit->append("读卡器端口未打开") ;
        return  ;
    }

    char t_szBankNo[256] = "";
    char *p, *q;
    unsigned char tmp;
    char t_szMsg[256] = "" ;

    long t_nRe = Donsee_GetBankCardNo(t_szBankNo);
    if (t_nRe != 0)
    {
        printf("读取银行卡号失败\n");
        ui->textEdit->append("读取银行卡号失败") ;
    }
    else
    {
        Donsee_Beep();
        tmp = (unsigned char)(strchr(t_szBankNo, 'D') - t_szBankNo);
        q = (tmp > 0) ? strndup(t_szBankNo, tmp) : strdup(t_szBankNo);
        printf("读取银行卡号成功:%s\n", q);

        sprintf(t_szMsg,"读取银行卡号成功:%s", q) ;
        ui->textEdit->append(t_szMsg) ;

    }
}

void MainWindow::on_btnSSCard_clicked()
{
    if(m_isOpen == false)
    {
        ui->textEdit->append("读卡器端口未打开") ;
        return  ;
    }

    char t_szMsg[256] = "" ;
    SSCard_IDINFO cardInfo;
    memset(&cardInfo, 0, sizeof(cardInfo));
    char pszError[256] = "" ;

    long t_nRead = Donsee_ReadSSCard(0x11, &cardInfo, pszError);
    if (t_nRead != 0)
    {
        printf("读社保卡失败,MSG:%s\n", pszError);
        sprintf(t_szMsg,"读社保卡失败,MSG:%s", pszError) ;
        ui->textEdit->append(t_szMsg) ;
        return ;
    }
    else
    {
        Donsee_Beep();
        printf("读社保卡成功\n");

        ui->textEdit->append("读社保卡成功") ;
        printf("姓名:%s\n", cardInfo.name);
        sprintf(t_szMsg,"姓名:%s", cardInfo.name) ;
        ui->textEdit->append(t_szMsg) ;
        printf("性别:%s\n", cardInfo.sex);
        sprintf(t_szMsg,"性别:%s", cardInfo.sex) ;
        ui->textEdit->append(t_szMsg) ;
        printf("民族:%s\n", cardInfo.nation);
        sprintf(t_szMsg,"民族:%s", cardInfo.nation) ;
        ui->textEdit->append(t_szMsg) ;
        printf("出生日期:%s\n", cardInfo.birthday);
        sprintf(t_szMsg,"出生日期:%s", cardInfo.birthday) ;
        ui->textEdit->append(t_szMsg) ;
        printf("发证日期:%s\n", cardInfo.signdate);
        sprintf(t_szMsg,"发证日期:%s", cardInfo.signdate) ;
        ui->textEdit->append(t_szMsg) ;
        printf("有效日期:%s\n", cardInfo.validterm);
        sprintf(t_szMsg,"有效日期:%s", cardInfo.validterm) ;
        ui->textEdit->append(t_szMsg) ;
        printf("卡号:%s\n", cardInfo.cardnumber);
        sprintf(t_szMsg,"卡号:%s", cardInfo.cardnumber) ;
        ui->textEdit->append(t_szMsg) ;
        printf("社会保障号码(身份证号):%s\n", cardInfo.idnumber);
        sprintf(t_szMsg,"社会保障号码(身份证号):%s", cardInfo.idnumber) ;
        ui->textEdit->append(t_szMsg) ;
        printf("城市代码:%s\n", cardInfo.city);
        sprintf(t_szMsg,"城市代码:%s", cardInfo.city) ;
        ui->textEdit->append(t_szMsg) ;
        printf("社保卡版本:%s\n", cardInfo.cardveVrsion);
        sprintf(t_szMsg,"社保卡版本:%s", cardInfo.cardveVrsion	) ;
        ui->textEdit->append(t_szMsg) ;
    }

}


void MainWindow::on_btnIdUid_clicked()
{
    if(m_isOpen == false)
    {
        ui->textEdit->append("读卡器端口未打开") ;
        return  ;
    }

    char Response[1024] = "";
    char t_szMsg[256] = "" ;
    long t_nRe = Donsee_ReadIDCardUid(Response);   //身份证Uid,有需要的可以这里获取
    if(t_nRe != 0)
    {
        ui->textEdit->append("获取身份证UID失败") ;
    }
    else
    {
        Donsee_Beep();
        sprintf(t_szMsg,"获取身份证UID成功:%s", Response) ;
        ui->textEdit->append(t_szMsg) ;
    }

}

void MainWindow::on_btnReadId_clicked()
{
    if(m_isOpen == false)
    {
        ui->textEdit->append("读卡器端口未打开") ;
        return  ;
    }


    IDINFO idInfo;
    char t_arrMsg[256];
    char t_szMsg[256] = "" ;

    // nType [in]:设置身份证读卡类型:0,文本信息;1,文本+照片;2,文本+照片+指纹
    // nMode [in]:设置读卡模式:0,读卡1次、拿开后放上重读;1,连续读卡,此功能未实现,填1就行
    int nType = 1;
    int nMode = 1;  //此功能未实现,填1就行
    memset(&idInfo, 0, sizeof(IDINFO));
//    char t_szPath[256] = "/tmp/IDPhoto.bmp";
    char t_szPath[256] = "./IDPhoto.bmp";
    // char t_szPath[256] = "";
    // char t_szPath[256] = NULL;

    long t_nRe = Donsee_ReadIDCard(nType, nMode, t_szPath, &idInfo, t_arrMsg);
    if (t_nRe != 0)
    {
        printf("读身份证失败\n");
        ui->textEdit->append("读身份证失败") ;
        return ;
    }
    else
    {
        Donsee_Beep();
        printf("读身份证成功\n");
        ui->textEdit->append("读身份证成功") ;
        printf(("中文姓名:%s\n"), idInfo.name);
        sprintf(t_szMsg,("中文姓名:%s"), idInfo.name) ;
        ui->textEdit->append(t_szMsg) ;

        printf(("英文姓名:%s\n"), idInfo.ENfullname);
        sprintf(t_szMsg,("英文姓名:%s"), idInfo.ENfullname) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("性    别:%s\n"), idInfo.sex);
        sprintf(t_szMsg,("性    别:%s"), idInfo.sex) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("民    族:%s\n"), idInfo.people);
        sprintf(t_szMsg,("民    族:%s"), idInfo.people) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("出身日期:%s\n"), idInfo.birthday);
        sprintf(t_szMsg,("出身日期:%s"), idInfo.birthday) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("住    址:%s\n"), idInfo.address);
        sprintf(t_szMsg,("住    址:%s"), idInfo.address) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("身份证号:%s\n"), idInfo.number);
        sprintf(t_szMsg,("身份证号:%s"), idInfo.number) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("签发机关:%s\n"), idInfo.organs);
        sprintf(t_szMsg,("签发机关:%s"), idInfo.organs) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("有效期开始:%s\n"), idInfo.signdate);
        sprintf(t_szMsg,("有效期开始:%s"), idInfo.signdate) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("有效期结束:%s\n"), idInfo.validterm);
        sprintf(t_szMsg,("有效期结束:%s"), idInfo.validterm) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("证件类别:%s\n"), idInfo.certType);
        sprintf(t_szMsg,("证件类别:%s"), idInfo.certType) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("证件版本:%s\n"), idInfo.certVersion);
        sprintf(t_szMsg,("证件版本:%s"), idInfo.certVersion) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("通行证号:%s\n"), idInfo.passNu);
        sprintf(t_szMsg,("通行证号:%s"), idInfo.passNu) ;
        ui->textEdit->append(t_szMsg) ;
        printf(("签发数次:%s\n"), idInfo.signCount);
        sprintf(t_szMsg,("签发数次:%s"), idInfo.signCount) ;
        ui->textEdit->append(t_szMsg) ;


    }
}

你可能感兴趣的:(1024程序员节)