fz
fz
  • 发布:2015-08-14 16:07
  • 更新:2015-08-14 16:07
  • 阅读:5152

指昂平板 指纹识别接口

分类:5+ SDK

基于厂家提供的例子 android060demo.rar

// FingerPrintFeature.java      
//依赖 demo 的 andriod060.java 和 za_finger.java;引入库 libandroid_060.so;把demo中的权限,加入项目  
//另 closeDevice方法 调用时发现有问题并没有调用,只open然后读取指纹发现没有问题  

package com.renhe.za.fingerPrintApi;  
import io.dcloud.DHInterface.IWebview;  
import io.dcloud.DHInterface.StandardFeature;  
import io.dcloud.util.JSUtil;  
import org.json.JSONArray;  
import org.json.JSONException;  
import org.json.JSONObject;  
import com.za.android060;  
import com.zafinger.ZA_finger;  
public class FingerPrintFeature extends StandardFeature{  

    public void openDevice(IWebview pWebview, JSONArray array){       
        int DEV_ADDR = 0xffffffff;  
        android060 a6= new android060();  
        try{  
            //a6.card_power_off(60, 3);  
            ZA_finger.fppower(1);  
            //ZA_finger.cardpower(1);  
            android.os.SystemClock.sleep(1000);  
            int status = a6.ZAZOpenDeviceEx(-1,2, 3, 12, 0, 0);  
            if(status!=1){  
                JSUtil.execCallback(pWebview, array.optString(0), "打开设备失败", JSUtil.ERROR, false);  
                return;  
            }  
            JSUtil.execCallback(pWebview, array.optString(0), "打开设备成功", JSUtil.OK, false);  
        }catch(Exception ex){  
            JSUtil.execCallback(pWebview, array.optString(0), "打开设备异常", JSUtil.ERROR, false);  
            return;  
        }  
    }  

    public void closeDevice(IWebview pWebview, JSONArray array)  
    {  
        int DEV_ADDR = 0xffffffff;  
        android060 a6= new android060();  
        try{  
            a6.ZAZCloseDeviceEx();  
            ZA_finger.fppower(0);  
            //ZA_finger.cardpower(0);  
            JSUtil.execCallback(pWebview, array.optString(0), "关闭设备成功", JSUtil.OK, false);  
        }catch(Exception ex){  
            JSUtil.execCallback(pWebview, array.optString(0), "关闭设备失败", JSUtil.ERROR, false);  
        }  
    }  

    public void doFingerPrint(IWebview pWebview, JSONArray array){  

        int DEV_ADDR = 0xffffffff;  
        android060 a6= new android060();  
        try{  
            int nRet = 0;  
            nRet = a6.ZAZGetImage(DEV_ADDR);  
            if(nRet == 0){  
                int[] len = { 0, 0 };  
                char[] Image = new char[256 * 288];  
                a6.ZAZUpImage(DEV_ADDR, Image, len);   
                String fingerPrintPath = android.os.Environment.getExternalStorageDirectory().getPath()+"/fingerPrint.bmp";  
                a6.ZAZImgData2BMP(Image, fingerPrintPath);  

                nRet= a6.ZAZGenChar(DEV_ADDR, a6.CHAR_BUFFER_A);  
                if(nRet ==a6.PS_OK){  
                    int[] iTempletLength = { 0, 0 };  
                    byte[] pTemplet = new byte[512];  
                    nRet=a6.ZAZUpChar(DEV_ADDR,a6.CHAR_BUFFER_A, pTemplet, iTempletLength);  
                    if(nRet ==a6.PS_OK){  
                        JSONObject obj = new JSONObject();  
                        obj.put("fingerPrintCode", charToHexString(pTemplet));  
                        obj.put("fingerPrintPath", fingerPrintPath);  
                        JSUtil.execCallback(pWebview, array.optString(0), obj, JSUtil.OK, false);  
                    }else{  
                        JSUtil.execCallback(pWebview, array.optString(0), "生成指纹特征码失败", JSUtil.ERROR, false);  
                    }  
                }else{  
                    JSUtil.execCallback(pWebview, array.optString(0), "指纹特征太差,重新录入", JSUtil.ERROR, false);  
                }     
            }else if(nRet==a6.PS_NO_FINGER){  
                JSUtil.execCallback(pWebview, array.optString(0), "未按手指", JSUtil.ERROR, false);  
            }else {  
                JSUtil.execCallback(pWebview, array.optString(0), "读取指纹失败", JSUtil.ERROR, false);  
            }  

        }catch(Exception ex){  
            JSUtil.execCallback(pWebview, array.optString(0), "读取指纹异常", JSUtil.ERROR, false);  
        }     
    }  

