A multi-application pool-oriented link fault-tolerant generation method, system, terminal and storage medium
Patent Information
- Application Number
- CN202611038585.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-13
- Publication Date
- 2026-10-23
AI Technical Summary
[0007]本发明的目的在于提供一种面向多应用池的链接容错生成方法、系统、终端设备及计算机可读存储介质,以解决现有技术中单一应用绑定方案缺乏容错切换能力、以及多应用轮询方案无法区分不同错误码类型进行差异化故障处理的问题
[0013]进一步地,所述链接生成请求用于生成二维码形式的短链接或小程序跳转链接,这些链接具有有限的有效期,实时性和正确性要求在有效期截止时间之前必须确保链接可正常访问。与普通的文本内容缓存不同,链接生成是实时性要求极高的操作——每一次链接生成请求都必须在几十毫秒至数秒内获得用户可预览并分享的二维码或短链接,生成失败或延迟直接影响用户分享行为的持续性和转化率。
Smart Images

Figure CN122963845A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of link generation and fault-tolerant scheduling technology, specifically relating to a link fault-tolerant generation method, system, terminal device, and computer-readable storage medium for multi-application pools. Background Technology
[0002] In mobile internet applications, business platforms often need to call link generation interfaces (i.e., URL link generation interfaces) provided by third-party platforms to create short links or redirect links so that users can share and access them through social channels. Taking the WeChat Mini Program ecosystem as an example, the WeChat Official Accounts Platform provides each Mini Program with the ability to call an interface to generate a URL link. When a user clicks this URL link, it directly redirects to a specified page within the Mini Program. The generated URL link is usually in the form of a QR code or a short link, and has a limited validity period. It is required that the link remain accessible before its expiration date; therefore, the real-time performance and accuracy of the link generation are extremely important.
[0003] In existing technologies, a common approach is to bind a business platform to the application identifier of a single mini-program, with all link generation requests being completed through this fixed mini-program calling third-party interfaces. While this approach is simple to operate under normal conditions, the system lacks effective fault tolerance mechanisms when the mini-program encounters the following two typical failure scenarios.
[0004] The first type of failure scenario is the expiration of access credentials. The access credentials issued by the third-party platform for each mini-program have a limited validity period (e.g., 7200 seconds). If the credential is used to call the link generation interface after it expires, a specific expiration error code will be received, causing all requests to generate links to fail.
[0005] The second type of failure is more serious: Third-party platforms may block a mini-program's link generation permission due to content compliance issues or abnormal call frequency. Once a mini-program is blocked, its link generation API calls will permanently return a permission blocking error code. In a single-mini-program-bound architecture, the blocking of that mini-program means that all shared links immediately become invalid.
[0006] Another known approach is to pre-configure multiple mini-programs and call them in a fixed order. This solution can alleviate the service termination problem after a mini-program is blocked to some extent, but due to the lack of a mechanism for classifying and handling different error codes, when the access credentials for a mini-program expire, this solution cannot distinguish between two fundamentally different fault types: "credential expired (requires refreshing and retrying the same mini-program)" and "permission blocked (requires jumping to the next mini-program)". If credential expiration is also treated as a block and the mini-program is switched directly, the service that could originally be restored by refreshing the credentials will increase the latency of the call chain and the complexity of credential management due to unnecessary application switching. Summary of the Invention
[0007] The purpose of this invention is to provide a link fault tolerance generation method, system, terminal device, and computer-readable storage medium for multi-application pools, in order to solve the problems of single-application binding schemes lacking fault tolerance switching capabilities and multi-application polling schemes being unable to distinguish different error code types for differentiated fault handling in the prior art.
[0008] To achieve the above objectives, the present invention provides the following technical solution.
[0009] In a first aspect, the present invention provides a link fault tolerance generation method for multi-application pools, comprising: In response to a link generation request, the most recently available application identifier is read from the cache storage, and the status flag corresponding to the most recently available application identifier is obtained. When the status flag is not marked as invalid, the application corresponding to the most recently available application identifier is selected as the target application. When the most recently available application identifier does not exist or has been marked as invalid, obtain a list of all enabled application identifiers from the pre-configured application pool, randomly arrange the identifier list, traverse each application identifier in the arrangement order, and select the application corresponding to the first application identifier that has not been marked as invalid as the target application. Obtain the access credentials corresponding to the target application; The access credentials are used to call the remote link generation interface, and the error code field returned by the remote link generation interface is parsed. When the error code field is the first error code, the access credentials of the target application are forcibly refreshed and the retry count counter is decremented. If the decremented retry count counter is greater than zero, the remote connection generation interface is called again with the refreshed access credentials and the error code field is parsed again. When the error code field is the second error code, the status flag of the target application is set to the invalid state in the cache memory, and a first valid duration is set for the invalid state flag. Then, the application that is not marked as invalid is switched as the new target application, the access credentials are re-acquired, and the remote link generation interface is called. When the error code field is a success code, the identifier of the target application is recorded in the cache memory as the most recently available application identifier, a second validity period is set for the most recently available application identifier, and the link generated by the remote link generation interface is returned.
[0010] Each application's status is defined in three states: Available – The application is within the normal scheduling range and can be selected as a target; Expired Credential Retry – Triggered by receiving the first error code (credential expiration error code), in which the system performs a credential refresh operation within the same application and then retryes without switching applications; Blocked Unavailable – Triggered by receiving the second error code (permission blocking error code), in which the application is removed from the scheduling candidate for a duration equal to the first valid duration (86400 seconds). The transition between states is performed through atomic write operations in the cache memory: when writing the status value, the corresponding expiration time stamp is written simultaneously to ensure consistency between the status and the timestamp in a single concurrent operation, avoiding race conditions caused by multiple concurrent requests modifying the status of the same application.
[0011] Furthermore, fault tolerance triggering conditions also include: server-side internal errors with HTTP response status codes of the 5xx series returned by the remote connection generation interface, connection timeouts, and connection rejection events. When these events occur, the current application is marked as temporarily unavailable and switched to the next application in the application pool.
[0012] Furthermore, the system also provides transaction integrity guarantees for URL parameters. During the URL parameter assembly process for generating a link, application switching operations within the application pool do not compromise the integrity of the URL parameters being generated. Specifically, when an application switch occurs during a link generation request, the URL parameters corresponding to the new application are reassembled using the new application's identifier and credentials. Incomplete URL parameters from the old application are discarded, ensuring that the application parameters carried in the final generated link are completely consistent with the actual application that issued the link. This prevents data inconsistencies such as "application A's credentials generated a link carrying application B's identifier."
[0013] Furthermore, the link generation request is used to generate short links in the form of QR codes or mini-program jump links. These links have a limited validity period, and real-time performance and accuracy are required to ensure that the links are accessible before the expiration date. Unlike ordinary text content caching, link generation is an operation with extremely high real-time requirements—each link generation request must obtain a QR code or short link that users can preview and share within tens of milliseconds to several seconds. Generation failure or delay directly affects the continuity of user sharing behavior and conversion rate.
[0014] Compared with the prior art, the beneficial effects of the present invention are as follows.
[0015] First, by maintaining an application pool containing multiple applications and classifying the different error codes returned—when a credential expires, refresh the credential within the same application and retry; when permissions are blocked, mark the credential as invalid and switch to the next application—precise differentiation and automatic fault tolerance for two different types of faults are achieved.
[0016] Second, the consistency and integrity of state transitions are ensured through a three-state transition diagram (available state, expired credential retry state, and blocked unavailable state) and atomic write operations. The state transition rules are clear: each state is uniquely determined by a triggering event, and a transition can only occur once at any given time, avoiding state chaos caused by concurrent requests.
[0017] Third, by randomly arranging the list of identifiers in the application pool and then sequentially traversing and selecting them, the probability of each application being ranked first in each connection generation request is equal, and the first call request is evenly distributed to all enabled applications in the application pool.
[0018] Fourth, by using the second effective duration (5 seconds) of the most recently available application identifier, local affinity scheduling is formed during peak periods of concurrent request arrival, reducing the credential acquisition overhead caused by frequent application switching.
[0019] Fifth, by ensuring the transaction integrity of URL parameters, the consistency between URL parameters and the issuing application is ensured during the application switching process, avoiding parameter conflicts and data inconsistencies caused by the switching. Attached Figure Description
[0020] Figure 1 This is a flowchart of the multi-application pool URL Link fault-tolerant generation method in this embodiment of the invention.
[0021] Figure 2 This is a schematic diagram of the error code classification processing and fault tolerance switching process in an embodiment of the present invention.
[0022] The meanings of the markings in the diagram are as follows: Figure 1In the process, 100-receive link generation request, 101-read the identifier of the most recently available application, 102-get the access credentials of the selected application, 103-call the remote link generation interface, 104-parse the error code, 108-randomly select from the pool of enabled applications, 109-check validity, 110-refresh the access credentials and decrement the number of retries, 111-mark the current application as invalid, 112-record the current application as the most recently available, 113-return the generated link; Figure 2 In the process, 200 - Request arrived, 201 - Select mini-program, 202 - Call the generation interface, 203 - Error code, 204 - Successful return, 205 - Refresh credentials and decrease retry count, 206 - Mark blocked status, 207 - Call the generation interface again, 208 - Switch to the next available application. Detailed Implementation
[0023] The present invention will now be described in further detail with reference to the accompanying drawings.
[0024] In this embodiment, the business platform is the "Add Micro Tool" WeChat mini-program service system. The core function of this system is: enterprise users create personalized WeChat business card pages (including title, description text, enterprise WeChat QR code, and custom background image). The system generates a short URL link (in QR code form) for this business card page. Users share this short link through social channels such as WeChat. Recipients can directly jump to the corresponding business card page in the mini-program after clicking the short link. This short link has a 30-day validity period and must be accessible within that period. Therefore, the real-time requirement for link generation is extremely high—every second of response delay may cause users to abandon sharing, and every generation failure means a break in the sharing link.
[0025] The system's backend server maintains a "mini-program pool" containing multiple WeChat mini-programs. In this embodiment, the application pool contains 5 enabled mini-programs. The server is configured with a cache storage to store the access credentials, status flags, and recently available application identifiers for each mini-program.
[0026] The key-value pair design in the cache is as follows: (1) Access credential key: The key name is "system prefix:access_token:application identifier", and the third validity period is set to 3600 seconds.
[0027] (2) Status flag key: The key name is "system prefix:status:application identifier". The status value can be "active" (available), "retrying" (credential expired and retrying) or "forbidden" (banned and unavailable). It is written with atomic write instructions in the cache memory to ensure that the update of the status value and the setting of the timestamp are completed in a single operation.
[0028] (3) Recently available application identifier key: use "system prefix:last_available" as the key name, and set the second validity period to 5 seconds.
[0029] The following combination Figure 1 Describe the complete process of a link generation request.
[0030] like Figure 1 As shown in the diagram marked 100, a user of a company fills in business card information on the front-end interface. After submission, the front-end sends a request to the back-end server to generate a link, and the server receives the request.
[0031] like Figure 1 As shown in label 101, the server reads the value of the recently available application identifier key from the cache. Assume there has been a successful link generation operation, and the key's value is "wx3e33f098f2ca8dc5" and is still valid for 5 seconds. The server then queries the application's status flag key, returning "active" (available).
[0032] like Figure 1 As shown in marker 109, the system determines whether the most recently available application exists and is not marked as invalid. If yes, the application is directly selected as the target application, and the process proceeds to marker 102; if no (the most recently available application identifier does not exist or has been marked as invalid), the process proceeds to marker 108, retrieves a list of all enabled application identifiers from the pre-configured application pool, randomly arranges the identifier list, iterates through each application identifier in the sorted order, selects the first application that is not marked as invalid as the target application, and then proceeds to marker 102.
[0033] like Figure 1 As shown in mark 102, after selecting the target application, the system obtains the access credential corresponding to that application. If no valid access credential exists in the cache, the system constructs request parameters and sends a request to the WeChat credential issuance interface to obtain a new access credential and write it to the cache.
[0034] like Figure 1As shown in mark 103, the system uses the access credentials obtained as URL parameters, carrying information such as the business card page path and query parameters, and sends a call request to the WeChat URL Link generation interface. This interface returns response data in JSON format, which includes the key field "errcode".
[0035] like Figure 1 As shown in mark 104, the system parses the error code field in the returned result and enters different processing branches according to the type of error code.
[0036] (a) Success branch (errcode=0): e.g. Figure 1 As shown in marker 112, the system records the identifier of the current target application in the cache as the most recently available application identifier and sets a second valid duration (5 seconds). Then as... Figure 1 As shown in marker 113, the generated link is returned.
[0037] (ii) Expired voucher branch (first error code): such as Figure 1 As shown in marker 110, the system forcibly refreshes the access credentials of the target application and decrements the retry count counter. If the decremented counter is still greater than zero, the system returns to marker 103 to call the generation interface with the refreshed credentials. If the retry count is exhausted and the system still fails, the application is marked as temporarily unavailable, and the system proceeds to marker 108 for application switching.
[0038] (iii) Branch blocking with access privileges (second error code): e.g. Figure 1 As shown in marker 111, the system sets the current target application's status to invalid in the cache and sets a first valid duration (86400 seconds). Then, it proceeds to marker 108, switches to the next application that is not marked as invalid, and re-executes marker 102 and subsequent steps.
[0039] like Figure 2 As shown, the state transition logic in the above process can be further described as follows.
[0040] like Figure 2 As indicated by mark 200, the request enters the state machine upon arrival. (See also...) Figure 2 As indicated by marker 201, the system enters the mini-program selection state, choosing an available application from the application pool. For example... Figure 2 As shown in mark 202, after selection, the system enters the state of calling the generation interface and sends a request to the remote link generation interface.
[0041] like Figure 2As shown in mark 203, the system judges based on the returned error code: if the return is successful (errcode=0), it enters the successful return state of mark 204 and the process ends; if the return is a voucher expiration error (first error code), it enters the voucher refresh and retry count decrement state of mark 205. After the refresh is completed, it enters mark 207 to call the generation interface again and returns to mark 202; if the return is a permission ban error (second error code), it enters the marked ban state of mark 206, marks the application as invalid, and then enters mark 208 to switch to the next available application and returns to mark 201 to select again.
[0042] Furthermore, when the remote connection generation interface returns an HTTP 5xx series server-side internal error, connection timeout, or connection refused event, the system also performs an application switching operation and enters flag 208. These fault tolerance triggering conditions indicate that the current application's server is in an abnormal state and is not suitable for continued use.
[0043] During application switching, the transaction integrity protection module ensures the integrity of URL parameters: when a link generation request switches from one application to another, the URL parameters corresponding to the new application are reassembled using the new application's identifier and credentials, and any incomplete parameters being constructed by the old application are discarded. Through this design, the final generated link always carries the correct parameters of the actual issuing application.
[0044] Each application's status flag is maintained in a cache memory. Status transitions between available, expired and retry, and blocked / unavailable states according to preset rules. The transition between states ensures uniqueness and consistency through atomic write operations in the cache memory. After a transition, a new status value and the corresponding expiration timestamp are written to the status flag. The write operation uses atomic instructions from the cache memory to complete the writing of the status value and expiration timestamp in a single network round trip, avoiding race conditions caused by multiple concurrent requests modifying the same application's status simultaneously.
[0045] It should be noted that the specific error code values (such as 40001, 40013) and cache key-value formats in the above embodiments are merely illustrative examples using the WeChat Mini Program platform and Redis cache as examples. Those skilled in the art will understand that the corresponding error code values and key-value formats may differ in other third-party platforms and caching systems. However, the core mechanism of differentiated fault tolerance processing based on error code classification and ensuring state transition consistency through atomic write operations in this invention is not limited by specific platforms and storage systems.
[0046] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A link fault-tolerant generation method for multi-application pools, characterized in that, include: In response to a link generation request, the most recently available application identifier is read from the cache storage, and the status flag corresponding to the most recently available application identifier is obtained. When the status flag is not marked as invalid, the application corresponding to the most recently available application identifier is selected as the target application. When the most recently available application identifier does not exist or has been marked as invalid, obtain a list of all enabled application identifiers from the pre-configured application pool, randomly arrange the identifier list, traverse each application identifier in the arrangement order, and select the application corresponding to the first application identifier that has not been marked as invalid as the target application. Obtain the access credentials corresponding to the target application; The access credentials are used to call the remote link generation interface, and the error code field returned by the remote link generation interface is parsed. When the error code field is the first error code, the access credentials of the target application are forcibly refreshed and the retry count counter is decremented. If the decremented retry count counter is greater than zero, the remote connection generation interface is called again with the refreshed access credentials and the error code field is parsed again. When the error code field is the second error code, the status flag of the target application is set to the invalid state in the cache memory, and a first valid duration is set for the invalid state flag. Then, the application that is not marked as invalid is switched as the new target application, the access credentials are re-acquired, and the remote link generation interface is called. When the error code field is a success code, the identifier of the target application is recorded in the cache memory as the most recently available application identifier, a second valid duration is set for the most recently available application identifier, and the link generated by the remote link generation interface is returned. The method is executed by the server-side processor.
2. The method according to claim 1, characterized in that, The status flags of each application are maintained in the cache memory, and the status transitions between at least three states according to preset rules: available state, credential expired retry state, and blocked unavailable state. The available state triggers the application to enter the normal scheduling range that can be selected as a target. The credential expired retry state is triggered by receiving the first error code. In this state, only the credential refresh retry operation is performed for the same application, without switching applications. The blocked unavailable state is triggered by receiving the second error code. In this state, the application is removed from the scheduling candidate for a specified first valid duration. The transition between states is ensured to be unique and consistent through atomic write operations of the cache memory. After the transition, a new status value and the corresponding expiration time stamp are written to the status flag.
3. The method according to claim 2, characterized in that, The first error code corresponds to an expired access credential error returned by the remote link generation interface, and the second error code corresponds to an interface call permission restriction error returned by the remote link generation interface; the first error code triggers the credential expired retry state, and the second error code triggers the blocked unavailability state.
4. The method according to claim 2, characterized in that, The fault tolerance triggering conditions also include: the HTTP response status code returned by the remote connection generation interface is a 5xx series server internal error, connection timeout, or connection rejection event; when any of the fault tolerance triggering conditions occurs, the current application is marked as temporarily unavailable and switched to the next application in the application pool; wherein, the temporary unavailable state is different from the blocked unavailable state, and only applies to the processing cycle of the current single call request, without setting a continuous valid duration mark for the application, and the application will still be restored to the available state and participate in the scheduling selection in the next connection generation request after the end of the request.
5. The method according to claim 2, characterized in that, The first valid duration is 86,400 seconds, the second valid duration is 5 seconds, and the access credentials in the cache memory are set with a third valid duration of 3,600 seconds.
6. A link fault-tolerant generation system for multi-application pools, characterized in that, include: The application selection module is used to respond to the link generation request, read the most recently available application identifier from the cache storage, obtain the status flag corresponding to the most recently available application identifier, and select the application first when the status flag is not marked as invalid. Otherwise, it obtains a list of all enabled application identifiers from the pre-configured application pool, randomly arranges the identifier list, and iterates through it to select the first application that is not marked as invalid as the target application. The credential acquisition module is used to acquire the access credentials corresponding to the target application; The interface call module is used to call the remote link generation interface with the access credentials and parse the error code field returned by the remote link generation interface. The fault tolerance module is used to force refresh the access credentials of the target application and retry with a reduced number of retries when the error code field is the first error code; to mark the target application as invalid and switch to the next available application when the error code field is the second error code; and to record the target application as the most recently available and return the generated link when the error code field is the success code. The state management module is used to maintain the state flags of each application in the cache memory, so that the state can be transferred between the available state, the credential expired retry state, and the blocked unavailable state according to preset rules. The migration between the states is guaranteed to be unique and consistent through the atomic write operation of the cache memory. The transaction integrity guarantee module is used to ensure that application switching operations within the application pool do not corrupt the integrity of the URL parameters being generated during the URL parameter assembly process of generating links. When an application switch occurs, the URL parameters corresponding to the new application are reassembled using the identifier and credentials of the new application, and the incomplete URL parameters of the old application are discarded.
7. The system according to claim 6, characterized in that, The fault tolerance processing module is also used to: mark the current application as temporarily unavailable and switch to the next application in the application pool when the HTTP response status code returned by the remote connection generation interface is a 5xx series server internal error, connection timeout, or connection rejection event; this temporary unavailable status only applies to the processing cycle of the current single call request and does not set a continuous effective duration flag.
8. The system according to claim 6, characterized in that, The state transition operation in the state management module includes: atomically reading the current state value and a predefined timestamp, comparing the timestamp to determine whether it has exceeded the first valid duration, and performing the transition from the blocked unavailable state to the available state only when the timestamp has not expired.
9. A terminal device, characterized in that, It includes a memory and one or more processors, wherein the memory stores a computer program, and the one or more processors execute the computer program to implement the method as described in any one of claims 1 to 5.
10. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by one or more processors, implements the method as described in any one of claims 1 to 5.