CN106657216B - Serial number generation method and device - Google Patents

Serial number generation method and device Download PDF

Info

Publication number
CN106657216B
CN106657216B CN201610831604.XA CN201610831604A CN106657216B CN 106657216 B CN106657216 B CN 106657216B CN 201610831604 A CN201610831604 A CN 201610831604A CN 106657216 B CN106657216 B CN 106657216B
Authority
CN
China
Prior art keywords
value
numerical value
serial number
key value
key
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610831604.XA
Other languages
Chinese (zh)
Other versions
CN106657216A (en
Inventor
李发霓
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Credit Co Ltd
Original Assignee
Tencent Credit Co Ltd
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 Tencent Credit Co Ltd filed Critical Tencent Credit Co Ltd
Priority to CN201610831604.XA priority Critical patent/CN106657216B/en
Publication of CN106657216A publication Critical patent/CN106657216A/en
Application granted granted Critical
Publication of CN106657216B publication Critical patent/CN106657216B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/146Markers for unambiguous identification of a particular session, e.g. session cookie or URL-encoding

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer And Data Communications (AREA)

Abstract

The invention relates to a method and a device for generating a serial number, wherein the method comprises the following steps: the server receives a serial number generation request sent by a terminal, and acquires the current system time according to the serial number generation request; converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value of a preset digit from the first numerical value as a key value corresponding to the system time; generating a corresponding second numerical value according to the generated key value, wherein the second numerical value is increased with the increment of the generation times corresponding to the key value; and generating a serial number according to the acquired system time and the second numerical value. The generated sequence numbers are not duplicated.

Description

Serial number generation method and device
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for generating a serial number.
Background
With the development of internet technology, people are more and more common in using the internet. The number of terminals communicating with the server through the network is also increasing. In order to facilitate the distinction management of the huge communication information, the related communication information needs to be distinguished and identified. For example, it is necessary to identify sessions between different clients and servers, or to identify sessions established between the same client and servers at different times.
It is generally desirable to uniquely identify the associated communication by generating a non-repeating serial number. For example, a unique, non-repeating session identification is generated to uniquely identify the session.
In a conventional method for generating a serial number, different serial numbers are generated according to a manner of incrementing a single value. However, since the numerical space is limited, a case where the numerical value is inverted after a period of use occurs, and thus a problem occurs in that the generated serial number is duplicated.
Disclosure of Invention
In view of the above, it is desirable to provide a serial number generation method and apparatus that can ensure that generated serial numbers do not overlap.
A method of sequence number generation, the method comprising the steps of:
the server receives a serial number generation request sent by a terminal, and acquires the current system time according to the serial number generation request;
converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value of a preset digit from the first numerical value as a key value corresponding to the system time;
generating a corresponding second numerical value according to the generated key value, wherein the second numerical value is increased with the increment of the generation times corresponding to the key value;
and generating a serial number according to the acquired system time and the second numerical value.
An apparatus for serial number generation, the apparatus comprising:
the acquisition module is used for receiving a serial number generation request sent by a terminal and acquiring the current system time according to the serial number generation request;
the key value generation module is used for converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value with a preset digit from the first numerical value as a key value corresponding to the system time;
the value generation module is used for generating a corresponding second value according to the generated key value, wherein the second value is increased progressively along with the increasing of the generation times corresponding to the key value;
and the serial number generating module is used for generating a serial number according to the acquired system time and the second numerical value.
According to the serial number generation method and device, the server receives a serial number generation request sent by the terminal, and acquires the current system time according to the serial number generation request; converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value of a preset digit from the first numerical value as a key value corresponding to the system time; generating a corresponding second numerical value according to the generated key value, wherein the second numerical value is increased along with the increment of the generation times corresponding to the key value; and generating a serial number according to the acquired system time and the second numerical value. That is, the sequence number is generated according to the system time, and the sequence number is prevented from being repeated to a certain extent by using the incremental characteristic in the time dimension. Meanwhile, even if the numerical value of the first preset digit of the first numerical value is selected as the key value due to time accuracy, the key values generated successively in the system time within a certain time range may be the same, but the second numerical values corresponding to the successively generated same key values may be different, because the second numerical value increases as the generation times corresponding to the same key value increases. Further, the generation of the serial number according to the second numerical value corresponding to the key value and the system time is not repeated.
Drawings
FIG. 1 is a diagram of an application environment of a method for generating a sequence number in one embodiment;
FIG. 2 is an internal schematic diagram of a server in one embodiment;
FIG. 3 is a flow diagram illustrating a method for sequence number generation in one embodiment;
FIG. 4 is a schematic flow chart diagram illustrating a second method for generating numerical values in one embodiment;
FIG. 5 is a flow chart illustrating a method for generating sequence numbers in another embodiment;
FIG. 6 is a system deployment diagram of a method for serial number generation in one embodiment;
FIG. 7A is a network topology diagram of a sequence number generation method in one embodiment;
FIG. 7B is a network topology diagram of a method of sequence number generation according to another embodiment;
FIG. 8 is a timing diagram of a method of sequence number generation according to one embodiment;
FIG. 9 is a diagram showing the structure of a serial number generation apparatus according to an embodiment;
fig. 10 is a schematic structural diagram of a serial number generation apparatus in another embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Fig. 1 is a diagram of an application environment of a serial number generation method in one embodiment. As shown in fig. 1, a terminal 110 communicates with a server 120 through a network. Various applications may be installed and run on the terminal 110, and the terminal 110 generates a serial number generation request through the applications and transmits the serial number generation request to any one of the servers 120 through the network. After receiving the serial number generation request, the server 120 obtains the current system time according to the serial number generation request, converts the obtained system time from a time format to a numerical format to obtain a first numerical value, and selects a numerical value with a preset digit from the first numerical value as a key value corresponding to the system time. Further, the server 120 generates a corresponding second value according to the generated key value, where the second value increases with the increase of the generation times corresponding to the key value. The server 120 may then generate a serial number based on the obtained system time and the generated second value. Further, the server 120 may return the generated serial number to the terminal 110.
Fig. 2 shows an internal schematic diagram of the server 120 in one embodiment, which includes a processor, a non-volatile storage medium, an internal memory, and a network interface connected by a system bus. The nonvolatile storage medium of the server stores an operating system, a database and a serial number generation device, wherein the database is used for storing data, such as key values, numerical values, generated serial numbers and the like. The serial number generation device is used for realizing a serial number generation method. The processor is used for providing calculation and control capacity and supporting the operation of the whole server. An internal memory in the server provides an environment for operation of the serial number generation apparatus in the non-volatile storage medium, the internal memory having stored therein computer readable instructions which, when executed by the processor, cause the processor to perform a method of serial number generation. The network interface is used for network communication with the terminal. Those skilled in the art will appreciate that the architecture shown in fig. 2 is a block diagram of only a portion of the architecture associated with the subject application, and does not constitute a limitation on the servers to which the subject application applies, as a particular server may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
As shown in fig. 3, in an embodiment, a serial number generation method is provided, which is exemplified by being applied to a server, and specifically includes the following steps:
step 302, the server receives a serial number generation request sent by the terminal, and acquires the current system time according to the serial number generation request.
In this embodiment, the terminal may send a serial number generation request to the server according to the operation of the user.
Specifically, when a user performs a relevant operation (for example, a login operation) on a client interface, which requires to establish communication with the server, the terminal running the client requests the server to create a session and requests to obtain a serial number uniquely identifying the created session. Alternatively, the user performs a related authentication operation (for example, a real-name authentication operation) based on the terminal, and the terminal sends a corresponding authentication operation request to the server and requests to acquire a serial number uniquely identifying the authentication operation request. In this embodiment, the use scenario in which the terminal sends the serial number request is not limited.
When receiving a serial number generation request sent by a terminal, a server triggers to acquire the current system time. The current system time is the system time when the server receives the serial number request.
In one embodiment, the server acquires the system time according to the set service program for generating the serial number, and performs the subsequent serial number generation processing. It is understood that a service program refers to a program, routine, or process that performs specified system functions. The service program in this embodiment refers to a program or a process for generating a sequence number.
Step 304, converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value with a preset digit from the first numerical value as a key value corresponding to the system time.
And the server generates a key value corresponding to the acquired system time according to the acquired system time. Specifically, the server performs format conversion processing on the acquired system time, that is, converts the format of the acquired system time from a time format to a numerical format, and obtains a first numerical value after the conversion. It is understood that the first value is a value obtained by converting the system time into a numerical format.
In one embodiment, the server may directly convert the system time into a first numerical value in a plaintext form, and then select a numerical value of a preset number of bits from the converted first numerical value in the plaintext form as a key value corresponding to the system time. The plaintext first value is used to directly obtain the corresponding system time by looking up the first value. For example, the system time is 2016-08-0414: the time format 20 is converted into a plaintext first value 201608041420, and by looking at the plaintext first value 201608041420, it can be known that the corresponding system time is 2016-08-0414: 20.
in another embodiment, the first numerical value may be a timestamp, that is, the server may convert the system time into a timestamp form, and select a numerical value of a preset number of bits before the conversion from the converted timestamp as a key value corresponding to the system time. It can be understood that the server may also perform other format conversion on the system time, which is not limited in this embodiment.
It can be understood that, since the key value is obtained by extracting the value of the preset digit before the first value generated by converting the format of the system time, the key values corresponding to the system time within the preset time range may be the same, but the system times corresponding to different key values are different. Assuming that the preset number of bits is 8, the first 8 bits of value are extracted, and the key values corresponding to the system time belonging to the same day are the same, for example, a request is generated according to a serial number, and the obtained system time is 2016-08-0414: 20, which has a first value 201608041420 after conversion, which corresponds to a key value 20160804, and also receives a further serial number generation request on the same day, which corresponds to a system time 2016-08-0417: 30, the first value obtained after conversion is 201608041730, and the corresponding key value is 20160804.
And 306, generating a corresponding second numerical value according to the generated key value, wherein the second numerical value is increased with the increment of the generation times corresponding to the key value.
In this embodiment, the server may generate a second numerical value corresponding to the key value according to the generated key value. And the second numerical value is increased along with the increment of the generation times corresponding to the key values. I.e. the second value is used to characterize the number of generation of key values.
In one embodiment, the second value itself corresponding to the key value is the number of times of generating the key value, that is, the same key value is generated for the second time. For example, in 2016-08-0400: 00, acquiring a first serial number generation request in the current day, and generating a serial number corresponding to time 2016-08-0400: 00 corresponds to a key value of 20160804, then the key value 20160804 generated at this time is generated for the first time and corresponds to a second value of 1. Then, in 2016-08-0400: 30, acquiring a second serial number generation request of the current day, and generating a serial number corresponding to the time 2016-08-0400: if 30 corresponds to the key value of 20160804, the second value of the 2 nd generated key value of 20160804 is 2.
In another embodiment, when the key value is generated for the first time, the corresponding second numerical value is a preset initial second numerical value, and as the number of times of generating the key value is increased, the corresponding second numerical value is also increased. For example, when the key value n is generated for the first time, the corresponding second numerical value is the preset starting second numerical value 2, when the key value n is generated for the second time, the corresponding second numerical value is increased progressively on the preset starting second numerical value 2, for example, 1 is increased progressively to obtain 3, when the key value n is generated for the third time, the corresponding second numerical value is increased progressively on the basis of 3 to obtain 4, and so on.
It should be noted that the increment here may be a linear increment, or may be other increment manners such as an exponential increment or an equal-ratio series.
Further, the preset starting value may be any integer. Further, when the second value is linearly incremented, the value of each increment may be 1, so as to satisfy some service demands requiring serial number continuity. It will be appreciated that the value of each increment may be any positive integer other than 1.
And 308, generating a serial number according to the acquired system time and the second value.
In particular, the server may convert the system time to a timestamp and then generate the sequence number with the timestamp and the second value as part of the sequence number, respectively. The server may also convert the format of the system time into a first numerical value in a plaintext form, and generate the serial number by using the first numerical value in the plaintext form and a second numerical value corresponding to the key value as components of the serial number, respectively.
It should be noted that the first and second embodiments are only used to distinguish different types of numerical values, and are not used to limit the size, order, and the like.
In the embodiment, a server receives a serial number generation request sent by a terminal, and acquires the current system time according to the serial number generation request; converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value of a preset digit from the first numerical value as a key value corresponding to the system time; generating a corresponding second numerical value according to the generated key value, wherein the second numerical value is increased along with the increment of the generation times corresponding to the key value; and generating a serial number according to the acquired system time and a second numerical value corresponding to the key value. That is, the sequence number is generated according to the system time, and the sequence number is prevented from being repeated to a certain extent by using the incremental characteristic in the time dimension. Meanwhile, even if the numerical value of the first preset digit of the first numerical value is selected as the key value due to time accuracy, the key values generated successively in the system time within a certain time range may be the same, but the second numerical values corresponding to the successively generated same key values may be different, because the second numerical value increases as the generation times corresponding to the same key value increases. Further, the generation of the serial number based on the generated second value together with the system time is not repeated.
In addition, the serial number generated according to the second numerical value and the system time does not need to be stored in a fixed character string mode, and can be stored in a digital data type, so that storage resources are saved.
In one embodiment, before the step of generating the serial number according to the acquired system time and the second value, the method further comprises: and acquiring a service program identifier of the service program used for generating the serial number, wherein the service program identifier is used for uniquely identifying the corresponding service program.
In this embodiment, the step of generating the serial number according to the acquired system time and the second value includes: and generating a serial number according to the service program identifier, the acquired system time and a second numerical value corresponding to the key value.
Specifically, a service program for generating a serial number is set in the server, and a corresponding service program identifier is set for the service program, where the service program refers to a program or a process for generating a serial number. The service program identification is used for uniquely identifying the corresponding service program.
It can be understood that a plurality of distributed servers with serial number generation functions may be set according to actual requirements, each server is provided with a service program for generating a serial number, and the service programs in the servers are respectively provided with corresponding unique service program identifiers. The terminal may send a sequence number generation request to any server.
Before generating the serial number, the server obtains the service program identification of the service program used for generating the serial number. And generating a serial number according to the acquired service program identifier, the system time and a second numerical value corresponding to the key value.
Likewise, the server may convert the system time to a timestamp and then combine the service identification, the timestamp, and the second value corresponding to the key to generate the sequence number. The server may also convert the system time into a first value in plaintext form and then combine the service identifier, the first value in plaintext form, and a second value corresponding to the key to generate the sequence number.
The traditional method for generating the serial number according to the single increment numerical value or the fixed-length character string uses a single service program, and is not easy to expand, because if a plurality of sets of service programs for generating the serial number are expanded, the plurality of sets of service programs generate the serial number according to the single increment numerical value or the fixed-length character string independently, obviously, the serial numbers generated by the plurality of sets of service programs are easy to repeat, and are not easy to expand. In this embodiment, the serial number is generated according to the service program identifier of the service program used for generating the serial number, the system time, and the second numerical value corresponding to the key value, and the service program identifier is used for uniquely identifying the service program corresponding to the service program identifier, thereby ensuring that the serial numbers generated according to different service programs are completely different. In addition, a plurality of sets of service programs for generating the sequence numbers can be expanded according to the actual traffic demands. The expandability is improved.
As shown in fig. 4, in an embodiment, the step of generating a corresponding second numerical value according to a generated key value (referred to as a second numerical value generating step for short) specifically includes the following steps:
step 402, when the generated key value does not exist in the stored key values, taking a preset initial second numerical value as a second numerical value corresponding to the generated key value.
Step 404, when the generated key value exists in the stored key values, obtaining a current second numerical value corresponding to the key value according to a correspondence between the pre-stored key value and the second numerical value, and performing incremental processing on the current second numerical value to obtain an incremented second numerical value, which is the second numerical value corresponding to the generated key value.
In this embodiment, the server stores all generated key values. Wherein the stored key values are completely different from each other. It is understood that when a key value is repeatedly generated, the repeatedly generated key value is not stored or replaces the existing same key value.
After the server generates the key value, whether the generated key value exists in the key values stored by the server is judged. Further, a preset initial second value is set in the server. And when the generated key value is judged not to exist in the stored key values, the key value is judged to be generated for the first time, a preset initial second numerical value is obtained, and the preset initial second numerical value is used as a second numerical value corresponding to the generated key value. Wherein the predetermined initial second value is an arbitrary integer.
Further, the server stores in advance a correspondence between the key value and the second value. When the generated key value is judged to exist in the stored key values, the server obtains a current second numerical value corresponding to the key value according to the corresponding relation between the pre-stored key value and the second numerical value, and performs incremental processing on the current second numerical value to obtain an incrementally increased second numerical value. The incremented second numerical value is the second numerical value corresponding to the generated key value.
The current second value may be subjected to linear increment processing, or may be subjected to exponential increment processing or increment in an array form such as an equal-ratio array.
It will be appreciated that each time the same key value is generated, the corresponding second value of the key value is incremented.
For example, the generated key value is n, the preset starting second numerical value is 1, and when the key value n does not exist in the key values stored by the server, it is indicated that the key value n is generated for the first time, and the preset starting second numerical value 1 is taken as the second numerical value corresponding to the key value n. When the key value n exists in the key values stored in the server, for example, when the key value n is generated for the second time, the server stores a corresponding relationship between the key value and the second numerical value, obtains that the current second numerical value corresponding to the stored key value n is 1 (because the second numerical value corresponding to the key value n generated for the first time is a preset initial second numerical value 1), performs increment processing on the current second numerical value 1, for example, increments by 1, and when the key value n is generated for the second time, the second numerical value corresponding to the key value n is incremented by 2. For another example, when the key value n is generated for the third time, the current second numerical value corresponding to the key value n stored in the server is 2, and the current second numerical value 2 is incremented by 1, and when the key value n is generated for the third time, the second numerical value corresponding to the key value n is incremented by 3.
In this embodiment, whether the generated key value exists in the stored key values is determined, and if not, the preset initial second numerical value is obtained as the second numerical value corresponding to the key value, and if so, the current second numerical value corresponding to the key value is obtained, and the current second numerical value is subjected to incremental processing to obtain the incremented second numerical value as a new second numerical value corresponding to the key value. That is, when the same key value is generated in the system time in the same time range, the corresponding second values are completely different. Furthermore, it is ensured that the sequence numbers generated from the system time and the second value are not repeated at all.
In addition, the serial number is not repeated, so that the identification of the data resource and the communication information in the big data is more accurate. Due to the fact that the method is more accurate, smooth and orderly proceeding of data resources and communication in the big data is guaranteed, various communication errors and data resource obtaining errors caused by disordered identification are avoided, and therefore efficiency of controlling the big data resources is improved.
In one embodiment, the step of performing increment processing on the current second value to obtain an incremented second value includes: and acquiring a preset increasing numerical value, and linearly overlapping the current second numerical value and the preset increasing numerical value to obtain an increased second numerical value.
In this embodiment, a preset increment value is set in the server. When the current second numerical value is subjected to increasing processing, the server can obtain a preset increasing numerical value, and linear superposition is carried out on the current numerical value corresponding to the key value and the preset increasing numerical value to obtain an increased numerical value. Wherein, the linear superposition is direct addition.
Wherein the preset addition value is any positive integer. The magnitude of the incremental value can be set according to actual needs.
In this embodiment, adopt and carry out linear stack with current second numerical value and predetermine the numerical value that adds, obtain the second numerical value after increasing gradually, can make more steady, the continuation of increasing gradually of second numerical value to can make the numerical space obtain more abundant use, improve the utilization ratio in numerical space.
In one embodiment, the method further comprises: and taking the serial number as a session identifier to uniquely identify the session between the client and the server, wherein the client refers to the step of the client corresponding to the user identifier contained in the serial number generation request.
In this embodiment, when a user performs a related operation (for example, a login operation) that requires communication with a server on a client interface, a terminal running a client requests the server to create a session and requests to acquire a serial number uniquely identifying the created session. The user identifier contained in the serial number generation request is the unique user identifier of the user who performs related communication operation through the client.
The server creates a session between the client and the server, and after generating the serial number, uses the generated serial number as a session identification to uniquely identify the session created between the client and the server. Specifically, the sequence number is stored as a correspondence between the session identifier and the session corresponding thereto. The client refers to a client corresponding to the user identifier included in the serial number generation request.
In the embodiment, the sequence number generated by the method is used as the session identifier, so that the session between the client and the server can be identified more accurately and uniquely, and the order and mutual interference of the sessions are ensured.
In another embodiment, the method further comprises: and a step of using the generated serial number as a credential serial number for uniquely identifying the received authentication operation request.
In this embodiment, a user performs a related authentication operation (for example, a real-name authentication operation) based on a terminal, and the terminal sends a corresponding authentication operation request to a server and requests to acquire a serial number uniquely identifying the authentication operation request.
The server generates a unique serial number, and the generated serial number is used as a certificate serial number for uniquely identifying the received authentication operation request.
It can be understood that the server may further perform authentication processing on the user identity information and the account information included in the authentication operation request, and return an authentication processing result and a corresponding credential serial number to the terminal.
When the server performs the authentication processing, the server may call the interface of another server, and then the generated credential serial number for uniquely identifying the authentication operation request may also play a role in recording the number of times of calling the interface. Further, the voucher serial number can play a role in reconciliation of the call cost of a subsequent settlement interface.
In this embodiment, the serial number generated by the above method is used as the serial number of the credential, so that the authentication operation request can be identified more accurately and uniquely. In addition, when the voucher serial number is used for checking account of the subsequent settlement interface calling cost, the account checking result can be more accurate.
In one embodiment, there are a plurality of servers, and each server has a service program for generating the serial number. The sequence number generation request sent by the terminal may be sent to the load balancing manager, the load balancing manager detects the number of sequence number generation requests currently required to be processed by the service programs in the servers, then allocates the received sequence number generation requests to the server with the minimum required processing number, and performs the sequence number generation processing by the service program for generating the sequence number in the server with the minimum required processing number.
The terminal may directly send the sequence number request to any server, and the server that receives the sequence number request sent by the terminal may detect and query the number of sequence number generation requests currently required to be processed by the service program in each server, and then forward the sequence number generation request to the server with the minimum required processing number, and perform the sequence number generation processing by the service program for generating the sequence number in the server with the minimum required processing number.
In this embodiment, when allocating the sequence number generation request, the number of sequence number generation requests currently required to be processed by the service program in each server is detected according to the load balancing principle, the sequence number generation request is allocated to the server with the smallest required processing number, and the sequence number generation processing is performed by the service program for generating the sequence number in the server with the smallest required processing number. The method and the system have the advantages that the use of serial number generation resources can be more sufficient, the utilization rate of the resources is improved, in addition, the load balance of each service program is also ensured, the normal operation of each service program is ensured, and the performance of the system in operation is improved.
As shown in fig. 5, in an embodiment, a serial number generation method is provided, which is exemplified by being applied to a server, and specifically includes the following steps:
step 502, the key value generation system receives a serial number generation request sent by the terminal, and acquires the current system time according to the serial number generation request.
Step 504, the key value generation system converts the acquired system time from the time format to the numerical value format to obtain a first numerical value, selects the numerical value with the preset number from the first numerical value as the key value corresponding to the system time, and sends the generated key value to the numerical value generation system.
Specifically, the key value generation system may directly convert the system time into a first numerical value in a plaintext form, and then select a numerical value of a preset number from the converted first numerical value in the plaintext form as a numerical value corresponding to the system time. The plaintext first value is used to directly obtain the corresponding system time by looking up the first value.
The key value generation system can also convert the system time into a timestamp form, and a numerical value of a preset digit is selected from the converted timestamp as a key value corresponding to the system time. It can be understood that the server may also perform other format conversion on the system time, which is not limited in this embodiment.
Step 506, the value generation system generates a corresponding second value according to the generated key value, wherein the second value increases with the increase of the generation times corresponding to the key value, and returns the second value to the key value generation system.
Specifically, the second value itself corresponding to the key value may be the number of times of generating the key value, that is, the same key value is generated for the second time. Or when the key value is generated for the first time, the corresponding second numerical value is the preset initial second numerical value, and the corresponding second numerical value is incremented along with the increment of the times of generating the key value. Wherein the predetermined starting second value may be any integer.
Further, the increment may be a linear increment, or may be other increment manners such as an exponential increment or an geometric progression, which is not limited in this embodiment.
Step 508, the key value generation system generates a serial number according to the obtained system time and the second numerical value.
In particular, the key-value generation system may convert the system time to a timestamp and then generate the sequence number with the timestamp and the second value as part of the sequence number, respectively. The server may also convert the format of the system time into a first numerical value in a plaintext form, and generate the serial number by using the first numerical value in the plaintext form and a second numerical value corresponding to the key value as components of the serial number, respectively.
In one embodiment, before the step of generating the serial number by the key value generation system according to the acquired system time and the second value, the method further includes: and the key value generation system acquires a service program identifier of the service program which belongs to the key value generation system and is used for generating the serial number, wherein the service program identifier is used for uniquely identifying the corresponding service program.
In this embodiment, the step of generating, by the key value generation system, the serial number according to the obtained system time and the second numerical value includes: and the key value generation system generates a serial number according to the acquired service program identifier, the system time and a second numerical value corresponding to the key value.
Specifically, a service program used for generating a serial number is set in the server, and a corresponding service program identifier is set for the service program, wherein the service program identifier is used for uniquely identifying the corresponding service program. A key value generation system and a value generation system together form a set of service programs for generating serial numbers. The service program refers to a program or a process for generating a sequence number.
Further, before generating the serial number, the key value generation system acquires the service program identifier of the service program which the key value generation system belongs to and is used for generating the serial number. And generating a serial number according to the acquired service program identifier, the system time and a second numerical value corresponding to the key value.
Likewise, the key-value generation system may convert the system time to a timestamp and then combine the service identification, the timestamp, and the second value corresponding to the key value to generate the sequence number. The key value generation system may also convert the system time into a first numerical value in a plaintext form, and then combine the obtained service program identifier, the first numerical value in the plaintext form, and a second numerical value corresponding to the key value to generate the sequence number. It should be noted that, according to actual requirements, one or more distributed groups of service programs for generating serial numbers may be set, and corresponding unique service program identifiers are set for each group of service programs. Furthermore, two different service programs can share one value generation system, so that system resources are saved, and the utilization rate of the system resources is improved.
When there are a plurality of sets of service programs for generating a sequence number, the terminal may transmit a sequence number generation request to any one set of the service programs. As shown in fig. 6, fig. 6 is a system deployment diagram of a serial number generation method in an embodiment. Wherein the terminal 610 may send a sequence number generation request to any set of service programs 620. A set of service routines 620 includes a key value generation system 622 and a value generation system 624.
In an embodiment, the key value generation system and the value generation system may be disposed in the same server, as shown in fig. 7A, fig. 7A is a network topology diagram of a sequence number generation method according to an embodiment. The terminal 710 communicates with a key value generation system deployed in the server 720 through a network, and the key value generation system and the numerical value generation system communicate with each other in the same server 720.
In another embodiment, the key-value generation system and the value generation system may be separately located in different servers. As shown in fig. 7B, fig. 7B is a network topology diagram of a sequence number generation method in another embodiment. The key value generation system is deployed in the server 730, the numerical value generation system is deployed in the server 740, the terminal 710 communicates with the key value generation system deployed in the server 730 through a network, and the key value generation system deployed in the server 730 communicates with the numerical value generation system in the server 740 through the network.
The method is equivalent to separate deployment of the key value generation system and the numerical value generation system, and is convenient for expansion through the separate deployment of the systems while the serial numbers are not repeatedly generated.
In one embodiment, the step of generating, by the value generation system, a corresponding second value according to the generated key value includes: when the generated key value does not exist in the stored key values, the numerical value generation system takes a preset initial second numerical value as a second numerical value corresponding to the generated key value; when the generated key value exists in the stored key value, the numerical value generation system acquires a current second numerical value corresponding to the key value according to the corresponding relation between the pre-stored key value and the second numerical value, and the numerical value generation system performs incremental processing on the current second numerical value to obtain the incremented second numerical value, namely the incremented second numerical value corresponding to the generated key value.
In one embodiment, the step of incrementally processing the current second numerical value corresponding to the key value by the numerical value generation system includes: the numerical value generation system acquires a preset addition numerical value; and linearly superposing the current second numerical value corresponding to the key value and a preset incremental numerical value to obtain an incrementally increased second numerical value.
The preset addition value is any positive integer and can be set according to actual requirements. Linear superposition is direct addition.
In one embodiment, the method further comprises: the key value generation system takes the generated serial number as a session identification to uniquely identify the session between the client and the server where the key value generation system is located, wherein the client refers to a step of the client corresponding to the user identification contained in the serial number generation request.
In another embodiment, the method further comprises: and the key value generation system takes the generated serial number as a certificate serial number for uniquely identifying the received authentication operation request.
Fig. 8 is a timing diagram illustrating the sequence number generation method described above in one embodiment. In this embodiment, the specific process of generating the sequence number is as follows:
1) the terminal sends a sequence number generation request to a key value generation system.
2) The key value generation system acquires the service program identifier of the service program which is used for generating the serial number and belongs to the key value generation system.
3) The key value generation system obtains the current system time, carries out format conversion on the current system time to generate a first numerical value, and generates a key value corresponding to the system time according to the first numerical value.
4) The key value generation system requests the value generation system to generate a second value corresponding to the key value.
5) And the value generation system generates a second value corresponding to the key value according to the key value.
6) And the numerical value generation system returns the generated second numerical value corresponding to the key value generation system.
7) And the key value generation system generates a serial number according to the acquired service program identifier, the system time and a second numerical value corresponding to the key value.
8) And the key value generation system returns the generated serial number to the terminal.
As shown in fig. 9, in one embodiment, a serial number generation apparatus is provided, which includes an obtaining module 902, a key value generation module 904, a numerical value generation module 906, and a serial number generation module 908, where:
an obtaining module 902, configured to receive a serial number generation request sent by a terminal, and obtain a current system time according to the serial number generation request.
The key value generating module 904 is configured to convert the acquired system time from a time format to a numerical value format to obtain a first numerical value, and select a numerical value with a preset number from the first numerical value as a key value corresponding to the system time.
A value generating module 906, configured to generate a corresponding second value according to the generated key value, where the second value increases with the increase of the generation times corresponding to the key value.
A serial number generation module 908 configured to generate a serial number according to the obtained system time and the second value.
In one embodiment, the obtaining module 902 is further configured to obtain a service program identifier of a service program used for generating the serial number, where the service program identifier is used for uniquely identifying the corresponding service program.
In this embodiment, the serial number generating module 908 is further configured to generate a serial number according to the service program identifier, the obtained system time, and the second value.
In one embodiment, the value generating module 906 is further configured to, when the generated key value does not exist in the stored key values, take a preset starting second value as a second value corresponding to the generated key value; when the generated key value exists in the stored key value, a current second numerical value corresponding to the key value is obtained according to the corresponding relation between the pre-stored key value and the second numerical value, and the current second numerical value corresponding to the key value is subjected to incremental processing, so that the obtained incremental second numerical value is the generated second numerical value corresponding to the key value.
In one embodiment, the value generation module 906 is further configured to obtain a preset incremental value; and linearly superposing the current second numerical value corresponding to the key value and the preset incremental numerical value to obtain the incremented second numerical value.
In one embodiment, as shown in fig. 10, the apparatus further comprises:
an identification module 910, configured to use the serial number as a session identifier to uniquely identify a session between a client and the server, where the client is a client corresponding to the user identifier included in the serial number generation request.
The serial number generating device receives a serial number generating request sent by the terminal and acquires the current system time according to the serial number generating request; converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value of a preset digit from the first numerical value as a key value corresponding to the system time; generating a corresponding second numerical value according to the generated key value, wherein the second numerical value is increased along with the increment of the generation times corresponding to the key value; and generating a serial number according to the acquired system time and the second numerical value. That is, the sequence number is generated according to the system time, and the sequence number is prevented from being repeated to a certain extent by using the incremental characteristic in the time dimension. Meanwhile, even if the numerical value of the first preset digit of the first numerical value is selected as the key value due to time accuracy, the key values generated successively in the system time within a certain time range may be the same, but the second numerical values corresponding to the successively generated same key values may be different, because the second numerical value increases as the generation times corresponding to the same key value increases. Further, the generation of the serial number based on the second value together with the system time is not repeated.
In addition, the serial number generated according to the second numerical value corresponding to the key value and the system time does not need to be stored in a fixed character string mode, and can be stored in a digital data type, so that the storage resource is saved.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and can include the processes of the embodiments of the methods described above when the computer program is executed. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a Random Access Memory (RAM).
The technical features of the embodiments described above may be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the embodiments described above are not described, but should be considered as being within the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (12)

