package cn.com.basic.face.util;
|
|
import android.graphics.Bitmap;
|
import android.graphics.BitmapFactory;
|
|
import com.bit.rfid.RFIDReader;
|
import com.bit.rfid.ReaderExtra;
|
import com.ivsign.android.IDCReader.IDCReaderSDK;
|
|
import org.xutils.http.RequestParams;
|
|
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayOutputStream;
|
|
import cn.com.basic.face.base.BaseApplication;
|
import cn.com.basic.face.base.MainActivity;
|
import cn.com.basic.face.fragment.RegisterFragment;
|
import cn.com.basic.face.service.RegisterMng;
|
|
import static cn.com.basic.face.util.FileUtil.writeToFile;
|
|
public class IdCardReaderThread extends Thread {
|
|
|
@Override
|
public void run() {
|
while(true) {
|
try{
|
Thread.sleep(2000);
|
try {
|
if (!RegisterFragment.getInstance().isVisible()) {
|
return;
|
}
|
|
RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart");
|
idCardReader.setUartDeviceName("/dev/ttyS4");
|
ByteArrayInputStream type = new ByteArrayInputStream("uart".getBytes());
|
idCardReader.control(ReaderExtra.CONNECT, type);
|
|
idCardReader.open("id_card");
|
|
idCardReader.open("id_sam");
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
idCardReader.control(ReaderExtra.ID_READ_TEXT_PHOTO, baos);
|
String textPhoto = byteArrayToHexString(baos.toByteArray());
|
|
|
|
if (textPhoto != null) {
|
final String[] decodeInfo = new String[10];
|
final StringBuilder imagePath = new StringBuilder();
|
String path = MainActivity.getInstance().getFilesDir().getAbsolutePath();
|
IDCReaderSDK.initialize(path);
|
IDCReaderSDK.decodeSamAck(textPhoto, decodeInfo, imagePath);
|
|
// if (fragment_register_surveillance_photo_img == null) {
|
// // MainActivity.getInstance().runOnUiThread(new Runnable() {
|
// // @Override
|
// // public void run() {
|
// // Toast.makeText(BaseApplication.getInstance(),"请先选择人物照片", Toast.LENGTH_SHORT).show();
|
// // }
|
// // });
|
// //return;
|
// }
|
testComparePicturesWithJpeg(new IdCard(decodeInfo[0], decodeInfo[5], decodeInfo[3], decodeInfo[1], imagePath.toString()));
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
|
protected static final char[] a = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
public static String byteArrayToHexString(byte[] bytes) {
|
if(bytes == null) {
|
return null;
|
} else {
|
char[] hexChars = new char[bytes.length * 2];
|
|
for(int j = 0; j < bytes.length; ++j) {
|
int v = bytes[j] & 255;
|
hexChars[j * 2] = a[v >>> 4];
|
hexChars[j * 2 + 1] = a[v & 15];
|
}
|
|
return new String(hexChars);
|
}
|
}
|
|
|
private void testComparePicturesWithJpeg(IdCard idCard) {
|
|
RequestParams params = new RequestParams();
|
|
if (idCard.getHeadPath() != null && !"".equals(idCard.getHeadPath())) {
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
Bitmap bitmap = BitmapFactory.decodeFile(idCard.getHeadPath(), options);
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
|
params.addBodyParameter("surveillancePhotoW",bitmap.getWidth()+"");
|
params.addBodyParameter("surveillancePhotoH",bitmap.getWidth()+"");
|
params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
|
} else {
|
params.addBodyParameter("surveillancePhotoW", "0");
|
params.addBodyParameter("surveillancePhotoH", "0");
|
params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
|
}
|
|
|
if (idCard.getHeadPath() != null && !"".equals(idCard.getHeadPath())) {
|
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
Bitmap bitmap = BitmapFactory.decodeFile(idCard.getHeadPath(), options);
|
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
|
params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+"");
|
params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+"");
|
params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
|
} else {
|
params.addBodyParameter("idCardPhotoW","0");
|
params.addBodyParameter("idCardPhotoH","0");
|
params.addBodyParameter("idCardPhoto", writeToFile("idCardHeadPhoto", new byte[]{}));
|
}
|
|
RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params, idCard);
|
}
|
|
}
|