WO2018218814A1 - Method for storing off-line transaction record, and computer device and storage medium - Google Patents

Method for storing off-line transaction record, and computer device and storage medium Download PDF

Info

Publication number
WO2018218814A1
WO2018218814A1 PCT/CN2017/102244 CN2017102244W WO2018218814A1 WO 2018218814 A1 WO2018218814 A1 WO 2018218814A1 CN 2017102244 W CN2017102244 W CN 2017102244W WO 2018218814 A1 WO2018218814 A1 WO 2018218814A1
Authority
WO
WIPO (PCT)
Prior art keywords
file
offline transaction
transaction record
storage device
length
Prior art date
Application number
PCT/CN2017/102244
Other languages
French (fr)
Chinese (zh)
Inventor
董时舫
谭明富
董江林
林宗平
Original Assignee
百富计算机技术(深圳)有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 百富计算机技术(深圳)有限公司 filed Critical 百富计算机技术(深圳)有限公司
Publication of WO2018218814A1 publication Critical patent/WO2018218814A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/0703Error 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/0793Remedial or corrective actions
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/08Error detection or correction by redundancy in data representation, e.g. by using checking codes

Definitions

  • the present application relates to the field of computer technology, and in particular, to an offline transaction record keeping method, a computer device, and a storage medium.
  • offline transactions are stored locally after the offline transaction is completed.
  • the offline transaction device uploads the offline transaction record to the background. If the offline trading device fails before the offline transaction record is uploaded, there is a high probability that the offline transaction record is incomplete.
  • an offline transaction record saving method a computer device, and a storage medium are provided.
  • An offline transaction record saving method comprising:
  • a computer device including a memory, a processor, and a memory and a processor
  • a computer program running thereon the processor implementing the computer program to implement the following steps:
  • a computer readable storage medium one or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, causing one or more processors Perform the following steps:
  • 1 is a flow chart of a method for saving an offline transaction record in an embodiment
  • FIG. 2 is a schematic structural diagram of an offline transaction record retaining apparatus in an embodiment
  • FIG. 3 is a schematic structural diagram of a computer device in an embodiment.
  • first, second and the like may be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another.
  • both the first user ID and the second user ID are user IDs, but they are not the same user ID.
  • FIG. 1 is a schematic flow chart of a method according to an embodiment of the present application. It should be understood that although the various steps in the flowchart of FIG. 1 are sequentially displayed as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Except as explicitly stated herein, the execution of these steps is not strictly limited, and may be performed in other sequences. Moreover, at least some of the steps in FIG. 1 may include a plurality of sub-steps or stages, which are not necessarily performed at the same time, but may be executed at different times, and the order of execution thereof is not necessarily This may be performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of the other steps.
  • an offline transaction record saving method is provided.
  • the method is applied to an offline transaction device as an example, and specifically includes:
  • Step 102 Acquire a first file of the first storage device, where the first file includes an offline transaction record.
  • Step 104 Acquire a second file of the second storage device, where the second file includes an offline transaction record.
  • the offline transaction device refers to a financial offline transaction device that performs offline transactions in an offline state, and may be a bus on-board toll terminal, a subway toll terminal, or a canteen toll terminal. Partial online trading device It can also be used as an offline transaction device in an offline state, for example, a POS machine (Point of Sales Terminal).
  • POS machine Point of Sales Terminal
  • the offline transaction device in this embodiment may include two or more storage devices, and the storage device includes 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) 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).
  • One of the internal storage devices may be referred to as a first storage device, and one of the external storage devices may be referred to as a second storage device.
  • One of the internal storage devices may also be referred to as a second storage device, and one of the external storage devices is correspondingly referred to as a first storage device.
  • a plurality of files are stored in the storage device, including an offline transaction log file.
  • Offline transaction records are stored in the offline transaction log file.
  • the offline transaction log file includes a first file and a second file, the offline transaction device stores the first file in the first storage device, and the second storage device stores the second file.
  • Offline transaction records include offline transaction information, such as offline transaction time, offline transaction amount, and offline transaction methods.
  • the offline transaction device writes the offline transaction record into the offline transaction record file of the storage device, specifically, the offline transaction record is respectively written into the first file in the first storage device and the second file in the second storage device file.
  • Step 106 Perform integrity verification on the first file and the second file respectively.
  • an offline transaction device When an offline transaction device writes an offline transaction record to an offline transaction log file, if the offline transaction record write fails, the offline transaction record in the offline transaction log file is incomplete. In order to ensure that the offline transaction record is complete, the offline transaction device needs to perform integrity verification on the offline transaction record file, including performing integrity verification on the first file and the second file respectively.
  • the offline transaction device performs integrity verification on the offline transaction record file, including verifying the length of the offline transaction record file and verifying the check code in the offline transaction record file.
  • the offline transaction device can detect partial off by verifying the length of the offline transaction record file.
  • the machine transaction records an incomplete offline transaction log file. For example, when an offline transaction device writes an offline transaction record, the offline transaction device is powered off, and the offline transaction device cannot continue to write the offline transaction record, the offline transaction record file is incomplete.
  • the offline transaction device verifies the offline transaction record file length
  • the offline transaction device obtains the offline transaction record file length, the number of single offline transaction record bytes, and the check code byte number.
  • the offline transaction device calculates the number of offline transaction records by the offline transaction record file length, the number of single offline transaction record bytes, and the check code byte number. Then, it is determined whether the number of offline transaction records is a positive integer. If the number of offline transaction records is not a positive integer, indicating that the offline transaction record is incomplete, the offline transaction record file verification fails. By calculating the number of offline transaction records by the length of the offline transaction record file, it is possible to determine whether the offline transaction record is defective according to the number of offline transaction records, and initially determine the integrity of the offline transaction record.
  • the offline transaction file includes a check code in addition to the offline transaction record. The checksum is generated using offline transactions and pre-stored keys in the offline transaction log file.
  • the first file includes an offline transaction record and a first verification code.
  • the second file includes an offline transaction record and a second check code. After the offline transaction device verifies the offline transaction record file length, it checks the check code in the offline transaction record file.
  • the offline transaction device acquires a preset key, calculates a first integrity check code of the first file by using the key and the offline transaction record in the first file, and determines whether the first check code is the first The integrity check codes are equal. If they are equal, the offline transaction record information included in the first check code is consistent with the offline transaction record information included in the first integrity check code of the first integrity check code, and the integrity check of the first file is successful; If they are not equal, the first integrity check code of the first check code is not the correct check code, but is an incomplete offline transaction record. If the offline transaction record in the first file is incomplete, the first The integrity check of the file failed.
  • the check code includes an offline transaction record attribute, and the offline transaction device further determines the integrity of the offline transaction record in the offline transaction record file by verifying the check code.
  • Step 108 If the first file verification is successful and the second file verification fails, the offline transaction record of the second file is replaced by the offline transaction record of the first file, and the replaced second is saved in the second storage device.
  • File if the first file verification fails and the second file is successfully verified, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced version is saved in the first storage device. a file.
  • the integrity verification result of the first file and the second file is obtained.
  • the integrity check result refers to the result of successful verification or verification failure of the offline transaction record file. If the first file verification is successful and the second file verification fails, the offline transaction record in the first file is saved completely and the offline transaction record in the second file is incompletely saved, and the offline transaction device utilizes the first file. The offline transaction record replaces the offline transaction record in the second file, and the replaced second file is saved in the second storage device. On the other hand, if the second file verification is successful and the first file verification fails, indicating that the offline transaction record in the second file is completely saved and the offline transaction record in the first file is incomplete, the second file is replaced.
  • the offline transaction device replaces the file that failed the verification by the file with the verification success, and the file with the incomplete transaction record is replaced with the complete file of the offline transaction record, the offline transaction record and the second file in the first file.
  • the offline transaction records in the middle are complete and consistent.
  • the offline transaction device replaces the contents of the offline transaction record file according to the integrity check result of the offline transaction record file, and may replace the offline transaction record in the offline transaction record file, or may replace the offline transaction.
  • the offline transaction record and check code in the transaction log file can also directly replace the offline transaction record file. For example, if the first file verification is successful and the second file verification fails, the offline transaction device may replace the offline transaction record in the second file by using the offline transaction record in the first file, or may use the first file.
  • the offline transaction record and the first check code respectively replace the offline transaction record and the second check code in the second file, and the first file can be directly replaced with the second file.
  • the method of directly replacing an offline transaction record file with an offline transaction device is relatively simple.
  • 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 including a first file and a second file, wherein the first file is stored in the first storage device and the 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 first file verification succeeds and the second file verification fails, the offline transaction record of the first file is used to replace the second file.
  • the machine transaction record stores the replaced second file in the second storage device, and vice versa.
  • the offline transaction device stores the offline transaction record by the first storage device and the second storage device, respectively, reducing the possibility of the storage device failure.
  • the method further includes: if the first file and the second file are successfully verified, acquiring the first file length and the second file Length; consistency check for the first file length and the second file length.
  • the offline transaction device Before the offline transaction device writes the offline transaction record to the storage device, if there is an offline transaction record in one of the offline transaction record files, and there is no offline transaction record in the other offline transaction record file, then In the case where two offline transaction log files are respectively written to the offline transaction record, both the first file and the second file can pass the integrity check, but the offline transaction records held in the two offline transaction record files are inconsistent. Therefore, the offline transaction device needs to further compare the first file and the second file, including comparing the first file length and the second file length, comparing the content of the first file and the content of the second file.
  • the offline transaction device compares the first file length with the second file length. If the first file length is greater than the second file length, indicating that the offline transaction record in the first file is more than the offline transaction record in the second file, in order to completely save the offline transaction record, the offline transaction device utilizes the offline transaction record. More files replace the files with fewer offline transaction records, that is, the offline transaction records in the first file replace the offline transaction records in the second file, and the replaced second file is saved in the second storage device. Conversely, if the first file length is less than the second file length, indicating that the offline transaction record in the first file is less than the offline transaction record in the second file, the first file is replaced with the offline transaction record in the second file.
  • Offline transaction record in the first storage Save the first file after replacement.
  • the offline transaction record file with fewer offline transaction records is replaced with the offline transaction record file with more offline transaction records, the offline transaction record in the first file, and the offline transaction in the second file.
  • the records are consistent, improving the accuracy of the offline transaction records in the first file and the offline transaction records in the second file.
  • the offline 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, the external storage device of the offline transaction device is taken out by the staff member before the offline transaction record is verified. Due to the negligence of the staff, the external storage device of the original offline transaction device is Replaced with an external storage device in other offline trading devices. If the offline transaction record in the replaced external storage device is completely saved, the integrity check may be passed, and the second file length in the replaced external storage device is the same as the first file length in the internal storage device, but The offline transaction record in the original external storage device is different from the offline transaction record 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.
  • the offline transaction record in the first file is as much as the offline transaction record in the second file
  • the offline transaction device has the content of the first file and 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, indicating that the offline transaction record in the first file is consistent with the offline transaction record in the second file, then in 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 and the content of the second file are inconsistent, that is, an offline transaction record in the first file or an offline transaction record in the second file is in error.
  • the offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file.
  • the first storage device may be an internal storage device
  • the second storage device may be an external storage device. Since the offline transaction record stored by the internal storage device is more accurate than the offline transaction record of the external storage device, the internal storage device is removed.
  • the machine transaction record replaces the offline transaction record of the external storage device, that is, the offline transaction record in the first file replaces the offline transaction record of the second file, and the replaced second file is saved in the second storage device.
  • the offline transaction record in the internal storage device is replaced with the offline transaction record in the external storage device, thereby further improving the accuracy of the offline transaction record.
  • the first file saved in one storage device and the second file saved in the second storage device are identical.
  • the offline transaction device further compares the first file and 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 the offline transaction record. The accuracy of the offline transaction record file is further improved by comparing the content of the first file with the content of the second file.
  • the first file further includes a first check code
  • the integrity check includes the step of verifying the length of the first file, and the step of verifying the length of the first file, including: acquiring a first file length; Get 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 check code bytes is obtained, and the number of check code bytes includes the number a byte occupied by the check code; calculating the number of offline transaction records in the first file by a single offline transaction record byte number, a check code byte number, and a first file length; determining 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 an offline transaction record and a first verification code
  • the second file includes an offline transaction record and a second verification code.
  • the first verification code is generated by using the key and the offline transaction record in the first file
  • the offline transaction device writes the offline transaction record to the second
  • the second check code is generated using the key and the offline transaction record in the second file.
  • the offline transaction device records a single offline transaction record occupation byte as a single offline transaction record byte number
  • the offline transaction device records the check code occupation byte as the check code byte number.
  • the offline transaction record occupies a single offline transaction record byte number, and the offline transaction record file length increases by the corresponding byte. Therefore, as the offline transaction record increases, the offline transaction record file length increases with the number of single offline transaction record bytes. The number of offline transaction records can be calculated by the offline transaction record file length.
  • an offline transaction device writes an offline transaction record to an offline transaction record file, if the offline transaction device loses power, the offline transaction device cannot continue to completely write the offline transaction record to the offline transaction record file.
  • the offline transaction record does not occupy the complete single offline transaction record byte number, which causes the offline transaction record in the offline transaction record file to be incomplete.
  • the offline transaction device In order to ensure that a single offline transaction record in an offline transaction log file is complete, the offline transaction device needs to verify the length of the offline transaction record file. Offline trading device to offline transaction log file The verification of the length includes checking the length of the first file and verifying the length of the second file.
  • the offline transaction device checks the first file length. First, the offline transaction device acquires the first file length, the number of single offline transaction record bytes, and the check code byte number. Second, the offline transaction device calculates the number of offline transaction records by the offline transaction record file length, the number of single offline transaction record bytes, and the check code byte number. Specifically, the offline transaction device uses the offline transaction record file length and the check code byte number to calculate the offline transaction record file length minus the check code byte number, and divides the result by a single offline transaction record word. The number of sections, that is, the number of offline transaction records. Then, it is determined whether the number of offline transaction records is a positive integer.
  • the offline transaction record file is verified. failure.
  • the offline transaction device can verify the length of the second file in the above manner, calculate the number of offline transaction records by the length of the offline transaction record file, and can detect whether the offline transaction record file includes incomplete
  • the offline transaction record initially determines the integrity of the offline transaction record storage in the second file.
  • 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 single offline transaction record bytes, and the number of check code bytes, and determines the number of offline transaction records. Whether it is a positive integer, initially determine whether the offline transaction record in the offline transaction record file is complete.
  • the first file further includes a first check code
  • the integrity check includes verifying the check code
  • the verifying the check code includes the step of verifying the first check code
  • the method includes: obtaining a preset key; calculating, by using a key and an offline transaction record in the first file, a first integrity check code corresponding to the first file; determining whether the first check code of the first file is the first The first integrity check code corresponding to the file is equal; if not equal, the first file check fails.
  • the offline transaction device determines that the number of offline transaction records in the offline transaction record file is a positive integer, and the integrity is initially determined.
  • the offline transaction device loses power when writing offline transaction records, and the number of offline transaction records that have not been written before the power failure, When it is just equal to the number of check code bytes, the offline transaction log file can still be verified by the length of the offline transaction record file. Therefore, after the offline transaction device verifies the length of the offline transaction record file, it is necessary to further verify the offline transaction record file.
  • the check code in the offline transaction record file is calculated by offline transaction record and key.
  • the check 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 check whether the offline transaction record is complete and more accurately determine the integrity of the offline transaction record by verifying the verification code of the offline transaction record file.
  • the offline trading device obtains a preset key from the background. Take advantage of offline transaction records and keys in offline transaction log files when an offline transaction device writes an offline transaction record to an offline transaction log file or verifies a check code in an offline transaction log file Calculate the check code. For example, an offline transaction device can calculate an offline transaction record and key in accordance with the HMAC-SHA256 algorithm to obtain a check code. Each time the offline transaction device writes an offline transaction record to the first file, the offline transaction device calculates the first verification code using all offline transaction records and keys in the current first file. The currently calculated first check code covers the first check code obtained last time. It can be understood that the second check code in the second file can also be calculated in a similar manner.
  • the offline transaction device verifies the first check code in the first file, it first acquires the key and all offline transaction records in the first file.
  • the first integrity check code of the first file is calculated by the key and all offline transaction records. It is determined whether the first check code is equal to the first integrity check code. If the first check code is equal to the first integrity check code, indicating that the offline transaction record information included in the first check code is consistent with the offline transaction record information included in the first integrity check code, the first file school Successful test. If the first check code and the first integrity check code are not equal, indicating that the offline transaction record information included in the first check code is inconsistent with the offline transaction record information included in the first integrity check code, the first The offline transaction record in the file is incomplete and the first file verification failed.
  • the offline transaction device may perform check code verification on the first integrity check code of the second file by using the foregoing manner, and details are not described herein.
  • the offline transaction device further determines the integrity of the offline transaction record by verifying the check code in the offline transaction log file.
  • 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 and the first integrity check code. The integrity of the offline transaction record in the first file. Calculating a second integrity check code by using the key and the offline transaction record in the second file, and further determining the offline transaction in the second file by comparing the second check code and the second integrity check code The integrity of the record.
  • the first storage device is an internal storage device
  • the second storage device is an external storage device.
  • the step of performing consistency check on the first file length and the second file length includes: if the first file length is greater than the first The second file length replaces the offline transaction record in the second file by using the offline transaction record in the first file; if the first file length is equal to the second file length and the content is inconsistent, the offline transaction in the first file is utilized The record replaces the offline transaction record in the second file; if the first file length is less than the second file length, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
  • an offline transaction device Before an offline transaction device writes an offline transaction record to a storage device, if one of the offline transaction record files already has an offline transaction record, and another offline transaction record file does not have an offline transaction record, then In the case where the machine transaction device writes the offline transaction records to the two offline transaction log files, both the first file and the second file can pass the integrity check, but the two offline transaction record files are saved offline. The transaction records are inconsistent. Therefore, the offline transaction device needs to further compare the first file and the second file, including comparing the first file length and the second file length, comparing the content of the first file and the content of the second file.
  • both the first file and the second file are successfully verified, and the offline transaction device compares the first file length and the second file length. If the first file length is greater than the second file length, indicating that the offline transaction record in the first file is more than the offline transaction record in the second file, in order to completely save the offline transaction record, the offline transaction device utilizes the offline transaction record. More files replace the files with fewer offline transaction records, that is, the offline transaction records in the first file replace the offline transaction records in the second file, and the replaced second file is saved in the second storage device. Conversely, if the first file length is less than the second file length, indicating that the offline transaction record in the first file is less than the offline transaction record in the second file, the first file is replaced with the offline transaction record in the second file.
  • the replaced first file is saved in the first storage device.
  • the offline transaction record file with fewer offline transaction records is replaced with the offline transaction record file with more offline transaction records, the offline transaction record in the first file, and the offline transaction in the second file.
  • the record reached a consensus, improving the offline transaction record and the second text in the first file The accuracy of offline transaction records in the piece.
  • the offline 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, the external storage device of the offline transaction device is taken out by the staff member before the offline transaction record is verified. Due to the negligence of the staff, the external storage device of the original offline transaction device is Replaced with an external storage device in other offline trading devices. If the offline transaction record in the replaced external storage device is completely saved, the second file in the replaced external storage device may also pass the integrity check, and the second file length and 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 not the same as 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.
  • the offline transaction record in the first file is as much as the offline transaction record in the second file
  • the offline transaction device has the content of the first file and the second Comparing the contents of the file: if the content in the first file is consistent with the content in the second file, indicating 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, and the second file is saved in the second storage device. If the content of the first file and the content of the second file are inconsistent, that is, an offline transaction record in the first file or an offline transaction record in the second file is in error.
  • the offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file, and saves the replaced second file in the second storage device.
  • the first storage device may be an internal storage device
  • the second storage device may be an external storage device. Since the offline storage record stored by the internal storage device is more accurate than the external storage device, the offline transaction record of the internal storage device is replaced. Offline transaction record of the storage device. That is, the offline transaction record in the first file is replaced with 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 record in the external storage device is replaced with the offline transaction record in the internal storage device, thereby further improving the accuracy of the offline transaction record.
  • the first file saved in one storage device and the second file saved in the second storage device are identical.
  • the step of comparing the content of the first file with the content of the second file may be performed by comparing the offline transaction record in the first file with the offline transaction record 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, the content of the first file is consistent with the content of the second file. It is also possible to determine by comparing the offline transaction record in the first file and 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.
  • the offline transaction device replaces the content in the offline transaction log file, can replace the offline transaction record in the offline transaction record file, or can replace the offline transaction record and the school in the offline transaction record file.
  • Code verification you can also directly replace the offline transaction record file.
  • the offline transaction device may replace the offline transaction record in the second file by using the offline transaction record in the first file, or may use the first file.
  • the offline transaction record and the first check code respectively replace the offline transaction record and the second check code in the second file, and the first file can be directly replaced with the second file. It is easier to replace an offline transaction log file directly with an offline trading device.
  • the offline transaction device further compares the first file and 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 the offline transaction record. The accuracy of the offline transaction record file is further improved by comparing the content of the first file with the content of the second file.
  • the method further comprises: replacing the offline transaction record in the second file with the first file if the first storage device fails to write and the second file integrity check in the second storage device succeeds In the offline transaction record, the offline transaction in the second file is uploaded to the background to generate an alarm prompt; if the second storage device fails to write and the first file integrity check in the first storage device is successful, The offline transaction record in the first file replaces the offline transaction record in the second file, and the offline transaction in the first file is uploaded to the background to generate an alarm prompt.
  • the offline transaction device detects the first storage device Whether or not the first file is included, if the first file is not in the first storage device, the first file is created in the first storage device. If the first file creation fails, the first storage device fails, and the offline transaction device marks the first storage device failure. 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 second file creation fails, the second storage device fails and the offline transaction device marks the second storage device failure. If the offline transaction device fails to create a file, an alert is generated.
  • the offline transaction device after the offline transaction log 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 to the offline transaction record separately. file.
  • the offline transaction device opens the offline transaction record file and detects whether the offline transaction record is included in the offline transaction record file. If there is no offline transaction record in the offline transaction log file, the new offline transaction record is written at the beginning of the offline transaction record file.
  • the offline transaction device calculates the check code using the key and offline transaction records in the offline transaction log file, and writes the check code after the offline transaction record.
  • the offline transaction device If an offline transaction record is already included in the offline transaction log file, the offline transaction device detects the check code in the offline transaction log file and inserts the new offline transaction record between the last offline transaction record and the check code. , using the key and all current offline transaction records to calculate a new check code, replacing the original check code. Thus, the offline transaction device writes the offline transaction record to the offline transaction record file.
  • the first storage device fails to write and the second storage device fails to write, it indicates that the offline transaction record in the first storage device and the offline transaction record in the second storage device are incomplete, and an alarm prompt is issued. If the first storage device fails to write, the second storage device does not fail to write, but the second file integrity check fails, indicating that the offline transaction record in the first storage device and the offline in the second storage device The transaction records are incomplete and an alert is issued. Similarly, if the second storage device fails to write, the first storage device does not fail to write, but the first file integrity check fails, indicating the offline transaction record in the first storage device and the second storage device The offline transaction records are incomplete and an alarm prompt is issued.
  • the second storage device does not fail to write, and the second file is successfully verified, indicating that the offline transaction record in the first storage device is incomplete, but the second storage device is off.
  • the machine transaction record is complete, and the offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file, uploads the background, and issues an alarm prompt.
  • the second storage device fails to write, the first storage device does not fail to write, and the first file
  • the verification succeeds, indicating that the offline transaction record in the second storage device is incomplete, but the offline transaction record in the first storage device is complete, and the offline transaction device replaces the offline transaction record in the first file with the second file.
  • the method before the step of acquiring the first file of the first storage device, the method further includes: if the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, If the first file and the second file are successfully created, the first file and the second file are respectively verified; and if the verification is passed, the offline transaction record is separately written to the first file and the first file.
  • the offline transaction device can directly write the offline transaction record to the first file and the second file, and does not verify the first file and the second file during the writing process, when offline transactions
  • the first file and the second file are verified when the device is powered on or uploading an offline transaction record.
  • the offline transaction device may also check the first file and the second file before the action of writing the offline transaction record, and determine that the first device and the second device are normal, the first file and the second file are consistent, The first file and the second file are respectively written into the new offline transaction record.
  • the first file and the second file are verified before each write of the offline transaction record, and the offline transaction record can be verified multiple times, thereby effectively improving the accuracy of the offline transaction record, and the offline transaction device after the failure occurs. Promptly issue an alarm prompt to avoid loss of offline transaction records.
  • the offline transaction device uploads a valid offline transaction record file to the background by analyzing the storage device failure and the offline transaction record file verification result, and issues an alarm prompt to avoid the loss of the transaction record and ensure the offline transaction. Record integrity.
  • the application provides that the internal structure of the offline transaction recording terminal can correspond to the structure shown in FIG. 2, and each of the following modules can be partially or partially passed through software and hardware. Or a combination of them to achieve.
  • the offline transaction recording terminal includes: an obtaining module 202, a verification module 204, a replacement module 206, and a saving module 208, wherein:
  • the obtaining module 202 is configured to acquire a first file of the first storage device, where the first file includes an offline transaction record; the second file of the second storage device is acquired, and the second file includes an offline transaction record.
  • the verification module 204 is configured to perform integrity verification on the first file and the second file respectively.
  • the replacement module 206 is configured to replace the offline transaction record in the second file by using the offline transaction record in the first file if the first file verification is successful and the second file verification fails; if the first file verification fails And if the second file is successfully verified, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
  • the saving module 208 is configured to save the replaced second file in the second storage device; and save the replaced first file in the first storage device.
  • the obtaining module 202 is further configured to: if the first file and the second file are successfully verified, obtain the first file length and the second file length, and the verification module 204 is further configured to use the first file length and The second file length is checked for consistency.
  • the first file further includes a first check code
  • the check module 204 is further configured to check the first file length, including: obtaining the first file length; and obtaining the number of the single offline transaction record bytes.
  • the number of bytes of a single offline transaction record includes a byte occupied by a single offline transaction record in the first file; the number of check code bytes is obtained, and the number of check code bytes includes a byte occupied by the first check code; Calculate the number of offline transaction records in the first file by a single offline transaction record byte number, check code byte number, and first file length; determine whether the number of offline transaction records in the first file is positive Integer; if not, the first file verification failed.
  • the first file further includes a first check code
  • the check module 204 is further configured to check the check code
  • the verifying the check code includes verifying the first check code.
  • the method includes: obtaining a preset key; calculating, by using a key and an offline transaction record in the first file, a first integrity check code corresponding to the first file; determining whether the first check code of the first file is the first The first integrity check code corresponding to the file is equal; if not equal, the first file check fails.
  • the verification module 204 is further configured to perform consistency check on the first file length and the second file length, including: if the first file length is greater than the second file length, using the first file The machine transaction record replaces the offline transaction record in the second file; if the first file length is equal to the second file length and the content is inconsistent, the offline transaction record in the second file is replaced by the offline transaction record in the first file; If the first file length is less than the second file length, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
  • a computer device including a non-volatile storage medium and storage device, a processor, and a computer stored on the storage device and operable on the processor
  • Programs, databases, etc., processors are used to provide computing and control capabilities.
  • the storage device provides an environment for the operation of the computer program.
  • the storage device includes a first storage device and a second storage device.
  • the first storage device may be an internal storage
  • the second storage device may be an external storage such as an SD card or the like.
  • the database is used to store offline transaction records, checksums, and so on.
  • the offline transaction record in the second file is replaced with the offline transaction record in the first file, and the replaced second file is saved in the second storage device. If the first file verification fails and the second file verification succeeds, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced first is saved in the first storage device. file.
  • the computer device can be implemented by a stand-alone computer device or a cluster of computer devices consisting of a plurality of computer devices. It will be understood by those skilled in the art that the structure shown in FIG. 3 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device to which the solution of the present application is applied.
  • the specific computer device may It includes more or fewer components than those shown in the figures, or some components are combined, or have different component arrangements.
  • the processor is further configured to:
  • the offline transaction record is written to the first file and the first file, respectively.
  • the processor is further configured to:
  • processing It is also used to execute:
  • the processor is further configured to:
  • the processor is further configured to:
  • the offline transaction record in the second file is replaced by the offline transaction record in the first file
  • the offline transaction record in the first file is replaced with the offline transaction record in the second file.
  • the processor is further configured to:
  • the offline transaction record in the second file is replaced with the offline transaction record in the first file, and the second file is deleted.
  • the offline transaction in the middle is uploaded to the background to generate an alarm prompt; if the second storage device fails to write and the first file integrity check in the first storage device is successful, the offline transaction record in the first file is generated. Replace the offline transaction record in the second file, upload the offline transaction in the first file to the background, and generate an alarm prompt.
  • one or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause one or more processors to perform the following step:
  • the offline transaction record in the second file is replaced with the offline transaction record in the first file, and the replaced second file is saved in the second storage device. If the first file verification fails and the second file verification succeeds, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced first is saved in the first storage device. file.
  • the processor is further configured to:
  • the offline transaction record is written to the first file and the first file, respectively.
  • the computer program is executed by the processor to also implement the following steps:
  • the processor is further configured to:
  • the processor is further configured to:
  • the processor is further configured to:
  • the offline transaction record in the second file is replaced by the offline transaction record in the first file
  • the offline transaction record in the first file is replaced with the offline transaction record in the second file.