1. A method of sequence number generation, the method comprising the steps of:
the server receives a serial number generation request sent by a terminal, and acquires the current system time according to the serial number generation request;
converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value with a preset digit from the first numerical value as a key value corresponding to the system time; the first value is a timestamp;
generating a corresponding second numerical value according to the generated key value, wherein the second numerical value increases with the increasing of the generation times corresponding to the key value, and the method comprises the following steps: when the key value exists in the stored key value, acquiring a current second numerical value corresponding to the key value according to a corresponding relation between the pre-stored key value and the second numerical value, carrying out incremental processing on the current second numerical value, and taking the incremented second numerical value as a second numerical value corresponding to the key value;
and generating a serial number according to the acquired system time and the second numerical value.
2. The method of claim 1, further comprising, prior to the step of generating a sequence number based on the obtained system time and the second value:
acquiring a service program identifier of a service program for generating a serial number, wherein the service program identifier is used for uniquely identifying the corresponding service program;
the step of generating a serial number according to the acquired system time and the second value includes:
and generating a serial number according to the service program identifier, the acquired system time and the second numerical value.
3. The method of claim 1, wherein the step of generating the corresponding second value according to the generated key value comprises:
and when the generated key value does not exist in the stored key values, taking a preset initial second numerical value as a second numerical value corresponding to the generated key value.
4. The method of claim 3, wherein the step of incrementing the current second value to obtain an incremented second value comprises:
acquiring a preset increasing numerical value;
and linearly superposing the current second numerical value and the preset incremental numerical value to obtain the incrementally increased second numerical value.
5. The method of claim 1, further comprising:
and taking the serial number as a session identifier to uniquely identify the session between the client and the server, wherein the client refers to the client corresponding to the user identifier contained in the serial number generation request.
6. An apparatus for generating a serial number, the apparatus comprising:
the acquisition module is used for receiving a serial number generation request sent by a terminal and acquiring the current system time according to the serial number generation request;
the key value generation module is used for converting the acquired system time from a time format to a numerical value format to obtain a first numerical value, and selecting a numerical value with a preset digit from the first numerical value as a key value corresponding to the system time; the first value is a timestamp;
a value generating module, configured to generate a corresponding second value according to the generated key value, where the second value increases progressively with increasing generation times corresponding to the key value, and the value generating module includes: when the key value exists in the stored key value, acquiring a current second numerical value corresponding to the key value according to a corresponding relation between the pre-stored key value and the second numerical value, carrying out incremental processing on the current second numerical value, and taking the incremented second numerical value as a second numerical value corresponding to the key value;
and the serial number generating module is used for generating a serial number according to the acquired system time and the second numerical value.
7. The apparatus according to claim 6, wherein the obtaining module is further configured to obtain a service program identifier of a service program used for generating a serial number, and the service program identifier is used for uniquely identifying the corresponding service program;
the serial number generation module is further configured to generate a serial number according to the service program identifier, the acquired system time, and the second value.
8. The apparatus of claim 6, wherein the value generation module is further configured to use a preset starting second value as the second value corresponding to the generated key value when the generated key value does not exist in the stored key values.
9. The apparatus of claim 8, wherein the value generation module is further configured to obtain a preset incremental value; and linearly superposing the current second numerical value and the preset incremental numerical value to obtain the incrementally increased second numerical value.
10. The apparatus of claim 6, further comprising:
and the identification module is used for taking the serial number as a session identification to uniquely identify the session between the client and the server, wherein the client refers to the client corresponding to the user identification contained in the serial number generation request.
11. A computer arrangement comprising a memory and a processor, the memory having stored therein a computer program which, when executed by the processor, causes the processor to carry out the steps of the method of any one of claims 1 to 5.
12. A computer-readable storage medium, having stored thereon a computer program which, when executed by a processor, causes the processor to carry out the steps of the method according to any one of claims 1 to 5.
CN201610831604.XA 2016-09-19 2016-09-19 Serial number generation method and device Active CN106657216B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610831604.XA CN106657216B (en) 2016-09-19 2016-09-19 Serial number generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610831604.XA CN106657216B (en) 2016-09-19 2016-09-19 Serial number generation method and device