    private String charToHexString(byte[] val) {  
        String temp="";  
        for(int i=0;i<val.length;i++)  
        {   
            String hex = Integer.toHexString(0xff & val[i]);  
            if (hex.length() == 1) {   
                hex = '0' + hex;   
            }   
            temp += hex.toUpperCase();     
        }  
        return temp;  
    }  
}
4 关注 分享
蔡繁荣 BoredApe m***@outlook.com 4***@qq.com

要回复文章请先登录注册

蔡繁荣

蔡繁荣

支持下,建议放一张设备的图片:)
2015-08-15 22:30
fz

fz (作者)

注意问题
1.指纹特征码 采用 charToHexString 方法编码,具体的编码方法为将一个byte 前四位 和后四位 分别转16进制。。所以 一个byte 被编码为 两个16进制字符。。服务器端校验的时候 记得 反向 将 两个16进制字符 转为 byte 进行校验。。(校验指纹参考厂家提供的DLL和文档)

2.编译的时候 。注意SO库的引入。如果不起作用最好将 SO库删掉 重新引入。。我很长时间耗在 库没有正常引入。。
2015-08-14 16:15
fz

fz (作者)

//简单调用例子。
var isOpenDevice = false;

var doFingerPrint = function () {
plus.rhFingerPrint.doFingerPrint(function (result) {
alert(result.fingerPrintCode); //编码过的指纹特征码
alert(result.fingerPrintPath); //指纹图像存放路径
}, function (err) {
if (err == '未按手指') {
setTimeout(doFingerPrint, 500);
}
});
}


plus.rhFingerPrint.openDevice(function (result) {
isOpenDevice = true;
setTimeout(doFingerPrint, 100);
}, function (err) {
isOpenDevice = false;
alert(err);
});
2015-08-14 16:09
fz

fz (作者)

//fingerPrintApi.js

document.addEventListener( 'plusready', function()
{
var _BARCODE = 'rhFingerPrint',
B = window.plus.bridge;
var rhFingerPrint = {
openDevice : function (successCallback, errorCallback ) {
var success = typeof successCallback !== 'function' ? null : function(args)
{
successCallback(args);
},
fail = typeof errorCallback !== 'function' ? null : function(code)
{
errorCallback(code);
};
callbackID = B.callbackId(success, fail);

return B.exec(_BARCODE, 'openDevice', [callbackID]);
},
closeDevice : function (successCallback, errorCallback ) {
var success = typeof successCallback !== 'function' ? null : function(args)
{
successCallback(args);
},
fail = typeof errorCallback !== 'function' ? null : function(code)
{
errorCallback(code);
};
callbackID = B.callbackId(success, fail);

return B.exec(_BARCODE, 'closeDevice', [callbackID]);

},
doFingerPrint : function (successCallback, errorCallback ) {

var success = typeof successCallback !== 'function' ? null : function(args)
{
successCallback(args);
},
fail = typeof errorCallback !== 'function' ? null : function(code)
{
errorCallback(code);
};
callbackID = B.callbackId(success, fail);

return B.exec(_BARCODE, 'doFingerPrint', [callbackID]);
}
};
window.plus.rhFingerPrint = rhFingerPrint;
}, true );
2015-08-14 16:09