API-based service processing method, device, and computer-readable storage medium
By encrypting the service request of the client calling the API interface, obtaining the request identifier and obtaining the service lock, the problem of poor performance and insufficient performance of the API interface in the prior art is solved, and the implementation of high concurrency scenarios Interface idempotence and data consistency.
Patent Information
- Application Number
- CN202110055221.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-01-15
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2041-01-15
AI Technical Summary
When the existing technology realizes the idempotence of API interfaces, the performance requirements of the method one pair of callers are high and the effect is poor, and it cannot prevent repeated operations of simulated requests; the performance of the method two is not high, and it cannot cope with high concurrent business scenarios, and optimistic locking is required. Version field in the database table.
By obtaining the service request uploaded by the client calling the API interface, encrypting the process to obtain the request identification, and obtain the service lock according to the request identification, thereby realizing business processing to ensure that the distributed system API interface does not repeatedly obtain the same data.
It realizes simple and fast interface idempotence, and can cope with high concurrency business scenarios, ensuring that the API interface does not repeatedly obtain the same data.
Smart Images

Figure CN112835916B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a business processing method, device and computer-readable storage medium based on an API interface. Background Art
[0002] With the development of Internet technology, more and more distributed systems provide API interfaces for internal and external system calls. After executing multiple operations, the results of a user's request or multiple requests for the same operation are consistent, and there will be no side effects due to multiple clicks. For example, if the front-end repeatedly submits the selected data, the back-end should only generate one response result corresponding to this data; for a payment request, the user's money is only deducted once, and when there is a network retransmission or system bug retransmission, the money should only be deducted once; when creating a business order, only one business request can be created. Such business logic needs to be supported based on the idempotence of the API interface. Currently, the following two methods are used to achieve interface idempotence:
[0003] The first method is to intercept the interface that the calling end interacts with the Web end through the front-end, for example, to prevent repeated form submissions, gray out, hide, or make buttons unclickable; or before calling the API, mark the request as being processed, and set the mark to complete after receiving the API response, thereby achieving interface idempotence; the second method is to use the pessimistic lock or optimistic lock of the database, and lock the API interface when operating the database to ensure that it is only executed once.
[0004] However, method 1 has high performance requirements on the calling end itself, and the actual execution effect is not good, and it cannot prevent the problem of repeated operations when simulating requests for calls; method 2's pessimistic locking mechanism has low performance and cannot cope with high-concurrency business scenarios; the optimistic locking mechanism has higher performance than the pessimistic locking, but it requires a version field in the database table. Summary of the invention
[0005] The present application aims to solve at least one of the technical problems existing in the prior art. To this end, the present application proposes a business processing method based on an API interface, which can simply and quickly realize the idempotence of the interface, and can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0006] This application also proposes another business processing method based on API interface.
[0007] The present application also proposes a server having the above-mentioned service processing method based on the API interface.
[0008] The present application also proposes a client having the above-mentioned service processing method based on the API interface.
[0009] The present application also proposes an electronic device having the above-mentioned service processing method based on the API interface.
[0010] The present application also proposes a computer-readable storage medium having the above-mentioned API interface-based business processing method.
[0011] According to the first aspect of the present application, the API interface-based service processing method includes: obtaining a service request uploaded by a client calling an API interface, wherein the service request includes request parameters;
[0012] Encrypting the request parameters to obtain a request identifier;
[0013] Acquire a service lock according to the request identifier;
[0014] According to the service lock, a corresponding target service is obtained from the service request to perform service processing.
[0015] The business processing method based on the API interface according to the embodiment of the present application has at least the following beneficial effects: by obtaining the business request including request parameters uploaded by the client calling the API interface, the request parameters are encrypted to obtain a request identifier, a business lock is obtained according to the request identifier, and the corresponding target business is obtained from the business request according to the business lock to perform business processing, the interface idempotence can be realized simply and quickly, and it can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0016] According to some embodiments of the present application, acquiring the service lock according to the request identifier includes:
[0017] Acquire pre-stored request information according to the request identifier;
[0018] The request information is called through a preset operation instruction to generate the service lock.
[0019] According to some embodiments of the present application, the request information includes time validity information, and the time validity information is used to identify the validity period of the service lock.
[0020] According to some embodiments of the present application, it further includes:
[0021] If the service lock cannot be obtained according to the request identifier, the target service is not obtained from the service request for service processing and the service request is returned to the client.
[0022] According to some embodiments of the present application, the selecting and obtaining a corresponding target service request from the service request according to the service lock for service processing further includes:
[0023] Obtaining the processing result of the target business after business processing;
[0024] The service lock is released, and the processing result is returned to the client.
[0025] According to the second aspect of the present application, the API interface-based service processing method includes: generating a service request, wherein the service request includes request parameters;
[0026] The service request is sent to the server by calling the API interface of the server, and the server configures a service lock for the service request and obtains the corresponding target service for service processing.
[0027] The business processing method based on the API interface according to the embodiment of the present application has at least the following beneficial effects: by generating a business request including request parameters, calling the server's API interface to send the business request to the server, and the server configuring a business lock for the business request and then obtaining the corresponding target business for business processing, the interface idempotence can be realized simply and quickly, and it can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0028] According to the server of the third aspect of the present application, the server includes: a first acquisition module, the first acquisition module is used to acquire a service request uploaded by a client calling an API interface, the service request including request parameters;
[0029] A processing module, the processing module is used to encrypt the request parameters to obtain a request identifier;
[0030] A second acquisition module, the second acquisition module is used to acquire the service lock according to the request identifier;
[0031] A business module is used to obtain a corresponding target business from the business request according to the business lock to perform business processing.
[0032] According to the business processing method based on the API interface of the embodiment of the present application, there are at least the following beneficial effects: the business request including the request parameters uploaded by the client calling the API interface is obtained by the first acquisition module, the processing module encrypts the request parameters to obtain the request identifier, the second acquisition module obtains the business lock according to the request identifier, and the business module obtains the corresponding target business from the business request according to the business lock to perform business processing, which can simply and quickly realize the idempotence of the interface, and can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0033] According to a fourth aspect of the present application, a client includes: a generation module, the generation module is used to generate a service request, the service request includes a request parameter;
[0034] The calling module is used to call the API interface of the server to send the service request to the server, and the server configures a service lock for the service request and obtains the corresponding target service for service processing.
[0035] According to the client of the embodiment of the present application, there are at least the following beneficial effects: a business request including request parameters is generated by a generation module, and a calling module calls the API interface of the server to send the business request to the server, and the server configures a business lock for the business request and obtains the corresponding target business for business processing. The interface idempotence can be realized simply and quickly, and it can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0036] According to an electronic device of an embodiment of the fifth aspect of the present application, the device includes: at least one processor, and a memory communicatively connected to the at least one processor; wherein the memory stores instructions, and the instructions are executed by the at least one processor so that when the at least one processor executes the instructions, the API interface-based business processing method as described in the first and second aspects is implemented.
[0037] The electronic device according to the present application has at least the following beneficial effects: by executing the business processing method based on the API interface mentioned in the first aspect and the second aspect embodiments, the interface idempotence can be simply and quickly realized, and high-concurrency business scenarios can be coped with, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0038] According to the computer-readable storage medium of the sixth aspect embodiment of the present application, the computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the business processing method based on the API interface as described in the first and second aspects.
[0039] The computer-readable storage medium according to the present application has at least the following beneficial effects: by executing the business processing method based on the API interface mentioned in the embodiments of the first aspect and the second aspect, the interface idempotence can be simply and quickly implemented, and high-concurrency business scenarios can be coped with, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0040] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 A specific flow chart of the business processing method in the embodiment of the present application;
[0042] Figure 2 A specific flow chart of step S130 of the business processing method in the embodiment of the present application;
[0043] Figure 3 This is another specific flow chart of the business processing method in the embodiment of the present application;
[0044] Figure 4 This is another specific flow chart of the business processing method in the embodiment of the present application;
[0045] Figure 5 A diagram showing a specific application example of the business processing method in an embodiment of the present application;
[0046] Figure 6 A schematic diagram of a specific module of a server in an embodiment of the present application;
[0047] Figure 7 This is a schematic diagram of a specific module of the client in the embodiment of the present application.
[0048] Reference numerals:
[0049] A first acquisition module 110 , a processing module 120 , a second acquisition module 130 , a business module 140 ; a generation module 210 , and a calling module 220 . DETAILED DESCRIPTION
[0050] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limiting the present application.
[0051] It should be noted that the logical order is shown in the flow chart, but in some cases, the steps shown or described can be performed in the order in different flow charts. If it is related to "several", it means more than one, if it is related to "multiple", it means more than two, if it is related to "below", it should be understood to include this number. The use of any and all examples or exemplary language ("for example", "such as", etc.) provided herein is only intended to better illustrate the embodiments of the present application, and unless otherwise required, it will not impose restrictions on the scope of the present application. Greater than, less than, exceed, etc. are understood to exclude this number, and above, below, within, etc. are understood to include this number. If there is a description of the first and second, it is only for the purpose of distinguishing technical features, and it cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated or implicitly indicating the order of technical features indicated.
[0052] It should be noted that, unless otherwise specified, the singular forms of "a", "said" and "the" used in the embodiments are also intended to include plural forms, unless the context clearly indicates other meanings. In addition, unless otherwise defined, all technical and scientific terms used herein have the same meanings as those generally understood by those skilled in the art. The terms used in this specification are only for describing specific embodiments, not for limiting this application. The term "and / or" used herein includes any combination of one or more related listed items.
[0053] With the development of Internet technology, more and more distributed systems provide API interfaces for internal and external system calls. After executing multiple operations, the results of a user's request or multiple requests for the same operation are consistent, and there will be no side effects due to multiple clicks. For example, if the front-end repeatedly submits the selected data, the back-end should only generate one response result corresponding to this data; for a payment request, the user's money is only deducted once, and when there is a network retransmission or system bug retransmission, the money should only be deducted once; when creating a business order, only one business request can be created. Such business logic needs to be supported based on the idempotence of the API interface. Currently, the following two methods are used to achieve interface idempotence:
[0054] The first method is to intercept the interface that the calling end interacts with the Web end through the front-end, for example, to prevent repeated form submissions, gray out, hide, or make buttons unclickable; or before calling the API, mark the request as being processed, and set the mark to complete after receiving the API response, thereby achieving interface idempotence; the second method is to use the pessimistic lock or optimistic lock of the database, and lock the API interface when operating the database to ensure that it is only executed once.
[0055] However, method 1 has high performance requirements on the calling end itself, and the actual execution effect is not good, and it cannot prevent the problem of repeated operations when simulating requests for calls; method 2's pessimistic locking mechanism has low performance and cannot cope with high-concurrency business scenarios; the optimistic locking mechanism has higher performance than the pessimistic locking, but it requires a version field in the database table.
[0056] Based on this, the embodiments of the present application provide a business processing method, device and computer-readable storage medium based on an API interface, which can simply and quickly implement interface idempotence, and can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0057] It should be noted that the server and client mentioned in the embodiment of the present application are connected through an API interface call, and the client can upload relevant business requests by calling the server's API (Application Programming Interface) interface so that the server can perform corresponding business processing according to the business request. In addition, the client can upload multiple different business requests at the same time, and the server performs corresponding business processing on them based on the distributed system.
[0058] In a first aspect, an embodiment of the present application provides a service processing method based on an API interface and applied to a server.
[0059] In some embodiments, reference Figure 1 , shows a flow chart of a business processing method based on an API interface in an embodiment of the present application. It specifically includes the following steps:
[0060] S110, obtaining a service request uploaded by the client by calling an API interface;
[0061] S120, encrypting the request parameters to obtain a request identifier;
[0062] S130, obtaining a service lock according to the request identifier;
[0063] S140, obtaining a corresponding target service from the service request according to the service lock and performing service processing.
[0064] In step S110, the API interface of the server is called by the client. When the client needs to perform related business processing, the target business to be processed is encapsulated into a business request, and the business request is uploaded to the server through the API interface of the server. The server will obtain the uploaded business request, wherein the business request includes request parameters. The request parameters are different according to different target businesses to be processed. The request parameters are used to identify the specific object and identifier of the target business to be processed by the client. The target business to be requested by the client and the business lock to be configured can be determined through the request parameters. In the application example that may be implemented, the request parameters include a 32-bit UUID (Universally Unique Identifier) generated by the client and other business parameters. UUID is used to ensure the uniqueness of the client's business request. In actual applications, in order to ensure the uniqueness of UUID, the specification defines elements including network card MAC address, timestamp, namespace, random or pseudo-random number, timing, and the algorithm for generating UUID from these elements. UUID can be generated by a variety of algorithms, such as snowflake algorithm, SHA1 (Secure Hash Algorithm 1) algorithm, etc.
[0065] In step S120, after the server obtains the request parameters in the business request, it encrypts the request parameters to obtain the request identifier. Specifically, the server generates a unique lock ID of the business lock, i.e., the request identifier, after encrypting the UUID and other business parameters in the request parameters. In actual applications, the unique identifier LockKey of the business request uploaded by the client is generated after encrypting the UUID and other business parameters using the MD5 algorithm. The LockKey includes the ID of the business lock that needs to be configured for the business request, i.e., LockKeyID, and the parameter value LockKeyValue of the business lock, which is used to obtain the business lock later.
[0066] In step S130, the server obtains the service lock according to the generated request identifier. Specifically, the service lock corresponding to the service requested by the client is unique, and the server needs to obtain the service lock by calling the database Redis (Remote Dictionary Server). Redis is a key-value database based on the BSD (Berkeley Software Distribution) protocol. The server can obtain the corresponding service lock from Redis through the request identifier.
[0067] In some embodiments, Figure 2 As shown, step S130 specifically further includes the steps of:
[0068] S131, obtaining pre-stored request information according to the request identifier;
[0069] S132, calling the request information through a preset operation instruction to generate a business lock.
[0070] In step S131, the server obtains the pre-stored request information according to the request identifier, that is, extracts the corresponding request information from the request identifier, such as the lock ID of the business lock, the value of the business lock, etc., wherein the lock ID and the business lock value are used by the server to obtain the corresponding business lock from Redis. By adopting Redis, the acquisition of business locks can be realized, and thus applied to distributed systems to cope with high-concurrency business scenarios.
[0071] In some embodiments, the request information includes time information, which is used to identify the effective time of the business lock. Specifically, the request information includes the lock ID of the business lock, namely LockKeyID, the lock value of the business lock, namely LockKeyValue, the timestamp EX of the business lock, the expiration time Time of the business lock, and whether the business lock exists NX. The timestamp EX and the expiration time Time can be used to identify the effective time and specific expiration time of the business lock. By setting the expiration time for the business lock, the problem of the business lock being unable to be released due to an abnormality in the client can be prevented.
[0072] In step S132, the server obtains the corresponding business lock from Redis through a preset operation instruction. Specifically, the server calls the Set operation in Redis to obtain the business lock through the request information corresponding to the request identifier. For example, the operation instruction is Set(LockKeyID, LockKeyValue, EX, Time, NX), thereby obtaining the corresponding business lock.
[0073] In some embodiments, if the server cannot obtain the business lock from Redis according to the request identifier, it means that the Set operation executed by the server has failed and the business lock cannot be obtained, that is, the business request is a repeated request, and therefore the corresponding target business cannot be obtained according to the repeated business request for business processing. The server will return the business request to the client to inform the client that the business request has failed.
[0074] In step S140, after the server obtains the business lock, it will configure the business lock on the business request, determine the corresponding target business according to the business request, and perform business processing on the target business, wherein the target business refers to the business content actually requested by the client. After receiving the business request configured with the business lock, the server determines that the business request is a business request initiated for the first time and not a repeated business request. Therefore, it can determine the business content requested by the client according to the business request, perform business processing on the business content, and thus complete the business processing.
[0075] In some embodiments, reference Figure 3 The API interface-based business processing method mentioned in the embodiment of the present application specifically includes:
[0076] Step S150, obtain the processing result of the target business after business processing, release the business lock, and return the processing result to the client.
[0077] In step S150, the server performs business processing according to the acquired target business, obtains the processing result after the business processing, releases the business lock configured on the business request, and returns the processing result obtained after processing to the client for acquisition. It should be noted that releasing the business lock means removing the business lock configured on the business request, so that the business request no longer carries the business lock, so that the subsequent client can obtain the business lock again after making a corresponding business request; the client can display and feedback the business result after receiving the business processing.
[0078] In an embodiment of the present application, by obtaining a business request including request parameters uploaded by a client calling an API interface, encrypting the request parameters to obtain a request identifier, obtaining a business lock based on the request identifier, and obtaining the corresponding target business from the business request based on the business lock to perform business processing, the interface idempotence can be simply and quickly implemented, and it can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0079] In a second aspect, an embodiment of the present application provides a business processing method based on an API interface applied to a client.
[0080] In some embodiments, reference Figure 4 , shows a flow chart of a business processing method based on an API interface in an embodiment of the present application. It specifically includes the following steps:
[0081] S210, generating a service request, where the service request includes request parameters;
[0082] S220, calling the API interface of the server to send the service request to the server, and after the server configures a service lock for the service request, it obtains the corresponding target service for service processing.
[0083] In step S210, the client encapsulates the target service requested as needed into a service request, wherein the encapsulated service request includes the request parameters of the target service. The request parameters are different according to the different target services to be processed, wherein the request parameters are used to identify the specific object and identifier of the target service to be processed by the client. The target service to be requested by the client and the service lock to be configured can be determined through the request parameters; in the application instance that may be implemented, the request parameters include a 32-bit UUID generated by the client and other service parameters. UUID is used to ensure the uniqueness of the client's service request. In order to ensure the uniqueness of UUID in actual applications, the specification defines elements including network card MAC address, timestamp, name space, random or pseudo-random number, timing, and the algorithm for generating UUID from these elements; UUID can be generated by a variety of algorithms, such as snowflake algorithm, SHA1 algorithm, etc.
[0084] In step S220, the client will call the API interface of the server, which is used by the client to upload the business request to the server. Specifically, the client establishes a communication connection with the server by calling the API interface of the server, and sends the encapsulated business request to the server. After receiving the business request, the server executes the business processing method mentioned in the first aspect embodiment.
[0085] Specifically, after receiving the business request, the server obtains the request parameters in the business request, encrypts the request parameters, and obtains the request identifier. The server generates a unique lock ID for the business lock, i.e., the request identifier, after encrypting the UUID and other business parameters in the request parameters. In actual applications, the UUID and other business parameters are encrypted using the MD5 algorithm to generate the unique identifier LockKey of the business request uploaded by the client. The LockKey includes the ID of the business lock that needs to be configured for the business request, i.e., LockKeyID, and the parameter value LockKeyValue of the business lock, which is used to obtain the business lock later.
[0086] When the server obtains the business lock, it will configure the business lock on the business request, determine the corresponding target business according to the business request, and perform business processing on the target business, where the target business refers to the business content actually requested by the client. When the server receives the business request configured with the business lock, it determines that the business request is the first business request initiated, not a repeated business request. Therefore, it can determine the business content requested by the client according to the business request, perform business processing on the business content, and thus complete the business processing.
[0087] The server performs business processing according to the acquired target business, obtains the processing result after the business processing, releases the business lock configured on the business request, and returns the processing result obtained after processing to the client for acquisition. It should be noted that releasing the business lock means removing the business lock configured on the business request, so that the business request no longer carries the business lock, so that the subsequent client can obtain the business lock again after making the corresponding business request; the client can display and feedback the business result after receiving the business processing.
[0088] It should be noted that if the business request generated by the client is a repeated business request, the corresponding business lock cannot be obtained at the server, and the server cannot perform corresponding business processing based on the business request that is not configured with a business lock. The server will return the business request to the client, and the client determines that it has not been processed by receiving the returned business request. The server can also avoid receiving repeated requests from the client in this way.
[0089] In an embodiment of the present application, by generating a business request including request parameters, calling the server's API interface to send the business request to the server, and the server configuring a business lock for the business request to obtain the corresponding target business for business processing, the interface idempotence can be achieved simply and quickly, and it can cope with high-concurrency business scenarios, ensuring that the API interface of the distributed system does not repeatedly obtain the same data.
[0090] In the possible application examples, refer to Figure 5 After the client generates a business request according to the business package to be processed, the client will call the server's API interface and upload the business request to the server. After receiving the business request, the server encrypts the request parameters of the business request to obtain the request identifier LockKey, and calls the Redis Set operation to obtain the business lock according to the request identifier LockKey to determine whether the corresponding business lock is obtained. If the business request can obtain the corresponding business lock, it means that the business request is the first request, and the server can perform business processing according to the business request configured with the business lock, thereby obtaining the corresponding business processing result. The server releases the business lock configured for the business request and returns the processing result to the client, thereby completing the entire business processing flow; if the business request cannot obtain the corresponding business lock, it means that the business request is a repeated business request, and the server cannot perform business processing according to the business request that is not configured with a business lock, and returns the business request to the client.
[0091] In a third aspect, an embodiment of the present application provides a server for executing the API interface-based business processing method mentioned in the embodiment of the first aspect.
[0092] In some embodiments, reference Figure 6, shows a schematic diagram of the modules of the server in the embodiment of the present application. It specifically includes: a first acquisition module 110, a processing module 120, a second acquisition module 130, and a service module 140;
[0093] The first acquisition module 110 is used to acquire the business request uploaded by the client calling the API interface, and the business request includes request parameters;
[0094] The processing module 120 is used to encrypt the request parameters to obtain a request identifier;
[0095] The second acquisition module 130 is used to acquire the service lock according to the request identifier;
[0096] The service module 140 is used to select and obtain a corresponding target service request from the service request according to the service lock to perform service processing.
[0097] It should be noted that the specific functions and introductions of the above-mentioned modules have been described in detail in the API interface-based business processing method in the first aspect of the embodiment, so they will not be repeated here.
[0098] In an embodiment of the present application, a business request including request parameters uploaded by a client calling an API interface is acquired by a first acquisition module 110, a processing module 120 encrypts the request parameters to obtain a request identifier, a second acquisition module 130 acquires a business lock according to the request identifier, and a business module 140 acquires a corresponding target business from the business request according to the business lock to perform business processing, which can simply and quickly implement interface idempotence, cope with high-concurrency business scenarios, and ensure that the API interface of the distributed system does not repeatedly acquire the same data.
[0099] In a fourth aspect, an embodiment of the present application provides a client for executing the API interface-based business processing method mentioned in the embodiment of the first aspect.
[0100] In some embodiments, reference Figure 7 , shows a schematic diagram of the modules of the client in the embodiment of the present application. It specifically includes: a generation module 210 and a calling module 220;
[0101] The generating module 210 is used to generate a service request, and the service request includes request parameters;
[0102] The calling module 220 is used to call the API interface of the server to send the service request to the server, and the server configures a service lock for the service request and obtains the corresponding target service for service processing.
[0103] It should be noted that the specific functions and introductions of the above-mentioned modules have been described in detail in the form processing method in the first embodiment, so they will not be repeated here.
[0104] In an embodiment of the present application, a business request including request parameters is generated by generating module 210, and calling module 220 calls the API interface of the server to send the business request to the server. The server configures a business lock for the business request and obtains the corresponding target business for business processing. This can simply and quickly implement interface idempotence, cope with high-concurrency business scenarios, and ensure that the API interface of the distributed system does not repeatedly obtain the same data.
[0105] In a fifth aspect, an embodiment of the present application further provides an electronic device, comprising: at least one processor, and a memory communicatively connected to the at least one processor;
[0106] The processor is used to execute the business processing method in the embodiment of the first aspect or the second aspect by calling the computer program stored in the memory.
[0107] The memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer executable programs, such as the business processing method in the first or second embodiment of the present application. The processor implements the business processing method in the first or second embodiment by running the non-transitory software programs and instructions stored in the memory.
[0108] The memory may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store a business processing method for executing the first aspect or the second aspect of the embodiment. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0109] The non-transient software programs and instructions required to implement the business processing method in the first or second aspect embodiments are stored in a memory, and when executed by one or more processors, the business processing method in the first or second aspect embodiments is executed.
[0110] In a sixth aspect, an embodiment of the present application further provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to: execute the service processing method in the embodiment of the first aspect or the second aspect;
[0111] In some embodiments, the computer-readable storage medium stores computer-executable instructions, which are executed by one or more control processors, for example, by a processor in an electronic device of the fifth aspect embodiment, so that the one or more processors can execute the business processing method in the first or second aspect embodiment.
[0112] The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separated, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0113] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, CD-ROM, digital versatile disks (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage or other magnetic storage devices, or any other medium that may be used to store desired information and may be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media typically embodies computer readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0114] In the description of this specification, the description with reference to the terms "some embodiments", "examples", "specific examples", or "some examples" means that the specific features or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example.
Claims
1. A business processing method based on an API interface, characterized in that: include: Obtaining a service request uploaded by a client calling an API interface, wherein the service request includes request parameters; wherein the request parameters include: a universal unique identification code and service parameters; The request parameter is encrypted to obtain a request identifier; wherein the request identifier is obtained by performing MD5 encryption on the universal unique identification code and the service parameter; Acquire a service lock according to the request identifier; Obtaining a corresponding target service from the service request according to the service lock for service processing; Wherein, acquiring the service lock according to the request identifier includes: Acquire pre-stored request information according to the request identifier, the request information including timeliness information, lock identifier, lock value and lock existence mark, the timeliness information including a timestamp and an expiration time, and the timeliness information is used to identify the validity period of the service lock; The lock identifier, the lock value, the lock existence mark, the timestamp and the expiration time are called through a preset operation instruction to generate the business lock.
2. The service processing method according to claim 1, characterized in that: Also includes: If the service lock cannot be obtained according to the request identifier, the target service is not obtained from the service request for service processing and the service request is returned to the client.
3. The service processing method according to claim 1, characterized in that: The step of selecting and acquiring a corresponding target service request from the service request according to the service lock for service processing also includes: Obtaining the processing result of the target business after business processing; The service lock is released, and the processing result is returned to the client.
4. The business processing method based on the API interface is characterized by: include: Generate a service request, wherein the service request includes request parameters; The service request is sent to the server by calling the API interface of the server, and the server configures a service lock for the service request and obtains the corresponding target service for service processing.
5. A server, characterized in that include: A first acquisition module, the first acquisition module is used to acquire a business request uploaded by a client calling an API interface, the business request including request parameters; wherein the request parameters include: a universal unique identification code and business parameters; A processing module, the processing module is used to encrypt the request parameters to obtain a request identifier; wherein the request identifier is obtained by performing MD5 encryption processing on the universal unique identification code and the service parameters; A second acquisition module, the second acquisition module is used to acquire the business lock according to the request identifier, specifically including acquiring pre-stored request information according to the request identifier, the request information including timeliness information, lock identifier, lock value and lock existence mark, the timeliness information including timestamp and expiration time, and the timeliness information is used to identify the validity period of the business lock; The lock identifier, the lock value, the lock existence mark, the timestamp and the expiration time are called by a preset operation instruction to generate the service lock; A business module is used to obtain a corresponding target business from the business request according to the business lock to perform business processing.
6. The client is characterized in that include: A generating module, the generating module is used to generate a service request, the service request includes a request parameter; The calling module is used to call the API interface of the server to send the service request to the server, and the server configures a service lock for the service request and obtains the corresponding target service for service processing.
7. An electronic device, characterized in that include: at least one processor, and a memory communicatively connected to the at least one processor; wherein, The memory stores instructions, and the instructions are executed by the at least one processor, so that the at least one processor implements the API interface-based business processing method as described in any one of claims 1 to 4 when executing the instructions.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to enable a computer to execute the API interface-based business processing method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Business instruction processing method and device, computer equipment and storage medium
CN110351342A
Method and device for realizing interface idempotence
CN111865970A