SDK (Software Development Kit) interface calling method and device, storage medium and electronic equipment
By introducing abstract interfaces and interface mapping tables into SDK interface calls, and combining them with automated code generation tools, the problem of SDK interface incompatibility was solved, thereby simplifying the development process and improving system scalability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- MOMENTA (SUZHOU) TECHNOLOGY CO LTD
- Filing Date
- 2024-11-05
- Publication Date
- 2026-05-08
AI Technical Summary
Incompatibility between different SDKs and high integration difficulty lead to increased software development complexity and maintenance costs, and frequent updates to client interfaces are required when business requirements change.
This paper provides an SDK interface calling method that enables unified interface calls between the client and the SDK through abstract interfaces and interface mapping tables. It also utilizes automated code generation tools to automatically generate SDK code, reducing manual intervention.
It simplifies the SDK interface call process, improves the system's scalability and maintainability, reduces the learning cost and integration time for developers, and improves development efficiency.
Smart Images

Figure CN121996439A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a method, apparatus, storage medium, and electronic device for calling an SDK interface. Background Technology
[0002] In software development, SDKs (Software Development Kits), as collections providing specific functional modules or data processing capabilities, are widely used to reduce repetitive coding and improve development efficiency. However, due to the diversity of platforms or languages and the complexity of software business requirements, different SDKs may have issues such as interface incompatibility and high integration difficulty. These problems increase the complexity of software development and maintenance costs.
[0003] The traditional solution is to customize the client version of the SDK for each platform or language. However, this leads to code redundancy, and when business requirements change and the SDK interface changes (including changes to existing interfaces and the addition of new interfaces), the corresponding client interface needs to be updated, which increases the maintenance difficulty. Summary of the Invention
[0004] This application provides a method, apparatus, storage medium, and electronic device for calling an SDK interface, which can simplify the development process of the client corresponding to the SDK, improve development efficiency, and enhance the scalability and maintainability of the system.
[0005] The specific technical solution is as follows:
[0006] In a first aspect, embodiments of this application provide a method for calling an SDK interface, the method being applied to any software development kit (SDK), the method comprising:
[0007] Receive data requests sent by clients through an abstract interface, wherein the abstract interface is a general interface developed uniformly when developing for multiple clients, and the data request includes the target client identifier;
[0008] The target SDK interface is obtained by querying the interface mapping table based on the target client identifier. The interface mapping table includes the mapping relationship between different client identifiers and SDK interfaces, and the target SDK interface is the SDK interface corresponding to the target client identifier.
[0009] The data request is processed by calling the target SDK interface.
[0010] As can be seen from the above scheme, the embodiments of this application pre-configure an abstract interface for each type of client. When a client sends a data request to the SDK, it can directly send the data request through this abstract interface. The SDK can query the interface mapping table based on the target client identifier in the data request to obtain the actual SDK interface for invocation. Thus, while ensuring normal communication between the client and the SDK, the client will not be affected regardless of whether the original actual SDK interface changes or a new SDK interface is added. The client's interface will not change with the change of the actual SDK interface, simplifying the calling process of the client application to the SDK interface. The client does not need to care about the underlying implementation details, thereby reducing the learning cost and integration time for developers and improving the scalability and maintainability of the system.
[0011] In one possible implementation, the code generation method for the SDK includes:
[0012] Receive interface configuration file, wherein the interface configuration file includes the interface information of the SDK;
[0013] An automated code generation tool is used to process the interface information of the SDK and automatically generate SDK code corresponding to the interface information.
[0014] As can be seen from the above solution, the embodiments of this application automatically generate complete SDK code through interface configuration files and automated code generation tools. Technicians only need to fill in the required interface information and do not need to write complete SDK code. This not only reduces the error rate and workload of manual code writing and saves manpower, but also speeds up the progress of software development.
[0015] In one possible implementation, the interface information includes at least one of the following: request method, Uniform Resource Locator (URL), protocol, request header, and request body.
[0016] In one possible implementation, the method further includes, before receiving a data request sent by the client through an abstract interface:
[0017] During initialization, the SDK submits its interface information and client identifier to the registry center so that the registry center can write the mapping relationship between the SDK's interface information and the SDK's client identifier into the interface mapping table.
[0018] As can be seen from the above scheme, the SDK provided in this application embodiment can automatically register interface information with the registration center during initialization, so that the registration center can automatically generate an interface mapping table without manual intervention, thereby improving the generation efficiency of the interface mapping table.
[0019] In one possible implementation, the target SDK interface is obtained by querying the interface mapping table based on the target client identifier, including:
[0020] Send an interface query request carrying the target client identifier to the registration center;
[0021] Receive the target SDK interface corresponding to the target client identifier as found by the registration center in the interface mapping table.
[0022] Secondly, embodiments of this application provide an SDK interface invocation device, which is applied to any software development kit (SDK). The device includes:
[0023] The receiving unit is used to receive data requests sent by clients through an abstract interface, wherein the abstract interface is a general interface developed uniformly when developing for multiple clients, and the data request includes a target client identifier;
[0024] The query unit is used to query the interface mapping table according to the target client identifier to obtain the target SDK interface, wherein the interface mapping table includes the mapping relationship between different client identifiers and SDK interfaces, and the target SDK interface is the SDK interface corresponding to the target client identifier;
[0025] The calling unit is used to process the data request by calling the target SDK interface.
[0026] As can be seen from the above scheme, the embodiments of this application pre-configure an abstract interface for each type of client. When a client sends a data request to the SDK, it can directly send the data request through this abstract interface. The SDK can query the interface mapping table based on the target client identifier in the data request to obtain the actual SDK interface for invocation. Thus, while ensuring normal communication between the client and the SDK, the client will not be affected regardless of whether the original actual SDK interface changes or a new SDK interface is added. The client's interface will not change with the change of the actual SDK interface, simplifying the calling process of the client application to the SDK interface. The client does not need to care about the underlying implementation details, thereby reducing the learning cost and integration time for developers and improving the scalability and maintainability of the system.
[0027] In one possible implementation, the SDK code generation process includes: receiving an interface configuration file, wherein the interface configuration file includes the interface information of the SDK; and using an automated code generation tool to process the interface information of the SDK and automatically generate SDK code corresponding to the interface information.
[0028] As can be seen from the above solution, the embodiments of this application automatically generate complete SDK code through interface configuration files and automated code generation tools. Technicians only need to fill in the required interface information and do not need to write complete SDK code. This not only reduces the error rate and workload of manual code writing and saves manpower, but also speeds up the progress of software development.
[0029] In one possible implementation, the interface information includes at least one of the following: request method, Uniform Resource Locator (URL), protocol, request header, and request body.
[0030] In one possible implementation, the device further includes:
[0031] The registration unit is used to submit the SDK's interface information and the SDK's client identifier to the registration center during initialization before receiving data requests sent by the client through the abstract interface, so that the registration center can write the mapping relationship between the SDK's interface information and the SDK's client identifier into the interface mapping table.
[0032] As can be seen from the above scheme, the SDK provided in this application embodiment can automatically register interface information with the registration center during initialization, so that the registration center can automatically generate an interface mapping table without manual intervention, thereby improving the generation efficiency of the interface mapping table.
[0033] In one possible implementation, the query unit includes:
[0034] The sending module is used to send an interface query request carrying the target client identifier to the registration center;
[0035] The receiving module is used to receive the target SDK interface corresponding to the target client identifier as found by the registration center in the interface mapping table.
[0036] Thirdly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon that, when executed by a processor, implements the method as described in any possible implementation of the first aspect.
[0037] Fourthly, embodiments of this application provide an electronic device, which includes:
[0038] One or more processors;
[0039] The processor is coupled to a storage device for storing one or more programs;
[0040] When one or more programs are executed by one or more processors, the electronic device performs the method as described in any possible implementation of the first aspect.
[0041] Fifthly, embodiments of this application provide a computer program product containing instructions that, when executed on a computer or processor, cause the computer or processor to perform the method described in any possible implementation of the first aspect. Attached Figure Description
[0042] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.
[0043] Figure 1 A flowchart illustrating a method for calling an SDK interface provided in an embodiment of this application;
[0044] Figure 2 A flowchart illustrating an interface registration method provided in an embodiment of this application;
[0045] Figure 3 An example diagram illustrating a method for calling an SDK interface provided in an embodiment of this application;
[0046] Figure 4 A flowchart illustrating an automatic SDK code generation process provided in this application embodiment;
[0047] Figure 5 A block diagram illustrating the composition of an SDK interface invocation device provided in this application embodiment;
[0048] Figure 6 This is a schematic diagram of the structure of an electronic device or computer device provided in an embodiment of this application. Detailed Implementation
[0049] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.
[0050] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. The terms "comprising" and "having," and any variations thereof, in the embodiments and drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.
[0051] Figure 1 This is a flowchart illustrating a method for calling an SDK interface. This method can be applied to electronic devices or computer devices, specifically to any SDK. The method includes:
[0052] S110: Receives data requests sent by clients through the abstract interface.
[0053] The abstract interface is a universal interface developed uniformly for various clients. It can also be understood as providing an abstract class along with the interface, using the abstract class to implement the interface. This application's embodiment can use the Factory Method pattern to unify different client interfaces into an abstract interface.
[0054] Since the client interfaces corresponding to different SDKs can be generic interfaces, the changes to the original actual SDK interface or the addition of new SDK interfaces will not affect the client. The client interface will not change with the changes to the actual SDK interface, which facilitates the research and development of the client and improves the scalability and maintainability of the system.
[0055] When any SDK receives a data request from its corresponding client, the data request will carry information such as the target client identifier. The target client identifier refers to the identifier of the client, such as the client's name or number.
[0056] S120: Query the interface mapping table based on the target client identifier to obtain the target SDK interface.
[0057] The interface mapping table includes the mapping relationship between different client identifiers and SDK interfaces, where the target SDK interface is the SDK interface corresponding to the target client identifier. For example, in the interface mapping table, client 1 corresponds to SDK interface 1, client 2 corresponds to SDK interface 2, and so on.
[0058] Before querying the interface mapping table, it is necessary to create the interface mapping table first. In practical applications, the interface mapping table can be created manually or automatically by a machine.
[0059] like Figure 2 As shown, the automatic creation method of the interface mapping table includes: when the SDK is initialized, it submits the SDK's interface information and the target client identifier to the registry center, so that the registry center writes the mapping relationship between the interface information and the target client identifier into the interface mapping table.
[0060] The SDK's interface information includes at least one of the following: request method, URL (Uniform Resource Locator), protocol, request header, and request body.
[0061] When the interface mapping table is stored locally in the SDK, the SDK can directly read and query the interface mapping table from the local machine. When the interface mapping table is stored in the registry, when querying the interface mapping table based on the target client identifier to obtain the target SDK interface, the SDK can first send an interface query request carrying the target client identifier to the registry, and then receive the target SDK interface corresponding to the target client identifier found by the registry in the interface mapping table.
[0062] S130: Process the data request by calling the target SDK interface.
[0063] Once the SDK obtains the target SDK interface, it can process the data request by calling the target SDK interface, and then send a data response back to the client through the abstract interface.
[0064] like Figure 3 As shown, for N clients 1 to N, when accessing their respective SDKs, they can all send data requests through the abstract interface. After receiving the data request, the corresponding SDK can look up the interface mapping table based on the target client identifier in the data request to obtain the actual interface (i.e., the native interface) of the corresponding SDK and call it.
[0065] The SDK interface calling method provided in this application pre-configures an abstract interface for each type of client. When a client sends a data request to the SDK, it can directly send the data request through this abstract interface. The SDK can query the interface mapping table based on the target client identifier in the data request to obtain the actual SDK interface for calling. Thus, while ensuring normal communication between the client and the SDK, the client will not be affected regardless of whether the original actual SDK interface changes or a new SDK interface is added. The client's interface will not change with the change of the actual SDK interface, simplifying the calling process of the client application to the SDK interface. The client does not need to care about the underlying implementation details, thereby reducing the learning cost and integration time for developers and improving the scalability and maintainability of the system.
[0066] In one possible implementation, to accelerate SDK development efficiency and save manpower, embodiments of this application can automate SDK code generation. For example... Figure 4 As shown, an automated code generation tool can be used to receive the interface configuration file, which includes the SDK's interface information. Then, the automated code generation tool can be used to process the SDK's interface information and automatically generate SDK code corresponding to the interface information.
[0067] The interface configuration file can be in formats such as YAML (YAML Ain't Markup Language). Interface information includes at least one of the following: request method, URL, protocol, request headers, and request body. Furthermore, the interface configuration file can also include the required code language type to generate SDK code that meets specific needs.
[0068] Automated code generation tools include a user-friendly interface (HMI) that displays the names of interface information, allowing users to input values for those names. To prevent user (technical) errors that could lead to incorrect code generation (e.g., missing characters, inconsistent wording, incorrect formatting), the tool also includes built-in verification functionality. Before automatically generating code, it verifies the spelling of each interface entry for errors. If errors are found, an error message box pops up for the user to correct, and the tool continues to generate code only after successful verification.
[0069] After obtaining the interface configuration file, the automated code generation tool can first read the interface information in the interface configuration file, and then generate the code required for each item in the interface information, as well as the code corresponding to other necessary information, in a predetermined order, thereby generating complete SDK code.
[0070] This application embodiment automatically generates complete SDK code through interface configuration files and automated code generation tools. Technical personnel only need to fill in the required interface information, without having to write complete SDK code. This not only reduces the error rate and workload of manual code writing and saves manpower, but also speeds up the software development process.
[0071] Based on the above method embodiments, another embodiment of this application provides an SDK interface invocation device, which is applied to any software development kit (SDK), such as... Figure 5 As shown, the device includes:
[0072] The receiving unit 210 is used to receive a data request sent by a client through an abstract interface, wherein the abstract interface is a general interface developed uniformly when developing for multiple clients, and the data request includes a target client identifier;
[0073] The query unit 220 is used to query the interface mapping table according to the target client identifier to obtain the target SDK interface, wherein the interface mapping table includes the mapping relationship between different client identifiers and SDK interfaces, and the target SDK interface is the SDK interface corresponding to the target client identifier;
[0074] The calling unit 230 is used to process the data request by calling the target SDK interface.
[0075] In one possible implementation, the SDK code generation process includes: receiving an interface configuration file, wherein the interface configuration file includes the interface information of the SDK; and using an automated code generation tool to process the interface information of the SDK and automatically generate SDK code corresponding to the interface information.
[0076] In one possible implementation, the interface information includes at least one of the following: request method, Uniform Resource Locator (URL), protocol, request header, and request body.
[0077] In one possible implementation, the device further includes:
[0078] The registration unit is used to submit the SDK's interface information and the SDK's client identifier to the registration center during initialization before receiving data requests sent by the client through the abstract interface, so that the registration center can write the mapping relationship between the SDK's interface information and the SDK's client identifier into the interface mapping table.
[0079] In one possible implementation, the query unit 220 includes:
[0080] The sending module is used to send an interface query request carrying the target client identifier to the registration center;
[0081] The receiving module is used to receive the target SDK interface corresponding to the target client identifier as found by the registration center in the interface mapping table.
[0082] The SDK interface calling device provided in this application pre-configures an abstract interface for each type of client. When a client sends a data request to the SDK, it can directly send the data request through this abstract interface. The SDK can query the interface mapping table based on the target client identifier in the data request to obtain the actual SDK interface for calling. Thus, while ensuring normal communication between the client and the SDK, the client will not be affected regardless of whether the original actual SDK interface changes or a new SDK interface is added. The client's interface will not change with the change of the actual SDK interface, simplifying the calling process of the client application to the SDK interface. The client does not need to care about the underlying implementation details, thereby reducing the learning cost and integration time for developers and improving the scalability and maintainability of the system.
[0083] Based on the above method embodiments, another embodiment of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method as described in any of the above embodiments.
[0084] Based on the above method embodiments, another embodiment of this application provides an electronic device or computer device, such as... Figure 6 As shown, it includes:
[0085] One or more processors 310;
[0086] The processor 310 is coupled to a storage device 320, the storage device 320 being used to store one or more programs;
[0087] When the one or more programs are executed by the one or more processors 310, the electronic device or computer device performs the method as described in any of the above embodiments.
[0088] Based on the above embodiments, another embodiment of this application provides a computer program product, which includes instructions that, when executed on a computer or processor, cause the computer or processor to perform the method described in any of the above embodiments.
[0089] The above-described device and system embodiments correspond to the method embodiments and have the same technical effects. For detailed descriptions, please refer to the method embodiments. The device embodiments are derived from the method embodiments; detailed descriptions can be found in the method embodiments section, and will not be repeated here. Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of one embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application.
[0090] Those skilled in the art will understand that the modules in the apparatus of the embodiments can be distributed in the apparatus of the embodiments as described in the embodiments, or they can be located in one or more devices different from this embodiment with corresponding changes. The modules of the above embodiments can be combined into one module, or they can be further divided into multiple sub-modules.
[0091] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method for calling an SDK interface, characterized in that, The method is applied to any software development kit (SDK), and the method includes: Receive data requests sent by clients through an abstract interface, wherein the abstract interface is a general interface developed uniformly when developing for multiple clients, and the data request includes the target client identifier; The target SDK interface is obtained by querying the interface mapping table based on the target client identifier. The interface mapping table includes the mapping relationship between different client identifiers and SDK interfaces, and the target SDK interface is the SDK interface corresponding to the target client identifier. The data request is processed by calling the target SDK interface.
2. The method according to claim 1, characterized in that, The SDK code generation method includes: Receive interface configuration file, wherein the interface configuration file includes the interface information of the SDK; An automated code generation tool is used to process the interface information of the SDK and automatically generate SDK code corresponding to the interface information.
3. The method according to claim 2, characterized in that, The interface information includes at least one of the following: request method, Uniform Resource Locator (URL), protocol, request header, and request body.
4. The method according to any one of claims 1-3, characterized in that, Before receiving data requests sent by clients through the abstract interface, the method further includes: During initialization, the SDK submits its interface information and client identifier to the registry center so that the registry center can write the mapping relationship between the SDK's interface information and the SDK's client identifier into the interface mapping table.
5. The method according to claim 4, characterized in that, Based on the target client identifier, query the interface mapping table to obtain the target SDK interface, including: Send an interface query request carrying the target client identifier to the registration center; Receive the target SDK interface corresponding to the target client identifier as found by the registration center in the interface mapping table.
6. A device for calling an SDK interface, characterized in that, The apparatus is applied to any software development kit (SDK), and the apparatus includes: The receiving unit is used to receive data requests sent by clients through an abstract interface, wherein the abstract interface is a general interface developed uniformly when developing for multiple clients, and the data request includes a target client identifier; The query unit is used to query the interface mapping table according to the target client identifier to obtain the target SDK interface, wherein the interface mapping table includes the mapping relationship between different client identifiers and SDK interfaces, and the target SDK interface is the SDK interface corresponding to the target client identifier; The calling unit is used to process the data request by calling the target SDK interface.
7. The apparatus according to claim 6, characterized in that, The SDK code generation process includes: receiving an interface configuration file, wherein the interface configuration file includes the interface information of the SDK; and using an automated code generation tool to process the interface information of the SDK and automatically generate SDK code corresponding to the interface information.
8. The apparatus according to claim 6 or 7, characterized in that, The device further includes: The registration unit is used to submit the SDK's interface information and the SDK's client identifier to the registration center during initialization before receiving data requests sent by the client through the abstract interface, so that the registration center can write the mapping relationship between the SDK's interface information and the SDK's client identifier into the interface mapping table.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.
10. An electronic device, characterized in that, The electronic device includes: One or more processors; The processor is coupled to a storage device for storing one or more programs; When the one or more programs are executed by the one or more processors, the electronic device performs the method as described in any one of claims 1-5.