CN107239357B - Offline transaction record storing method, device, computer equipment and storage medium - Google Patents
Offline transaction record storing method, device, computer equipment and storage medium Download PDFInfo
- Publication number
- CN107239357B CN107239357B CN201710393605.5A CN201710393605A CN107239357B CN 107239357 B CN107239357 B CN 107239357B CN 201710393605 A CN201710393605 A CN 201710393605A CN 107239357 B CN107239357 B CN 107239357B
- Authority
- CN
- China
- Prior art keywords
- file
- offline transaction
- transaction record
- storage device
- offline
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/07—Responding to the occurrence of a fault, e.g. fault tolerance
- G06F11/0703—Error or fault processing not based on redundancy, i.e. by taking additional measures to deal with the error or fault not making use of redundancy in operation, in hardware, or in data representation
- G06F11/0793—Remedial or corrective actions
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/07—Responding to the occurrence of a fault, e.g. fault tolerance
- G06F11/08—Error detection or correction by redundancy in data representation, e.g. by using checking codes
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Quality & Reliability (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明涉及一种脱机交易记录保存方法、装置、计算机设备和存储介质,所述方法包括:获取第一存储装置的第一文件,第一文件包括脱机交易记录;获取第二存储装置的第二文件,第二文件包括脱机交易记录;对第一文件和第二文件分别进行完整性校验;若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件;在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。通过本方法能够有效保存脱机交易记录,并提高脱机交易记录完整性。
The present invention relates to a method, device, computer equipment and storage medium for saving offline transaction records. The method includes: obtaining a first file of a first storage device, the first file including offline transaction records; obtaining a file of a second storage device The second file, the second file includes offline transaction records; the integrity check is performed on the first file and the second file respectively; if the first file check is successful and the second file check fails, then use the first file in the first file The offline transaction record replaces the offline transaction record in the second file, and saves the replaced second file in the second storage device; saves the replaced second file in the second storage device; if the verification of the first file fails And the verification of the second file is successful, the offline transaction record in the first file is replaced by the offline transaction record in the second file, and the replaced first file is saved in the first storage device. The method can effectively save offline transaction records and improve the integrity of offline transaction records.
Description
技术领域technical field
本发明涉及计算机技术领域,特别是涉及一种脱机交易记录保存方法、装置、计算机设备和存储介质。The invention relates to the field of computer technology, in particular to a method, device, computer equipment and storage medium for saving off-line transaction records.
背景技术Background technique
在脱机交易设备中,脱机交易完成后,会在本地存储脱机交易记录。当脱机交易记录达到一定数量时,脱机交易设备将脱机交易记录上传给后台。如果在脱机交易记录上传之前,脱机交易设备发生了故障,很可能出现脱机交易记录不完整的问题。因此,如何有效保存脱机交易记录,提高脱机交易记录完整性是目前需要解决的一个技术问题。In the offline transaction device, after the offline transaction is completed, the offline transaction record will be stored locally. When the offline transaction records reach a certain amount, the offline transaction device will upload the offline transaction records to the background. If the offline transaction device fails before the offline transaction records are uploaded, the offline transaction records may be incomplete. Therefore, how to effectively save offline transaction records and improve the integrity of offline transaction records is a technical problem that needs to be solved at present.
发明内容Contents of the invention
基于此,有必要针对上述技术问题,提供一种既能有效保存脱机交易记录又能提高脱机交易记录完整性的脱机交易记录保存方法、装置、计算机设备和存储介质。Based on this, it is necessary to address the above technical problems and provide an off-line transaction record preservation method, device, computer equipment and storage medium that can effectively preserve off-line transaction records and improve the integrity of the off-line transaction records.
一种脱机交易记录保存方法,所述方法包括:A method for keeping offline transaction records, the method comprising:
获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;obtaining a first file of a first storage device, the first file including an offline transaction record;
获取第二存储装置的第二文件,所述第二文件包括脱机交易记录;obtaining a second file of a second storage device, the second file comprising an offline transaction record;
对所述第一文件和所述第二文件分别进行完整性校验;performing an integrity check on the first file and the second file respectively;
若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the verification of the first file succeeds and the verification of the second file fails, the offline transaction record in the first file is used to replace the offline transaction record in the second file, and the offline transaction record in the second file Save the replaced second file in the storage device; if the verification of the first file fails and the verification of the second file succeeds, then use the offline transaction record in the second file to replace the transaction record in the first file The offline transaction record of the first file after replacement is stored in the first storage device.
在其中一个实施例中,所述对所述第一文件和所述第二文件分别进行完整性校验的步骤之后,所述方法还包括:In one of the embodiments, after the step of performing integrity verification on the first file and the second file respectively, the method further includes:
若所述第一文件和所述第二文件均校验成功,则获取所述第一文件长度和所述第二文件长度;If both the first file and the second file are verified successfully, then obtaining the first file length and the second file length;
对所述第一文件长度和所述第二文件长度进行一致性校验。A consistency check is performed on the first file length and the second file length.
在其中一个实施例中,所述第一文件还包括第一校验码,所述完整性校验包括对所述第一文件长度进行校验,所述对所述第一文件长度进行校验的步骤,包括:In one of the embodiments, the first file further includes a first check code, the integrity check includes checking the length of the first file, and the checking the length of the first file steps, including:
获取所述第一文件长度;Obtain the length of the first file;
获取单条脱机交易记录字节数,所述单条脱机交易记录字节数包括所述第一文件中的单条脱机交易记录占用的字节;Obtain the byte count of a single offline transaction record, where the byte count of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file;
获取校验码字节数,所述校验码字节数包括所述第一校验码占用的字节;Obtain the number of bytes of the check code, the number of bytes of the check code includes the bytes occupied by the first check code;
通过所述单条脱机交易记录字节数、所述校验码字节数和所述第一文件长度,计算所述第一文件中的脱机交易记录条数;Calculate the number of offline transaction records in the first file through the number of bytes of the single offline transaction record, the number of bytes of the verification code and the length of the first file;
判断所述第一文件中的脱机交易记录条数是否为正整数;Judging whether the number of offline transaction records in the first file is a positive integer;
若不是,则所述第一文件校验失败。If not, the verification of the first file fails.
在其中一个实施例中,所述第一文件还包括第一校验码,所述完整性校验还包括对校验码进行校验,所述对校验码进行校验包括对所述第一校验码进行校验的步骤,包括:In one of the embodiments, the first file further includes a first check code, and the integrity check also includes checking the check code, and the checking the check code includes checking the first check code. A step of verifying the verification code, including:
获取预设的密钥;Obtain the preset key;
通过所述密钥和所述第一文件中的脱机交易记录计算所述第一文件对应的第一完整性校验码;calculating a first integrity check code corresponding to the first file through the key and the offline transaction record in the first file;
判断所述第一文件的第一校验码是否与所述第一文件对应的第一完整性校验码相等;judging whether the first check code of the first file is equal to the first integrity check code corresponding to the first file;
若不相等,则所述第一文件校验失败。If they are not equal, the verification of the first file fails.
在其中一个实施例中,所述第一存储装置为内存储装置,所述第二存储装置为外存储装置,对所述第一文件长度和所述第二文件长度进行一致性校验的步骤,包括:In one of the embodiments, the first storage device is an internal storage device, the second storage device is an external storage device, and the step of performing consistency check on the first file length and the second file length ,include:
若所述第一文件长度大于所述第二文件长度,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;If the length of the first file is greater than the length of the second file, then use the offline transaction record in the first file to replace the offline transaction record in the second file;
若所述第一文件长度等于所述第二文件长度且内容不一致,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;If the length of the first file is equal to the length of the second file and the content is inconsistent, then use the offline transaction record in the first file to replace the offline transaction record in the second file;
若所述第一文件长度小于所述第二文件长度,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录。If the length of the first file is smaller than the length of the second file, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
一种脱机交易记录保存装置,所述装置包括:An off-line transaction record storage device, said device comprising:
获取模块,用于获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;获取第二存储装置的第二文件,所述第二文件包括脱机交易记录;An acquisition module, configured to acquire a first file of the first storage device, the first file including offline transaction records; acquire a second file of the second storage device, the second file including offline transaction records;
校验模块,用于对所述第一文件和所述第二文件分别进行完整性校验;A verification module, configured to perform integrity verification on the first file and the second file respectively;
替换模块,用于若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录;保存模块,用于在所述第二存储装置中保存替换后的第二文件,在所述第一存储装置中保存替换后的第一文件。A replacement module, configured to replace the offline transaction record in the second file with the offline transaction record in the first file if the verification of the first file is successful and the verification of the second file fails; If the verification of the first file fails and the verification of the second file succeeds, the offline transaction record in the second file is used to replace the offline transaction record in the first file; the saving module is used for The replaced second file is saved in the second storage device, and the replaced first file is saved in the first storage device.
在其中一个实施例中,所述获取模块还用于若所述第一文件和所述第二文件均校验成功,则获取所述第一文件长度和所述第二文件长度,所述校验模块还用于对所述第一文件长度和所述第二文件长度进行一致性校验。In one of the embodiments, the obtaining module is further configured to obtain the length of the first file and the length of the second file if the verification of the first file and the second file is successful, and the verification The checking module is also used to check the consistency of the first file length and the second file length.
在其中一个实施例中,所述第一文件还包括第一校验码,所述校验模块还用于对所述第一文件长度进行校验,包括:获取所述第一文件长度;获取单条脱机交易记录字节数,所述单条脱机交易记录字节数包括所述第一文件中的单条脱机交易记录占用的字节;获取校验码字节数,所述校验码字节数包括所述第一校验码占用的字节;通过所述单条脱机交易记录字节数、所述校验码字节数和所述第一文件长度,计算所述第一文件中的脱机交易记录条数;判断所述第一文件中的脱机交易记录条数是否为正整数;若不是,则所述第一文件校验失败。In one of the embodiments, the first file further includes a first verification code, and the verification module is also used to verify the length of the first file, including: obtaining the length of the first file; obtaining The number of bytes of a single offline transaction record, the number of bytes of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file; the number of bytes of a check code obtained, the check code The number of bytes includes the bytes occupied by the first verification code; the number of bytes of the single offline transaction record, the number of bytes of the verification code and the length of the first file are used to calculate the first file the number of offline transaction records in the first file; judge whether the number of offline transaction records in the first file is a positive integer; if not, the verification of the first file fails.
一种计算机设备,包括存储器、处理器以及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现上述实施例中提供的方法步骤。A computer device includes a memory, a processor, and a computer program stored in the memory and operable on the processor. When the processor executes the computer program, the method steps provided in the foregoing embodiments are implemented.
一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现上述实施例中提供的方法步骤。A computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method steps provided in the above-mentioned embodiments are implemented.
上述脱机交易记录保存方法、装置、计算机设备和存储介质,脱机交易设备通过第一存储装置和第二存储装置分别存储脱机交易记录,降低了第一存储装置和第二存储装置同时故障的可能性。通过对第一文件和第二文件进行完整性校验,可以发现脱机交易记录是否完整。通过将校验成功的文件中的脱机交易记录替换校验失败的文件中的脱机交易记录,使第一文件中的脱机交易记录和第二文件中的脱机交易记录完整、一致,进一步提高脱机交易记录的完整性。In the above-mentioned off-line transaction record storage method, device, computer equipment and storage medium, the off-line transaction equipment respectively stores off-line transaction records through the first storage device and the second storage device, which reduces the simultaneous failure of the first storage device and the second storage device. possibility. By checking the integrity of the first file and the second file, it can be found whether the offline transaction records are complete. By replacing the offline transaction record in the file with successful verification with the offline transaction record in the file with failed verification, the offline transaction record in the first file and the offline transaction record in the second file are complete and consistent, Further improve the integrity of offline transaction records.
附图说明Description of drawings
图1为一个实施例中脱机交易记录保存方法的流程图;Fig. 1 is the flow chart of off-line transaction record preservation method in an embodiment;
图2为一个实施例中脱机交易记录保存装置的结构示意图;Fig. 2 is a schematic structural diagram of an off-line transaction record storage device in an embodiment;
图3为一个实施例中计算机设备的结构示意图。Fig. 3 is a schematic structural diagram of a computer device in an embodiment.
具体实施方式Detailed ways
为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。In order to make the object, technical solution and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain the present invention, not to limit the present invention.
在一个实施例中,如图1所示,提供了一种脱机交易记录保存方法,以该方法应用于脱机交易设备为例进行说明,具体包括:In one embodiment, as shown in FIG. 1 , a method for saving offline transaction records is provided, and the application of the method to an offline transaction device is used as an example for illustration, specifically including:
步骤102,获取第一存储装置的第一文件,第一文件包括脱机交易记录。Step 102, acquire a first file of the first storage device, where the first file includes offline transaction records.
步骤104,获取第二存储装置的第二文件,第二文件包括脱机交易记录。Step 104, acquire a second file of the second storage device, the second file includes offline transaction records.
脱机交易设备是指在脱机状态下进行脱机交易的金融脱机交易设备,可以是公交车车载收费终端、地铁收费终端或食堂收费终端等。部分联机交易设备在脱机状态下也可以作为脱机交易设备使用,例如,POS机(Point of Sales Terminal,销售点终端管理系统)。Offline transaction equipment refers to financial offline transaction equipment that conducts offline transactions in an offline state, and can be a bus toll terminal, a subway toll terminal, or a canteen toll terminal. Some online transaction devices can also be used as offline transaction devices in an offline state, for example, a POS machine (Point of Sales Terminal, point of sale terminal management system).
传统的脱机交易设备只包括一个存储装置。一旦存储装置发生故障,脱机交易记录将会丢失。本实施例中的脱机交易设备可以包括两个或两个以上存储装置,存储装置包括内存储装置和外存储装置。内存储装置可以包括至少一个存储装置,内存储装置可以是FLASH存储装置,也可以是SRAM(Static Random Access Memory,静态随机存取存储器)存储装置。外存储装置可以包括至少一个存储装置,外存储装置可以是SD卡(Secure DigitalCard)存储装置,也可以是ESAM卡(Embedded Secure Access Module,嵌入式安全模块)。内存储装置中的一个存储装置可以叫做第一存储装置,外存储装置中的一个存储装置可以叫做第二存储装置。内存储装置中的一个存储装置也可以叫做第二存储装置,外存储装置中的一个存储装置相应的叫做第一存储装置。存储装置中存储了多个文件,包括脱机交易记录文件。脱机交易记录文件中存储了脱机交易记录。脱机交易记录文件包括第一文件和第二文件,脱机交易设备在第一存储装置中存储了第一文件,第二存储装置中存储了第二文件。A traditional off-line transaction device includes only a storage device. Once the storage device fails, offline transaction records will be lost. The offline transaction device in this embodiment may include two or more storage devices, and the storage devices include an internal storage device and an external storage device. The internal storage device may include at least one storage device, and the internal storage device may be a FLASH storage device or an SRAM (Static Random Access Memory, static random access memory) storage device. The external storage device may include at least one storage device, and the external storage device may be an SD card (Secure Digital Card) storage device, or an ESAM card (Embedded Secure Access Module, embedded security module). One of the internal storage devices may be called a first storage device, and one of the external storage devices may be called a second storage device. One of the internal storage devices may also be called a second storage device, and one of the external storage devices is correspondingly called a first storage device. A number of files are stored in the storage device, including offline transaction log files. Offline transactions are stored in the offline transaction file. The offline transaction record file includes a first file and a second file, the offline transaction device stores the first file in the first storage device, and stores the second file in the second storage device.
当脱机交易设备发生交易时,产生脱机交易记录。脱机交易记录包括脱机交易信息,例如,脱机交易时间、脱机交易金额以及脱机交易方式等。脱机交易设备将脱机交易记录写入存储装置的脱机交易记录文件中,具体地,将脱机交易记录分别写入第一存储装置中的第一文件以及第二存储装置中的第二文件。When a transaction occurs on the offline transaction device, an offline transaction record is generated. The offline transaction records include offline transaction information, such as offline transaction time, offline transaction amount, and offline transaction method. The offline transaction device writes the offline transaction record into the offline transaction record file of the storage device, specifically, writes the offline transaction record into the first file in the first storage device and the second file in the second storage device respectively. document.
步骤106,对第一文件和第二文件分别进行完整性校验。Step 106, performing an integrity check on the first file and the second file respectively.
当脱机交易设备向脱机交易记录文件写入脱机交易记录时,如果脱机交易记录写入失败,将导致脱机交易记录文件中的脱机交易记录不完整。为了确保脱机交易记录完整,脱机交易设备需要对脱机交易记录文件进行完整性校验,包括对第一文件和对第二文件分别进行完整性校验。When the offline transaction device writes the offline transaction record to the offline transaction record file, if the writing of the offline transaction record fails, the offline transaction record in the offline transaction record file will be incomplete. In order to ensure the integrity of the offline transaction records, the offline transaction device needs to perform integrity checks on the offline transaction record files, including performing integrity checks on the first file and the second file respectively.
具体地,脱机交易设备对脱机交易记录文件进行完整性校验,包括对脱机交易记录文件长度进行校验以及对脱机交易记录文件中的校验码进行校验。其中,脱机交易设备通过对脱机交易记录文件长度进行校验,可以检测出部分脱机交易记录不完整的脱机交易记录文件。例如,当脱机交易设备写入脱机交易记录时,脱机交易设备发生断电,脱机交易设备无法继续写入该条脱机交易记录,则该条脱机交易记录文件不完整。Specifically, the offline transaction device checks the integrity of the offline transaction record file, including checking the length of the offline transaction record file and checking the check code in the offline transaction record file. Wherein, the offline transaction device can detect some offline transaction record files with incomplete offline transaction records by verifying the length of the offline transaction record file. For example, when the offline transaction device writes the offline transaction record, the offline transaction device is powered off, and the offline transaction device cannot continue to write the offline transaction record, then the offline transaction record file is incomplete.
脱机交易设备对脱机交易记录文件长度进行校验时,首先,脱机交易设备获取脱机交易记录文件长度、单条脱机交易记录字节数和校验码字节数。其次,脱机交易设备通过脱机交易记录文件长度、单条脱机交易记录字节数和校验码字节数计算脱机交易记录条数。然后,判断脱机交易记录条数是否为正整数,如果脱机交易记录条数不是正整数,说明脱机交易记录不完整,则该脱机交易记录文件校验失败。通过脱机交易记录文件长度计算脱机交易记录条数,可以根据脱机交易记录条数判断脱机交易记录是否残缺,初步确定脱机交易记录的完整性。When the offline transaction device verifies the length of the offline transaction record file, firstly, the offline transaction device obtains the length of the offline transaction record file, the number of bytes of a single offline transaction record and the number of bytes of the verification code. Secondly, the offline transaction device calculates the number of offline transaction records based on the length of the offline transaction record file, the number of bytes of a single offline transaction record and the number of bytes of the verification code. Then, it is judged whether the number of offline transaction records is a positive integer, if the number of offline transaction records is not a positive integer, it means that the offline transaction records are incomplete, and the verification of the offline transaction record file fails. By calculating the number of offline transaction records based on the length of the offline transaction record file, you can judge whether the offline transaction records are incomplete according to the number of offline transaction records, and preliminarily determine the integrity of the offline transaction records.
进一步地,如果脱机交易设备写入脱机交易记录时,突然发生断电,且断电时刻写入的那条脱机交易记录字节数等于校验码字节数,校验码没有生成,则通过对脱机交易记录文件长度进行校验时,脱机交易设备将该条不完整的脱机交易记录误认为校验码,无法检查出脱机交易记录是否完整。因此,脱机交易设备对脱机交易记录文件长度进行校验之后,还可以进一步对脱机交易记录文件中的校验码进行校验。脱机交易文件中除了脱机交易记录之外,还包括校验码。校验码是利用脱机交易记录文件中的脱机交易记录和预存的密钥生成的。第一文件中包括脱机交易记录和第一校验码。第二文件中包括脱机交易记录和第二校验码。脱机交易设备对脱机交易记录文件长度进行校验之后,对脱机交易记录文件中的校验码进行校验。Furthermore, if the offline transaction device writes offline transaction records, a sudden power failure occurs, and the number of bytes of the offline transaction record written at the moment of power failure is equal to the number of bytes of the check code, the check code is not generated , then when verifying the length of the offline transaction record file, the offline transaction device mistakes the incomplete offline transaction record as a verification code, and cannot check whether the offline transaction record is complete. Therefore, after the offline transaction device verifies the length of the offline transaction record file, it can further verify the verification code in the offline transaction record file. In addition to offline transaction records, offline transaction files also include checksums. The verification code is generated using the offline transaction record in the offline transaction record file and the pre-stored key. The first file includes offline transaction records and a first check code. The second file includes offline transaction records and a second verification code. After the offline transaction device verifies the length of the offline transaction record file, it verifies the verification code in the offline transaction record file.
具体地,脱机交易设备获取预设的密钥,通过密钥和第一文件中的脱机交易记录计算第一文件的第一完整性校验码,判断第一校验码是否与第一完整性校验码相等。如果相等,表示第一校验码包含的脱机交易记录信息和第一完整性校验码第一完整性校验码包含的脱机交易记录信息一致,第一文件的完整性校验成功;若不相等,表示第一校验码的第一完整性校验码不是正确的校验码,而是不完整的脱机交易记录,第一文件中的脱机交易记录不完整,则第一文件的完整性校验失败。Specifically, the offline transaction device obtains a preset key, calculates the first integrity check code of the first file through the key and the offline transaction record in the first file, and judges whether the first check code is consistent with the first integrity check code. The integrity check codes are equal. If they are equal, it means that the offline transaction record information contained in the first check code is consistent with the offline transaction record information contained in the first integrity check code, and the integrity check of the first file is successful; If they are not equal, it means that the first integrity check code of the first check code is not a correct check code, but an incomplete offline transaction record, and the offline transaction record in the first file is incomplete, then the first The integrity check of the file failed.
可以理解地,脱机交易设备对第二文件进行校验码校验也可以采用上述方式,不再赘述。校验码包括脱机交易记录属性,脱机交易设备通过对校验码进行校验进一步确定脱机交易记录文件中的脱机交易记录的完整性。It can be understood that the offline transaction device can also use the above method to verify the verification code of the second file, which will not be repeated here. The verification code includes the attribute of the offline transaction record, and the offline transaction device further determines the integrity of the offline transaction record in the offline transaction record file by verifying the verification code.
步骤108,若第一文件校验成功且第二文件校验失败,则利用第一文件的脱机交易记录替换第二文件的脱机交易记录,在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。Step 108, if the verification of the first file succeeds and the verification of the second file fails, then use the offline transaction record of the first file to replace the offline transaction record of the second file, and store the replaced second file in the second storage device. file; if the first file check fails and the second file check succeeds, then utilize the offline transaction record in the second file to replace the offline transaction record in the first file, and save the replaced first file in the first storage device a file.
脱机交易设备对第一文件和第二文件分别进行完整性校验之后,获取第一文件和第二文件的完整性校验结果。完整性校验结果是指脱机交易记录文件校验成功或校验失败的结果。如果第一文件校验成功且第二文件校验失败,说明第一文件中的脱机交易记录保存完整且第二文件中的脱机交易记录保存不完整,脱机交易设备利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。反之,如果第二文件校验成功且第一文件校验失败,说明第二文件中的脱机交易记录保存完整且第一文件中的脱机交易记录保存不完整,则利用第二文件替换第一文件,在第一存储装置中保存替换后的第一文件。脱机交易设备通过将校验成功的文件替换校验失败的文件,脱机交易记录不完整的文件替换成了脱机交易记录完整的文件,第一文件中的脱机交易记录和第二文件中的脱机交易记录均完整,且达到了一致。The offline transaction device obtains the integrity verification results of the first file and the second file after performing the integrity verification on the first file and the second file respectively. Integrity verification result refers to the result of successful verification or verification failure of the offline transaction record file. If the verification of the first file is successful and the verification of the second file fails, it means that the offline transaction records in the first file are completely preserved and the offline transaction records in the second file are incomplete. The offline transaction record in the second file is replaced by the offline transaction record in the second file, and the replaced second file is saved in the second storage device. Conversely, if the verification of the second file is successful and the verification of the first file fails, it means that the offline transaction records in the second file are completely preserved and the offline transaction records in the first file are not completely preserved, then the second file is used to replace the first file. A file, saving the replaced first file in the first storage device. The offline transaction device replaces the file with successful verification with the file with failed verification, the file with incomplete offline transaction records is replaced with the file with complete offline transaction records, the offline transaction records in the first file and the second file The offline transaction records in are complete and consistent.
在一个实施例中,脱机交易设备根据脱机交易记录文件的完整性校验结果替换脱机交易记录文件的内容,可以替换脱机交易记录文件中的脱机交易记录,也可以替换脱机交易记录文件中的脱机交易记录和校验码,还可以直接将脱机交易记录文件替换。例如,如果第一文件校验成功且第二文件校验失败,脱机交易设备可以利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,也可以利用第一文件中的脱机交易记录和第一校验码分别替换第二文件中的脱机交易记录和第二校验码,还可以将第一文件直接替换第二文件。脱机交易设备直接替换脱机交易记录文件的方法较为简单。In one embodiment, the offline transaction device replaces the content of the offline transaction record file according to the integrity check result of the offline transaction record file, and can replace the offline transaction record in the offline transaction record file, or replace the offline transaction record file. Offline transaction records and verification codes in the transaction record file can also directly replace the offline transaction record file. For example, if the verification of the first file succeeds and the verification of the second file fails, the offline transaction device can use the offline transaction records in the first file to replace the offline transaction records in the second file, or use the offline transaction records in the first file The offline transaction record and the first verification code in the second file respectively replace the offline transaction record and the second verification code in the second file, and the first file can also directly replace the second file. It is relatively simple to directly replace the offline transaction record file with the offline transaction device.
本实施例中,脱机交易设备的存储装置包括第一存储装置和第二存储装置,存储装置中包括脱机交易记录文件,脱机交易记录文件包括第一文件和第二文件,其中,第一文件存储在第一存储装置中,第二文件存储在第二存储装置中。脱机交易设备对第一文件和第二文件分别进行完整性校验,若第一文件校验成功且第二文件校验失败,则利用第一文件的脱机交易记录替换第二文件的脱机交易记录,在第二存储装置中保存替换后的第二文件,反之亦可。脱机交易设备通过第一存储装置和第二存储装置分别存储脱机交易记录,降低了存储装置故障的可能性。通过对第一文件和第二文件进行完整性校验,可以发现脱机交易记录是否完整。通过将校验成功的文件中的脱机交易记录替换校验失败的文件中的脱机交易记录,使第一文件中的脱机交易记录和第二文件中的脱机交易记录完整、一致,进一步提高脱机交易记录的完整性。In this embodiment, the storage device of the offline transaction device includes a first storage device and a second storage device, the storage device includes an offline transaction record file, and the offline transaction record file includes a first file and a second file, wherein the first A file is stored in the first storage device, and a second file is stored in the second storage device. The offline transaction device performs integrity verification on the first file and the second file respectively. If the verification of the first file succeeds and the verification of the second file fails, the offline transaction record of the first file is used to replace the offline transaction record of the second file. machine transaction records, save the replaced second file in the second storage device, and vice versa. The off-line transaction equipment respectively stores off-line transaction records through the first storage device and the second storage device, which reduces the possibility of failure of the storage devices. By checking the integrity of the first file and the second file, it can be found whether the offline transaction records are complete. By replacing the offline transaction record in the file with successful verification with the offline transaction record in the file with failed verification, the offline transaction record in the first file and the offline transaction record in the second file are complete and consistent, Further improve the integrity of offline transaction records.
在一个实施例中,对第一文件和第二文件分别进行完整性校验的步骤之后,还包括:若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度;对第一文件长度和第二文件长度进行一致性校验。In one embodiment, after the step of checking the integrity of the first file and the second file respectively, it further includes: if both the first file and the second file are verified successfully, then obtaining the length of the first file and the length of the second file length; check the consistency between the length of the first file and the length of the second file.
脱机交易设备向存储装置写入脱机交易记录之前,如果其中一个脱机交易记录文件中已经存有脱机交易记录,而另一个脱机交易记录文件中没有脱机交易记录,那么,向两个脱机交易记录文件分别写入脱机交易记录的情况下,第一文件和第二文件均能通过完整性校验,但是两个脱机交易记录文件中保存的脱机交易记录不一致。因此,脱机交易设备需要进一步对第一文件和第二文件进行比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。Before the offline transaction device writes offline transaction records to the storage device, if there are offline transaction records in one of the offline transaction record files, but there is no offline transaction record in the other offline transaction record file, then the When the two offline transaction record files are respectively written into the offline transaction records, both the first file and the second file can pass the integrity check, but the offline transaction records stored in the two offline transaction record files are inconsistent. Therefore, the offline transaction device needs to further compare the first file with the second file, including comparing the length of the first file with the length of the second file, and comparing the content of the first file with the content of the second file.
具体地,如果第一文件和第二文件均校验成功,脱机交易设备对第一文件长度和第二文件长度进行比较。如果第一文件长度大于第二文件长度,说明第一文件中的脱机交易记录多于第二文件中的脱机交易记录,为了完整保存脱机交易记录,脱机交易设备利用脱机交易记录较多的文件替换脱机交易记录较少的文件,即第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。反之,如果第一文件长度小于第二文件长度,说明第一文件中的脱机交易记录少于第二文件中的脱机交易记录,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。由此,将脱机交易记录较少的脱机交易记录文件替换成了脱机交易记录较多的脱机交易记录文件,第一文件中的脱机交易记录和第二文件中的脱机交易记录达到了一致,提高第一文件中的脱机交易记录和第二文件中的脱机交易记录的准确性。Specifically, if both the first file and the second file are verified successfully, the offline transaction device compares the length of the first file with the length of the second file. If the length of the first file is greater than the length of the second file, it means that the offline transaction records in the first file are more than the offline transaction records in the second file. In order to completely save the offline transaction records, the offline transaction device uses the offline transaction records More files replace files with less offline transaction records, that is, offline transaction records in the first file replace offline transaction records in the second file, and the replaced second file is saved in the second storage device. Conversely, if the length of the first file is smaller than the length of the second file, it means that the offline transaction records in the first file are less than the offline transaction records in the second file, then use the offline transaction records in the second file to replace the first file In the offline transaction record, save the replaced first file in the first storage device. Thus, the offline transaction record file with less offline transaction records is replaced with the offline transaction record file with more offline transaction records, the offline transaction records in the first file and the offline transaction records in the second file The records are aligned, improving the accuracy of the offline transaction records in the first file and the offline transaction records in the second file.
如果第一文件长度等于第二文件长度,脱机交易设备对第一文件的内容和第二文件的内容进行比较。如果第二存储装置为外存储装置,在对脱机交易记录进行校验之前,脱机交易设备的外存储装置被工作人员取出,由于工作人员疏忽,原来的脱机交易设备的外存储装置被替换成了其他脱机交易设备中的外存储装置。如果替换后的外存储装置中的脱机交易记录保存完整,也可以通过完整性校验、且替换后的外存储装置中的第二文件长度和内存储装置中的第一文件长度一致,但是原来的外存储装置中的脱机交易记录与替换后的外存储装置中的脱机交易记录不同。在这种情况下,脱机交易设备需要对第一文件中的内容和第二文件中的内容进行比较。If the length of the first file is equal to the length of the second file, the off-line transaction device compares the content of the first file with the content of the second file. If the second storage device is an external storage device, before the offline transaction records are verified, the external storage device of the offline transaction device is taken out by the staff, and due to the negligence of the staff, the original external storage device of the offline transaction device is taken out. Replaced with external storage in other off-line transaction devices. If the offline transaction record in the replaced external storage device is kept intact, it can also pass the integrity check, and the second file length in the replaced external storage device is consistent with the first file length in the internal storage device, but The offline transaction records in the original external storage device are different from the offline transaction records in the replaced external storage device. In this case, the offline transaction device needs to compare the content in the first file with the content in the second file.
具体地,如果第一文件长度等于第二文件长度,说明第一文件中的脱机交易记录和第二文件中的脱机交易记录一样多,脱机交易设备对第一文件的内容和第二文件的内容是进行比较:如果第一文件中的内容和第二文件中的内容一致,说明第一文件中的脱机交易记录和第二文件中的脱机交易记录一致,则在第一存储装置中保存第一文件,在第二存储装置中保存第二文件。如果第一文件的内容和第二文件的内容不一致,即第一文件中的脱机交易记录或第二文件中的脱机交易记录出错。脱机交易设备利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录。优选地,第一存储装置可以是内存储装置,第二存储装置可以是外存储装置,由于内存储装置存储的脱机交易记录比外存储装置的脱机交易记录准确,将内存储装置的脱机交易记录替换外存储装置的脱机交易记录,即将第一文件中的脱机交易记录替换第二文件的脱机交易记录,在第二存储装置中保存替换后的第二文件。通过对第一文件的内容和第二文件的内容进行比较,将内存储装置中的脱机交易记录替换成了外存储装置中的脱机交易记录,进一步提高脱机交易记录的准确性,第一存储装置中保存的第一文件和第二存储装置中保存的第二文件达到了一致。Specifically, if the length of the first file is equal to the length of the second file, it means that there are as many offline transaction records in the first file as there are offline transaction records in the second file, and the offline transaction device compares the contents of the first file with the second The content of the file is compared: if the content in the first file is consistent with the content in the second file, it means that the offline transaction records in the first file are consistent with the offline transaction records in the second file, then the first storage The first file is saved in the device, and the second file is saved in the second storage device. If the content of the first file is inconsistent with the content of the second file, that is, the offline transaction record in the first file or the offline transaction record in the second file is wrong. The offline transaction facility replaces the offline transaction records in the second file with the offline transaction records in the first file. Preferably, the first storage device can be an internal storage device, and the second storage device can be an external storage device. Since the offline transaction records stored in the internal storage device are more accurate than the offline transaction records of the external storage device, the offline transaction records of the internal storage device The offline transaction record of the external storage device is replaced by the offline transaction record of the external storage device, that is, the offline transaction record of the first file is replaced by the offline transaction record of the second file, and the replaced second file is saved in the second storage device. By comparing the content of the first file with the content of the second file, the offline transaction records in the internal storage device are replaced with the offline transaction records in the external storage device, so as to further improve the accuracy of the offline transaction records. The first file stored in a storage device is consistent with the second file stored in the second storage device.
本实施例中,在第一文件和第二文件均校验成功的情况下,脱机交易设备对第一文件和第二文件进行进一步比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。通过对第一文件长度和第二文件长度进行比较,将脱机交易记录较多的文件替换脱机交易记录较少的文件,提高脱机交易记录的准确性。通过对第一文件的内容和第二文件的内容进行比较,进一步提高脱机交易记录文件的准确性。In this embodiment, when both the first file and the second file are verified successfully, the offline transaction device further compares the first file with the second file, including comparing the length of the first file with the length of the second file , Comparing the content of the first file with the content of the second file. By comparing the length of the first file with the length of the second file, the file with more offline transaction records is replaced with the file with less offline transaction records, thereby improving the accuracy of offline transaction records. By comparing the content of the first file with the content of the second file, the accuracy of the offline transaction record file is further improved.
在一个实施例中,第一文件还包括第一校验码,完整性校验包括对第一文件长度进行校验,对第一文件长度进行校验的步骤,包括:获取第一文件长度;获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;获取校验码字节数,校验码字节数包括第一校验码占用的字节;通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;判断第一文件中的脱机交易记录条数是否为正整数;若不是,则第一文件校验失败。In one embodiment, the first file further includes a first check code, the integrity check includes checking the length of the first file, and the step of checking the length of the first file includes: obtaining the length of the first file; Obtain the number of bytes of a single offline transaction record, the number of bytes of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file; obtain the number of bytes of the verification code, the number of bytes of the verification code includes the number of bytes occupied by the first file Bytes occupied by a check code; calculate the number of offline transaction records in the first file through the number of bytes of a single offline transaction record, the number of bytes of the check code, and the length of the first file; determine the number of offline transaction records in the first file Whether the number of offline transaction records is a positive integer; if not, the first file verification fails.
第一文件包括脱机交易记录和第一验证码,第二文件包括脱机交易记录和第二校验码。脱机交易设备将脱机交易记录写入第一存储装置时,利用密钥和第一文件中的脱机交易记录生成第一校验码;脱机交易设备将脱机交易记录写入第二存储装置时,利用密钥和第二文件中的脱机交易记录生成第二校验码。脱机交易设备将单条脱机交易记录占用字节记录为单条脱机交易记录字节数;脱机交易设备将校验码占用字节记录为校验码字节数。当脱机交易设备将脱机交易记录写入脱机交易记录文件时,脱机交易记录占用单条脱机交易记录字节数,脱机交易记录文件长度增加相应的字节。因此,随着脱机交易记录增加,脱机交易记录文件长度以单条脱机交易记录字节数增加。通过脱机交易记录文件长度可以计算得到脱机交易记录条数。当脱机交易设备向脱机交易记录文件写入脱机交易记录时,如果脱机交易设备断电,则脱机交易设备无法继续将该条脱机交易记录完整的写入脱机交易记录文件,该条脱机交易记录没有占用完整的单条脱机交易记录字节数,导致脱机交易记录文件中的该条脱机交易记录不完整。为了确保脱机交易记录文件中的单条脱机交易记录完整,脱机交易设备需要对脱机交易记录文件长度进行校验。脱机交易设备对脱机交易记录文件长度进行校验包括对第一文件长度进行校验和对第二文件长度进行校验。The first file includes offline transaction records and a first verification code, and the second file includes offline transaction records and a second verification code. When the offline transaction device writes the offline transaction record into the first storage device, it uses the key and the offline transaction record in the first file to generate the first verification code; the offline transaction device writes the offline transaction record into the second When the storage device is used, the second verification code is generated using the key and the offline transaction records in the second file. The offline transaction device records the bytes occupied by a single offline transaction record as the number of bytes of a single offline transaction record; the offline transaction device records the bytes occupied by the verification code as the number of bytes of the verification code. When the offline transaction device writes the offline transaction record into the offline transaction record file, the offline transaction record occupies the number of bytes of a single offline transaction record, and the length of the offline transaction record file increases by the corresponding bytes. Therefore, as the offline transaction records increase, the offline transaction record file length increases by the number of bytes of a single offline transaction record. The number of offline transaction records can be calculated by the length of the offline transaction record file. When the offline transaction device writes the offline transaction record to the offline transaction record file, if the offline transaction device is powered off, the offline transaction device cannot continue to write the offline transaction record completely into the offline transaction record file , the offline transaction record does not occupy the complete number of bytes of a single offline transaction record, resulting in incomplete offline transaction record in the offline transaction record file. In order to ensure the integrity of a single offline transaction record in the offline transaction record file, the offline transaction device needs to verify the length of the offline transaction record file. Checking the length of the offline transaction record file by the offline transaction device includes checking the length of the first file and checking the length of the second file.
具体地,脱机交易设备对第一文件长度进行校验,首先,脱机交易设备获取第一文件长度、单条脱机交易记录字节数和校验码字节数。其次,脱机交易设备通过脱机交易记录文件长度、单条脱机交易记录字节数和校验码字节数计算脱机交易记录条数。具体地,脱机交易设备利用脱机交易记录文件长度和校验码字节数计算脱机交易记录文件长度减去校验码字节数的结果,利用该结果除以单条脱机交易记录字节数,即得到脱机交易记录条数。然后,判断脱机交易记录条数是否为正整数,如果脱机交易记录条数不是正整数,说明脱机交易记录文件中存在单条脱机交易记录不完整,则该脱机交易记录文件校验失败。通过脱机交易记录文件长度计算脱机交易记录条数,可以检测出脱机交易记录文件中是否包括不完整的脱机交易记录,初步判断第一文件中的脱机交易记录存储的完整性。Specifically, the offline transaction device verifies the length of the first file. First, the offline transaction device obtains the first file length, the number of bytes of a single offline transaction record, and the number of bytes of a verification code. Secondly, the offline transaction device calculates the number of offline transaction records based on the length of the offline transaction record file, the number of bytes of a single offline transaction record and the number of bytes of the verification code. Specifically, the offline transaction device uses the length of the offline transaction record file and the number of bytes of the verification code to calculate the result of subtracting the length of the offline transaction record file from the number of bytes of the verification code, and divides the result by the number of bytes of the single offline transaction record. The number of nodes, that is, the number of offline transaction records obtained. Then, judge whether the number of offline transaction records is a positive integer, if the number of offline transaction records is not a positive integer, it means that there is a single offline transaction record in the offline transaction record file that is incomplete, then the offline transaction record file is verified fail. By calculating the number of offline transaction records based on the length of the offline transaction record file, it is possible to detect whether the offline transaction record file includes incomplete offline transaction records, and preliminarily judge the integrity of the offline transaction record storage in the first file.
可以理解地,脱机交易设备可以按照上述方式对第二文件长度进行校验,通过脱机交易记录文件长度计算脱机交易记录条数,可以检测出脱机交易记录文件中是否包括不完整的脱机交易记录,初步判断第二文件中的脱机交易记录存储的完整性。Understandably, the offline transaction device can check the length of the second file according to the above method, calculate the number of offline transaction records according to the length of the offline transaction record file, and detect whether the offline transaction record file includes incomplete Offline transaction records, preliminarily judge the integrity of offline transaction records stored in the second file.
本实施例中,脱机交易设备利用脱机交易记录文件长度、单条脱机交易记录字节数以及校验码字节数准确计算出脱机交易记录条数,通过判断脱机交易记录条数是否为正整数,初步确定脱机交易记录文件中的脱机交易记录是否完整。In this embodiment, the offline transaction device accurately calculates the number of offline transaction records by using the length of the offline transaction record file, the number of bytes of a single offline transaction record, and the number of bytes of the verification code. By judging the number of offline transaction records Whether it is a positive integer, preliminarily determines whether the offline transaction records in the offline transaction record file are complete.
在一个实施例中,第一文件还包括第一校验码,完整性校验包括对校验码进行校验,对校验码进行校验包括对第一校验码进行校验的步骤,包括:获取预设的密钥;通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;若不相等,则第一文件校验失败。In one embodiment, the first file further includes a first verification code, the integrity verification includes verifying the verification code, and verifying the verification code includes a step of verifying the first verification code, Including: obtaining a preset key; calculating the first integrity check code corresponding to the first file through the key and the offline transaction record in the first file; judging whether the first check code of the first file is consistent with the first The first integrity check codes corresponding to the files are equal; if they are not equal, the first file check fails.
脱机交易设备通过对脱机交易记录文件长度进行校验,确定了脱机交易记录文件中脱机交易记录条数为正整数,初步判断了的完整性。但是当脱机交易设备在写入脱机交易记录时发生断电,且断电前未写完的脱机交易记录字节数刚好等于校验码字节数时,脱机交易记录文件仍然能够通过对脱机交易记录文件长度进行的校验。因此,脱机交易设备通过对脱机交易记录文件长度进行校验之后,需要进一步对脱机交易记录文件进行校验。脱机交易记录文件中的校验码是通过脱机交易记录和密钥计算得到的,校验码中包括与脱机交易记录相关的信息,与脱机交易记录的内容完全不同。因此,脱机交易设备可以通过对脱机交易记录文件的校验码进行校验,进一步检测脱机交易记录是否完整,更准确的判断脱机交易记录的完整性。The offline transaction device checks the length of the offline transaction record file to determine that the number of offline transaction records in the offline transaction record file is a positive integer, and preliminarily judges the integrity. However, when the offline transaction device is powered off when writing offline transaction records, and the number of bytes of unfinished offline transaction records is just equal to the number of check code bytes, the offline transaction record files can still be saved. By checking the length of the offline transaction log file. Therefore, after the offline transaction device has verified the length of the offline transaction record file, it needs to further verify the offline transaction record file. The verification code in the offline transaction record file is calculated from the offline transaction record and the key, and the verification code includes information related to the offline transaction record, which is completely different from the content of the offline transaction record. Therefore, the offline transaction device can further detect whether the offline transaction record is complete by verifying the verification code of the offline transaction record file, and judge the integrity of the offline transaction record more accurately.
脱机交易设备从后台获取预设的密钥。当脱机交易设备向脱机交易记录文件写入脱机交易记录、或者对脱机交易记录文件中的校验码进行校验时,利用脱机交易记录文件中的脱机交易记录和密钥计算校验码。例如,脱机交易设备可以将脱机交易记录和密钥按照HMAC-SHA256算法计算得到校验码。脱机交易设备每次向第一文件写入一条脱机交易记录时,脱机交易设备利用当前第一文件中所有的脱机交易记录和密钥计算第一校验码。当前计算得到的第一校验码覆盖上一次计算得到的第一校验码。可以理解地,第二文件中的第二校验码也可以以类似方式计算得到。The offline transaction device obtains the preset key from the background. When the offline transaction device writes offline transaction records to the offline transaction record file, or verifies the verification code in the offline transaction record file, the offline transaction record and key in the offline transaction record file are used Calculate the checksum. For example, the offline transaction device can calculate the verification code according to the HMAC-SHA256 algorithm from the offline transaction record and the key. Every time the offline transaction device writes an offline transaction record to the first file, the offline transaction device uses all the current offline transaction records and keys in the first file to calculate the first verification code. The currently calculated first check code overwrites the last calculated first check code. Understandably, the second check code in the second file can also be calculated in a similar manner.
脱机交易设备对第一文件中的第一校验码进行校验时,首先获取密钥和第一文件中的全部脱机交易记录。其次,通过密钥和全部脱机交易记录计算第一文件的第一完整性校验码。判断第一校验码是否与第一完整性校验码相等。如果第一校验码与第一完整性校验码相等,表示第一校验码包含的脱机交易记录信息和第一完整性校验码包含的脱机交易记录信息一致,第一文件校验成功。如果第一校验码和第一完整性校验码不相等,表示第一校验码包含的脱机交易记录信息和第一完整性校验码包含的脱机交易记录信息不一致,则第一文件中的脱机交易记录不完整,第一文件校验失败。同样地,脱机交易设备可以利用上述方式对第二文件的第一完整性校验码进行校验码校验,不再赘述。脱机交易设备通过对脱机交易记录文件中的校验码进行校验,进一步确定了脱机交易记录的完整性。When the offline transaction device verifies the first verification code in the first file, it first obtains the key and all offline transaction records in the first file. Second, the first integrity check code of the first file is calculated by using the key and all offline transaction records. It is judged whether the first check code is equal to the first integrity check code. If the first verification code is equal to the first integrity verification code, it means that the offline transaction record information contained in the first verification code is consistent with the offline transaction record information contained in the first integrity verification code, and the first file verification code The test was successful. If the first verification code and the first integrity verification code are not equal, it means that the offline transaction record information contained in the first verification code is inconsistent with the offline transaction record information contained in the first integrity verification code, then the first The offline transaction records in the file are incomplete, and the first file verification failed. Similarly, the offline transaction device can use the above method to perform verification code verification on the first integrity verification code of the second file, which will not be repeated here. The offline transaction device further confirms the integrity of the offline transaction record by verifying the verification code in the offline transaction record file.
本实施例中,脱机交易设备利用密钥和第一文件中的脱机交易记录计算得到第一完整性校验码,通过对比第一校验码和第一完整性校验码,进一步确定第一文件中的脱机交易记录的完整性。利用密钥和第二文件中的脱机交易记录计算得到第二完整性校验码,通过比对第二校验码和第二完整性校验码,进一步确定第二文件中的脱机交易记录的完整性。In this embodiment, the offline transaction device calculates the first integrity check code by using the key and the offline transaction record in the first file, and further determines by comparing the first check code with the first integrity check code Integrity of offline transactions in the first file. Calculate the second integrity check code by using the key and the offline transaction record in the second file, and further determine the offline transaction in the second file by comparing the second check code with the second integrity check code Integrity of records.
在一个实施例中,第一存储装置为内存储装置,第二存储装置为外存储装置,对第一文件长度和第二文件长度进行一致性校验的步骤包括:若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。In one embodiment, the first storage device is an internal storage device, and the second storage device is an external storage device, and the step of checking the consistency of the first file length and the second file length includes: if the first file length is greater than the second file length Two file lengths, use the offline transaction records in the first file to replace the offline transaction records in the second file; if the first file length is equal to the second file length and the content is inconsistent, use the offline transaction records in the first file The records replace the offline transaction records in the second file; if the length of the first file is smaller than the length of the second file, the offline transaction records in the second file are used to replace the offline transaction records in the first file.
脱机交易设备向存储装置写入脱机交易记录之前,如果其中一个脱机交易记录文件中已经存有脱机交易记录,而另一个脱机交易记录文件中没有脱机交易记录,那么,脱机交易设备向两个脱机交易记录文件分别写入脱机交易记录的情况下,第一文件和第二文件均能通过完整性校验,但是两个脱机交易记录文件中保存的脱机交易记录不一致。因此,脱机交易设备需要进一步对第一文件和第二文件进行比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。Before the offline transaction device writes offline transaction records to the storage device, if there are offline transaction records in one of the offline transaction record files, but there is no offline transaction record in the other offline transaction record file, then the offline When the machine-based transaction device writes offline transaction records to two offline transaction record files, both the first file and the second file can pass the integrity check, but the offline transaction records saved in the two offline transaction record files Transaction records are inconsistent. Therefore, the offline transaction device needs to further compare the first file with the second file, including comparing the length of the first file with the length of the second file, and comparing the content of the first file with the content of the second file.
具体地,第一文件和第二文件均校验成功,脱机交易设备对第一文件长度和第二文件长度进行比较。如果第一文件长度大于第二文件长度,说明第一文件中的脱机交易记录多于第二文件中的脱机交易记录,为了完整保存脱机交易记录,脱机交易设备利用脱机交易记录较多的文件替换脱机交易记录较少的文件,即第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。反之,如果第一文件长度小于第二文件长度,说明第一文件中的脱机交易记录少于第二文件中的脱机交易记录,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。由此,将脱机交易记录较少的脱机交易记录文件替换成了脱机交易记录较多的脱机交易记录文件,第一文件中的脱机交易记录和第二文件中的脱机交易记录达到了一致,提高第一文件中的脱机交易记录和第二文件中的脱机交易记录的准确性。Specifically, both the first file and the second file are verified successfully, and the offline transaction device compares the length of the first file with the length of the second file. If the length of the first file is greater than the length of the second file, it means that the offline transaction records in the first file are more than the offline transaction records in the second file. In order to completely save the offline transaction records, the offline transaction device uses the offline transaction records More files replace files with less offline transaction records, that is, offline transaction records in the first file replace offline transaction records in the second file, and the replaced second file is saved in the second storage device. Conversely, if the length of the first file is smaller than the length of the second file, it means that the offline transaction records in the first file are less than the offline transaction records in the second file, then use the offline transaction records in the second file to replace the first file In the offline transaction record, save the replaced first file in the first storage device. Thus, the offline transaction record file with less offline transaction records is replaced with the offline transaction record file with more offline transaction records, the offline transaction records in the first file and the offline transaction records in the second file The records are aligned, improving the accuracy of the offline transaction records in the first file and the offline transaction records in the second file.
如果第一文件长度等于第二文件长度,脱机交易设备对第一文件的内容和第二文件的内容进行比较。如果第二存储装置为外存储装置,在对脱机交易记录进行校验之前,脱机交易设备的外存储装置被工作人员取出,由于工作人员疏忽,原来的脱机交易设备的外存储装置被替换成了其他脱机交易设备中的外存储装置。如果替换后的外存储装置中的脱机交易记录保存完整,则替换后的外存储装置中的第二文件也可以通过完整性校验、且第二文件长度和内存储装置中的第一文件长度一致,但是替换后的外存储装置中的脱机交易记录和原来的外存储装置中的脱机交易记录并不相同。在这种情况下,脱机交易设备需要对第一文件中的内容和第二文件中的内容进行比较。If the length of the first file is equal to the length of the second file, the off-line transaction device compares the content of the first file with the content of the second file. If the second storage device is an external storage device, before the offline transaction records are verified, the external storage device of the offline transaction device is taken out by the staff, and due to the negligence of the staff, the original external storage device of the offline transaction device is taken out. Replaced with external storage in other off-line transaction devices. If the offline transaction records in the replaced external storage device are kept intact, the second file in the replaced external storage device can also pass the integrity check, and the length of the second file is the same as that of the first file in the internal storage device. The lengths are the same, but the offline transaction records in the replaced external storage device are different from the offline transaction records in the original external storage device. In this case, the offline transaction device needs to compare the content in the first file with the content in the second file.
具体地,如果第一文件长度等于第二文件长度,说明第一文件中的脱机交易记录和第二文件中的脱机交易记录一样多,脱机交易设备对第一文件的内容和第二文件的内容进行比较:如果第一文件中的内容和第二文件中的内容一致,说明第一文件中的脱机交易记录和第二文件中的脱机交易记录一致,则在第一存储装置中保存第一文件,在第二存储装置中保存第二文件。如果第一文件的内容和第二文件的内容不一致,即第一文件中的脱机交易记录或第二文件中的脱机交易记录出错。脱机交易设备利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。优选地,第一存储装置可以是内存储装置,第二存储装置可以是外存储装置,由于内存储装置存储的脱机交易记录比外存储装置准确,将内存储装置的脱机交易记录替换外存储装置的脱机交易记录。也就是说,将第一文件中的脱机交易记录替换第二文件的脱机交易记录,在第二存储装置中保存替换后的第二文件。通过对第一文件的内容和第二文件的内容进行比较,将外存储装置中的脱机交易记录替换成了内存储装置中的脱机交易记录,进一步提高脱机交易记录的准确性,第一存储装置中保存的第一文件和第二存储装置中保存的第二文件达到了一致。Specifically, if the length of the first file is equal to the length of the second file, it means that there are as many offline transaction records in the first file as there are offline transaction records in the second file, and the offline transaction device compares the contents of the first file with the second The content of the file is compared: if the content in the first file is consistent with the content in the second file, it means that the offline transaction record in the first file is consistent with the offline transaction record in the second file, then the first storage device The first file is saved in the storage device, and the second file is saved in the second storage device. If the content of the first file is inconsistent with the content of the second file, that is, the offline transaction record in the first file or the offline transaction record in the second file is wrong. The offline transaction device replaces the offline transaction records in the second file with the offline transaction records in the first file, and saves the replaced second file in the second storage device. Preferably, the first storage device can be an internal storage device, and the second storage device can be an external storage device. Since the offline transaction records stored in the internal storage device are more accurate than the external storage device, the offline transaction records of the internal storage device are replaced by the external storage device. Offline transaction records for storage devices. That is to say, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced second file is saved in the second storage device. By comparing the content of the first file with the content of the second file, the offline transaction records in the external storage device are replaced with the offline transaction records in the internal storage device, so as to further improve the accuracy of the offline transaction records. The first file stored in a storage device is consistent with the second file stored in the second storage device.
在其中一个实施例中,对第一文件的内容和第二文件的内容进行比较的步骤,可以通过比对第一文件中的脱机交易记录和第二文件中的脱机交易记录判断第一文件的内容和第二文件的内容是否一致。如果第一文件中的脱机交易记录和第二文件中的脱机交易记录一致,则第一文件的内容和第二文件的内容一致。也可以通过比对第一文件中的脱机交易记录和第二文件中的脱机交易记录、比对第一文件中的第一校验码和第二文件中的第二校验码,判断第一文件的内容和第二文件的内容是否一致,如果第一文件中的脱机交易记录和第二文件中的脱机交易记录一致且第一校验码和第二校验码一致,则第一文件的内容和第二文件的内容一致。比对脱机交易记录和校验码两项内容的结果更准确。In one of the embodiments, in the step of comparing the content of the first file and the content of the second file, it can be determined by comparing the offline transaction records in the first file and the offline transaction records in the second file Whether the content of the file is consistent with the content of the second file. If the offline transaction record in the first file is consistent with the offline transaction record in the second file, then the content of the first file is consistent with the content of the second file. It can also be judged by comparing the offline transaction record in the first file with the offline transaction record in the second file, comparing the first check code in the first file with the second check code in the second file Whether the content of the first file is consistent with the content of the second file, if the offline transaction record in the first file is consistent with the offline transaction record in the second file and the first check code is consistent with the second check code, then The content of the first file is consistent with the content of the second file. It is more accurate than the results of offline transaction records and checksums.
在一个实施例中,脱机交易设备替换脱机交易记录文件中的内容,可以替换脱机交易记录文件中的脱机交易记录,也可以替换脱机交易记录文件中的脱机交易记录和校验码,还可以直接将脱机交易记录文件替换。例如,如果第一文件校验成功且第二文件校验失败,脱机交易设备可以利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,也可以利用第一文件中的脱机交易记录和第一校验码分别替换第二文件中的脱机交易记录和第二校验码,还可以将第一文件直接替换第二文件。脱机交易设备直接替换脱机交易记录文件较为简单。In one embodiment, the offline transaction device replaces the content in the offline transaction record file, can replace the offline transaction record in the offline transaction record file, and can also replace the offline transaction record and proofreading in the offline transaction record file. Code verification, you can also directly replace the offline transaction record file. For example, if the verification of the first file succeeds and the verification of the second file fails, the offline transaction device can use the offline transaction records in the first file to replace the offline transaction records in the second file, or use the offline transaction records in the first file The offline transaction record and the first verification code in the second file respectively replace the offline transaction record and the second verification code in the second file, and the first file can also directly replace the second file. It is relatively simple for the offline transaction device to directly replace the offline transaction record file.
本实施例中,在第一文件和第二文件均校验成功的情况下,脱机交易设备对第一文件和第二文件进行进一步比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。通过对第一文件长度和第二文件长度进行比较,将脱机交易记录较多的文件替换脱机交易记录较少的文件,提高脱机交易记录的准确性。通过对第一文件的内容和第二文件的内容进行比较,进一步提高脱机交易记录文件的准确性。In this embodiment, when both the first file and the second file are verified successfully, the offline transaction device further compares the first file with the second file, including comparing the length of the first file with the length of the second file , Comparing the content of the first file with the content of the second file. By comparing the length of the first file with the length of the second file, the file with more offline transaction records is replaced with the file with less offline transaction records, thereby improving the accuracy of offline transaction records. By comparing the content of the first file with the content of the second file, the accuracy of the offline transaction record file is further improved.
在一个实施例中,当通过脱机交易设备首次发生脱机交易时,脱机交易设备检测第一存储装置是否包括第一文件,如果第一存储装置中没有第一文件,在第一存储装置中创建第一文件。如果第一文件创建失败,说明第一存储装置故障,脱机交易设备标记第一存储装置故障。同样地,脱机交易设备检测第二存储装置是否包括第二文件,如果第二存储装置中没有第二文件,在第二存储装置中创建第二文件。如果第二文件创建失败,说明第二存储装置故障,脱机交易设备标记第二存储装置故障。如果脱机交易设备发生创建文件失败,生成报警提示。In one embodiment, when an offline transaction occurs for the first time through an offline transaction device, the offline transaction device detects whether the first storage device includes the first file, and if there is no first file in the first storage device, the first file is stored in the first storage device. Create the first file in . If the creation of the first file fails, it indicates that the first storage device is faulty, and the offline transaction device marks the first storage device as faulty. Likewise, the offline transaction device detects whether the second storage device includes the second file, and if there is no second file in the second storage device, creates the second file in the second storage device. If the creation of the second file fails, it indicates that the second storage device is faulty, and the offline transaction device marks the second storage device as faulty. If the offline transaction device fails to create a file, an alarm prompt will be generated.
在一个实施例中,脱机交易记录文件创建成功之后,当发生脱机交易时,脱机交易设备生成新的脱机交易记录,脱机交易设备将脱机交易记录分别写入脱机交易记录文件。首先,脱机交易设备打开脱机交易记录文件,检测脱机交易记录文件中是否包括脱机交易记录。如果脱机交易记录文件中没有脱机交易记录,则将新的脱机交易记录写在脱机交易记录文件的开端。脱机交易设备利用密钥和脱机交易记录文件中的脱机交易记录计算校验码,将校验码写在脱机交易记录之后。如果脱机交易记录文件中已包括脱机交易记录,脱机交易设备检测脱机交易记录文件中的校验码,将新的脱机交易记录插入最后一条脱机交易记录和校验码之间,利用密钥和当前全部脱机交易记录计算新的校验码,替换原来的校验码。由此,脱机交易设备将脱机交易记录写入脱机交易记录文件。In one embodiment, after the offline transaction record file is successfully created, when an offline transaction occurs, the offline transaction device generates a new offline transaction record, and the offline transaction device writes the offline transaction record into the offline transaction record respectively document. First, the offline transaction device opens the offline transaction record file, and detects whether the offline transaction record file includes the offline transaction record. If there is no offline transaction record in the offline transaction log file, a new offline transaction record is written at the beginning of the offline transaction log file. The offline transaction device uses the key and the offline transaction record in the offline transaction record file to calculate the verification code, and writes the verification code after the offline transaction record. If the offline transaction record file already includes an offline transaction record, the offline transaction device detects the verification code in the offline transaction record file, and inserts a new offline transaction record between the last offline transaction record and the verification code , using the key and all current offline transaction records to calculate a new verification code to replace the original verification code. Thus, the offline transaction device writes the offline transaction record into the offline transaction record file.
如果第一存储装置发生写入失败且第二存储装置发生写入失败,说明第一存储装置中的脱机交易记录和第二存储装置中的脱机交易记录均不完整,发出报警提示。如果第一存储装置发生写入失败,第二存储装置未发生写入失败,但是第二文件完整性校验失败,说明第一存储装置中的脱机交易记录和第二存储装置中的脱机交易记录均不完整,发出报警提示。同样地,如果第二存储装置发生写入失败,第一存储装置未发生写入失败,但是第一文件完整性校验失败,说明第一存储装置中的脱机交易记录和第二存储装置中的脱机交易记录均不完整,发出报警提示。如果第一存储装置发生写入失败,第二存储装置未发生写入失败,且第二文件校验成功,说明第一存储装置中的脱机交易记录不完整,但第二存储装置中的脱机交易记录完整,脱机交易设备将第二文件中脱机交易记录替换第一文件中的脱机交易记录,上传后台,发出报警提示。同样地,如果第二存储装置发生写入失败,第一存储装置未发生写入失败,且第一文件校验成功,说明第二存储装置中的脱机交易记录不完整,但第一存储装置中的脱机交易记录完整,脱机交易设备将第一文件中脱机交易记录替换第二文件中的脱机交易记录,上传后台,发出报警提示。通过对存储装置写入故障和脱机交易记录文件完整性校验结果进行分析,及时地将有效脱机交易记录文件上传后台,避免发生交易记录丢失,确保了脱机交易记录完整性。If the first storage device fails to write and the second storage device fails to write, it means that the offline transaction records in the first storage device and the offline transaction records in the second storage device are incomplete, and an alarm is issued. If a write failure occurs in the first storage device and no write failure occurs in the second storage device, but the second file integrity verification fails, it means that the offline transaction records in the first storage device and the offline transaction records in the second storage device The transaction records are incomplete, and an alarm is issued. Similarly, if a write failure occurs in the second storage device and no write failure occurs in the first storage device, but the integrity check of the first file fails, it means that the offline transaction records in the first storage device are different from those in the second storage device. The offline transaction records of are all incomplete, and an alarm prompt is issued. If the first storage device fails to write, the second storage device does not fail to write, and the second file verification succeeds, it means that the offline transaction records in the first storage device are incomplete, but the offline transaction records in the second storage device If the machine transaction record is complete, the offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file, uploads it to the background, and sends out an alarm prompt. Similarly, if a write failure occurs in the second storage device, but no write failure occurs in the first storage device, and the first file verification succeeds, it means that the offline transaction records in the second storage device are incomplete, but the first storage device The offline transaction records in the file are complete, and the offline transaction device replaces the offline transaction records in the first file with the offline transaction records in the second file, uploads them to the background, and sends out an alarm prompt. By analyzing the write failure of the storage device and the integrity verification result of the offline transaction record file, the effective offline transaction record file is uploaded to the background in a timely manner to avoid loss of transaction records and ensure the integrity of the offline transaction records.
在其中一个实施例中,当发生脱机交易时,脱机交易设备可以直接将脱机交易记录写入第一文件和第二文件,在写入的过程中不对第一文件和第二文件进行校验,当脱机交易设备开机或上传脱机交易记录时,对第一文件和第二文件进行校验。脱机交易设备也可以在写脱机交易记录的动作之前,先对第一文件和第二文件进行校验,确定第一装置和第二装置正常、第一文件和第二文件一致之后,向第一文件和第二文件分别写入新的脱机交易记录。每次写入脱机交易记录前对第一文件和第二文件进行校验,可以多次对脱机交易记录进行校验,有效提高脱机交易记录的准确性,出现故障之后脱机交易设备及时发出报警提示,避免脱机交易记录丢失。In one of the embodiments, when an offline transaction occurs, the offline transaction device can directly write the offline transaction record into the first file and the second file, and the first file and the second file are not modified during the writing process. Verifying, verifying the first file and the second file when the offline transaction device is turned on or when the offline transaction record is uploaded. The offline transaction device can also verify the first file and the second file before writing the offline transaction record, and after confirming that the first device and the second device are normal and that the first file and the second file are consistent, send The first file and the second file respectively write new offline transaction records. Verify the first file and the second file before writing offline transaction records each time, and you can verify the offline transaction records multiple times, effectively improving the accuracy of offline transaction records, and offline transaction equipment after failure Send an alarm prompt in time to avoid loss of offline transaction records.
本实施例中,脱机交易设备通过分析存储装置故障和脱机交易记录文件校验结果,将有效的脱机交易记录文件上传后台,发出报警提示,避免发生交易记录丢失,确保了脱机交易记录完整性。In this embodiment, the offline transaction device uploads the valid offline transaction record file to the background by analyzing the failure of the storage device and the verification result of the offline transaction record file, and sends out an alarm prompt to avoid loss of transaction records and ensure offline transaction Record integrity.
在一个实施例中,如图2所示,提供了一种脱机交易记录保存装置,包括:获取模块202、校验模块204、替换模块206、保存模块208,其中:In one embodiment, as shown in FIG. 2 , a device for saving offline transaction records is provided, including: an acquisition module 202, a verification module 204, a replacement module 206, and a preservation module 208, wherein:
获取模块202,用于获取第一存储装置的第一文件,第一文件包括脱机交易记录;获取第二存储装置的第二文件,第二文件包括脱机交易记录。The acquiring module 202 is configured to acquire a first file of the first storage device, the first file includes offline transaction records; acquire a second file of the second storage device, the second file includes offline transaction records.
校验模块204,用于对第一文件和第二文件分别进行完整性校验。The checking module 204 is configured to check the integrity of the first file and the second file respectively.
替换模块206,用于若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。Replacement module 206, for if the first file verification is successful and the second file verification fails, then use the offline transaction record in the first file to replace the offline transaction record in the second file; if the first file verification fails And the verification of the second file is successful, then the offline transaction record in the first file is replaced with the offline transaction record in the second file.
保存模块208,用于在第二存储装置中保存替换后的第二文件;在第一存储装置中保存替换后的第一文件。The saving module 208 is configured to save the replaced second file in the second storage device; save the replaced first file in the first storage device.
在一个实施例中,获取模块202还用于若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度,校验模块204还用于对第一文件长度和第二文件长度进行一致性校验。In one embodiment, the obtaining module 202 is also used to obtain the first file length and the second file length if both the first file and the second file are verified successfully, and the verification module 204 is also used to check the first file length and the second file length. The second file length is checked for consistency.
在一个实施例中,第一文件还包括第一校验码,校验模块204还用于对第一文件长度进行校验,包括:获取第一文件长度;获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;获取校验码字节数,校验码字节数包括第一校验码占用的字节;通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;判断第一文件中的脱机交易记录条数是否为正整数;若不是,则第一文件校验失败。In one embodiment, the first file also includes a first verification code, and the verification module 204 is also used to verify the length of the first file, including: obtaining the length of the first file; obtaining the number of bytes of a single offline transaction record , the number of bytes of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file; the number of bytes of the verification code is obtained, and the number of bytes of the verification code includes the bytes occupied by the first verification code; Calculate the number of offline transaction records in the first file through the number of bytes of a single offline transaction record, the number of bytes of the check code and the length of the first file; determine whether the number of offline transaction records in the first file is positive Integer; if not, the first file check fails.
在一个实施例中,第一文件还包括第一校验码,校验模块204还用于对校验码进行校验,对校验码进行校验包括对第一校验码进行校验,包括:获取预设的密钥;通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;若不相等,则第一文件校验失败。In one embodiment, the first file further includes a first verification code, and the verification module 204 is also configured to verify the verification code, and verifying the verification code includes verifying the first verification code, Including: obtaining a preset key; calculating the first integrity check code corresponding to the first file through the key and the offline transaction record in the first file; judging whether the first check code of the first file is consistent with the first The first integrity check codes corresponding to the files are equal; if they are not equal, the first file check fails.
在一个实施例中,校验模块204还用于对第一文件长度和第二文件长度进行一致性校验,包括:若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。In one embodiment, the checking module 204 is also used to check the consistency of the first file length and the second file length, including: if the first file length is greater than the second file length, using Replace the offline transaction records in the second file with the offline transaction records; if the length of the first file is equal to the length of the second file and the content is inconsistent, use the offline transaction records in the first file to replace the offline transaction records in the second file; If the length of the first file is smaller than the length of the second file, the offline transaction records in the second file are used to replace the offline transaction records in the first file.
在一个实施例中,提供了一种计算机设备,如图3所示,该计算机设备包括存储器、处理器以及存储在存储器上并可在处理器上运行的计算机程序以及数据库等,处理器用于提供计算和控制能力。存储器为计算机程序的运行提供环境。数据库用于存储脱机交易记录以及校验码等。处理器执行计算机程序时实现以下步骤:In one embodiment, a computer device is provided. As shown in FIG. 3 , the computer device includes a memory, a processor, a computer program and a database stored on the memory and operable on the processor, and the processor is used to provide Calculation and control capabilities. Memory provides the environment for the execution of computer programs. The database is used to store offline transaction records and verification codes, etc. The following steps are implemented when the processor executes the computer program:
获取第一存储装置的第一文件,第一文件包括脱机交易记录;Obtain a first file of the first storage device, where the first file includes an offline transaction record;
获取第二存储装置的第二文件,第二文件包括脱机交易记录;Obtaining a second file of the second storage device, the second file includes an offline transaction record;
对第一文件和第二文件分别进行完整性校验;Carrying out integrity verification on the first file and the second file respectively;
若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。If the verification of the first file is successful and the verification of the second file fails, the offline transaction record in the first file is used to replace the offline transaction record in the second file, and the replaced second file is saved in the second storage device ; If the verification of the first file fails and the verification of the second file is successful, the offline transaction record in the second file is used to replace the offline transaction record in the first file, and the first storage device after the replacement is saved in the first storage device. document.
该计算机设备可以用独立的计算机设备或者是多个计算机设备组成的计算机设备集群来实现。本领域技术人员可以理解,图3中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。The computer device can be realized by an independent computer device or a computer device cluster composed of multiple computer devices. Those skilled in the art can understand that the structure shown in Figure 3 is only a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation to the computer equipment on which the solution of the application is applied. The specific computer equipment can be More or fewer components than shown in the figures may be included, or some components may be combined, or have a different arrangement of components.
在一个实施例中,处理器执行计算机程序时还实现以下步骤:In one embodiment, the following steps are also implemented when the processor executes the computer program:
若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度;If both the first file and the second file are verified successfully, the length of the first file and the length of the second file are obtained;
对第一文件长度和第二文件长度进行一致性校验。A consistency check is performed on the length of the first file and the length of the second file.
在一个实施例中,处理器执行计算机程序时还实现以下步骤:In one embodiment, the following steps are also implemented when the processor executes the computer program:
获取第一文件长度;Get the length of the first file;
获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;Obtain the byte count of a single offline transaction record, where the byte count of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file;
获取校验码字节数,校验码字节数包括第一校验码占用的字节;Obtain the number of bytes of the check code, the number of bytes of the check code includes the bytes occupied by the first check code;
通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;Calculate the number of offline transaction records in the first file based on the number of bytes in the single offline transaction record, the number of bytes in the check code and the length of the first file;
判断第一文件中的脱机交易记录条数是否为正整数;Judging whether the number of offline transaction records in the first file is a positive integer;
若不是,则第一文件校验失败。If not, the first file verification fails.
在一个实施例中,处理器执行计算机程序时还实现以下步骤:In one embodiment, the following steps are also implemented when the processor executes the computer program:
获取预设的密钥;Get the preset key;
通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;calculating a first integrity check code corresponding to the first file through the key and the offline transaction record in the first file;
判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;judging whether the first check code of the first file is equal to the first integrity check code corresponding to the first file;
若不相等,则第一文件校验失败。If they are not equal, the first file verification fails.
在一个实施例中,处理器执行计算机程序时还实现以下步骤:In one embodiment, the following steps are also implemented when the processor executes the computer program:
若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the length of the first file is greater than the length of the second file, the offline transaction record in the first file is used to replace the offline transaction record in the second file;
若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the length of the first file is equal to the length of the second file and the content is inconsistent, then the offline transaction record in the first file is used to replace the offline transaction record in the second file;
若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。If the length of the first file is smaller than the length of the second file, the offline transaction records in the second file are used to replace the offline transaction records in the first file.
在一个实施例中,提供了一种计算机可读存储介质,其上存储有计算机程序,计算机程序被处理器执行时实现以下步骤:In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
获取第一存储装置的第一文件,第一文件包括脱机交易记录;Obtain a first file of the first storage device, where the first file includes an offline transaction record;
获取第二存储装置的第二文件,第二文件包括脱机交易记录;Obtaining a second file of the second storage device, the second file includes an offline transaction record;
对第一文件和第二文件分别进行完整性校验;Carrying out integrity verification on the first file and the second file respectively;
若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。If the verification of the first file is successful and the verification of the second file fails, the offline transaction record in the first file is used to replace the offline transaction record in the second file, and the replaced second file is saved in the second storage device ; If the verification of the first file fails and the verification of the second file is successful, the offline transaction record in the second file is used to replace the offline transaction record in the first file, and the first storage device after the replacement is saved in the first storage device. document.
在一个实施例中,计算机程序被处理器执行时还实现以下步骤:In one embodiment, when the computer program is executed by the processor, the following steps are also implemented:
若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度;If both the first file and the second file are verified successfully, the length of the first file and the length of the second file are obtained;
对第一文件长度和第二文件长度进行一致性校验。A consistency check is performed on the length of the first file and the length of the second file.
在一个实施例中,计算机程序被处理器执行时还实现以下步骤:In one embodiment, when the computer program is executed by the processor, the following steps are also implemented:
获取第一文件长度;Get the length of the first file;
获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;Obtain the byte count of a single offline transaction record, where the byte count of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file;
获取校验码字节数,校验码字节数包括第一校验码占用的字节;Obtain the number of bytes of the check code, the number of bytes of the check code includes the bytes occupied by the first check code;
通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;Calculate the number of offline transaction records in the first file based on the number of bytes in the single offline transaction record, the number of bytes in the check code and the length of the first file;
判断第一文件中的脱机交易记录条数是否为正整数;Judging whether the number of offline transaction records in the first file is a positive integer;
若不是,则第一文件校验失败。If not, the first file verification fails.
在一个实施例中,计算机程序被处理器执行时还实现以下步骤:In one embodiment, when the computer program is executed by the processor, the following steps are also implemented:
获取预设的密钥;Get the preset key;
通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;calculating a first integrity check code corresponding to the first file through the key and the offline transaction record in the first file;
判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;judging whether the first check code of the first file is equal to the first integrity check code corresponding to the first file;
若不相等,则第一文件校验失败。If they are not equal, the first file verification fails.
在一个实施例中,计算机程序被处理器执行时还实现以下步骤:In one embodiment, when the computer program is executed by the processor, the following steps are also implemented:
若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the length of the first file is greater than the length of the second file, the offline transaction record in the first file is used to replace the offline transaction record in the second file;
若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the length of the first file is equal to the length of the second file and the content is inconsistent, then the offline transaction record in the first file is used to replace the offline transaction record in the second file;
若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。If the length of the first file is smaller than the length of the second file, the offline transaction records in the second file are used to replace the offline transaction records in the first file.
以上所述实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above-mentioned embodiments can be combined arbitrarily. To make the description concise, all possible combinations of the technical features in the above-mentioned embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, should be considered as within the scope of this specification.
以上所述实施例仅表达了本发明的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干变形和改进,这些都属于本发明的保护范围。因此,本发明专利的保护范围应以所附权利要求为准。The above-mentioned embodiments only express several implementation modes of the present invention, and the descriptions thereof are relatively specific and detailed, but should not be construed as limiting the patent scope of the invention. It should be noted that those skilled in the art can make several modifications and improvements without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the patent for the present invention should be based on the appended claims.
Claims (12)
Priority Applications (2)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710393605.5A CN107239357B (en) | 2017-05-27 | 2017-05-27 | Offline transaction record storing method, device, computer equipment and storage medium |
| PCT/CN2017/102244 WO2018218814A1 (en) | 2017-05-27 | 2017-09-19 | Method for storing off-line transaction record, and computer device and storage medium |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710393605.5A CN107239357B (en) | 2017-05-27 | 2017-05-27 | Offline transaction record storing method, device, computer equipment and storage medium |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN107239357A CN107239357A (en) | 2017-10-10 |
| CN107239357B true CN107239357B (en) | 2019-11-29 |
Family
ID=59984728
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201710393605.5A Active CN107239357B (en) | 2017-05-27 | 2017-05-27 | Offline transaction record storing method, device, computer equipment and storage medium |
Country Status (2)
| Country | Link |
|---|---|
| CN (1) | CN107239357B (en) |
| WO (1) | WO2018218814A1 (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN109857708B (en) * | 2019-02-26 | 2022-12-23 | 上海仰歌电子科技有限公司 | Data access method of embedded system and computer readable storage medium |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102243604A (en) * | 2011-06-28 | 2011-11-16 | 深圳市联祥瑞实业有限公司 | Petty offline transaction record backup method, terminal and backup card |
| CN103646467A (en) * | 2013-12-24 | 2014-03-19 | 拉卡拉支付有限公司 | Off-line transaction data processing method and device of logic encryption card |
| CN103678043A (en) * | 2013-12-26 | 2014-03-26 | 东信和平科技股份有限公司 | Offline terminal transaction data backup method and system used in payment system |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1418423A (en) * | 2000-03-09 | 2003-05-14 | @因特网公司 | Method and system providing advertisement using tone of ringing sounds of mobile phone and commercial transaction service in association with the same |
-
2017
- 2017-05-27 CN CN201710393605.5A patent/CN107239357B/en active Active
- 2017-09-19 WO PCT/CN2017/102244 patent/WO2018218814A1/en not_active Ceased
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN102243604A (en) * | 2011-06-28 | 2011-11-16 | 深圳市联祥瑞实业有限公司 | Petty offline transaction record backup method, terminal and backup card |
| CN103646467A (en) * | 2013-12-24 | 2014-03-19 | 拉卡拉支付有限公司 | Off-line transaction data processing method and device of logic encryption card |
| CN103678043A (en) * | 2013-12-26 | 2014-03-26 | 东信和平科技股份有限公司 | Offline terminal transaction data backup method and system used in payment system |
Also Published As
| Publication number | Publication date |
|---|---|
| CN107239357A (en) | 2017-10-10 |
| WO2018218814A1 (en) | 2018-12-06 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN111880740B (en) | Data processing method, device, computer system and readable storage medium | |
| CN108646982B (en) | Automatic data restoration method and device based on UBIFS | |
| CN109189405A (en) | A kind of method and system of proving program Flash data consistency | |
| CN106708665A (en) | Metadata restoration method and device | |
| CN108573007A (en) | Method, device, electronic device and storage medium for detecting data consistency | |
| CN108664358A (en) | Single-chip microcomputer parameter processing method and system, readable storage medium and terminal equipment | |
| CN111428280A (en) | SoC (System on chip) security chip key information integrity storage and error self-repairing method | |
| CN106168918A (en) | Extended error correction coded data stores | |
| CN105868127A (en) | Data storage method and device and data reading method and device | |
| CN113312205B (en) | Data verification method and device, storage medium and computer equipment | |
| CN120540917A (en) | Hard disk testing method, device, equipment and storage medium | |
| CN119576238A (en) | A method, device, equipment and readable storage medium for determining abnormal blocks | |
| CN105183641B (en) | The data consistency verification method and system of a kind of kernel module | |
| CN107239357B (en) | Offline transaction record storing method, device, computer equipment and storage medium | |
| CN113050887B (en) | Flash memory partition data processing method, device, computer equipment and storage medium | |
| CN103685471B (en) | Method and system for updating software client sides in monopoly mode | |
| CN117391099B (en) | Smart card data download and verification method and system, storage medium | |
| CN114203252A (en) | Bad block detection method, device, equipment and storage medium of nonvolatile memory | |
| CN119883713A (en) | Data reconstruction method, device, equipment, medium and product | |
| CN103870355B (en) | BIOS access system and method | |
| CN101470666A (en) | Data memory method | |
| CN117037892A (en) | Method, system and equipment for testing stability of hard disk | |
| CN103631676B (en) | The snapshot data of a kind of read-only materialized view generates method and device | |
| CN103823637A (en) | Data processing method and data processing device | |
| CN112463019B (en) | Data reading method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |