The front end wants to read the id card information roughly needs three steps, 1: install FFI library; 2: recompile ffI module; 3. Decode the Buffer data and get the real data;
Nodejs calls DLL dynamic link libraries
- Environment configuration
- System version
- Related modules
- install VC++ Build Tools and set environment variables * computer - properties - advanced system environment - environment variables * set environment variables depending on whether the system is 64-bit or 32-bit if the system is 64-bit, the specific installation path depends on. * 64-bit OS: C: Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\ AMd64; * 32-bit operating system: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin - Download python2.7. X because Node-gyp does not support Python3 - If the environment is clean, CNPM install --global --production Windows-build-tools * Windows build-tools https://msdn.microsoft.com/en-us/library/ms235639.aspx?__hstc=268264337.9321b9803d33050e091ca8e53849b297.1521437931527.1 521437931527.1521511183075.2 & __hssc = 268264337.1.1521511183075 & __hsfp = 2211679638Copy the code
System version - computers are 64 - bit DLL dynamic library files,32 - bit DLL files. * Windows can't call.so, and Linux can't call.dll. Command line run: dumpbin /headers path/dirname.dll * Warning: always check to see if the DLL files are all 64-bit or 32-bit before developing the project to reduce the number of bugs. - VS2010 or 2015 will workCopy the code
NPM install -g node-gyp NPM install --save ffI CD node_modules\ffi node-gyp rebuild --target=1.8.2 --arch=ia32 - CD node_modules dist - url = https://atom.io/download/electron \ ref node - gyp rebuild -- target = 1.8.2 - arch = ia32 - dist - url = https://atom.io/download/electron simple explanation: - target indicates the electron version, arch indicates how many bits you want to recompile to - IA32-bit x86 platforms, X64-bit 64-bit platforms, DLL bits, module bits, node.js bits should be the same, - dist- URL specifies where to download the electron header file. You may be slow to download the electron header fileCopy the code
Install node – gyP global install if not successful first remove install again then install electron-rebuild, electron then re-compile the native node module execute to compile FFI and REF modules so that ffI modules can be introduced
Before installing Node-gyp, VS2015 must be installed, the environment must be configured, and python2.7. X must be installed
The ffi and ref modules need to be recompiled, and the command is as follows (ref module does not need to be installed manually, ref will be installed automatically when ffI module is installed)
- Compile scheme 1: Ordinary electron HTML pages can be compiled using this
.\node_modules\.bin\electron-rebuild.cmd
- Compilation scheme 2: The project constructed by electron-vue needs to be compiled in the current directory
CD node_modules \ ffi node - gyp rebuild -- target = 1.8.2 - arch = ia32 - dist - url = https://atom.io/download/electron CD Node_modules \ ref node - gyp rebuild -- target = 1.8.2 - arch = ia32 - dist - url = https://atom.io/download/electronCopy the code
Simple explanation: Target indicates the electron version, arch indicates how many bits you want to recompile to, IA32-bit x86 platforms, X64-bit 64-bit platforms, DLL bits, module bits, node.js bits should be the same, otherwise an error will be reported, dist- URL specifies where to download the electron header file. If you are slow to download here, go ahead and see how to manually download the electron header file
Two: the problem of adjusting the ID card security module API is solved
Chinese characters are garbled. Memory overflow. Data type conversion
Chinese characters are garbled. The base code of the ID card picture obtained needs to be decoded again before it can be displayed normally.
// Save the base64 image POST method
App. POST ('/upload', function(req, res){imgData = req.body.imgData; Imgdata. replace(/^data:image\/\w+; base64,/, ""); var dataBuffer = new Buffer(base64Data, 'base64'); Fs.writefile ("out.png", dataBuffer, function(err) {if(err){res.send(err); fs.writefile ("out.png", dataBuffer, function(err) {if(err){res.send(err); }else{res.send(" Save successfully!" ); }}); });Copy the code
Solution: Node character encoding
- ASCII ASCLL character string
- Utf8 UTF-8 The value is a character string
- Utf16le UTF-16LE The value is a character string
- Ucs2 UCS2 The value is a character string
- Base64 Indicates the character string encoded in Base64
- Binary Data (not recommended)
- Hex A string in hexadecimal numbers
Eg: Here is a list of Chinese characters transcoding, other characters transcoding see the code… Const msgInfo = MSG. ToString (‘ utf16le, 0256);
## 3: printer TWO-DIMENSIONAL code device API file to solve the local generation of two-dimensional code: use to generate two-dimensional code plug-in ----canvas2image.js to use the technical points: 1. Transfer the pictures drawn by canvas into Base64 encoding. 2. Transcode the base64 image encoding generated by FS module into new Buffer and save it locally downloadFile(uri,filename,callback){ var stream = fs.createWriteStream(filename); request(uri).pipe(stream).on('close', callback); } downloadFile (fileUrl, filename, function () {/ / do something}) # # 4: binocular camera problem solving # # 5: NPM run build: Win32 // x86 packCopy the code
// test.js var ffi = require('ffi') const newPort = ffi.Library('./YkPosdll',{ 'YkOpenDevice': ['int', ['int', 'int']], // Linking Error: Win32 error 193 *解决 : 193 this number means is not a valid Win32 program. Node.js is 64-bit and DLL is 32-bit. If DLL is compiled to 64-bit, output will be normal. - Error: Dynamic Linking Error: Var iopath = path.join(__dirname, '/ ioc.dll '); var iopath = path.join(__dirname, '/ ioc.dll '); var io = ffi.Library(iopath ,{ 'IOC_Init':['int32',[]], }); -uncaught Error:Dynamic Symbol Retrieval Error:Win32 Error 127 at dynamicLibrary.get * DLL is not C style module, can be in to export method with extern "C" (note that this is to modify the DLL source code and recompile generated DLL)Copy the code
Fs.writefile = fs.writefile = fs.stat = fs.stat = fs.stat
DLL files will not be packaged during packaging? Solution 1: Manually place the DLL files in the packed root directory. Solution 2:
Refer to the article: https://blog.yasking.org/a/electron-build-env.htmlCopy the code
Copy the code
Three: Audio network Agora SDK video call
< span style = "box-sizing: border-box; color: RGB (74, 74, 74); font-size: 14px! Important; word-wrap: inherit! Important;" $is not defined the solution: add a line in the end the jquery judgment. < script SRC = "https://code.jquery.com/jquery-2.2.0.min.js" > < / script > <script>if (typeof module === 'object') {window.jQuery = window.$ = module.exports; }; </script> So return to familiar with the common JS way on the method that solves the normal browsing of the Web side, but also ensure the normal application side. ------ check browser compatibility (checkSystemRequirements) 1. ------ enumerate system devices (getDevices) 2. ------ create audio and video objects (createClient) 3. -- -- -- -- -- - initializes the client object (init) 4. -- -- -- -- -- - to join AgoraRTC channel (join) 5. -- -- -- -- -- - to create audio and video stream objects (createStream) 6. -- -- -- -- -- - set the local flow Profile (localStream setVideoProfile (" 480 p_4 ");) ------ initialize localStream (localstream.init) 8. ------ publish localStream (client.publish) 9. ------ play local/remote stream (localstream.play ("agora-remote");)Copy the code
The author encountered a lot of problems in the process of debugging equipment, the article did not list one by one, if you also happen to debug hardware equipment, if you encounter problems, please leave a message, I can help you provide ideas.