Publications (2)

Publication Number Publication Date
CN106657216A CN106657216A (en) 2017-05-10
CN106657216B true CN106657216B (en) 2020-07-24

Family

ID=58852480

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610831604.XA Active CN106657216B (en) 2016-09-19 2016-09-19 Serial number generation method and device

Country Status (1)

Country Link
CN (1) CN106657216B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107786628B (en) * 2017-07-24 2020-08-18 深圳壹账通智能科技有限公司 Service number distribution method and device, computer equipment and storage medium
CN107622102B (en) * 2017-09-11 2019-04-19 平安科技(深圳)有限公司 Entity card number generation method and terminal device
CN108647193B (en) * 2018-04-20 2021-11-19 河南中烟工业有限责任公司 Unique identifier generation method and device applicable to distributed system
CN109063088B (en) * 2018-07-26 2020-07-28 阿里巴巴集团控股有限公司 Serial number generation method and device
CN109948012B (en) * 2019-03-14 2021-11-16 北京达佳互联信息技术有限公司 Serial number generation method and device and storage medium
CN110362573A (en) * 2019-06-27 2019-10-22 北京大米科技有限公司 Recommend generation method, device, electronic equipment and the storage medium of code
CN110377268A (en) * 2019-07-25 2019-10-25 中国工商银行股份有限公司 Serial number generation method, device and storage medium
CN110928442A (en) * 2019-10-18 2020-03-27 北京字节跳动网络技术有限公司 Electronic whiteboard operation instruction coding method, system, medium and electronic equipment
CN112491996B (en) * 2020-11-18 2022-08-12 深圳前海微众银行股份有限公司 Method and device for generating service request

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102769667A (en) * 2012-06-29 2012-11-07 北京奇虎科技有限公司 Method, equipment and system for generating ID
CN105072160A (en) * 2015-07-17 2015-11-18 联动优势科技有限公司 Serial number generating method and device, and a server
CN105653639A (en) * 2015-12-25 2016-06-08 北京奇虎科技有限公司 ID generation method and apparatus

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9246912B2 (en) * 2014-04-01 2016-01-26 Bank Of America Corporation Password generator

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102769667A (en) * 2012-06-29 2012-11-07 北京奇虎科技有限公司 Method, equipment and system for generating ID
CN105072160A (en) * 2015-07-17 2015-11-18 联动优势科技有限公司 Serial number generating method and device, and a server
CN105653639A (en) * 2015-12-25 2016-06-08 北京奇虎科技有限公司 ID generation method and apparatus