Abstract

A method for storing an off-line transaction record. The method comprises: acquiring a first file of a first storage apparatus, the first file comprising an off-line transaction record; acquiring a second file of a second storage apparatus, the second file comprising an off-line transaction record; separately verifying the integrity of the first file and the second file; if the verification of the first file succeeds and the verification of the second file fails, using the off-line transaction record in the first file to replace the off-line transaction record in the second file, and storing the second file, to which replacements have been made, in the second storage apparatus; and if the verification of the first file fails and the verification of the second file succeeds, using the off-line transaction record in the second file to replace the off-line transaction record in the first file, and storing the first file, to which replacements have been made, in the first storage apparatus.

Description

脱机交易记录保存方法、计算机设备和存储介质Offline transaction record saving method, computer device and storage medium 技术领域Technical field
本申请涉及计算机技术领域,特别是涉及一种脱机交易记录保存方法、计算机设备和存储介质。The present application relates to the field of computer technology, and in particular, to an offline transaction record keeping method, a computer device, and a storage medium.
背景技术Background technique
在脱机交易设备中,脱机交易完成后,会在本地存储脱机交易记录。当脱机交易记录达到一定数量时,脱机交易设备将脱机交易记录上传给后台。如果在脱机交易记录上传之前,脱机交易设备发生了故障,很可能出现脱机交易记录不完整的问题。In an offline trading device, offline transactions are stored locally after the offline transaction is completed. When the offline transaction record reaches a certain amount, the offline transaction device uploads the offline transaction record to the background. If the offline trading device fails before the offline transaction record is uploaded, there is a high probability that the offline transaction record is incomplete.
发明内容Summary of the invention
根据本申请的各种实施例,提供一种脱机交易记录保存方法、计算机设备和存储介质。According to various embodiments of the present application, an offline transaction record saving method, a computer device, and a storage medium are provided.
一种脱机交易记录保存方法,所述方法包括:An offline transaction record saving method, the method comprising:
获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;Obtaining 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, where the second file includes an offline transaction record;
对所述第一文件和所述第二文件分别进行完整性校验;及Performing integrity verification on the first file and the second file respectively; and
若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the first file verification is successful and the second file verification fails, replacing the offline transaction record in the second file with the offline transaction record in the first file, in the second Saving the replaced second file in the storage device; if the first file verification fails and the second file verification is successful, replacing the first file with the offline transaction record in the second file The offline transaction record stores the replaced first file in the first storage device.
一种计算机设备,包括存储器、处理器以及存储在存储器上并可在处理器 上运行的计算机程序,所述处理器执行所述计算机程序时实现以下步骤:A computer device including a memory, a processor, and a memory and a processor A computer program running thereon, the processor implementing the computer program to implement the following steps:
获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;Obtaining 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, where the second file includes an offline transaction record;
对所述第一文件和所述第二文件分别进行完整性校验;及Performing integrity verification on the first file and the second file respectively; and
若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the first file verification is successful and the second file verification fails, replacing the offline transaction record in the second file with the offline transaction record in the first file, in the second Saving the replaced second file in the storage device; if the first file verification fails and the second file verification is successful, replacing the first file with the offline transaction record in the second file The offline transaction record stores the replaced first file in the first storage device.
一种计算机可读存储介质,一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:A computer readable storage medium, one or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, causing one or more processors Perform the following steps:
获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;Obtaining 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, where the second file includes an offline transaction record;
对所述第一文件和所述第二文件分别进行完整性校验;及Performing integrity verification on the first file and the second file respectively; and
若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the first file verification is successful and the second file verification fails, replacing the offline transaction record in the second file with the offline transaction record in the first file, in the second Saving the replaced second file in the storage device; if the first file verification fails and the second file verification is successful, replacing the first file with the offline transaction record in the second file The offline transaction record stores the replaced first file in the first storage device.
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征和优点将从说明书、附图以及权利要求书变得明显。Details of one or more embodiments of the present application are set forth in the accompanying drawings and description below. Other features and advantages of the present invention will be apparent from the description, drawings and claims.
附图说明DRAWINGS
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一 些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings to be used in the embodiments will be briefly described below. Obviously, the drawings in the following description are only one of the present application. For other embodiments, other drawings may be obtained from those skilled in the art without any inventive effort.
图1为一个实施例中脱机交易记录保存方法的流程图;1 is a flow chart of a method for saving an offline transaction record in an embodiment;
图2为一个实施例中脱机交易记录保存装置的结构示意图;2 is a schematic structural diagram of an offline transaction record retaining apparatus in an embodiment;
图3为一个实施例中计算机设备的结构示意图。FIG. 3 is a schematic structural diagram of a computer device in an embodiment.
具体实施方式detailed description
为了使本申请的技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。In order to make the technical solutions and advantages of the present application more clear, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It is understood that the specific embodiments described herein are merely illustrative of the application and are not intended to be limiting.
可以理解,本申请所使用的术语“第一”、“第二”等可在本文中用于描述各种元件,但这些元件不受这些术语限制。这些术语仅用于将第一个元件与另一个元件区分。举例来说,第一用户标识和第二用户标识两者都是用户标识,但其不是同一用户标识。It will be understood that the terms "first", "second" and the like, as used herein, may be used to describe various elements, but these elements are not limited by these terms. These terms are only used to distinguish one element from another. For example, both the first user ID and the second user ID are user IDs, but they are not the same user ID.
图1为本申请一个实施例的方法的流程示意图。应该理解的是,虽然图1的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,其可以以其他的顺序执行。而且,图1中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,其执行顺序也不必然是依次进行,而是可以与其他步骤或者其他步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。FIG. 1 is a schematic flow chart of a method according to an embodiment of the present application. It should be understood that although the various steps in the flowchart of FIG. 1 are sequentially displayed as indicated by the arrows, these steps are not necessarily performed in the order indicated by the arrows. Except as explicitly stated herein, the execution of these steps is not strictly limited, and may be performed in other sequences. Moreover, at least some of the steps in FIG. 1 may include a plurality of sub-steps or stages, which are not necessarily performed at the same time, but may be executed at different times, and the order of execution thereof is not necessarily This may be performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of the other steps.
在一个实施例中,如图1所示,提供了一种脱机交易记录保存方法,以该方法应用于脱机交易设备为例进行说明,具体包括:In an embodiment, as shown in FIG. 1 , an offline transaction record saving method is provided. The method is applied to an offline transaction device as an example, and specifically includes:
步骤102,获取第一存储装置的第一文件,第一文件包括脱机交易记录。Step 102: Acquire a first file of the first storage device, where the first file includes an offline transaction record.
步骤104,获取第二存储装置的第二文件,第二文件包括脱机交易记录。Step 104: Acquire a second file of the second storage device, where the second file includes an offline transaction record.
脱机交易设备是指在脱机状态下进行脱机交易的金融脱机交易设备,可以是公交车车载收费终端、地铁收费终端或食堂收费终端等。部分联机交易设备 在脱机状态下也可以作为脱机交易设备使用,例如,POS机(Point of Sales Terminal,销售点终端管理系统)。The offline transaction device refers to a financial offline transaction device that performs offline transactions in an offline state, and may be a bus on-board toll terminal, a subway toll terminal, or a canteen toll terminal. Partial online trading device It can also be used as an offline transaction device in an offline state, for example, a POS machine (Point of Sales Terminal).
传统的脱机交易设备只包括一个存储装置。一旦存储装置发生故障,脱机交易记录将会丢失。本实施例中的脱机交易设备可以包括两个或两个以上存储装置,存储装置包括内存储装置和外存储装置。内存储装置可以包括至少一个存储装置,内存储装置可以是FLASH存储装置,也可以是SRAM(Static Random Access Memory,静态随机存取存储器)存储装置。外存储装置可以包括至少一个存储装置,外存储装置可以是SD卡(Secure Digital Card)存储装置,也可以是ESAM卡(Embedded Secure Access Module,嵌入式安全模块)。内存储装置中的一个存储装置可以叫做第一存储装置,外存储装置中的一个存储装置可以叫做第二存储装置。内存储装置中的一个存储装置也可以叫做第二存储装置,外存储装置中的一个存储装置相应的叫做第一存储装置。存储装置中存储了多个文件,包括脱机交易记录文件。脱机交易记录文件中存储了脱机交易记录。脱机交易记录文件包括第一文件和第二文件,脱机交易设备在第一存储装置中存储了第一文件,第二存储装置中存储了第二文件。Traditional offline trading devices include only one 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 device includes 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) 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). One of the internal storage devices may be referred to as a first storage device, and one of the external storage devices may be referred to as a second storage device. One of the internal storage devices may also be referred to as a second storage device, and one of the external storage devices is correspondingly referred to as a first storage device. A plurality of files are stored in the storage device, including an offline transaction log file. Offline transaction records are stored in the offline transaction log file. The offline transaction log file includes a first file and a second file, the offline transaction device stores the first file in the first storage device, and the second storage device stores the second file.
当脱机交易设备发生交易时,产生脱机交易记录。脱机交易记录包括脱机交易信息,例如,脱机交易时间、脱机交易金额以及脱机交易方式等。脱机交易设备将脱机交易记录写入存储装置的脱机交易记录文件中,具体地,将脱机交易记录分别写入第一存储装置中的第一文件以及第二存储装置中的第二文件。An offline transaction record is generated when a transaction occurs on an offline trading device. Offline transaction records include offline transaction information, such as offline transaction time, offline transaction amount, and offline transaction methods. The offline transaction device writes the offline transaction record into the offline transaction record file of the storage device, specifically, the offline transaction record is respectively written into the first file in the first storage device and the second file in the second storage device file.
步骤106,对第一文件和第二文件分别进行完整性校验。Step 106: Perform integrity verification on the first file and the second file respectively.
当脱机交易设备向脱机交易记录文件写入脱机交易记录时,如果脱机交易记录写入失败,将导致脱机交易记录文件中的脱机交易记录不完整。为了确保脱机交易记录完整,脱机交易设备需要对脱机交易记录文件进行完整性校验,包括对第一文件和对第二文件分别进行完整性校验。When an offline transaction device writes an offline transaction record to an offline transaction log file, if the offline transaction record write fails, the offline transaction record in the offline transaction log file is incomplete. In order to ensure that the offline transaction record is complete, the offline transaction device needs to perform integrity verification on the offline transaction record file, including performing integrity verification on the first file and the second file respectively.
具体地,脱机交易设备对脱机交易记录文件进行完整性校验,包括对脱机交易记录文件长度进行校验以及对脱机交易记录文件中的校验码进行校验。其中,脱机交易设备通过对脱机交易记录文件长度进行校验,可以检测出部分脱 机交易记录不完整的脱机交易记录文件。例如,当脱机交易设备写入脱机交易记录时,脱机交易设备发生断电,脱机交易设备无法继续写入该条脱机交易记录,则该条脱机交易记录文件不完整。Specifically, the offline transaction device performs integrity verification on the offline transaction record file, including verifying the length of the offline transaction record file and verifying the check code in the offline transaction record file. Among them, the offline transaction device can detect partial off by verifying the length of the offline transaction record file. The machine transaction records an incomplete offline transaction log file. For example, when an offline transaction device writes an offline transaction record, the offline transaction device is powered off, and the offline transaction device cannot continue to write the offline transaction record, the offline transaction record file is incomplete.
脱机交易设备对脱机交易记录文件长度进行校验时,首先,脱机交易设备获取脱机交易记录文件长度、单条脱机交易记录字节数和校验码字节数。其次,脱机交易设备通过脱机交易记录文件长度、单条脱机交易记录字节数和校验码字节数计算脱机交易记录条数。然后,判断脱机交易记录条数是否为正整数,如果脱机交易记录条数不是正整数,说明脱机交易记录不完整,则该脱机交易记录文件校验失败。通过脱机交易记录文件长度计算脱机交易记录条数,可以根据脱机交易记录条数判断脱机交易记录是否残缺,初步确定脱机交易记录的完整性。When the offline transaction device verifies the offline transaction record file length, first, the offline transaction device obtains the offline transaction record file length, the number of single offline transaction record bytes, and the check code byte number. Second, the offline transaction device calculates the number of offline transaction records by the offline transaction record file length, the number of single offline transaction record bytes, and the check code byte number. Then, it is determined whether the number of offline transaction records is a positive integer. If the number of offline transaction records is not a positive integer, indicating that the offline transaction record is incomplete, the offline transaction record file verification fails. By calculating the number of offline transaction records by the length of the offline transaction record file, it is possible to determine whether the offline transaction record is defective according to the number of offline transaction records, and initially determine the integrity of the offline transaction record.
进一步地,如果脱机交易设备写入脱机交易记录时,突然发生断电,且断电时刻写入的那条脱机交易记录字节数等于校验码字节数,校验码没有生成,则通过对脱机交易记录文件长度进行校验时,脱机交易设备将该条不完整的脱机交易记录误认为校验码,无法检查出脱机交易记录是否完整。因此,脱机交易设备对脱机交易记录文件长度进行校验之后,还可以进一步对脱机交易记录文件中的校验码进行校验。脱机交易文件中除了脱机交易记录之外,还包括校验码。校验码是利用脱机交易记录文件中的脱机交易记录和预存的密钥生成的。第一文件中包括脱机交易记录和第一校验码。第二文件中包括脱机交易记录和第二校验码。脱机交易设备对脱机交易记录文件长度进行校验之后,对脱机交易记录文件中的校验码进行校验。Further, if the offline transaction device writes the offline transaction record, the power failure suddenly occurs, and the number of offline transaction record bytes written at the time of power failure is equal to the check code byte number, and the check code is not generated. By verifying the length of the offline transaction record file, the offline transaction device mistakes the incomplete offline transaction record for the check code, and cannot check whether the offline transaction record is complete. Therefore, after the offline transaction device verifies the offline transaction record file length, the verification code in the offline transaction record file can be further verified. The offline transaction file includes a check code in addition to the offline transaction record. The checksum is generated using offline transactions and pre-stored keys in the offline transaction log file. The first file includes an offline transaction record and a first verification code. The second file includes an offline transaction record and a second check code. After the offline transaction device verifies the offline transaction record file length, it checks the check code in the offline transaction record file.
具体地,脱机交易设备获取预设的密钥,通过密钥和第一文件中的脱机交易记录计算第一文件的第一完整性校验码,判断第一校验码是否与第一完整性校验码相等。如果相等,表示第一校验码包含的脱机交易记录信息和第一完整性校验码第一完整性校验码包含的脱机交易记录信息一致,第一文件的完整性校验成功;若不相等,表示第一校验码的第一完整性校验码不是正确的校验码,而是不完整的脱机交易记录,第一文件中的脱机交易记录不完整,则第一文件的完整性校验失败。 Specifically, the offline transaction device acquires a preset key, calculates a first integrity check code of the first file by using the key and the offline transaction record in the first file, and determines whether the first check code is the first The integrity check codes are equal. If they are equal, the offline transaction record information included in the first check code is consistent with the offline transaction record information included in the first integrity check code of the first integrity check code, and the integrity check of the first file is successful; If they are not equal, the first integrity check code of the first check code is not the correct check code, but is an incomplete offline transaction record. If the offline transaction record in the first file is incomplete, the first The integrity check of the file failed.
可以理解地,脱机交易设备对第二文件进行校验码校验也可以采用上述方式,不再赘述。校验码包括脱机交易记录属性,脱机交易设备通过对校验码进行校验进一步确定脱机交易记录文件中的脱机交易记录的完整性。It can be understood that the verification of the second file by the offline transaction device may also be performed in the above manner, and details are not described herein. The check code includes an offline transaction record attribute, and the offline transaction device further determines the integrity of the offline transaction record in the offline transaction record file by verifying the check code.
步骤108,若第一文件校验成功且第二文件校验失败,则利用第一文件的脱机交易记录替换第二文件的脱机交易记录,在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。Step 108: If the first file verification is successful and the second file verification fails, the offline transaction record of the second file is replaced by the offline transaction record of the first file, and the replaced second is saved in the second storage device. File; if the first file verification fails and the second file is successfully verified, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced version is saved in the first storage device. a file.
脱机交易设备对第一文件和第二文件分别进行完整性校验之后,获取第一文件和第二文件的完整性校验结果。完整性校验结果是指脱机交易记录文件校验成功或校验失败的结果。如果第一文件校验成功且第二文件校验失败,说明第一文件中的脱机交易记录保存完整且第二文件中的脱机交易记录保存不完整,脱机交易设备利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。反之,如果第二文件校验成功且第一文件校验失败,说明第二文件中的脱机交易记录保存完整且第一文件中的脱机交易记录保存不完整,则利用第二文件替换第一文件,在第一存储装置中保存替换后的第一文件。脱机交易设备通过将校验成功的文件替换校验失败的文件,脱机交易记录不完整的文件替换成了脱机交易记录完整的文件,第一文件中的脱机交易记录和第二文件中的脱机交易记录均完整,且达到了一致。After the offline transaction device performs integrity verification on the first file and the second file respectively, the integrity verification result of the first file and the second file is obtained. The integrity check result refers to the result of successful verification or verification failure of the offline transaction record file. If the first file verification is successful and the second file verification fails, the offline transaction record in the first file is saved completely and the offline transaction record in the second file is incompletely saved, and the offline transaction device utilizes the first file. The offline transaction record replaces the offline transaction record in the second file, and the replaced second file is saved in the second storage device. On the other hand, if the second file verification is successful and the first file verification fails, indicating that the offline transaction record in the second file is completely saved and the offline transaction record in the first file is incomplete, the second file is replaced. a file in which the replaced first file is saved in the first storage device. The offline transaction device replaces the file that failed the verification by the file with the verification success, and the file with the incomplete transaction record is replaced with the complete file of the offline transaction record, the offline transaction record and the second file in the first file. The offline transaction records in the middle are complete and consistent.
在一个实施例中,脱机交易设备根据脱机交易记录文件的完整性校验结果替换脱机交易记录文件的内容,可以替换脱机交易记录文件中的脱机交易记录,也可以替换脱机交易记录文件中的脱机交易记录和校验码,还可以直接将脱机交易记录文件替换。例如,如果第一文件校验成功且第二文件校验失败,脱机交易设备可以利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,也可以利用第一文件中的脱机交易记录和第一校验码分别替换第二文件中的脱机交易记录和第二校验码,还可以将第一文件直接替换第二文件。脱机交易设备直接替换脱机交易记录文件的方法较为简单。In one embodiment, the offline transaction device replaces the contents of the offline transaction record file according to the integrity check result of the offline transaction record file, and may replace the offline transaction record in the offline transaction record file, or may replace the offline transaction. The offline transaction record and check code in the transaction log file can also directly replace the offline transaction record file. For example, if the first file verification is successful and the second file verification fails, the offline transaction device may replace the offline transaction record in the second file by using the offline transaction record in the first file, or may use the first file. The offline transaction record and the first check code respectively replace the offline transaction record and the second check code in the second file, and the first file can be directly replaced with the second file. The method of directly replacing an offline transaction record file with an offline transaction device is relatively simple.
本实施例中,脱机交易设备的存储装置包括第一存储装置和第二存储装置, 存储装置中包括脱机交易记录文件,脱机交易记录文件包括第一文件和第二文件,其中,第一文件存储在第一存储装置中,第二文件存储在第二存储装置中。脱机交易设备对第一文件和第二文件分别进行完整性校验,若第一文件校验成功且第二文件校验失败,则利用第一文件的脱机交易记录替换第二文件的脱机交易记录,在第二存储装置中保存替换后的第二文件,反之亦可。脱机交易设备通过第一存储装置和第二存储装置分别存储脱机交易记录,降低了存储装置故障的可能性。通过对第一文件和第二文件进行完整性校验,可以发现脱机交易记录是否完整。通过将校验成功的文件中的脱机交易记录替换校验失败的文件中的脱机交易记录,使第一文件中的脱机交易记录和第二文件中的脱机交易记录完整、一致,进一步提高脱机交易记录的完整性。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 including a first file and a second file, wherein the first file is stored in the first storage device and the 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 first file verification succeeds and the second file verification fails, the offline transaction record of the first file is used to replace the second file. The machine transaction record stores the replaced second file in the second storage device, and vice versa. The offline transaction device stores the offline transaction record by the first storage device and the second storage device, respectively, reducing the possibility of the storage device failure. By performing an integrity check on the first file and the second file, it can be found whether the offline transaction record is complete. By replacing the offline transaction record in the file that failed the verification with the offline transaction record in the successfully verified file, 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 an embodiment, after the step of performing integrity verification on the first file and the second file respectively, the method further includes: if the first file and the second file are successfully verified, acquiring the first file length and the second file Length; consistency check for the first file length and the second file length.
脱机交易设备向存储装置写入脱机交易记录之前,如果其中一个脱机交易记录文件中已经存有脱机交易记录,而另一个脱机交易记录文件中没有脱机交易记录,那么,向两个脱机交易记录文件分别写入脱机交易记录的情况下,第一文件和第二文件均能通过完整性校验,但是两个脱机交易记录文件中保存的脱机交易记录不一致。因此,脱机交易设备需要进一步对第一文件和第二文件进行比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。Before the offline transaction device writes the offline transaction record to the storage device, if there is an offline transaction record in one of the offline transaction record files, and there is no offline transaction record in the other offline transaction record file, then In the case where two offline transaction log files are respectively written to the offline transaction record, both the first file and the second file can pass the integrity check, but the offline transaction records held in the two offline transaction record files are inconsistent. Therefore, the offline transaction device needs to further compare the first file and the second file, including comparing the first file length and the second file length, comparing the content of the first file and the content of the second file.
具体地,如果第一文件和第二文件均校验成功,脱机交易设备对第一文件长度和第二文件长度进行比较。如果第一文件长度大于第二文件长度,说明第一文件中的脱机交易记录多于第二文件中的脱机交易记录,为了完整保存脱机交易记录,脱机交易设备利用脱机交易记录较多的文件替换脱机交易记录较少的文件,即第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。反之,如果第一文件长度小于第二文件长度,说明第一文件中的脱机交易记录少于第二文件中的脱机交易记录,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装 置中保存替换后的第一文件。由此,将脱机交易记录较少的脱机交易记录文件替换成了脱机交易记录较多的脱机交易记录文件,第一文件中的脱机交易记录和第二文件中的脱机交易记录达到了一致,提高第一文件中的脱机交易记录和第二文件中的脱机交易记录的准确性。Specifically, if both the first file and the second file are successfully verified, the offline transaction device compares the first file length with the second file length. If the first file length is greater than the second file length, indicating that the offline transaction record in the first file is more than the offline transaction record in the second file, in order to completely save the offline transaction record, the offline transaction device utilizes the offline transaction record. More files replace the files with fewer offline transaction records, that is, the offline transaction records in the first file replace the offline transaction records in the second file, and the replaced second file is saved in the second storage device. Conversely, if the first file length is less than the second file length, indicating that the offline transaction record in the first file is less than the offline transaction record in the second file, the first file is replaced with the offline transaction record in the second file. Offline transaction record in the first storage Save the first file after replacement. Thus, the offline transaction record file with fewer offline transaction records is replaced with the offline transaction record file with more offline transaction records, the offline transaction record in the first file, and the offline transaction in the second file. The records are consistent, improving the accuracy of the offline transaction records in the first file and the offline transaction records in the second file.
如果第一文件长度等于第二文件长度,脱机交易设备对第一文件的内容和第二文件的内容进行比较。如果第二存储装置为外存储装置,在对脱机交易记录进行校验之前,脱机交易设备的外存储装置被工作人员取出,由于工作人员疏忽,原来的脱机交易设备的外存储装置被替换成了其他脱机交易设备中的外存储装置。如果替换后的外存储装置中的脱机交易记录保存完整,也可以通过完整性校验、且替换后的外存储装置中的第二文件长度和内存储装置中的第一文件长度一致,但是原来的外存储装置中的脱机交易记录与替换后的外存储装置中的脱机交易记录不同。在这种情况下,脱机交易设备需要对第一文件中的内容和第二文件中的内容进行比较。If the first file length is equal to the second file length, the offline 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, the external storage device of the offline transaction device is taken out by the staff member before the offline transaction record is verified. Due to the negligence of the staff, the external storage device of the original offline transaction device is Replaced with an external storage device in other offline trading devices. If the offline transaction record in the replaced external storage device is completely saved, the integrity check may be passed, and the second file length in the replaced external storage device is the same as the first file length in the internal storage device, but The offline transaction record in the original external storage device is different from the offline transaction record 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 first file length is equal to the second file length, the offline transaction record in the first file is as much as the offline transaction record in the second file, and the offline transaction device has the content of the first file and 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, indicating that the offline transaction record in the first file is consistent with the offline transaction record in the second file, then in 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 and the content of the second file are inconsistent, that is, an offline transaction record in the first file or an offline transaction record in the second file is in error. The offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file. Preferably, the first storage device may be an internal storage device, and the second storage device may be an external storage device. Since the offline transaction record stored by the internal storage device is more accurate than the offline transaction record of the external storage device, the internal storage device is removed. The machine transaction record replaces the offline transaction record of the external storage device, that is, the offline transaction record in the first file replaces 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 record in the internal storage device is replaced with the offline transaction record in the external storage device, thereby further improving the accuracy of the offline transaction record. The first file saved in one storage device and the second file saved in the second storage device are identical.
本实施例中,在第一文件和第二文件均校验成功的情况下,脱机交易设备对第一文件和第二文件进行进一步比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。通过对第一文件长度和第二文件长度进行比较,将脱机交易记录较多的文件替换脱机交易记录较少的文件,提高脱机交易记录的准确性。通过对第一文件的内容和第二文件的内容进行比较,进一步提高脱机交易记录文件的准确性。In this embodiment, in the case that both the first file and the second file are successfully verified, the offline transaction device further compares the first file and 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 the offline transaction record. The accuracy of the offline transaction record file is further improved by comparing the content of the first file with the content of the second file.
在一个实施例中,第一文件还包括第一校验码,完整性校验包括对第一文件长度进行校验,对第一文件长度进行校验的步骤,包括:获取第一文件长度;获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;获取校验码字节数,校验码字节数包括第一校验码占用的字节;通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;判断第一文件中的脱机交易记录条数是否为正整数;若不是,则第一文件校验失败。In an embodiment, the first file further includes a first check code, the integrity check includes the step of verifying the length of the first file, and the step of verifying the length of the first file, including: acquiring a first file length; Get 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 check code bytes is obtained, and the number of check code bytes includes the number a byte occupied by the check code; calculating the number of offline transaction records in the first file by a single offline transaction record byte number, a check code byte number, and a first file length; determining 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 an offline transaction record and a first verification code, and the second file includes an offline transaction record and a second verification code. When the offline transaction device writes the offline transaction record to the first storage device, the first verification code is generated by using the key and the offline transaction record in the first file; the offline transaction device writes the offline transaction record to the second When the device is stored, the second check code is generated using the key and the offline transaction record in the second file. The offline transaction device records a single offline transaction record occupation byte as a single offline transaction record byte number; the offline transaction device records the check code occupation byte as the check code byte number. When an offline transaction device writes an offline transaction record to an offline transaction record file, the offline transaction record occupies a single offline transaction record byte number, and the offline transaction record file length increases by the corresponding byte. Therefore, as the offline transaction record increases, the offline transaction record file length increases with the number of single offline transaction record bytes. The number of offline transaction records can be calculated by the offline transaction record file length. When an offline transaction device writes an offline transaction record to an offline transaction record file, if the offline transaction device loses power, the offline transaction device cannot continue to completely write the offline transaction record to the offline transaction record file. The offline transaction record does not occupy the complete single offline transaction record byte number, which causes the offline transaction record in the offline transaction record file to be incomplete. In order to ensure that a single offline transaction record in an offline transaction log file is complete, the offline transaction device needs to verify the length of the offline transaction record file. Offline trading device to offline transaction log file The verification of the length includes checking the length of the first file and verifying the length of the second file.
具体地,脱机交易设备对第一文件长度进行校验,首先,脱机交易设备获取第一文件长度、单条脱机交易记录字节数和校验码字节数。其次,脱机交易设备通过脱机交易记录文件长度、单条脱机交易记录字节数和校验码字节数计算脱机交易记录条数。具体地,脱机交易设备利用脱机交易记录文件长度和校验码字节数计算脱机交易记录文件长度减去校验码字节数的结果,利用该结果除以单条脱机交易记录字节数,即得到脱机交易记录条数。然后,判断脱机交易记录条数是否为正整数,如果脱机交易记录条数不是正整数,说明脱机交易记录文件中存在单条脱机交易记录不完整,则该脱机交易记录文件校验失败。通过脱机交易记录文件长度计算脱机交易记录条数,可以检测出脱机交易记录文件中是否包括不完整的脱机交易记录,初步判断第一文件中的脱机交易记录存储的完整性。Specifically, the offline transaction device checks the first file length. First, the offline transaction device acquires the first file length, the number of single offline transaction record bytes, and the check code byte number. Second, the offline transaction device calculates the number of offline transaction records by the offline transaction record file length, the number of single offline transaction record bytes, and the check code byte number. Specifically, the offline transaction device uses the offline transaction record file length and the check code byte number to calculate the offline transaction record file length minus the check code byte number, and divides the result by a single offline transaction record word. The number of sections, that is, the number of offline transaction records. Then, it is determined whether the number of offline transaction records is a positive integer. If the number of offline transaction records is not a positive integer, indicating that there is a single offline transaction record in the offline transaction record file, the offline transaction record file is verified. failure. By calculating the number of offline transaction records by the length of the offline transaction record file, it is possible to detect whether the offline transaction record file includes an incomplete offline transaction record, and initially determine the integrity of the offline transaction record storage in the first file.
可以理解地,脱机交易设备可以按照上述方式对第二文件长度进行校验,通过脱机交易记录文件长度计算脱机交易记录条数,可以检测出脱机交易记录文件中是否包括不完整的脱机交易记录,初步判断第二文件中的脱机交易记录存储的完整性。It can be understood that the offline transaction device can verify the length of the second file in the above manner, calculate the number of offline transaction records by the length of the offline transaction record file, and can detect whether the offline transaction record file includes incomplete The offline transaction record initially determines the integrity of the offline transaction record storage 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 single offline transaction record bytes, and the number of check code bytes, and determines the number of offline transaction records. Whether it is a positive integer, initially determine whether the offline transaction record in the offline transaction record file is complete.
在一个实施例中,第一文件还包括第一校验码,完整性校验包括对校验码进行校验,对校验码进行校验包括对第一校验码进行校验的步骤,包括:获取预设的密钥;通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;若不相等,则第一文件校验失败。In an embodiment, the first file further includes a first check code, the integrity check includes verifying the check code, and the verifying the check code includes the step of verifying the first check code, The method includes: obtaining a preset key; calculating, by using a key and an offline transaction record in the first file, a first integrity check code corresponding to the first file; determining whether the first check code of the first file is the first The first integrity check code corresponding to the file is equal; if not equal, the first file check fails.
脱机交易设备通过对脱机交易记录文件长度进行校验,确定了脱机交易记录文件中脱机交易记录条数为正整数,初步判断了的完整性。但是当脱机交易设备在写入脱机交易记录时发生断电,且断电前未写完的脱机交易记录字节数 刚好等于校验码字节数时,脱机交易记录文件仍然能够通过对脱机交易记录文件长度进行的校验。因此,脱机交易设备通过对脱机交易记录文件长度进行校验之后,需要进一步对脱机交易记录文件进行校验。脱机交易记录文件中的校验码是通过脱机交易记录和密钥计算得到的,校验码中包括与脱机交易记录相关的信息,与脱机交易记录的内容完全不同。因此,脱机交易设备可以通过对脱机交易记录文件的校验码进行校验,进一步检测脱机交易记录是否完整,更准确的判断脱机交易记录的完整性。By verifying the length of the offline transaction record file, the offline transaction device determines that the number of offline transaction records in the offline transaction record file is a positive integer, and the integrity is initially determined. However, when the offline transaction device loses power when writing offline transaction records, and the number of offline transaction records that have not been written before the power failure, When it is just equal to the number of check code bytes, the offline transaction log file can still be verified by the length of the offline transaction record file. Therefore, after the offline transaction device verifies the length of the offline transaction record file, it is necessary to further verify the offline transaction record file. The check code in the offline transaction record file is calculated by offline transaction record and key. The check 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 check whether the offline transaction record is complete and more accurately determine the integrity of the offline transaction record by verifying the verification code of the offline transaction record file.
脱机交易设备从后台获取预设的密钥。当脱机交易设备向脱机交易记录文件写入脱机交易记录、或者对脱机交易记录文件中的校验码进行校验时,利用脱机交易记录文件中的脱机交易记录和密钥计算校验码。例如,脱机交易设备可以将脱机交易记录和密钥按照HMAC-SHA256算法计算得到校验码。脱机交易设备每次向第一文件写入一条脱机交易记录时,脱机交易设备利用当前第一文件中所有的脱机交易记录和密钥计算第一校验码。当前计算得到的第一校验码覆盖上一次计算得到的第一校验码。可以理解地,第二文件中的第二校验码也可以以类似方式计算得到。The offline trading device obtains a preset key from the background. Take advantage of offline transaction records and keys in offline transaction log files when an offline transaction device writes an offline transaction record to an offline transaction log file or verifies a check code in an offline transaction log file Calculate the check code. For example, an offline transaction device can calculate an offline transaction record and key in accordance with the HMAC-SHA256 algorithm to obtain a check code. Each time the offline transaction device writes an offline transaction record to the first file, the offline transaction device calculates the first verification code using all offline transaction records and keys in the current first file. The currently calculated first check code covers the first check code obtained last time. It can be understood that the second check code in the second file can also be calculated in a similar manner.
脱机交易设备对第一文件中的第一校验码进行校验时,首先获取密钥和第一文件中的全部脱机交易记录。其次,通过密钥和全部脱机交易记录计算第一文件的第一完整性校验码。判断第一校验码是否与第一完整性校验码相等。如果第一校验码与第一完整性校验码相等,表示第一校验码包含的脱机交易记录信息和第一完整性校验码包含的脱机交易记录信息一致,第一文件校验成功。如果第一校验码和第一完整性校验码不相等,表示第一校验码包含的脱机交易记录信息和第一完整性校验码包含的脱机交易记录信息不一致,则第一文件中的脱机交易记录不完整,第一文件校验失败。同样地,脱机交易设备可以利用上述方式对第二文件的第一完整性校验码进行校验码校验,不再赘述。脱机交易设备通过对脱机交易记录文件中的校验码进行校验,进一步确定了脱机交易记录的完整性。When the offline transaction device verifies the first check code in the first file, it first acquires the key and all offline transaction records in the first file. Second, the first integrity check code of the first file is calculated by the key and all offline transaction records. It is determined whether the first check code is equal to the first integrity check code. If the first check code is equal to the first integrity check code, indicating that the offline transaction record information included in the first check code is consistent with the offline transaction record information included in the first integrity check code, the first file school Successful test. If the first check code and the first integrity check code are not equal, indicating that the offline transaction record information included in the first check code is inconsistent with the offline transaction record information included in the first integrity check code, the first The offline transaction record in the file is incomplete and the first file verification failed. Similarly, the offline transaction device may perform check code verification on the first integrity check code of the second file by using the foregoing manner, and details are not described herein. The offline transaction device further determines the integrity of the offline transaction record by verifying the check code in the offline transaction log 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 and the first integrity check code. The integrity of the offline transaction record in the first file. Calculating a second integrity check code by using the key and the offline transaction record in the second file, and further determining the offline transaction in the second file by comparing the second check code and the second integrity check code The integrity of the record.
在一个实施例中,第一存储装置为内存储装置,第二存储装置为外存储装置,对第一文件长度和第二文件长度进行一致性校验的步骤包括:若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。In one embodiment, the first storage device is an internal storage device, and the second storage device is an external storage device. The step of performing consistency check on the first file length and the second file length includes: if the first file length is greater than the first The second file length replaces the offline transaction record in the second file by using the offline transaction record in the first file; if the first file length is equal to the second file length and the content is inconsistent, the offline transaction in the first file is utilized The record replaces the offline transaction record in the second file; if the first file length is less than the second file length, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
脱机交易设备向存储装置写入脱机交易记录之前,如果其中一个脱机交易记录文件中已经存有脱机交易记录,而另一个脱机交易记录文件中没有脱机交易记录,那么,脱机交易设备向两个脱机交易记录文件分别写入脱机交易记录的情况下,第一文件和第二文件均能通过完整性校验,但是两个脱机交易记录文件中保存的脱机交易记录不一致。因此,脱机交易设备需要进一步对第一文件和第二文件进行比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。Before an offline transaction device writes an offline transaction record to a storage device, if one of the offline transaction record files already has an offline transaction record, and another offline transaction record file does not have an offline transaction record, then In the case where the machine transaction device writes the offline transaction records to the two offline transaction log files, both the first file and the second file can pass the integrity check, but the two offline transaction record files are saved offline. The transaction records are inconsistent. Therefore, the offline transaction device needs to further compare the first file and the second file, including comparing the first file length and the second file length, comparing the content of the first file and the content of the second file.
具体地,第一文件和第二文件均校验成功,脱机交易设备对第一文件长度和第二文件长度进行比较。如果第一文件长度大于第二文件长度,说明第一文件中的脱机交易记录多于第二文件中的脱机交易记录,为了完整保存脱机交易记录,脱机交易设备利用脱机交易记录较多的文件替换脱机交易记录较少的文件,即第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件。反之,如果第一文件长度小于第二文件长度,说明第一文件中的脱机交易记录少于第二文件中的脱机交易记录,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。由此,将脱机交易记录较少的脱机交易记录文件替换成了脱机交易记录较多的脱机交易记录文件,第一文件中的脱机交易记录和第二文件中的脱机交易记录达到了一致,提高第一文件中的脱机交易记录和第二文 件中的脱机交易记录的准确性。Specifically, both the first file and the second file are successfully verified, and the offline transaction device compares the first file length and the second file length. If the first file length is greater than the second file length, indicating that the offline transaction record in the first file is more than the offline transaction record in the second file, in order to completely save the offline transaction record, the offline transaction device utilizes the offline transaction record. More files replace the files with fewer offline transaction records, that is, the offline transaction records in the first file replace the offline transaction records in the second file, and the replaced second file is saved in the second storage device. Conversely, if the first file length is less than the second file length, indicating that the offline transaction record in the first file is less than the offline transaction record in the second file, the first file is replaced with the offline transaction record in the second file. In the offline transaction record, the replaced first file is saved in the first storage device. Thus, the offline transaction record file with fewer offline transaction records is replaced with the offline transaction record file with more offline transaction records, the offline transaction record in the first file, and the offline transaction in the second file. The record reached a consensus, improving the offline transaction record and the second text in the first file The accuracy of offline transaction records in the piece.
如果第一文件长度等于第二文件长度,脱机交易设备对第一文件的内容和第二文件的内容进行比较。如果第二存储装置为外存储装置,在对脱机交易记录进行校验之前,脱机交易设备的外存储装置被工作人员取出,由于工作人员疏忽,原来的脱机交易设备的外存储装置被替换成了其他脱机交易设备中的外存储装置。如果替换后的外存储装置中的脱机交易记录保存完整,则替换后的外存储装置中的第二文件也可以通过完整性校验、且第二文件长度和内存储装置中的第一文件长度一致,但是替换后的外存储装置中的脱机交易记录和原来的外存储装置中的脱机交易记录并不相同。在这种情况下,脱机交易设备需要对第一文件中的内容和第二文件中的内容进行比较。If the first file length is equal to the second file length, the offline 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, the external storage device of the offline transaction device is taken out by the staff member before the offline transaction record is verified. Due to the negligence of the staff, the external storage device of the original offline transaction device is Replaced with an external storage device in other offline trading devices. If the offline transaction record in the replaced external storage device is completely saved, the second file in the replaced external storage device may also pass the integrity check, and the second file length and 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 not the same as 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 first file length is equal to the second file length, the offline transaction record in the first file is as much as the offline transaction record in the second file, and the offline transaction device has the content of the first file and the second Comparing the contents of the file: if the content in the first file is consistent with the content in the second file, indicating 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, and the second file is saved in the second storage device. If the content of the first file and the content of the second file are inconsistent, that is, an offline transaction record in the first file or an offline transaction record in the second file is in error. The offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file, and saves the replaced second file in the second storage device. Preferably, the first storage device may be an internal storage device, and the second storage device may be an external storage device. Since the offline storage record stored by the internal storage device is more accurate than the external storage device, the offline transaction record of the internal storage device is replaced. Offline transaction record of the storage device. That is, the offline transaction record in the first file is replaced with 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 record in the external storage device is replaced with the offline transaction record in the internal storage device, thereby further improving the accuracy of the offline transaction record. The first file saved in one storage device and the second file saved in the second storage device are identical.
在其中一个实施例中,对第一文件的内容和第二文件的内容进行比较的步骤,可以通过比对第一文件中的脱机交易记录和第二文件中的脱机交易记录判 断第一文件的内容和第二文件的内容是否一致。如果第一文件中的脱机交易记录和第二文件中的脱机交易记录一致,则第一文件的内容和第二文件的内容一致。也可以通过比对第一文件中的脱机交易记录和第二文件中的脱机交易记录、比对第一文件中的第一校验码和第二文件中的第二校验码,判断第一文件的内容和第二文件的内容是否一致,如果第一文件中的脱机交易记录和第二文件中的脱机交易记录一致且第一校验码和第二校验码一致,则第一文件的内容和第二文件的内容一致。比对脱机交易记录和校验码两项内容的结果更准确。In one of the embodiments, the step of comparing the content of the first file with the content of the second file may be performed by comparing the offline transaction record in the first file with the offline transaction record 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, the content of the first file is consistent with the content of the second file. It is also possible to determine by comparing the offline transaction record in the first file and 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 and the content of the second file are consistent, if the offline transaction record in the first file and the offline transaction record in the second file are consistent and the first check code and the second check code are consistent, then The content of the first file is consistent with the content of the second file. The result of comparing the two contents of the offline transaction record and the check code is more accurate.
在一个实施例中,脱机交易设备替换脱机交易记录文件中的内容,可以替换脱机交易记录文件中的脱机交易记录,也可以替换脱机交易记录文件中的脱机交易记录和校验码,还可以直接将脱机交易记录文件替换。例如,如果第一文件校验成功且第二文件校验失败,脱机交易设备可以利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,也可以利用第一文件中的脱机交易记录和第一校验码分别替换第二文件中的脱机交易记录和第二校验码,还可以将第一文件直接替换第二文件。脱机交易设备直接替换脱机交易记录文件较为简单。In one embodiment, the offline transaction device replaces the content in the offline transaction log file, can replace the offline transaction record in the offline transaction record file, or can replace the offline transaction record and the school in the offline transaction record file. Code verification, you can also directly replace the offline transaction record file. For example, if the first file verification is successful and the second file verification fails, the offline transaction device may replace the offline transaction record in the second file by using the offline transaction record in the first file, or may use the first file. The offline transaction record and the first check code respectively replace the offline transaction record and the second check code in the second file, and the first file can be directly replaced with the second file. It is easier to replace an offline transaction log file directly with an offline trading device.
本实施例中,在第一文件和第二文件均校验成功的情况下,脱机交易设备对第一文件和第二文件进行进一步比较,包括对第一文件长度和第二文件长度进行比较、对第一文件的内容和第二文件的内容进行比较。通过对第一文件长度和第二文件长度进行比较,将脱机交易记录较多的文件替换脱机交易记录较少的文件,提高脱机交易记录的准确性。通过对第一文件的内容和第二文件的内容进行比较,进一步提高脱机交易记录文件的准确性。In this embodiment, in the case that both the first file and the second file are successfully verified, the offline transaction device further compares the first file and 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 the offline transaction record. The accuracy of the offline transaction record file is further improved by comparing the content of the first file with the content of the second file.
在一个实施例中,该方法还包括:若第一存储装置发生写入失败且第二存储装置中第二文件完整性校验成功,则将第二文件中的脱机交易记录替换第一文件中的脱机交易记录,将第二文件中的脱机交易上传至后台,生成报警提示;若第二存储装置发生写入失败且第一存储装置中第一文件完整性校验成功,则将第一文件中的脱机交易记录替换第二文件中的脱机交易记录,将第一文件中的脱机交易上传至后台,生成报警提示。In one embodiment, the method further comprises: replacing the offline transaction record in the second file with the first file if the first storage device fails to write and the second file integrity check in the second storage device succeeds In the offline transaction record, the offline transaction in the second file is uploaded to the background to generate an alarm prompt; if the second storage device fails to write and the first file integrity check in the first storage device is successful, The offline transaction record in the first file replaces the offline transaction record in the second file, and the offline transaction in the first file is uploaded to the background to generate an alarm prompt.
当通过脱机交易设备首次发生脱机交易时,脱机交易设备检测第一存储装 置是否包括第一文件,如果第一存储装置中没有第一文件,在第一存储装置中创建第一文件。如果第一文件创建失败,说明第一存储装置故障,脱机交易设备标记第一存储装置故障。同样地,脱机交易设备检测第二存储装置是否包括第二文件,如果第二存储装置中没有第二文件,在第二存储装置中创建第二文件。如果第二文件创建失败,说明第二存储装置故障,脱机交易设备标记第二存储装置故障。如果脱机交易设备发生创建文件失败,生成报警提示。When the offline transaction occurs for the first time through the offline transaction device, the offline transaction device detects the first storage device Whether or not the first file is included, if the first file is not in the first storage device, the first file is created in the first storage device. If the first file creation fails, the first storage device fails, and the offline transaction device marks the first storage device failure. 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 second file creation fails, the second storage device fails and the offline transaction device marks the second storage device failure. If the offline transaction device fails to create a file, an alert is generated.
在一个实施例中,脱机交易记录文件创建成功之后,当发生脱机交易时,脱机交易设备生成新的脱机交易记录,脱机交易设备将脱机交易记录分别写入脱机交易记录文件。首先,脱机交易设备打开脱机交易记录文件,检测脱机交易记录文件中是否包括脱机交易记录。如果脱机交易记录文件中没有脱机交易记录,则将新的脱机交易记录写在脱机交易记录文件的开端。脱机交易设备利用密钥和脱机交易记录文件中的脱机交易记录计算校验码,将校验码写在脱机交易记录之后。如果脱机交易记录文件中已包括脱机交易记录,脱机交易设备检测脱机交易记录文件中的校验码,将新的脱机交易记录插入最后一条脱机交易记录和校验码之间,利用密钥和当前全部脱机交易记录计算新的校验码,替换原来的校验码。由此,脱机交易设备将脱机交易记录写入脱机交易记录文件。In one embodiment, after the offline transaction log 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 to the offline transaction record separately. file. First, the offline transaction device opens the offline transaction record file and detects whether the offline transaction record is included in the offline transaction record file. If there is no offline transaction record in the offline transaction log file, the new offline transaction record is written at the beginning of the offline transaction record file. The offline transaction device calculates the check code using the key and offline transaction records in the offline transaction log file, and writes the check code after the offline transaction record. If an offline transaction record is already included in the offline transaction log file, the offline transaction device detects the check code in the offline transaction log file and inserts the new offline transaction record between the last offline transaction record and the check code. , using the key and all current offline transaction records to calculate a new check code, replacing the original check code. Thus, the offline transaction device writes the offline transaction record to the offline transaction record file.
如果第一存储装置发生写入失败且第二存储装置发生写入失败,说明第一存储装置中的脱机交易记录和第二存储装置中的脱机交易记录均不完整,发出报警提示。如果第一存储装置发生写入失败,第二存储装置未发生写入失败,但是第二文件完整性校验失败,说明第一存储装置中的脱机交易记录和第二存储装置中的脱机交易记录均不完整,发出报警提示。同样地,如果第二存储装置发生写入失败,第一存储装置未发生写入失败,但是第一文件完整性校验失败,说明第一存储装置中的脱机交易记录和第二存储装置中的脱机交易记录均不完整,发出报警提示。如果第一存储装置发生写入失败,第二存储装置未发生写入失败,且第二文件校验成功,说明第一存储装置中的脱机交易记录不完整,但第二存储装置中的脱机交易记录完整,脱机交易设备将第二文件中脱机交易记录替换第一文件中的脱机交易记录,上传后台,发出报警提示。同样地,如果第二存储装置发生写入失败,第一存储装置未发生写入失败,且第一文件 校验成功,说明第二存储装置中的脱机交易记录不完整,但第一存储装置中的脱机交易记录完整,脱机交易设备将第一文件中脱机交易记录替换第二文件中的脱机交易记录,上传后台,发出报警提示。通过对存储装置写入故障和脱机交易记录文件完整性校验结果进行分析,及时地将有效脱机交易记录文件上传后台,避免发生交易记录丢失,确保了脱机交易记录完整性。If the first storage device fails to write and the second storage device fails to write, it indicates that the offline transaction record in the first storage device and the offline transaction record in the second storage device are incomplete, and an alarm prompt is issued. If the first storage device fails to write, the second storage device does not fail to write, but the second file integrity check fails, indicating that the offline transaction record in the first storage device and the offline in the second storage device The transaction records are incomplete and an alert is issued. Similarly, if the second storage device fails to write, the first storage device does not fail to write, but the first file integrity check fails, indicating the offline transaction record in the first storage device and the second storage device The offline transaction records are 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 is successfully verified, indicating that the offline transaction record in the first storage device is incomplete, but the second storage device is off. The machine transaction record is complete, and the offline transaction device replaces the offline transaction record in the second file with the offline transaction record in the first file, uploads the background, and issues an alarm prompt. Similarly, if the second storage device fails to write, the first storage device does not fail to write, and the first file The verification succeeds, indicating that the offline transaction record in the second storage device is incomplete, but the offline transaction record in the first storage device is complete, and the offline transaction device replaces the offline transaction record in the first file with the second file. Offline transaction records, upload background, and issue alarm prompts. By analyzing the storage device write failure and the offline transaction record file integrity check result, the effective offline transaction record file is uploaded to the background in time to avoid the loss of the transaction record and ensure the integrity of the offline transaction record.
在一个实施例中,在获取第一存储装置的第一文件的步骤之前,还包括:若在第一存储装置中创建第一文件失败,或者第二存储装置中创建第二文件失败,则生成报警提示;若第一文件和第二文件创建成功,对第一文件和第二文件分别进行校验;及若校验通过,则向第一文件和第一文件分别写入脱机交易记录。In an embodiment, before the step of acquiring the first file of the first storage device, the method further includes: if the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, If the first file and the second file are successfully created, the first file and the second file are respectively verified; and if the verification is passed, the offline transaction record is separately written to the first file and the first file.
当发生脱机交易时,脱机交易设备可以直接将脱机交易记录写入第一文件和第二文件,在写入的过程中不对第一文件和第二文件进行校验,当脱机交易设备开机或上传脱机交易记录时,对第一文件和第二文件进行校验。脱机交易设备也可以在写脱机交易记录的动作之前,先对第一文件和第二文件进行校验,确定第一装置和第二装置正常、第一文件和第二文件一致之后,向第一文件和第二文件分别写入新的脱机交易记录。每次写入脱机交易记录前对第一文件和第二文件进行校验,可以多次对脱机交易记录进行校验,有效提高脱机交易记录的准确性,出现故障之后脱机交易设备及时发出报警提示,避免脱机交易记录丢失。When an offline transaction occurs, the offline transaction device can directly write the offline transaction record to the first file and the second file, and does not verify the first file and the second file during the writing process, when offline transactions The first file and the second file are verified when the device is powered on or uploading an offline transaction record. The offline transaction device may also check the first file and the second file before the action of writing the offline transaction record, and determine that the first device and the second device are normal, the first file and the second file are consistent, The first file and the second file are respectively written into the new offline transaction record. The first file and the second file are verified before each write of the offline transaction record, and the offline transaction record can be verified multiple times, thereby effectively improving the accuracy of the offline transaction record, and the offline transaction device after the failure occurs. Promptly issue an alarm prompt to avoid loss of offline transaction records.
本实施例中,脱机交易设备通过分析存储装置故障和脱机交易记录文件校验结果,将有效的脱机交易记录文件上传后台,发出报警提示,避免发生交易记录丢失,确保了脱机交易记录完整性。In this embodiment, the offline transaction device uploads a valid offline transaction record file to the background by analyzing the storage device failure and the offline transaction record file verification result, and issues an alarm prompt to avoid the loss of the transaction record and ensure the offline transaction. Record integrity.
在一个实施例中,如图2所示,本申请提供了一种脱机交易记录终端的内部结构可对应于如图2所示的结构,下述每个模块可全部或部分通过软件、硬件或其组合来实现。在一个实施例中,该脱机交易记录终端包括:获取模块202、校验模块204、替换模块206、保存模块208,其中:In an embodiment, as shown in FIG. 2, the application provides that the internal structure of the offline transaction recording terminal can correspond to the structure shown in FIG. 2, and each of the following modules can be partially or partially passed through software and hardware. Or a combination of them to achieve. In an embodiment, the offline transaction recording terminal includes: an obtaining module 202, a verification module 204, a replacement module 206, and a saving module 208, wherein:
获取模块202,用于获取第一存储装置的第一文件,第一文件包括脱机交易记录;获取第二存储装置的第二文件,第二文件包括脱机交易记录。 The obtaining module 202 is configured to acquire a first file of the first storage device, where the first file includes an offline transaction record; the second file of the second storage device is acquired, and the second file includes an offline transaction record.
校验模块204,用于对第一文件和第二文件分别进行完整性校验。The verification module 204 is configured to perform integrity verification on the first file and the second file respectively.
替换模块206,用于若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。The replacement module 206 is configured to replace the offline transaction record in the second file by using the offline transaction record in the first file if the first file verification is successful and the second file verification fails; if the first file verification fails And if the second file is successfully verified, 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; and save the replaced first file in the first storage device.
在一个实施例中,获取模块202还用于若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度,校验模块204还用于对第一文件长度和第二文件长度进行一致性校验。In an embodiment, the obtaining module 202 is further configured to: if the first file and the second file are successfully verified, obtain the first file length and the second file length, and the verification module 204 is further configured to use the first file length and The second file length is checked for consistency.
在一个实施例中,第一文件还包括第一校验码,校验模块204还用于对第一文件长度进行校验,包括:获取第一文件长度;获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;获取校验码字节数,校验码字节数包括第一校验码占用的字节;通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;判断第一文件中的脱机交易记录条数是否为正整数;若不是,则第一文件校验失败。In an embodiment, the first file further includes a first check code, and the check module 204 is further configured to check the first file length, including: obtaining the first file length; and obtaining the number of the single offline transaction record bytes. The number of bytes of a single offline transaction record includes a byte occupied by a single offline transaction record in the first file; the number of check code bytes is obtained, and the number of check code bytes includes a byte occupied by the first check code; Calculate the number of offline transaction records in the first file by a single offline transaction record byte number, check code byte number, and first file length; determine whether the number of offline transaction records in the first file is positive Integer; if not, the first file verification failed.
在一个实施例中,第一文件还包括第一校验码,校验模块204还用于对校验码进行校验,对校验码进行校验包括对第一校验码进行校验,包括:获取预设的密钥;通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;若不相等,则第一文件校验失败。In an embodiment, the first file further includes a first check code, the check module 204 is further configured to check the check code, and the verifying the check code includes verifying the first check code. The method includes: obtaining a preset key; calculating, by using a key and an offline transaction record in the first file, a first integrity check code corresponding to the first file; determining whether the first check code of the first file is the first The first integrity check code corresponding to the file is equal; if not equal, the first file check fails.
在一个实施例中,校验模块204还用于对第一文件长度和第二文件长度进行一致性校验,包括:若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。 In an embodiment, the verification module 204 is further configured to perform consistency check on the first file length and the second file length, including: if the first file length is greater than the second file length, using the first file The machine transaction record replaces the offline transaction record in the second file; if the first file length is equal to the second file length and the content is inconsistent, the offline transaction record in the second file is replaced by the offline transaction record in the first file; If the first file length is less than the second file length, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
在一个实施例中,提供了一种计算机设备,如图3所示,该计算机设备包括非易失性存储介质和存储装置、处理器以及存储在存储装置上并可在处理器上运行的计算机程序以及数据库等,处理器用于提供计算和控制能力。存储装置为计算机程序的运行提供环境。存储装置包括第一存储装置和第二存储装置。其中第一存储装置可以是内存储器,第二存储装置可以是外存储器,如SD卡等。数据库用于存储脱机交易记录以及校验码等。处理器执行计算机程序时实现以下步骤:获取第一存储装置的第一文件,第一文件包括脱机交易记录;In one embodiment, a computer device is provided, as shown in FIG. 3, including a non-volatile storage medium and storage device, a processor, and a computer stored on the storage device and operable on the processor Programs, databases, etc., processors are used to provide computing and control capabilities. The storage device provides an environment for the operation of the computer program. The storage device includes a first storage device and a second storage device. The first storage device may be an internal storage, and the second storage device may be an external storage such as an SD card or the like. The database is used to store offline transaction records, checksums, and so on. When the processor executes the computer program, the following steps are implemented: acquiring 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, where the second file includes an offline transaction record;
对第一文件和第二文件分别进行完整性校验;Performing integrity verification on the first file and the second file respectively;
若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。If the first file is successfully verified and the second file verification fails, the offline transaction record in the second file is replaced with the offline transaction record in the first file, and the replaced second file is saved in the second storage device. If the first file verification fails and the second file verification succeeds, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced first is saved in the first storage device. file.
该计算机设备可以用独立的计算机设备或者是多个计算机设备组成的计算机设备集群来实现。本领域技术人员可以理解,图3中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。The computer device can be implemented by a stand-alone computer device or a cluster of computer devices consisting of a plurality of computer devices. It will be understood by those skilled in the art that the structure shown in FIG. 3 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation of the computer device to which the solution of the present application is applied. The specific computer device may It includes more or fewer components than those shown in the figures, or some components are combined, or have different component arrangements.
在一个实施例中,处理器还用于执行:In one embodiment, the processor is further configured to:
若在第一存储装置中创建第一文件失败,或者第二存储装置中创建第二文件失败,则生成报警提示;If the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, an alarm prompt is generated;
若第一文件和第二文件创建成功,对第一文件和第二文件分别进行校验;及If the first file and the second file are successfully created, the first file and the second file are respectively verified; and
若校验通过,则向第一文件和第一文件分别写入脱机交易记录。If the verification passes, the offline transaction record is written to the first file and the first file, respectively.
在一个实施例中,处理器还用于执行:In one embodiment, the processor is further configured to:
若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度;If the first file and the second file are successfully verified, obtaining the first file length and the second file length;
对第一文件长度和第二文件长度进行一致性校验。在一个实施例中,处理 器还用于执行:Perform consistency check on the first file length and the second file length. In one embodiment, processing It is also used to execute:
获取第一文件长度;Obtain the first file length;
获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;Get the number of bytes of a single offline transaction record, and the number of bytes of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file;
获取校验码字节数,校验码字节数包括第一校验码占用的字节;Obtaining a check code byte number, where the check code byte number includes a byte occupied by the first check code;
通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一文件中的脱机交易记录条数;Calculating the number of offline transaction records in the first file by a single offline transaction record byte number, a check code byte number, and a first file length;
判断第一文件中的脱机交易记录条数是否为正整数;Determining 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 processor is further configured to:
获取预设的密钥;Obtain a preset key;
通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;Calculating, by using the key and the offline transaction record in the first file, a first integrity check code corresponding to the first file;
判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;Determining 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 processor is further configured to:
若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the first file length is greater than the second file length, replacing the offline transaction record in the second file with the offline transaction record in the first file;
若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the first file length is equal to the second file length and the content is inconsistent, the offline transaction record in the second file is replaced by the offline transaction record in the first file;
若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。If the first file length is less than the second file length, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
在一个实施例中,处理器还用于执行:In one embodiment, the processor is further configured to:
若第一存储装置发生写入失败且第二存储装置中第二文件完整性校验成功,则将第二文件中的脱机交易记录替换第一文件中的脱机交易记录,将第二文件中的脱机交易上传至后台,生成报警提示;若第二存储装置发生写入失败且第一存储装置中第一文件完整性校验成功,则将第一文件中的脱机交易记录 替换第二文件中的脱机交易记录,将第一文件中的脱机交易上传至后台,生成报警提示。If the first storage device fails to write and the second file integrity check in the second storage device succeeds, the offline transaction record in the second file is replaced with the offline transaction record in the first file, and the second file is deleted. The offline transaction in the middle is uploaded to the background to generate an alarm prompt; if the second storage device fails to write and the first file integrity check in the first storage device is successful, the offline transaction record in the first file is generated. Replace the offline transaction record in the second file, upload the offline transaction in the first file to the background, and generate an alarm prompt.
在一个实施例中,一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:In one embodiment, one or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause one or more processors to perform the following step:
获取第一存储装置的第一文件,第一文件包括脱机交易记录;Obtaining 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, where the second file includes an offline transaction record;
对第一文件和第二文件分别进行完整性校验;Performing integrity verification on the first file and the second file respectively;
若第一文件校验成功且第二文件校验失败,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录,在第二存储装置中保存替换后的第二文件;若第一文件校验失败且第二文件校验成功,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录,在第一存储装置中保存替换后的第一文件。If the first file is successfully verified and the second file verification fails, the offline transaction record in the second file is replaced with the offline transaction record in the first file, and the replaced second file is saved in the second storage device. If the first file verification fails and the second file verification succeeds, the offline transaction record in the first file is replaced with the offline transaction record in the second file, and the replaced first is saved in the first storage device. file.
在一个实施例中,处理器还用于执行:In one embodiment, the processor is further configured to:
若在第一存储装置中创建第一文件失败,或者第二存储装置中创建第二文件失败,则生成报警提示;If the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, an alarm prompt is generated;
若第一文件和第二文件创建成功,对第一文件和第二文件分别进行校验;及If the first file and the second file are successfully created, the first file and the second file are respectively verified; and
若校验通过,则向第一文件和第一文件分别写入脱机交易记录。If the verification passes, the offline transaction record is written to the first file and the first file, respectively.
在一个实施例中,计算机程序被处理器执行时还实现以下步骤:In one embodiment, the computer program is executed by the processor to also implement the following steps:
若第一文件和第二文件均校验成功,则获取第一文件长度和第二文件长度;If the first file and the second file are successfully verified, obtaining the first file length and the second file length;
对第一文件长度和第二文件长度进行一致性校验。Perform consistency check on the first file length and the second file length.
在一个实施例中,处理器还用于执行:In one embodiment, the processor is further configured to:
获取第一文件长度;Obtain the first file length;
获取单条脱机交易记录字节数,单条脱机交易记录字节数包括第一文件中的单条脱机交易记录占用的字节;Get the number of bytes of a single offline transaction record, and the number of bytes of a single offline transaction record includes the bytes occupied by a single offline transaction record in the first file;
获取校验码字节数,校验码字节数包括第一校验码占用的字节;Obtaining a check code byte number, where the check code byte number includes a byte occupied by the first check code;
通过单条脱机交易记录字节数、校验码字节数和第一文件长度,计算第一 文件中的脱机交易记录条数;Calculate first by counting the number of bytes in a single offline transaction, the number of check code bytes, and the length of the first file. The number of offline transaction records in the file;
判断第一文件中的脱机交易记录条数是否为正整数;Determining 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 processor is further configured to:
获取预设的密钥;Obtain a preset key;
通过密钥和第一文件中的脱机交易记录计算第一文件对应的第一完整性校验码;Calculating, by using the key and the offline transaction record in the first file, a first integrity check code corresponding to the first file;
判断第一文件的第一校验码是否与第一文件对应的第一完整性校验码相等;Determining 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 processor is further configured to:
若第一文件长度大于第二文件长度,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the first file length is greater than the second file length, replacing the offline transaction record in the second file with the offline transaction record in the first file;
若第一文件长度等于第二文件长度且内容不一致,则利用第一文件中的脱机交易记录替换第二文件中的脱机交易记录;If the first file length is equal to the second file length and the content is inconsistent, the offline transaction record in the second file is replaced by the offline transaction record in the first file;
若第一文件长度小于第二文件长度,则利用第二文件中的脱机交易记录替换第一文件中的脱机交易记录。If the first file length is less than the second file length, the offline transaction record in the first file is replaced with the offline transaction record in the second file.
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。The technical features of the above embodiments may be arbitrarily combined. For the sake of brevity of description, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, It is considered to be the range described in this specification.
以上实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。 The above embodiments are merely illustrative of several embodiments of the present application, and the description thereof is more specific and detailed, but is not to be construed as limiting the scope of the invention. It should be noted that a number of variations and modifications may be made by those skilled in the art without departing from the spirit and scope of the present application. Therefore, the scope of the invention should be determined by the appended claims.

