Mobile scan ID for ID card information (front-end section)
Recently made a scan of the identity of the function of the following several steps
1: Use h5+ to call the phone camera
if (window.plus) {Playcamera ();} else{Document.addeventlistener ("Plusready", Playcamera (), false);
Call camera to take pictures:
Playcamera:function () {var _self=ext.getcmp ("Add_client_view"); var CMR = Plus.camera.getCamera (); var res = Cmr.supportedimageresolutions[0];var FMT = cmr.supportedimageformats[0];cmr.captureimage (path) {_ Self. Getbase64code (path);},function (Error) {alert ("Capture image failed:" + error.message);} ,
2: Convert acquired images to base64 format data
There are 2 ways to convert base64 format photos here:
(1): Use H5 FileReader according to the picture Road to convert to Base64 format picture;
Convert the picture to Base64 format img2dataurl:function (path) { Plus.io.resolveLocalFileSystemURL (path, function (entry) { entry.file (function (file) { debugger var reader = new Plus.io.FileReader (); Reader.onload = function (e) { imgbase64=e.target.result; Console.log ("* * * *" +e.target.result); }; Reader.readasdataurl (file) ,},function (e) { ext.toast ("Read and write exception:" + E.message) ,}) },
(2): Use bitmap native Picture object provided by h5+
Please see here Http://www.html5plus.org/doc/zh_cn/nativeobj.html#plus.nativeObj.Bitmap the concrete method;
With detailed instructions
Getbase64code:function (path) { var bitmap = new Plus.nativeObj.Bitmap ("xxx"); Load bitmap picture from local to convert picture to base64 format bitmap.load (Path,function () { var base4=bitmap.tobase64data (); var datastr=base4.split (', ', 3);//intercept the useless prefix var imgbase64 = []; if (datastr.length>1) { imgbase64.push (datastr[1]); } else { imgbase64.push (datastr[0]); } Console.log (imgbase64); var traceno=utils.gentrn ();//serial number//Then send Ajax request },function (e) { console.log (' Load picture failed: ' +json.stringify (e) ); }); },
(3) Call Ali identity card Scan information interface, obtain identity card information;
Mobile Scan ID for obtaining identity card information.