Also Published As

Publication number Publication date
CN106657216A (en) 2017-05-10

Similar Documents

Publication Publication Date Title
CN106657216B (en) Serial number generation method and device
CN107819828B (en) Data transmission method and device, computer equipment and storage medium
CN109949111B (en) Electronic bill identification distribution method, electronic bill generation method, device and system
CN107968836B (en) Task distribution method and device
CN110619114B (en) Serial number generation method and system
US11055277B2 (en) Integrity verification method, apparatus, and system and device for data in a blockchain-type ledger
CN110995513B (en) Data sending and receiving method in Internet of things system, internet of things equipment and platform
TWI678909B (en) Safety authentication method, device and system
CN111625593A (en) Data processing method and device based on block chain and computer equipment
CN110661829B (en) File downloading method and device, client and computer readable storage medium
US10917231B2 (en) Data storage method, apparatus, system and device
CN111245910B (en) Block chain light node multi-copy deployment method
CN109413202B (en) System and method for sorting block chain transaction information
CN113900810A (en) Distributed graph processing method, system and storage medium
CN110460536B (en) Data processing method and apparatus for block chain, medium, and electronic device
CN113067802A (en) User identification method, device, equipment and computer readable storage medium
CN111953931A (en) Data sharing method and device and storage medium
CN105610593B (en) Method and device for distributing resource identification in network management system
CN110839077A (en) File request processing method, request feedback information processing method and related components
CN105447141A (en) Data processing method and node
CN112766486A (en) Searching method of neural network structure, terminal, server and readable storage medium
CN107528797B (en) Data processing method, device and system
CN110935168A (en) Distributed ID generation method, device and equipment for global uniform architecture
CN114866371B (en) Method and device for establishing IPSec tunnel, storage medium and electronic equipment
CN113505155B (en) Transaction information retrieval method and retrieval device based on blockchain network

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant