Login status maintenance method and system
By generating cookies that match the login terminal and using asynchronous queues and heartbeat connections to maintain the login status, the problem of users logging into the office system anytime, anywhere is solved, enabling intelligent office processing under network fluctuations and server limitations, and improving the system's concurrency and throughput.
Patent Information
- Application Number
- CN202410488872.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-23
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-04-23
AI Technical Summary
In existing technologies, due to network fluctuations and server login restrictions, users find it difficult to log in to the office system anytime and anywhere, which affects normal office work.
Generate a cookie that matches the login terminal, save the request through an asynchronous queue, maintain the login status using a heartbeat connection, and record the status using asynchronous logs.
Despite network fluctuations and server limitations, the system maintains user login status, enabling intelligent office processing and improving concurrency and throughput.
Smart Images

Figure CN118214610B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and in particular to a method and system for maintaining a login status. Background Art
[0002] When users log in to the office system, it is difficult to ensure that they can log in smoothly anytime and anywhere due to network fluctuations. In addition, for the sake of service stability, the server side of some office systems usually limits the number of logins for the same user to avoid multiple frequent logins. Under such circumstances, it is very likely to affect the user's normal work.
[0003] Based on this, there is an urgent need for a solution that can maintain the user's login status and use limited server resources to achieve intelligent office processing. Summary of the invention
[0004] The present invention provides a login status maintaining method and system, which are used to solve the defect in the prior art that it is difficult to ensure that users can successfully log in to the office system anytime and anywhere due to network fluctuations. The method and system can maintain the user's login status and realize intelligent office processing by using limited server resources.
[0005] The present invention provides a method for maintaining a login status, comprising:
[0006] Interact with the login terminal and generate a cookie that matches the login terminal;
[0007] Receive the cookie saving request from the login terminal and put the cookie saving request into the asynchronous queue;
[0008] The login terminal saves the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
[0009] According to the login status maintaining method provided by the present invention, after generating a cookie matching the login terminal, the method further includes:
[0010] Verify the cookie, and if the verification passes, store the cookie in the login terminal.
[0011] According to the login status maintaining method provided by the present invention, a cookie saving request from a login terminal is received, and the cookie saving request is placed in an asynchronous queue, including:
[0012] Receive the heartbeat request from the login terminal and send a reply instruction to the login terminal to maintain the heartbeat connection with the login terminal.
[0013] According to the login status maintaining method provided by the present invention, the cookie saving request is an API maintaining request, and the heartbeat request of the login terminal is a non-blocking request.
[0014] According to the login status maintaining method provided by the present invention, the cookie saving request is a driver maintaining request, and the login terminal sends a heartbeat request by continuously refreshing.
[0015] According to the login status maintaining method provided by the present invention, the login terminal sends a heartbeat request at random intervals of N minutes until no reply instruction is received.
[0016] The method for maintaining the login status according to the present invention further includes:
[0017] The login status is recorded through asynchronous logs.
[0018] The present invention also provides a login status maintaining system, comprising:
[0019] A generation module, used to interact with the login terminal and generate a cookie matching the login terminal;
[0020] The receiving module is used to receive the cookie saving request from the login terminal and put the cookie saving request into the asynchronous queue;
[0021] The maintenance module is used for the login terminal to save the cookie. The login terminal maintains the login status of the login terminal based on the cookie.
[0022] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the above-mentioned methods for maintaining a login status is implemented.
[0023] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any of the above-mentioned login status maintaining methods is implemented.
[0024] The present invention also provides a computer program product, including a computer program, and when the computer program is executed by a processor, any of the above-mentioned login status maintaining methods is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0026] Figure 1 This is one of the flow charts of the method for maintaining the login status provided by an embodiment of the present invention;
[0027] Figure 2 is a structural diagram of a login status maintaining system provided by an embodiment of the present invention;
[0028] Figure 3 This is a second flow chart of the method for maintaining the login status provided by an embodiment of the present invention;
[0029] Figure 4 This is a third flow chart of the method for maintaining the login status provided by an embodiment of the present invention;
[0030] Figure 5 This is a fourth flow chart of the method for maintaining the login status provided by an embodiment of the present invention;
[0031] Figure 6 This is a fifth flow chart of the method for maintaining the login status provided by an embodiment of the present invention;
[0032] Figure 7 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0033] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0034] Figure 1 This is one of the flow charts of the method for maintaining the login status provided by an embodiment of the present invention.
[0035] like Figure 1 As shown, this embodiment provides a method for maintaining a login status, including:
[0036] Step 101, interacting with a login terminal to generate a cookie matching the login terminal;
[0037] Step 102, receiving a cookie saving request from the login terminal, and placing the cookie saving request into an asynchronous queue;
[0038] Step 103: The login terminal saves the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
[0039] In practical applications, the login status maintenance method provided in this embodiment can be applied to the field of tax reporting. Specifically, in the prior art, facing the complex and changeable network environment and the limitations of tax reporting login at the bureau end, it is difficult to ensure that users can log in to the tax office system anytime and anywhere to perform remote tax reporting operations. Based on this, the solution provided in this embodiment can enable users to maintain the login status after logging in once, and realize intelligent tax processing with limited resources.
[0040] The use of an asynchronous queue in step 102 has the benefits of improving concurrency and throughput, as follows:
[0041] In multi-threaded programming, it may take a long time for a thread to complete a task. If the next thread starts working after waiting for the thread to complete the task, the concurrency of the program will be greatly reduced. Asynchronous queues can store pending tasks and allow multiple threads to take tasks from the queue for processing at the same time, which improves concurrency and fully utilizes the computing power of multi-core processors.
[0042] Since asynchronous queues allow multiple threads to process tasks simultaneously, the throughput of the program can be significantly improved. This is very important for applications that need to handle a large number of requests.
[0043] In an exemplary embodiment, after generating a cookie matching the login terminal, the method further includes:
[0044] Verify the cookie, and if the verification passes, store the cookie in the login terminal.
[0045] In an exemplary embodiment, receiving a cookie saving request from a login terminal and placing the cookie saving request in an asynchronous queue includes:
[0046] Receive the heartbeat request from the login terminal and send a reply instruction to the login terminal to maintain the heartbeat connection with the login terminal.
[0047] In an exemplary embodiment, the cookie preservation request is an API retention request, and the heartbeat request of the login terminal is a non-blocking request.
[0048] In an exemplary embodiment, the cookie saving request is a driver retention request, and the login terminal sends a heartbeat request by continuously refreshing.
[0049] In an exemplary embodiment, the login terminal sends a heartbeat request at random intervals of N minutes until no reply instruction is received.
[0050] In an exemplary embodiment, it further includes:
[0051] The login status is recorded through asynchronous logs.
[0052] The login status maintaining system provided by the present invention is described below. The login status maintaining system described below and the login status maintaining method described above can be referenced to each other.
[0053] Figure 2 It is a structural diagram of a login status maintaining system provided by an embodiment of the present invention.
[0054] like Figure 2 As shown, the login status maintaining system provided in this embodiment includes:
[0055] A generation module 201 is used to interact with a login terminal and generate a cookie matching the login terminal;
[0056] The receiving module 202 is used to receive a cookie saving request from a login terminal and place the cookie saving request into an asynchronous queue;
[0057] The maintaining module 203 is used for the login terminal to save the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
[0058] In an exemplary embodiment, a verification module is also included, and the verification module is specifically used to: verify the cookie, and after the verification passes, store the cookie in the login terminal.
[0059] In an exemplary embodiment, the receiving module 202 is further used to: receive a heartbeat request from the login terminal, and send a reply instruction to the login terminal to maintain a heartbeat connection with the login terminal.
[0060] In an exemplary embodiment, the cookie saving request is an API holding request, and the heartbeat request of the login terminal is a non-blocking request.
[0061] In an exemplary embodiment, the cookie saving request is a driver retention request, and the login terminal sends a heartbeat request by continuously refreshing.
[0062] In an exemplary embodiment, the login terminal sends a heartbeat request at random intervals of N minutes until no reply instruction is received.
[0063] In an exemplary embodiment, a recording module is also included, and the recording module is specifically used for:
[0064] The login status is recorded through asynchronous logs.
[0065] The specific implementation method of the login status maintaining system provided in this embodiment can be implemented with reference to the above embodiment and will not be described in detail here.
[0066] The following provides a specific embodiment to illustrate the login status maintenance method provided by the present application.
[0067] Figure 3 This is the second flow chart of the method for maintaining the login status provided by the embodiment of the present invention.
[0068] Figure 4 This is the third flow chart of the method for maintaining the login status provided by the embodiment of the present invention.
[0069] Figure 5 This is the fourth flow chart of the method for maintaining the login status provided by the embodiment of the present invention.
[0070] Figure 6 This is the fifth flow chart of the method for maintaining the login status provided by the embodiment of the present invention.
[0071] in Figure 3 is a specific flow chart of the method for maintaining the login status provided by an embodiment of the present invention, Figure 4-Figure 6 It is a timing diagram of three different login methods provided in an embodiment of the present invention.
[0072] like Figure 3 As shown, the login status maintaining method provided in this embodiment includes:
[0073] 1. Obtain cookie task. In this step, there are different ways to obtain cookies depending on the login terminal. Specifically, when the login terminal is an ordinary mobile terminal, after the first login is successful, the mobile terminal interacts with the server and saves cookies, and maintains a heartbeat connection with the server to maintain the session state; when the login terminal is a fixed device, a larger driver pool can be managed by a group of machines. When logging in, each driver can open the login interface and send the QR code to the middle station for scanning and verification. Once the QR code is scanned by the user and the login is successful, it will interact with the server to obtain and save cookies, and maintain a heartbeat connection with the server.
[0074] 2. Receive a cookie saving request from the login terminal and verify some fields of the cookie. For example, when the login status maintenance method provided in this embodiment is applied to tax declaration services, it can be verified whether the tax number length is 18 digits;
[0075] 3. After the verification is passed, the cookie is stored in redis, and the task of keeping the cookie is placed in the asynchronous queue. The asynchronous queue will distribute the task to the machine group used to keep the cookie heartbeat;
[0076] 4. After receiving the cookie save request, the machines in the machine group that maintains the cookie heartbeat are divided into two modes: API request preservation and driver preservation according to the different cookie types in the cookie save request. For API request preservation, aiohttp can be used to send non-blocking requests to maintain the heartbeat of the server; for driver preservation, a driver object can be randomly obtained from the pre-established asynchronous driver pool, and the driver object will be continuously refreshed to maintain the heartbeat;
[0077] 5. Maintain the heartbeat connection at random intervals of N minutes until the heartbeat connection reaches the maximum duration or the heartbeat fails, then you need to log in again. Once it is determined that the heartbeat connection has reached the maximum duration or the heartbeat fails, the resources will be released, and you can close the API request or release the driver.
[0078] 6. After the resources are released, the invalid cookies in redis can be deleted;
[0079] 7. The entire process mentioned above can be recorded through asynchronous logs.
[0080] in Figure 3 Playwright headless means Playwright runs the browser's automated operations with a UI interface.
[0081] Playwright headless means that Playwright runs the browser's automated operations without a UI interface.
[0082] like Figure 4 As shown, this embodiment illustrates a login process for maintaining the login status through an API, including:
[0083] The first time a client logs in through RPA, after successful login, it sends a request to the server with the cookie and specifies the refresh mode as API. After receiving the cookie, the server saves the cookie to redis and inserts a cookie task into the MQ message queue.
[0084] The MQ message queue distributes tasks to the refresh robot. The robot executes API requests to refresh the cookie regularly until the cookie expires or reaches the maximum retention time and deletes the cookie from redis.
[0085] The second time, the client directly requests the server to obtain the cookie. If the cookie is valid, it will directly jump to the system to be logged in. If the cookie is invalid, it will continue to repeat the first login process.
[0086] like Figure 5 As shown, this embodiment also illustrates a login process for maintaining the login status through a driver, including:
[0087] The first time a client logs in through RPA, after successful login, it sends a request to the server with the cookie and specifies the refresh mode as driver. After receiving the cookie, the server saves the cookie to redis and inserts a cookie task into the MQ message queue.
[0088] The MQ message queue distributes tasks to the refresh robot. The robot executes the RPA tool and refreshes the cookie regularly until the cookie expires or reaches the maximum retention time and deletes the cookie from redis.
[0089] The second time, the client directly requests the server to obtain the cookie. If the cookie is valid, it will directly jump to the system to be logged in. If the cookie is invalid, it will continue to repeat the first login process.
[0090] like Figure 6 As shown, this embodiment also illustrates a login process for maintaining the login status through QR code login, including:
[0091] The customer opens the RPA tool on the client and passes the QR code information to the middle platform. The middle platform saves the QR code and waits for the customer to scan it.
[0092] The client periodically checks its own login status. When it detects that the status has changed to successful login, it sends a request with cookies to the server and specifies the refresh mode as api.
[0093] The server receives the cookie, saves it to redis, and inserts a cookie task into the MQ message queue.
[0094] The MQ queue distributes tasks to the refresh robot, and the robot executes API requests to refresh the cookie regularly until the cookie expires or reaches the maximum retention time and deletes the cookie from redis.
[0095] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the login status maintenance method, which includes:
[0096] Interact with the login terminal and generate a cookie that matches the login terminal;
[0097] Receive the cookie saving request from the login terminal and put the cookie saving request into the asynchronous queue;
[0098] The login terminal saves the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
[0099] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0100] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored in a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the login status maintenance method provided by the above methods, the method includes:
[0101] Interact with the login terminal and generate a cookie that matches the login terminal;
[0102] Receive the cookie saving request from the login terminal and put the cookie saving request into the asynchronous queue;
[0103] The login terminal saves the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
[0104] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to perform the login status maintaining method provided by the above methods, the method comprising:
[0105] Interact with the login terminal and generate a cookie that matches the login terminal;
[0106] Receive the cookie saving request from the login terminal and put the cookie saving request into the asynchronous queue;
[0107] The login terminal saves the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
[0108] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, i.e., they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Those of ordinary skill in the art may understand and implement it without creative effort.
[0109] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods of each embodiment or some parts of the embodiment.
[0110] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for maintaining a logged-in state, characterized in that: include: Obtain cookie task. When the login terminal is an ordinary mobile terminal, after the first login is successful, the mobile terminal interacts with the server and saves cookies, and maintains a heartbeat connection with the server to maintain the session state. When the login terminal is a fixed device, a driver pool is managed by a group of machines. When logging in, each driver can open the login interface and send the QR code to the middle station for scanning and verification. Once the QR code is scanned by the user and the login is successful, it will interact with the server to obtain and save cookies, and maintain a heartbeat connection with the server. Receive the cookie saving request from the login terminal and verify some fields of the cookie. When applied to tax declaration services, verify whether the tax number length is 18 digits; After the verification is passed, the cookie is stored in redis, and the task of keeping the cookie is put into the asynchronous queue. The asynchronous queue will distribute the task to the machine group used to keep the cookie heartbeat; After receiving a cookie save request, the machines in the machine group that keeps the cookie heartbeat are divided into two modes: API request preservation and driver preservation according to the different cookie types in the cookie save request. For API request preservation, aiohttp is used to send non-blocking requests to keep the heartbeat on the server side; for driver preservation, a driver object is randomly obtained from the pre-established asynchronous driver pool, and the driver object will be continuously refreshed to keep the heartbeat; The heartbeat connection is maintained at random intervals of N minutes until the heartbeat connection reaches the maximum duration or the heartbeat fails, in which case you need to log in again. Once it is determined that the heartbeat connection has reached the maximum duration or the heartbeat fails, resources will be released, and the API request will be closed or the driver will be released. After the resources are released, delete the invalid cookies in redis; Record the process through asynchronous logging; The login process of maintaining the login status through API includes: The first time a client logs in through RPA, after successful login, it sends a request to the server with the cookie and specifies the refresh mode as API. After receiving the cookie, the server saves the cookie to redis and inserts a cookie task into the MQ message queue. The MQ message queue distributes tasks to the refresh robot, which executes API requests to refresh the cookie regularly until the cookie expires or reaches the maximum retention time and deletes the cookie from redis; The second time the client directly requests the server to obtain the cookie. If the cookie is valid, it will directly jump to the system to be logged in. If the cookie is invalid, it will continue to repeat the first login process.
2. A login status maintaining system, applied to the login status maintaining method according to claim 1, characterized in that: include: A generation module, used to interact with the login terminal and generate a cookie matching the login terminal; A receiving module, used for receiving a cookie saving request from the login terminal, and placing the cookie saving request into an asynchronous queue; The maintaining module is used for the login terminal to save the cookie, and the login terminal maintains the login status of the login terminal based on the cookie.
3. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the login status maintaining method as claimed in claim 1 is implemented.
4. A computer program product, comprising a computer program, which implements the login status maintaining method as claimed in claim 1 when the computer program is executed by a processor.
Citation Information
Patent Citations
Duplex full-duplex communication method and device, computer equipment and storage medium
CN112689014A
Decentralized single sign-on method and device and storage medium
CN113852628A
Login state keeping method and device
CN116232754A
Network auction bidding pushing method and device, computer equipment and medium
CN117575756A
Cookie based session management
US20150088978A1
