A kind of method and system for preventing to repeat
Technical field
The present invention relates to Internet technical field, more particularly to a kind of method and system for preventing to repeat.
Background technology
With the development of network, computer has turned into the indispensable part of people's life, when accessing website, often
Need to submit some lists to carry out Data Enter, and for performance is not good or program runs slow computer, the page
Update slow, user to ensure that list submits state, can repeatedly click on " it is determined that " cue button, so as to cause list to repeat to carry
Hand over, and information updating mistake is occurred.List, which repeats to submit, turns into major websites increasingly stubborn problem, not only attacks major
The security of website data, but also test the patience of user.
Similar the problem of, is also such as:
1st, when user carries out order activity by APP, after click confirms an order, due to network or other reasonses, APP
The problem of in the presence of not responding, now user can be repeated several times click and confirm an order, so as to cause to duplicate the problem of placing an order;
2nd, when user carries out communication exchange by APP, receive or send message it sometimes appear that message repeats what is pushed
Problem, resulting influence may be very big.
For this problem, in the prior art it is also proposed that some corrective measures.
It is " a kind of to prevent the page from repeating the side submitted as disclosed in Application No. CN200910014312.7 patent document
Method ", the invention is based on the anti-submission technologies that repeat of STRUTS there is provided a kind of method for preventing the page from repeating submission, and this method is logical
Modification STRUTS TOKEN token mechanisms are crossed, using the multiple TOKEN objects of a page, each TOKEN objects correspondence is multiple
URL request, all TOKEN objects constitute a round-robin queue, and then prevent the multiple of the page from concurrently repeating to submit, this hair
TOKEN, TOKEN is set to use the principle of first in first out inside bright use TOKEN queues, a FORM.It can thus realize
Prevent from repeating to submit the page when multiple FORM.This mode is server end before the request that processing is reached, and will can be asked
In the token value of the token value that includes with being stored in active user's session be compared, see whether match.Please having handled this
After asking, and before answer is sent to client, it will produce a new token, the token in addition to client is transmitted to,
The old token preserved in user conversation can be replaced.If so user return back to the submission page just now and carried again
If friendship, client be transmitted through come token just and server end token it is inconsistent so that prevent repeat submit generation.But this
The mode of kind client and server needs multiple interaction, due to be modified to token token mechanism, with the addition of a lot
Corresponding program, to speed of service itself with regard to it is not high for computer it is possible that response it is slow in addition crash situation.
In addition, this screen locking function be able to can not also be used by being influenceed in terms of operating system schema, language, framework.
It is and for example " a kind of to prevent user from repeating the side submitted disclosed in Application No. CN201310039142.4 patent document
Method and system ", the invention provides a kind of method and system for preventing user from repeating submission, and the system includes a screen lock module, one
List submits client and a server end, clicks on submitting button triggering list in user, when submission, triggers screen locking
Module works, and carries out screen locking to screen, it is impossible to submit again, prevents user from performing and repeatedly clicks on order;Uploaded completing information
After release screen locking so that effectively prevent repeat submit.The screen locking of supporting frame rank is gone back in the invention, by searching current page automatically
By the corresponding father's framework of the subframe of screen locking in face, across framework screen locking is realized.This method can be to screen after user submits request
Curtain carries out screen locking, can just be unlocked, when it is not especially desirable to run into network service effect, can lead only after the completion of request
Cause unlocked time longer, so as to reduce Consumer's Experience sense.
The content of the invention
In view of the above-mentioned state of the art, the present invention is directed to propose a kind of method and system for preventing to repeat, energy
Enough ensure the uniqueness operated in distributed environment.
The present invention solve the technical scheme that is used of above-mentioned technical problem for:
A kind of method for preventing to repeat, including step:
S1. the corresponding multiple unique marks of multiple business operations are received;
S2. corresponding multiple Global IDs are generated according to the multiple unique mark;
If S3. there is identical Global ID, judge the corresponding business operation to repeat;
If in the absence of identical Global ID, judging the corresponding business operation for non-duplicate operation.
Further, in step S1, the unique mark includes:APP_KEY, business operation content information.
Further, step S2 is specifically included:
S21. according to multiple unique marks of the reception, multiple Global IDs are generated by MD5 algorithms, set Global ID to make
For keyword;
S22., key value is set, and the key value includes timestamp, unique mark;
S23. the keyword and key value are stored into external storage engine.
Further, in step S3, searched by keyword, search whether to exist in the external storage engine identical
Global ID, whether judge the business operation is to repeat.
Further, step S3 is specially:
If S31. there is identical Global ID, the business operation is judged to repeat, and is returned and is failed to business side
Information;
If identical Global ID is S32. not present, the business operation is judged for non-duplicate operation, is returned to business side
Successful information.
Further, if returning success, in addition to:
S4., out-of-service time is set, and the keyword and key value are carried out from deletion according to the timestamp and out-of-service time.
Further, include the checked operation of returning result information, be specially:
S51. after returning success, business side is carried out after the completion of business operation, the business operation, and business side will be operated
As a result, returning result information is sent to system;
S52. search the corresponding keyword of the business operation, key value, and with the operating result, returning result information
It is compared;
If S53. keyword is consistent, extend the keyword and key value corresponding out-of-service time.
A kind of system for preventing to repeat, including:
Receiving module, for receiving the corresponding multiple unique marks of multiple business operations;
Generation module, for generating corresponding multiple Global IDs according to the multiple unique mark;
Judge module, for judging whether corresponding business operation is to repeat according to the Global ID:If there is phase
Same Global ID, then judge the corresponding business operation to repeat;If in the absence of identical Global ID, judging described
Corresponding business operation is non-duplicate operation.
Further, in addition to:
External storage engine, for storing keyword, key value.
Further, in addition to:
Setup module, for setting the out-of-service time;
The setup module also includes:
Verification unit, the checked operation for completing returning result information;
Time lengthening unit, for extending the keyword and key value corresponding out-of-service time.
The present invention proposes a kind of method and system for preventing to repeat, by being assigned to each different business operation
Its uniqueness is given, whether is to repeat the harmful effect that is brought to realize prevention to repeat or more by checked operation
Serious the problem of.
Brief description of the drawings
Fig. 1 is to prevent the method flow diagram that repeats in the embodiment of the present invention one;
Fig. 2 is to prevent the system construction drawing that repeats in the embodiment of the present invention two;
Fig. 3 is to prevent the system construction drawing that repeats in the embodiment of the present invention four;
Fig. 4 is setup module structure chart in the embodiment of the present invention four.
Embodiment
The following is specific embodiment of the invention and with reference to accompanying drawing, technical scheme is further described,
But the present invention is not limited to these embodiments.
The present invention is directed to propose a kind of method and system for preventing to repeat, it can be ensured that operated in distributed environment
Uniqueness.
Its general principles are as follows:The realization approach that prevention repeats system is by each different business operation
Its uniqueness is assigned, this uniqueness is by believing unique APP_KEY corresponding to different operating, business operation content
Breath, generates a unique Global ID to realize.In the present invention, identical operation generation identical Global ID, different operations
The different Global ID of generation.
It is the specific embodiment of the invention below.
Embodiment one
Fig. 1 is in a kind of method flow diagram for preventing to repeat, the present embodiment in the present embodiment, one kind prevention repeats behaviour
The method of work includes step:
S1. the corresponding multiple unique marks of multiple business operations are received;
Business side is carried out before business operation, and corresponding unique mark Trans_ is generated according to the business operation
Contents, the unique mark Trans_Contents include APP_KEY, business operation content information.
APP_KEY is third-party application secret key, for encryption and decryption.
In the present embodiment, APP_KEY, equivalent to the mark of application, is unique.
Business operation content information includes the business object of current operation, and user's information etc..
Unique mark Trans_Contents generation after, business side by the unique mark Trans_Contents send to
Prevention repeats system.
S2. corresponding multiple Global IDs are generated according to the multiple unique mark;
In this step, system receives the unique mark that business side is sent, and corresponding complete according to unique mark generation
Office ID, and multiple Global IDs of generation are stored in external storage engine.
If S3. there is identical Global ID, judge the corresponding business operation to repeat;
If in the absence of identical Global ID, judging the corresponding business operation for non-duplicate operation.
In this step, by searching whether there is identical Global ID in the external storage engine, the industry is judged
Whether business operation is to repeat, and is specially:
If there is identical Global ID, the business operation is judged to repeat, and failure information is returned to business side;
If in the absence of identical Global ID, judging that the business operation, for non-duplicate operation, is returned successfully to business side
Information.
The present embodiment proposes a kind of method and system for preventing to repeat, and passes through the business operation different to each
Its uniqueness is assigned, whether is to repeat the harmful effect that is brought to realize prevention to repeat or more by checked operation
For it is serious the problem of.
Embodiment two
Fig. 2 is in a kind of system construction drawing for preventing to repeat, the present embodiment in the present embodiment, one kind prevention repeats behaviour
The system of work includes:
Receiving module 100, for receiving the corresponding multiple unique marks of multiple business operations;
Generation module 200, for generating corresponding multiple Global IDs according to the multiple unique mark;
Judge module 300, for judging whether corresponding business operation is to repeat according to the Global ID:If in the presence of
Identical Global ID, then judge the corresponding business operation to repeat;If in the absence of identical Global ID, judging institute
Corresponding business operation is stated for non-duplicate operation.
When the system works, the unique mark Trans_Contents of business side's transmission is received by receiving module 100 first;
Then, generation module 200 carries out Context resolution to unique mark Trans_Contents, and generates unique corresponding
Global ID, and Global ID is preserved to external storage engine;
Judge whether the business operation is to repeat by judge module 300 again;
If there is identical Global ID, the business operation is judged to repeat, and failure information is returned to business side;
If in the absence of identical Global ID, judging that the business operation, for non-duplicate operation, is returned successfully to business side
Information.
In the present embodiment, in addition to:
External storage engine 400, for storing the multiple Global IDs generated according to multiple unique marks.
Embodiment three
The present embodiment is with the difference of embodiment one, in the present embodiment, and step S2 is specifically included:
S21. according to multiple unique marks of the reception, multiple Global IDs are generated by MD5 algorithms, set Global ID to make
For keyword;
MD5, i.e. Message Digest Algorithm MD5 (Chinese entitled Message Digest Algorithm 5) are calculating
A kind of widely used hash function in machine security fields, the integrity protection to provide message.The document number of the algorithm is RFC
1321(R.Rivest,MIT Laboratory for Computer Science and RSA Data Security
Inc.April 1992)。
MD5 effect is to allow Large Copacity information to be protected before private key is signed with digital signature software by " compression " into one kind
Close form (being exactly the hexadecimal number word string for the byte serial of a random length being transformed into a fixed length).In addition to MD5,
Wherein compare famous also sha-1, RIPEMD and Haval etc..
The features such as MD5 algorithms have compressibility, easily calculating, anti-modification property, strong impact resistant.
For high concurrent distributed system data, in burst, typically divide storehouse point table, just there is a Global ID
The problem of generation.
Global ID's generation is main by following several ways:
1.UUID
What UUID was generated is the character string of length=32 16 system forms, the core concept combination machine of algorithm
Network interface card, local time, random number generate UUID.
2. the distributed ID makers based on redis
Using redis lua script perform functions, unique ID is generated by lua scripts on each node.
3.MongoDB documents (Document) globally unique ID
In order to consider distribution, " machine that _ id " requires different can easily be generated with globally unique method of the same race
It, therefore the method for having selected generation ObjectId objects.ObjectId uses the memory space of 12 bytes, and its generating mode is such as
Under:Preceding 9 bytes ensure that the uniqueness for the ObjectId that the different processes of same second different machines are produced.Three bytes are afterwards
One automatic increased counter (a mongod process needs a global counter), it is ensured that the ObjectId of same second
It is unique.
After Global ID's generation, it is keyword key to set the Global ID.
S22., key value is set, and the key value includes timestamp, unique mark;
In this step, setting key value value is:Timestamp+unique mark Trans_Contents.
Wherein, timestamp is used to mark current operation thread.
S23. the keyword and key value are stored into external storage engine.
In the present embodiment, in step S3, searched by keyword, search whether there is phase in the external storage engine
Whether same Global ID, it is to repeat to judge the business operation.
If return success, in addition to:
S4., out-of-service time is set, and the keyword and key value are carried out from deletion according to the timestamp and out-of-service time.
In addition, also including the checked operation of returning result information, it is specially:
S51. after returning success, business side is carried out after the completion of business operation, the business operation, and business side will be operated
As a result, returning result information is sent to system;
S52. search the corresponding keyword of the business operation, key value, and with the operating result, returning result information
It is compared;
If S53. keyword is consistent, extend the keyword and key value corresponding out-of-service time.
In the present embodiment, when system is searched by keyword, certain business operation is judged for non-duplicate operation, and to business side
Return success.
Business side is received after the successful information, starts to perform the business operation.
In addition, system can be also set when setting key value in the business operation corresponding out-of-service time, step S22,
Key value specifically includes timestamp, unique mark;
Set after the out-of-service time, according to the timestamp, it may be determined that key value and related keyword when
Failure, now facilitates the key value and keyword to carry out from deletion.
The out-of-service time can be by user's voluntarily configuration definition.
In the present embodiment, include the checked operation of returning result information, operating result and request are returned to knot by business side
Fruit is sent to system, and system once ask the inspection of returning result, i.e.,:
If this time is operated successfully, system takes out value values according to key, is compared with incoming returning result, if two
Person is equal, then is changed into the long period out-of-service time of the Global ID.
The present embodiment proposes a kind of method for preventing to repeat, and it is assigned by the business operation different to each
Uniqueness, and corresponding keyword, key value are set;By search key and key value, whether checked operation is to repeat to grasp
Make, with the harmful effect realizing prevention to repeat to bring or it is even more serious the problem of.
Example IV
Fig. 3 is in a kind of system construction drawing for preventing to repeat, the present embodiment in the present embodiment, the system also includes:
Setup module 500, for setting the out-of-service time;
As shown in figure 4, the setup module 500 also includes:
Verification unit 510, the checked operation for completing returning result information;
Time lengthening unit 520, for extending the keyword and key value corresponding out-of-service time.
When the system works, the unique mark Trans_Contents of business side's transmission is received by receiving module 100 first;
Then, generation module 200 carries out Context resolution, and the unique corresponding Global ID of generation to unique mark Trans_Contents,
And corresponding keyword key, key value value are set;
Judge whether the business operation is to repeat according to the keyword key by judge module 300 again;
If there is identical Global ID, the business operation is judged to repeat, and failure information is returned to business side;
If in the absence of identical Global ID, judging that the business operation, for non-duplicate operation, is returned successfully to business side
Information.
In the present embodiment, setup module 500 set the out-of-service time after, according to the timestamp, it may be determined that key value with
And when related keyword is failing, the key value and keyword is now facilitated to carry out from deletion.
In addition, also including the checked operation of returning result information, after system is return success to business side, business side is entered
After the completion of row business operation, the business operation, business side sends operating result, returning result information to system;In system
Verification unit 510 searches the corresponding keyword of the business operation, key value, and with the operating result, returning result information
It is compared, if keyword is consistent, time lengthening unit 520 extends the keyword and key value corresponding out-of-service time.
Specific embodiment described herein is only to spirit explanation for example of the invention.Technology neck belonging to of the invention
The technical staff in domain can be made various modifications or supplement to described specific embodiment or be replaced using similar mode
Generation, but without departing from the spiritual of the present invention or surmount scope defined in appended claims.