Claims (20)

  1. 一种脱机交易记录保存方法,包括:An offline transaction record saving method, comprising:
    获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;Obtaining 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, where the second file includes an offline transaction record;
    对所述第一文件和所述第二文件分别进行完整性校验;及Performing integrity verification on the first file and the second file respectively; and
    若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the first file verification is successful and the second file verification fails, replacing the offline transaction record in the second file with the offline transaction record in the first file, in the second Saving the replaced second file in the storage device; if the first file verification fails and the second file verification is successful, replacing the first file with the offline transaction record in the second file The offline transaction record stores the replaced first file in the first storage device.
  2. 根据权利要求1所述的方法,其特征在于,在所述获取第一存储装置的第一文件的步骤之前,还包括:The method according to claim 1, wherein before the step of acquiring the first file of the first storage device, the method further comprises:
    若在第一存储装置中创建第一文件失败,或者第二存储装置中创建第二文件失败,则生成报警提示;If the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, an alarm prompt is generated;
    若所述第一文件和所述第二文件创建成功,对第一文件和第二文件分别进行校验;及If the first file and the second file are successfully created, respectively verifying the first file and the second file; and
    若校验通过,则向第一文件和第一文件分别写入脱机交易记录。If the verification passes, the offline transaction record is written to the first file and the first file, respectively.
  3. 根据权利要求1所述的方法,其特征在于,所述对所述第一文件和所述第二文件分别进行完整性校验的步骤之后,还包括:The method according to claim 1, wherein after the step of performing integrity verification on the first file and the second file respectively, the method further comprises:
    若所述第一文件和所述第二文件均校验成功,则获取所述第一文件长度和所述第二文件长度;及Obtaining the first file length and the second file length if both the first file and the second file are successfully verified; and
    对所述第一文件长度和所述第二文件长度进行一致性校验。Performing consistency check on the first file length and the second file length.
  4. 根据权利要求3所述的方法,其特征在于,所述第一存储装置为内存储装置,所述第二存储装置为外存储装置,所述对所述第一文件长度和所述第二文件长度进行一致性校验的步骤,包括:The method according to claim 3, wherein said first storage device is an internal storage device, said second storage device is an external storage device, said pair of said first file length and said second file The steps for length verification, including:
    若所述第一文件长度大于所述第二文件长度,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录; If the first file length is greater than the second file length, replacing an offline transaction record in the second file with an offline transaction record in the first file;
    若所述第一文件长度等于所述第二文件长度且内容不一致,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;及If the first file length is equal to the second file length and the content is inconsistent, replacing the offline transaction record in the second file with the offline transaction record in the first file; and
    若所述第一文件长度小于所述第二文件长度,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录。If the first file length is less than the second file length, replacing the offline transaction record in the first file with the offline transaction record in the second file.
  5. 根据权利要求1所述的方法,其特征在于,所述第一文件还包括第一校验码,所述完整性校验包括对所述第一文件长度进行校验,所述对所述第一文件长度进行校验的步骤,包括:The method according to claim 1, wherein said first file further comprises a first check code, said integrity check comprising verifying said first file length, said pair of said The step of verifying a file length includes:
    获取所述第一文件长度;Obtaining the length of the first file;
    获取单条脱机交易记录字节数,所述单条脱机交易记录字节数包括所述第一文件中的单条脱机交易记录占用的字节;Obtaining a single offline transaction record byte number, where the single offline transaction record byte number includes a byte occupied by a single offline transaction record in the first file;
    获取校验码字节数,所述校验码字节数包括所述第一校验码占用的字节;Obtaining a check code byte number, where the check code byte number includes a byte occupied by the first check code;
    通过所述单条脱机交易记录字节数、所述校验码字节数和所述第一文件长度,计算所述第一文件中的脱机交易记录条数;Calculating, by the single offline transaction record byte number, the check code byte number, and the first file length, the number of offline transaction records in the first file;
    判断所述第一文件中的脱机交易记录条数是否为正整数;及Determining whether the number of offline transaction records in the first file is a positive integer; and
    若不是,则所述第一文件校验失败。If not, the first file verification fails.
  6. 根据权利要求1所述的方法,其特征在于,所述第一文件还包括第一校验码,所述完整性校验还包括对校验码进行校验,所述对校验码进行校验包括对所述第一校验码进行校验的步骤,包括:The method according to claim 1, wherein the first file further comprises a first check code, the integrity check further comprises verifying the check code, and the check code is calibrated The verification includes the step of verifying the first verification code, including:
    获取预设的密钥;Obtain a preset key;
    通过所述密钥和所述第一文件中的脱机交易记录计算所述第一文件对应的第一完整性校验码;Calculating, by using the key and the offline transaction record in the first file, a first integrity check code corresponding to the first file;
    判断所述第一文件的第一校验码是否与所述第一文件对应的第一完整性校验码相等;及Determining whether the first check code of the first file is equal to the first integrity check code corresponding to the first file; and
    若不相等,则所述第一文件校验失败。If they are not equal, the first file verification fails.
  7. 根据权利要求1所述的方法,其特征在于,还包括:The method of claim 1 further comprising:
    若第一存储装置发生写入失败且第二存储装置中第二文件完整性校验成功,则将第二文件中的脱机交易记录替换第一文件中的脱机交易记录,将第 二文件中的脱机交易上传至后台,生成报警提示;若第二存储装置发生写入失败且第一存储装置中第一文件完整性校验成功,则将第一文件中的脱机交易记录替换第二文件中的脱机交易记录,将第一文件中的脱机交易上传至后台,生成报警提示。If the first storage device fails to write and the second file integrity check in the second storage device succeeds, the offline transaction record in the second file is replaced with the offline transaction record in the first file, The offline transaction in the second file is uploaded to the background to generate an alarm prompt; if the second storage device fails to write and the first file integrity check in the first storage device is successful, the offline transaction record in the first file is generated. Replace the offline transaction record in the second file, upload the offline transaction in the first file to the background, and generate an alarm prompt.
  8. 一种计算机设备,包括存储器及处理器,所述存储器中储存有计算机程序,所述计算机程序被所述处理器执行时,使得所述处理器执行以下步骤:获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;A computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the processor performs the step of: acquiring a first file of the first storage device The first file includes an offline transaction record;
    获取第二存储装置的第二文件,所述第二文件包括脱机交易记录;Obtaining a second file of the second storage device, where the second file includes an offline transaction record;
    对所述第一文件和所述第二文件分别进行完整性校验;及Performing integrity verification on the first file and the second file respectively; and
    若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the first file verification is successful and the second file verification fails, replacing the offline transaction record in the second file with the offline transaction record in the first file, in the second Saving the replaced second file in the storage device; if the first file verification fails and the second file verification is successful, replacing the first file with the offline transaction record in the second file The offline transaction record stores the replaced first file in the first storage device.
  9. 根据权利要求8所述的计算机设备,其特征在于,所述处理器还用于执行:The computer device according to claim 8, wherein the processor is further configured to:
    若在第一存储装置中创建第一文件失败,或者第二存储装置中创建第二文件失败,则生成报警提示;If the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, an alarm prompt is generated;
    若所述第一文件和所述第二文件创建成功,对第一文件和第二文件分别进行校验;及If the first file and the second file are successfully created, respectively verifying the first file and the second file; and
    若校验通过,则向第一文件和第一文件分别写入脱机交易记录。If the verification passes, the offline transaction record is written to the first file and the first file, respectively.
  10. 根据权利要求8所述的计算机设备,其特征在于,所述处理器还用于执行:The computer device according to claim 8, wherein the processor is further configured to:
    若所述第一文件和所述第二文件均校验成功,则获取所述第一文件长度和所述第二文件长度;及Obtaining the first file length and the second file length if both the first file and the second file are successfully verified; and
    对所述第一文件长度和所述第二文件长度进行一致性校验。 Performing consistency check on the first file length and the second file length.
  11. 根据权利要求10所述的计算机设备,其特征在于,所述处理器还用于执行:The computer device according to claim 10, wherein the processor is further configured to:
    若所述第一文件长度大于所述第二文件长度,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;If the first file length is greater than the second file length, replacing an offline transaction record in the second file with an offline transaction record in the first file;
    若所述第一文件长度等于所述第二文件长度且内容不一致,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;及If the first file length is equal to the second file length and the content is inconsistent, replacing the offline transaction record in the second file with the offline transaction record in the first file; and
    若所述第一文件长度小于所述第二文件长度,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录。If the first file length is less than the second file length, replacing the offline transaction record in the first file with the offline transaction record in the second file.
  12. 根据权利要求8所述的计算机设备,其特征在于,所述第一文件还包括第一校验码,所述完整性校验包括对所述第一文件长度进行校验,所述处理器还用于执行:The computer device according to claim 8, wherein the first file further comprises a first check code, the integrity check comprises verifying the length of the first file, and the processor further Used to execute:
    获取所述第一文件长度;Obtaining the length of the first file;
    获取单条脱机交易记录字节数,所述单条脱机交易记录字节数包括所述第一文件中的单条脱机交易记录占用的字节;Obtaining a single offline transaction record byte number, where the single offline transaction record byte number includes a byte occupied by a single offline transaction record in the first file;
    获取校验码字节数,所述校验码字节数包括所述第一校验码占用的字节;Obtaining a check code byte number, where the check code byte number includes a byte occupied by the first check code;
    通过所述单条脱机交易记录字节数、所述校验码字节数和所述第一文件长度,计算所述第一文件中的脱机交易记录条数;Calculating, by the single offline transaction record byte number, the check code byte number, and the first file length, the number of offline transaction records in the first file;
    判断所述第一文件中的脱机交易记录条数是否为正整数;及Determining whether the number of offline transaction records in the first file is a positive integer; and
    若不是,则所述第一文件校验失败。If not, the first file verification fails.
  13. 根据权利要求8所述的计算机设备,其特征在于,所述第一文件还包括第一校验码,所述完整性校验还包括对校验码进行校验,所述处理器还用于执行:The computer device according to claim 8, wherein the first file further comprises a first check code, the integrity check further comprises verifying the check code, and the processor is further configured to: carried out:
    获取预设的密钥;Obtain a preset key;
    通过所述密钥和所述第一文件中的脱机交易记录计算所述第一文件对应的第一完整性校验码;Calculating, by using the key and the offline transaction record in the first file, a first integrity check code corresponding to the first file;
    判断所述第一文件的第一校验码是否与所述第一文件对应的第一完整性校验码相等;及 Determining whether the first check code of the first file is equal to the first integrity check code corresponding to the first file; and
    若不相等,则所述第一文件校验失败。If they are not equal, the first file verification fails.
  14. 根据权利要求8所述的计算机设备,其特征在于,所述处理器还用于执行:The computer device according to claim 8, wherein the processor is further configured to:
    若第一存储装置发生写入失败且第二存储装置中第二文件完整性校验成功,则将第二文件中的脱机交易记录替换第一文件中的脱机交易记录将第二文件中的脱机交易上传至后台,生成报警提示;若第二存储装置发生写入失败且第一存储装置中第一文件完整性校验成功,则将第一文件中的脱机交易记录替换第二文件中的脱机交易记录,将第一文件中的脱机交易上传至后台,生成报警提示。If the first storage device fails to write and the second file integrity check in the second storage device is successful, replacing the offline transaction record in the second file with the offline transaction record in the first file in the second file The offline transaction is uploaded to the background to generate an alarm prompt; if the second storage device fails to write and the first file integrity check in the first storage device is successful, the offline transaction record in the first file is replaced with the second The offline transaction record in the file uploads the offline transaction in the first file to the background to generate an alarm prompt.
  15. 一个或多个存储有计算机可读指令的计算机可读非易失性存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:获取第一存储装置的第一文件,所述第一文件包括脱机交易记录;One or more computer readable non-volatile storage media storing computer readable instructions, when executed by one or more processors, cause one or more processors to perform the steps of: acquiring a first storage a first file of the device, the first file including an offline transaction record;
    获取第二存储装置的第二文件,所述第二文件包括脱机交易记录;Obtaining a second file of the second storage device, where the second file includes an offline transaction record;
    对所述第一文件和所述第二文件分别进行完整性校验;及Performing integrity verification on the first file and the second file respectively; and
    若所述第一文件校验成功且所述第二文件校验失败,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录,在所述第二存储装置中保存替换后的第二文件;若所述第一文件校验失败且所述第二文件校验成功,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录,在所述第一存储装置中保存替换后的第一文件。If the first file verification is successful and the second file verification fails, replacing the offline transaction record in the second file with the offline transaction record in the first file, in the second Saving the replaced second file in the storage device; if the first file verification fails and the second file verification is successful, replacing the first file with the offline transaction record in the second file The offline transaction record stores the replaced first file in the first storage device.
  16. 根据权利要求15所述的存储介质,其特征在于,所述处理器还用于执行:The storage medium according to claim 15, wherein the processor is further configured to:
    若在第一存储装置中创建第一文件失败,或者第二存储装置中创建第二文件失败,则生成报警提示;If the first file fails to be created in the first storage device, or the second file fails to be created in the second storage device, an alarm prompt is generated;
    若所述第一文件和所述第二文件创建成功,对第一文件和第二文件分别进行校验;及If the first file and the second file are successfully created, respectively verifying the first file and the second file; and
    若校验通过,则向第一文件和第一文件分别写入脱机交易记录。If the verification passes, the offline transaction record is written to the first file and the first file, respectively.
  17. 根据权利要求15所述的计算机设备,其特征在于,所述处理器还用 于执行:The computer device of claim 15 wherein said processor is further For execution:
    若所述第一文件和所述第二文件均校验成功,则获取所述第一文件长度和所述第二文件长度;及Obtaining the first file length and the second file length if both the first file and the second file are successfully verified; and
    对所述第一文件长度和所述第二文件长度进行一致性校验。Performing consistency check on the first file length and the second file length.
  18. 根据权利要求17所述的存储介质,其特征在于,所述第一存储装置为内存储装置,所述第二存储装置为外存储装置,所述处理器还用于执行:The storage medium according to claim 17, wherein the first storage device is an internal storage device, the second storage device is an external storage device, and the processor is further configured to:
    若所述第一文件长度大于所述第二文件长度,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;If the first file length is greater than the second file length, replacing an offline transaction record in the second file with an offline transaction record in the first file;
    若所述第一文件长度等于所述第二文件长度且内容不一致,则利用所述第一文件中的脱机交易记录替换所述第二文件中的脱机交易记录;及If the first file length is equal to the second file length and the content is inconsistent, replacing the offline transaction record in the second file with the offline transaction record in the first file; and
    若所述第一文件长度小于所述第二文件长度,则利用所述第二文件中的脱机交易记录替换所述第一文件中的脱机交易记录。If the first file length is less than the second file length, replacing the offline transaction record in the first file with the offline transaction record in the second file.
  19. 根据权利要求15所述的存储介质,其特征在于,所述第一文件还包括第一校验码,所述完整性校验包括对所述第一文件长度进行校验,所述处理器还用于执行时:The storage medium according to claim 15, wherein the first file further comprises a first check code, the integrity check comprises verifying the length of the first file, and the processor further For execution:
    获取所述第一文件长度;Obtaining the length of the first file;
    获取单条脱机交易记录字节数,所述单条脱机交易记录字节数包括所述第一文件中的单条脱机交易记录占用的字节;Obtaining a single offline transaction record byte number, where the single offline transaction record byte number includes a byte occupied by a single offline transaction record in the first file;
    获取校验码字节数,所述校验码字节数包括所述第一校验码占用的字节;Obtaining a check code byte number, where the check code byte number includes a byte occupied by the first check code;
    通过所述单条脱机交易记录字节数、所述校验码字节数和所述第一文件长度,计算所述第一文件中的脱机交易记录条数;Calculating, by the single offline transaction record byte number, the check code byte number, and the first file length, the number of offline transaction records in the first file;
    判断所述第一文件中的脱机交易记录条数是否为正整数;及Determining whether the number of offline transaction records in the first file is a positive integer; and
    若不是,则所述第一文件校验失败。If not, the first file verification fails.
  20. 根据权利要求15所述的存储介质,其特征在于,所述第一文件还包括第一校验码,所述完整性校验还包括对校验码进行校验,所述处理器还用于执行:The storage medium according to claim 15, wherein the first file further comprises a first check code, the integrity check further comprises verifying the check code, and the processor is further configured to: carried out:
    获取预设的密钥; Obtain a preset key;
    通过所述密钥和所述第一文件中的脱机交易记录计算所述第一文件对应的第一完整性校验码;Calculating, by using the key and the offline transaction record in the first file, a first integrity check code corresponding to the first file;
    判断所述第一文件的第一校验码是否与所述第一文件对应的第一完整性校验码相等;及Determining whether the first check code of the first file is equal to the first integrity check code corresponding to the first file; and
    若不相等,则所述第一文件校验失败。 If they are not equal, the first file verification fails.
