Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Referring to fig. 1, fig. 1 is a flowchart of an invitation code generating method according to an embodiment of the present invention, as shown in fig. 1, the method mainly includes the following steps:
step 101, receiving an invitation code generation request of a user;
step 102, generating an invitation code array according to the length of the invitation code to be generated carried by the invitation code generation request;
Step 103, performing scaled assignment, bit diffusion and bit confusion on the invitation code array based on the character sequence length for the invitation code according to the global unique identifier id carried by the invitation code generation request and the basic data information corresponding to the length of the invitation code to be generated, so that the element values in the invitation code array fall into a value interval [0, L 1 -1], wherein the basic data information corresponding to the length of the invitation code to be generated and the character sequence for the invitation code are both preconfigured, and L 1 is the length of the character sequence for the invitation code;
and 104, extracting the character of each element value corresponding to the invitation code array in the character sequence for the invitation code, and determining the character string formed by the extracted characters as the invitation code of the user.
As can be seen from the method shown in fig. 1, in this embodiment, in the process of generating the invitation code, according to the global unique identifier id carried by the invitation code generation request and the basic data information corresponding to the length of the invitation code to be generated, the operation of performing the operations of performing the scaled assignment, the bitwise diffusion and the bitwise confusion on the invitation code array based on the length of the character sequence of the preconfigured invitation code is performed, so that the characters of the preconfigured invitation code are uniformly distributed, and further, the invitation code obtained by extracting the characters corresponding to the value of each element of the invitation code array in the character sequence of the invitation code is not repeated. The invention does not need to query the database and pre-generate the main key of the database, and also supports the invitation code generation mechanism with specified length, thereby improving the generation efficiency of the invitation code, reducing the complexity of the generation of the invitation code and controlling the length of the generated invitation code under the condition of ensuring that the invitation code is not repeated.
Referring to fig. 2, fig. 2 is a flowchart of a second invitation code generating method according to an embodiment of the present invention, and as shown in fig. 2, the method mainly includes the following steps:
step 201, receiving an invitation code generation request of a user;
In this embodiment, the invitation code generation request carries information such as a length of an invitation code to be generated, a global unique identifier (id), and the like.
Step 202, generating an invitation code array according to the length of the invitation code to be generated carried by the invitation code generation request;
in this embodiment, the length of the invitation code array is the same as the length of the invitation code to be generated.
In the embodiment, corresponding basic data information is configured in advance for the length of the to-be-generated invitation code, and specifically comprises first basic data which is mutually equal to the length of a character sequence for the invitation code, second basic data which is mutually equal to the length of the to-be-generated invitation code and random data, wherein the character sequence for the invitation code is preconfigured.
Step 2031, calculating a product of an id carried by the invitation code generation request and first basic data corresponding to the length of the invitation code to be generated, and adding the product and random data corresponding to the length of the invitation code to be generated to obtain an initial value;
step 2032, performing scaled assignment and bitwise diffusion on the invitation code array based on the character sequence length for the invitation code according to the initial value and the assignment sequence corresponding to the length of the invitation code to be generated;
In this embodiment, a corresponding assignment sequence is configured in advance for the length of the invitation code to be generated.
In this embodiment, the assignment of the number of the invitation codes based on the length of the character sequence for the invitation codes is performed according to the assignment sequence corresponding to the length of the invitation codes to be generated, so that the element values in the number of the invitation codes fall into the value interval [0, l 1 -1], and the initial values are obtained by multiplying the id by the first basic data of the character sequence length for the invitation codes and then adding the multiplied values to the random data, so that the characters for the invitation codes can be uniformly distributed in the number of the invitation codes when the assignment of the number of the invitation codes based on the length of the character sequence for the invitation codes is performed and the diffusion of the number of the invitation codes by bits is performed.
Step 2033, performing bit confusion on the invitation code array by using the second basic data corresponding to the length of the invitation code to be generated.
In this embodiment, the elements in the invitation code array may be scrambled by bit confusion on the invitation code array, so as to further increase the difficulty of decoding the invitation code.
The above steps 2031 to 2033 are specific refinements of step 103 shown in fig. 1.
And 204, extracting the character of each element value corresponding to the invitation code array in the character sequence for the invitation code, and determining the character string formed by the extracted characters as the invitation code of the user.
According to the method shown in fig. 2, in this embodiment, when generating the invitation code, the number array of the invitation code is subjected to scaled assignment and bit-wise diffusion according to the global unique identifier id carried by the invitation code generation request, and the first basic data and the random data corresponding to the length of the invitation code to be generated, so that the characters of the pre-configured invitation code are uniformly distributed, and then the number array of the invitation code is subjected to bit-wise confusion by using the second basic data corresponding to the length of the invitation code to be generated, so as to increase the decoding difficulty of the invitation code obtained by subsequent extraction. The invention does not need to query the database and pre-generate the main key of the database, and also supports the invitation code generation mechanism with specified length, thereby improving the generation efficiency of the invitation code, reducing the complexity of the generation of the invitation code and controlling the length of the generated invitation code under the condition of ensuring that the invitation code is not repeated.
Referring to fig. 3, fig. 3 is a flowchart of a method for generating a three-invitation code according to an embodiment of the present invention, as shown in fig. 3, the method mainly includes the following steps:
step 301, receiving an invitation code generation request of a user;
step 302, generating an invitation code array according to the length of the invitation code to be generated carried by the invitation code generation request;
In this embodiment, the invitation code generation request carries information such as a length of an invitation code to be generated, a global unique identifier (id), and the like.
In the embodiment, corresponding basic data information is configured in advance for the length of the to-be-generated invitation code, and specifically comprises first basic data which is mutually equal to the length of a character sequence for the invitation code, second basic data which is mutually equal to the length of the to-be-generated invitation code and random data, wherein the character sequence for the invitation code is preconfigured. In addition, a corresponding assignment sequence is configured for the length of the invitation code to be generated in advance.
In this embodiment, the length of the random data corresponding to the length of the invitation code to be generated may be kept consistent with the length of the invitation code to be generated, so that the numerical range of the modulo calculation result may be larger in the subsequent diffusing process of the elements in the invitation code array.
Step 3031, calculating the product of the id carried by the invitation code generation request and the first basic data corresponding to the length of the invitation code to be generated, and adding the product and the random data corresponding to the length of the invitation code to be generated to obtain an initial value;
Step 3032a, performing scaled assignment on the first L 2 -1 elements of the invitation code array based on the character sequence length for the invitation code according to the initial value and the assignment sequence corresponding to the length of the invitation code to be generated (the length of the invitation code to be generated is recorded as L 2);
in this embodiment, the assignment sequence corresponding to the length of the invitation code to be generated may be the sequence of the sequence numbers of the first L 2 -1 sets of the invitation code sets. Here, the length of the invitation code to be generated is L 2, the length of the invitation code array is L 2, the first L 2 -1 elements of the invitation code array are subjected to scaled assignment, the last element of the invitation code array is used as an interference item, and other methods are adopted for assignment.
In this embodiment, performing, according to the initial value, a scaled assignment based on the length of the character sequence for the invitation code on the first L 2 -1 elements of the invitation code array according to an assignment sequence corresponding to the length of the invitation code to be generated, specifically includes:
s11, setting an element corresponding to the 1 st array serial number in the sequencing order in the invitation code array as the initial value;
And S12, setting an element corresponding to the i-th array serial number in the ordering sequence in the invitation code array as a quotient of an element value corresponding to the i-1-th array serial number in the ordering sequence in the invitation code array and the character sequence length L 1 for the invitation code, wherein i=2.
Assuming that the length of the to-be-generated invitation code is 5, the length of the invitation code Array is also 5, and the specific process of performing the scaled assignment on the first 4 elements of the invitation code Array according to the scaled assignment method given in the steps S11-S12 includes the steps of assigning the initial value to Array [0], assigning the quotient of Array [0] and L 1 to Array [1], assigning the quotient of Array [1] and L 1 to Array [2], and assigning the quotient of Array [2] and L 1 to Array [3].
Step 3032b, using the initial value and the character sequence length for the invitation code, performing bit-wise diffusion on the first L 2 -1 elements of the invitation code array based on the character sequence length for the invitation code;
In this embodiment, after performing assignment on the first L 2 -1 elements of the invite code array in step 3032a, bit-wise diffusion based on the character sequence length for the invite code is further performed on these elements in step 3032 b.
In this embodiment, using the initial value and the character sequence length for the invitation code, performing bit-wise diffusion on the first L 2 -1 elements of the invitation code array based on the character sequence length for the invitation code, including:
For each element in the first L 2 -1 elements of the invitation code array, calculating the product of the array serial number corresponding to the element and the initial value, calculating the addition result of the element value and the product, determining the modulo calculation result of the addition result on the character sequence length for the invitation code, and updating the element value to be the modulo calculation result.
Here, by performing the above-described diffusion operation on the first L 2 -1 elements of the invitation code array, the values of the first L 2 -1 elements of the invitation code array can all fall into the interval [0, L 1 -1].
Step 3032c, determining an interference value according to the first L 2 -1 elements in the invitation code array, calculating the product of the interference value and the first basic data corresponding to the length of the invitation code to be generated, determining the modulo calculation result of the product on the length of the character sequence for the invitation code, and setting the element value with the array sequence number of L 2 -1 in the invitation code array as the modulo calculation result.
In this embodiment, determining an interference value according to the first L 2 -1 elements in the invitation code array specifically includes:
And calculating the addition result of the element values from the L 2 -1-m element to the L 2 -1 element in the invitation code array, and determining the addition result as the interference value, wherein m is a preset integer value and is positioned in the interval [2, L 2 -1 ]. Here, L 2 is an integer greater than 2.
It can be seen that, in this embodiment, the last element (i.e. the L 2 th element) of the invitation code array does not refer to the operation of performing the scaled assignment on the previous L 2 -1 elements, but determines an interference value according to the previous L 2 -1 elements, calculates the product of the interference value and the first basic data corresponding to the length of the invitation code to be generated, and assigns the result of modulo calculation of the product on the length of the character sequence for the invitation code to the element, so as to further increase the decoding difficulty of the finally generated invitation code.
The above steps 3032a through 3032c are specific refinements of step 2032 shown in fig. 2.
Step 3033, using the second basic data corresponding to the length of the invitation code to be generated to mix the invitation code array according to the bits.
In this embodiment, the elements in the invitation code array may be scrambled by bit confusion on the invitation code array, so as to further increase the difficulty of decoding the invitation code.
The above steps 3031 to 3033 are specific refinements of step 103 shown in fig. 1.
And 304, extracting the character of each element value corresponding to the invitation code array in the character sequence for the invitation code, and determining the character string formed by the extracted characters as the invitation code of the user.
According to the method shown in fig. 3, in this embodiment, when generating the invitation code, the first L 2 -1 elements of the invitation code array are assigned by a reduced multiple and spread by bits according to the global unique id carried by the invitation code generation request, and the first basic data and the random data corresponding to the length of the invitation code to be generated, and the last element of the invitation code array is assigned by other methods, so that, on one hand, the characters of the preconfigured invitation code are uniformly distributed, and on the other hand, the decoding difficulty of the subsequently extracted invitation code is increased, and then, the second basic data corresponding to the length of the invitation code to be generated is utilized to carry out bit confusion on the invitation code array, thereby further increasing the decoding difficulty of the subsequently extracted invitation code. The invention does not need to query the database and pre-generate the main key of the database, and also supports the invitation code generation mechanism with specified length, thereby improving the generation efficiency of the invitation code, reducing the complexity of the generation of the invitation code and controlling the length of the generated invitation code under the condition of ensuring that the invitation code is not repeated.
Referring to fig. 4, fig. 4 is a flowchart of a method for generating a fourth invitation code according to an embodiment of the present invention, as shown in fig. 4, the method mainly includes the following steps:
Step 401, receiving an invitation code generation request of a user;
step 402, generating an invitation code array according to the length of the invitation code to be generated carried by the invitation code generation request;
In this embodiment, the invitation code generation request carries information such as a length of an invitation code to be generated, a global unique identifier (id), and the like.
In the embodiment, corresponding basic data information is configured in advance for the length of the to-be-generated invitation code, and specifically comprises first basic data which is mutually equal to the length of a character sequence for the invitation code, second basic data which is mutually equal to the length of the to-be-generated invitation code and random data, wherein the character sequence for the invitation code is preconfigured. In addition, a corresponding assignment sequence is configured for the length of the invitation code to be generated in advance.
In this embodiment, the character sequence for the invitation code may be any set of characters input by the user through the electronic device, specifically set by the user, for example, a plurality of characters may be selected from 10 number characters, 0-9, and 26 english alphabets, a-Z, as the characters for the invitation code, and arranged in any order into one character sequence, and the specific arrangement order may be set by the user, which is not limited by the present invention.
Step 4031, calculating the product of the id carried by the invitation code generation request and the first basic data corresponding to the length of the invitation code to be generated, and adding the product and the random data corresponding to the length of the invitation code to be generated to obtain an initial value;
step 4032, performing scaled assignment and bitwise diffusion on the invitation code array based on the character sequence length for the invitation code according to the initial value and the assignment sequence corresponding to the length of the invitation code to be generated;
In this embodiment, the assignment of the number of the invitation codes based on the length of the character sequence for the invitation codes is performed according to the assignment sequence corresponding to the length of the invitation codes to be generated, so that the element values in the number of the invitation codes fall into the value interval [0, l 1 -1], and the initial values are obtained by multiplying the id by the first basic data of the character sequence length for the invitation codes and then adding the multiplied values to the random data, so that the characters for the invitation codes can be uniformly distributed in the number of the invitation codes when the assignment of the number of the invitation codes based on the length of the character sequence for the invitation codes is performed and the diffusion of the number of the invitation codes by bits is performed.
Step 4033a, for each element in the invitation code array, determining a new array sequence number corresponding to the element according to the array sequence number corresponding to the element and the second basic data corresponding to the length of the invitation code to be generated;
In this embodiment, determining the new array sequence number corresponding to the element according to the array sequence number corresponding to the element and the second basic data corresponding to the length of the invitation code to be generated specifically includes:
And calculating the product of the array serial number corresponding to the element and the second basic data corresponding to the length of the invitation code to be generated, determining the modulo calculation result of the product to the length of the invitation code to be generated, and determining the modulo calculation result as the new array serial number corresponding to the element.
Step 4033b, performing position adjustment on the elements in the invitation code array according to the new array serial numbers corresponding to each element in the invitation code array.
In this embodiment, let the character sequence for the invitation code be :'H','V','E','8','S','2','D','Z','X','9','C','7','P','1','5','I','K','3','M','J','U','F','R','4','W','Y','L','T','N','6','B','G','Q', as follows, L 1 =35.
Assuming that the length of the invitation code to be generated is 5, and that the values of the 1 st to 5 th elements of the invitation code Array are sequentially determined in step 4043a to be Array [0] =1, array [1] =5, array [2] =7, array [3] =4, and Array [4]8 ], and that the new sequence of the 1 st to 5 th elements is sequentially determined in step 4043b to be 0,1, 3, 2, and 4, the position-adjusted invitation code Array may be determined in which Array [0] =1, array [1] =5, array [2] =4, array [3] =7, and Array [4] =8.
The above steps 4033a to 4033b are specific refinements of step 2033 shown in fig. 2.
The above steps 4031 to 4033b are specific refinements of step 103 shown in fig. 1.
And step 404, extracting the character of each element value corresponding to the invitation code array in the character sequence for the invitation code, and determining the character string formed by the extracted characters as the user's invitation code.
In this embodiment, the character corresponding to the value of each element of the invitation code array in the character sequence for the invitation code may be extracted, for example, in the invitation code array obtained after the step 4043b is executed, the extracted characters are sequentially as follows:
Array [0] =1, corresponding to 'V' in the character sequence for the invitation code;
array [1] =5, corresponding to '2' in the character sequence for the invitation code;
array [2] =4, corresponding to 'S' in the character sequence for the invitation code;
Array [3] =7, corresponding to 'Z' in the character sequence for the invitation code;
Array [4] =8, corresponding to 'X' in the character sequence for the invitation code.
The invitation code of the user is thus available as V2SZX.
According to the method shown in fig. 4, in this embodiment, when generating the invitation code, the number sets of the invitation code are subjected to scaled assignment and bit-wise diffusion according to the global unique identifier id carried by the invitation code generation request, and the first basic data and the random data corresponding to the length of the invitation code to be generated, so that the characters of the pre-configured invitation code are uniformly distributed, and then the number sets of the invitation code are subjected to bit-wise confusion by using the second basic data corresponding to the length of the invitation code to be generated, so that the element positions in the number sets of the invitation code are disturbed, and the decoding difficulty of the invitation code obtained by subsequent extraction can be increased. The invention does not need to query the database and pre-generate the main key of the database, and also supports the invitation code generation mechanism with specified length, thereby improving the generation efficiency of the invitation code, reducing the complexity of the generation of the invitation code and controlling the length of the generated invitation code under the condition of ensuring that the invitation code is not repeated.
The embodiment of the invention also provides an invitation code generating device, as shown in fig. 5, which comprises:
A receiving unit 501, configured to receive an invitation code generation request of a user;
A generating unit 502, configured to generate an invitation code array according to the length of the to-be-generated invitation code carried by the invitation code generating request;
A processing unit 503, configured to perform, on the invitation code array, assignment by multiplication, diffusion by bit, and confusion by bit based on the length of the character sequence for the invitation code according to the global unique identifier id carried by the invitation code generation request and the basic data information corresponding to the length of the invitation code to be generated, so that the element values in the invitation code array fall into a value interval [0, L 1 -1], where the basic data information corresponding to the length of the invitation code to be generated and the character sequence for the invitation code are preconfigured, and L 1 is the length of the character sequence for the invitation code;
And an extracting unit 504, configured to extract a character corresponding to each element value of the invitation code array in the character sequence for the invitation code, and determine a character string formed by the extracted characters as the user's invitation code.
In the apparatus shown in figure 5 of the drawings,
The basic data information corresponding to the length of the invitation code to be generated comprises first basic data which are mutually equal to the length of the character sequence used for the invitation code, second basic data which are mutually equal to the length of the invitation code to be generated and random data;
The processing unit 503 performs, according to the id carried by the invitation code generation request and the basic data information corresponding to the length of the invitation code to be generated, assignment of a scaled number, diffusion by bit, and confusion by bit on the invitation code array based on the length of the character sequence for the invitation code, where the assignment includes:
calculating the product of the id and the first basic data corresponding to the length of the invitation code to be generated, and adding the product and the random data corresponding to the length of the invitation code to be generated to obtain an initial value;
Performing scaled assignment and bit-wise diffusion on the invitation code array based on the character sequence length for the invitation code according to the initial value and the assignment sequence corresponding to the length of the invitation code to be generated, wherein the assignment sequence corresponding to the length of the invitation code to be generated is preconfigured;
And carrying out bit confusion on the invitation code array by utilizing second basic data corresponding to the length of the invitation code to be generated.
In the apparatus shown in figure 5 of the drawings,
The assignment sequence corresponding to the length of the invitation code to be generated is the sequence of the sequence numbers of the first L 2 -1 arrays of the invitation code arrays, wherein L 2 is the length of the invitation code to be generated;
the processing unit 503 performs, according to the initial value, assignment of the number group of the invitation codes based on the multiple of the character sequence length for the invitation codes and bit-wise diffusion according to an assignment sequence corresponding to the length of the invitation codes to be generated, including:
performing scaled assignment on the first L 2 -1 elements of the invitation code array based on the character sequence length for the invitation code according to the initial value and an assignment sequence corresponding to the length of the invitation code to be generated;
performing bit-wise diffusion on the first L 2 -1 elements of the invitation code array based on the character sequence length for the invitation code by using the initial value and the character sequence length for the invitation code;
And determining an interference value according to the first L 2 -1 elements in the invitation code array, calculating the product of the interference value and first basic data corresponding to the length of the invitation code to be generated, determining the modulo calculation result of the product on the character sequence length for the invitation code, and setting the element value with the array serial number L 2 -1 in the invitation code array as the modulo calculation result.
In the apparatus shown in figure 5 of the drawings,
The processing unit 503 performs, according to the initial value, assignment of the first L 2 -1 elements of the invite code array according to an assignment sequence corresponding to a length of the invite code to be generated, where the assignment is based on a reduction of the length of the character sequence used for the invite code, where the assignment includes:
Setting an element corresponding to the 1 st digit group serial number in the ordering order in the invitation code digit group as the initial value;
Setting an element corresponding to the i-th array serial number in the ordering order in the invitation code array as a quotient of an element value corresponding to the i-1-th array serial number in the ordering order in the invitation code array and the character sequence length L 1 for the invitation code, wherein i=2.
In the apparatus shown in figure 5 of the drawings,
The processing unit 503 performs bit-wise diffusion on the first L 2 -1 elements of the invite code array based on the character sequence length for the invite code by using the initial value and the character sequence length for the invite code, including:
For each element in the first L 2 -1 elements of the invitation code array, calculating the product of the array serial number corresponding to the element and the initial value, calculating the addition result of the element value and the product, determining the modulo calculation result of the addition result on the character sequence length for the invitation code, and updating the element value to be the modulo calculation result.
In the apparatus shown in figure 5 of the drawings,
The processing unit 503 determines an interference value according to the first L 2 -1 elements in the invitation code array, including:
And calculating the addition result of the element values from the L 2 -1-m element to the L 2 -1 element in the invitation code array, and determining the addition result as the interference value, wherein m is a preset integer value and is positioned in the interval [2, L 2 -1 ].
In the apparatus shown in figure 5 of the drawings,
The processing unit 503 performs bit confusion on the invitation code array by using second basic data corresponding to the length of the invitation code to be generated, including:
for each element in the invitation code array, determining a new array sequence number corresponding to the element according to the array sequence number corresponding to the element and second basic data corresponding to the length of the invitation code to be generated;
And carrying out position adjustment on the elements in the invitation code array according to the new array serial numbers corresponding to each element in the invitation code array.
In the apparatus shown in figure 5 of the drawings,
The processing unit 503 determines a new array sequence number corresponding to the element according to the array sequence number corresponding to the element and the second basic data corresponding to the length of the invitation code to be generated, including:
And calculating the product of the array serial number corresponding to the element and the second basic data corresponding to the length of the invitation code to be generated, determining the modulo calculation result of the product to the length of the invitation code to be generated, and determining the modulo calculation result as the new array serial number corresponding to the element.
The embodiment of the invention also provides an electronic device, as shown in fig. 6, which comprises a processor 601 and a memory 602;
The memory 602 stores one or more computer programs executable by the processor 601, which when executed implement the steps in the invitation code generation method as shown in any of the flowcharts of figures 1-4.
Embodiments of the present invention also provide a non-transitory computer readable storage medium storing instructions, which when executed by a processor cause the processor to implement steps in an invitation code generation method as shown in any of the flowcharts of fig. 1-4.
The foregoing description of the preferred embodiments of the invention is not intended to be limiting, but rather to enable any modification, equivalent replacement, improvement or the like to be made within the spirit and principles of the invention.