PCT/CN2017/102244 2017-05-27 2017-09-19 Method for storing off-line transaction record, and computer device and storage medium WO2018218814A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710393605.5 2017-05-27
CN201710393605.5A CN107239357B (en) 2017-05-27 2017-05-27 Offline transaction record storing method, device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
WO2018218814A1 true WO2018218814A1 (en) 2018-12-06

Family

ID=59984728

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2017/102244 WO2018218814A1 (en) 2017-05-27 2017-09-19 Method for storing off-line transaction record, and computer device and storage medium

Country Status (2)

Country Link
CN (1) CN107239357B (en)
WO (1) WO2018218814A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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)

* Cited by examiner, † Cited by third party
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

Patent Citations (3)

* Cited by examiner, † Cited by third party
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

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
CHEN, WEIGUO: "The Design & Realization Based on WiFi Offline Payment System", ELECTRONIC TECHNOLOGY & INFORMATION SCIENCE , CHINA MASTER'S THESES FULL-TEXT DATABASE, 15 April 2016 (2016-04-15) *
DING, CHANGYUE: "The E-Wallet Based on NFC offline Transaction Processing System Implementation", ELECTRONIC TECHNOLOGY & INFORMATION SCIENCE , CHINA MASTER'S THESES FULL-TEXT DATABASE, 15 March 2016 (2016-03-15) *

Also Published As

Publication number Publication date
CN107239357A (en) 2017-10-10
CN107239357B (en) 2019-11-29

Similar Documents

Publication Publication Date Title
US8751859B2 (en) Monitoring lost data in a storage system
CN109690493B (en) System and method for repairing images in a deduplication store
US8862953B2 (en) Memory testing with selective use of an error correction code decoder
CN110209521B (en) Data verification method and device, computer readable storage medium and computer equipment
US9727411B2 (en) Method and processor for writing and error tracking in a log subsystem of a file system
JP2017534944A (en) Conditional validation rules
WO2021135280A1 (en) Data check method for distributed storage system, and related apparatus
WO2019019640A1 (en) Simulated processing method and apparatus for order information, and storage medium and computer device
US9336100B2 (en) Efficient debugging of memory miscompare failures in post-silicon validation
US20190332480A1 (en) Method, device and computer program product for detecting incomplete write of data
US20200026427A1 (en) System and method for handling data storage on storage devices
CN111104246B (en) Method, device, computer equipment and storage medium for improving verification efficiency of error detection and correction of DRAM
CN110136769B (en) OTP register data correction method and device, computer equipment and storage medium
CN108664358A (en) Microcontroller parameter processing method, system, readable storage medium storing program for executing and terminal device
CN105868127A (en) Data storage method and device and data reading method and device
WO2018218814A1 (en) Method for storing off-line transaction record, and computer device and storage medium
CN113312205B (en) Data verification method and device, storage medium and computer equipment
TWI474163B (en) Access system and method for accessing basic input output system
CN107562593A (en) A kind of automated testing method and system for verifying internal memory ECC functions
CN114639437B (en) Memory test method, device, equipment and storage medium
US20220188221A1 (en) Regression testing method and regression testing apparatus
CN103870355B (en) BIOS accesses system and method
CN115827691A (en) Batch processing result verification method and device, computer equipment and storage medium
CN109683980B (en) Method for realizing reliable loading of U disk configuration file of trackside safety platform
CN116930727B (en) Chip detection method based on circuit board

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 17911900

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 17911900

Country of ref document: EP

Kind code of ref document: A1