Interface data acquisition method and device, equipment, storage medium and program product

Through automated tools, scan and parse routing configuration code files, identify view functions and extract interface parameter information, solving the problem of inefficiency when integrating third-party service APIs in the service platform, and achieving efficient and reliable API integration.

CN119420807APending Publication Date: 2025-02-11ZHONGDIAN DATA IND CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411461375.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-18
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

When integrating third-party service APIs into service platforms, the method of manually integrating APIs is inefficient and highly dependent on manual operations.

Method used

Automatically scan the routing configuration code file of the target project through the preset toolkit, quickly identify the view function, and store the interface parameter information in the view function through the inspection module to be parsed and stored in the database of the service platform.

Benefits of technology

It simplifies the API integration process, improves the overall integration efficiency of the integrated API, reduces the integration complexity, avoids errors and omissions caused by manual operations, and improves the reliability and accuracy of integration.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119420807A_ABST
    Figure CN119420807A_ABST
Patent Text Reader

Abstract

The invention discloses an interface data acquisition method and device, equipment, a storage medium and a program product, and relates to the technical field of data processing.The interface data acquisition method comprises the steps that when a service platform receives an interface scanning command, a preset toolkit in a project root directory of a target project is operated to scan the project root directory to acquire a routing configuration code file, the target project is a project integrated with a third-party Python application in the service platform; determining a view function of the target project based on the routing configuration code file; the view function is analyzed through an inspection module to obtain interface parameter information of a calling interface, the interface parameter information is stored in a database of the service platform, and the calling interface is an interface which is packaged in the service platform and used for calling the third-party Python application. According to the application, the efficiency of integrating the third-party service API by the service platform is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to an interface data acquisition method, device, equipment, storage medium and program product. Background Art

[0002] With the development of Internet technology, service-oriented architecture has gradually become the mainstream model in software development, especially in the fields of cloud computing and microservices. In this context, API (Application Programming Interface) is an important bridge for interaction between different services, and its importance is becoming increasingly prominent. At present, most API integration methods are based on the needs of actual business scenarios. Developers need to manually understand the business logic and select appropriate APIs for integration according to business needs. However, in the actual service platform development process, there are a lot of third-party service API integration problems. The manual API integration method is highly dependent on manual operation and is inefficient when facing a large number of APIs.

[0003] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention

[0004] The main purpose of this application is to provide an interface data acquisition method, device, equipment, storage medium and program product, aiming to solve the technical problem of low efficiency when a service platform integrates a third-party service API.

[0005] To achieve the above purpose, the present application proposes a method for obtaining interface data, the method comprising:

[0006] In one embodiment, the interface data acquisition method is applied to a service platform, and the interface data acquisition method includes:

[0007] When receiving the interface scanning command, running a preset toolkit in the project root directory of the target project to scan the project root directory to obtain a routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform;

[0008] Determine the view function of the target project based on the routing configuration code file;

[0009] The view function is parsed by the inspection module to obtain interface parameter information of the calling interface, and the interface parameter information is stored in the database of the service platform, wherein the calling interface is an interface encapsulated within the service platform for calling the third-party Python application.

[0010] In one embodiment, the step of determining the view function of the target project based on the routing configuration code file includes:

[0011] Determine a URL routing list from the routing configuration code file, and traverse each URL routing in the URL routing list to determine a routing mode of the URL routing;

[0012] If the routing mode is a nested mode, access the sub-routes contained in the URL routing, and update the sub-routes to the URL routing, and execute the step of determining the routing mode of the URL routing;

[0013] If the routing mode is the normal mode, the view function associated with the URL routing is extracted.

[0014] In one embodiment, the step of scanning the project root directory by a preset toolkit in the project root directory of the running target project to obtain the routing configuration code file includes:

[0015] Run the preset toolkit in the project root directory of the target project to open the management script code file in the project root directory, and determine the file location of the routing configuration code file in the management script code file;

[0016] Determine the relative position between the file location and the project root directory through the reference statement of the routing configuration code file, and generate the file route of the routing configuration file based on the relative position through a routing parsing method;

[0017] Open the routing configuration code file according to the file routing.

[0018] In one embodiment, the step of parsing the view function through the inspection module to obtain interface parameter information of the calling interface includes:

[0019] Obtain the function method and function properties of the view function through the obtain member function in the inspection module;

[0020] Extracting a parameter list in the function method through a parameter acquisition function in the viewing module, wherein the parameter list includes input parameter information and output parameter information of the view function;

[0021] Extracting the function definition and function source code in the function attributes through the get code function in the viewing module, and determining the calling method of the view function based on the function source code;

[0022] The input parameter information, the output parameter information, the function definition and the calling method are used as interface parameter information.

[0023] In one embodiment, the step of storing the interface parameter information in a database of the service platform includes:

[0024] Convert the function definition, the calling method, the input parameter information and the output parameter information into an interface information file according to a preset text rule;

[0025] The interface information file is stored in the database of the service platform.

[0026] In one embodiment, before the step of running a preset toolkit in the project root directory of the target project to scan the project root directory to obtain the routing configuration code file upon receiving the interface scanning command, the method further includes:

[0027] Receiving project information input by a user based on a human-computer interaction interface, and parsing the project information to determine a target project corresponding to the project information;

[0028] A scanning toolkit is downloaded from a preset server, and the scanning toolkit is stored in a project root directory of the target project, and the scanning toolkit stored in the project root directory is used as a preset toolkit.

[0029] In addition, to achieve the above purpose, the present application also proposes an interface data acquisition device, which is deployed on a service platform and includes:

[0030] A running module, for, upon receiving an interface scanning command, running a preset toolkit in a project root directory of a target project to scan the project root directory to obtain a routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform;

[0031] A determination module, used to determine the view function of the target project based on the routing configuration code file;

[0032] A storage module is used to parse the view function through the inspection module to obtain interface parameter information of the calling interface, and store the interface parameter information in the database of the service platform, wherein the calling interface is an interface encapsulated inside the service platform for calling the third-party Python application.

[0033] In addition, to achieve the above-mentioned purpose, the present application also proposes an interface data acquisition device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the interface data acquisition method described above.

[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the interface data acquisition method described above are implemented.

[0035] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the interface data acquisition method described above are implemented.

[0036] In the present application, when an interface scanning command is received, a preset toolkit in the project root directory of the target project is run to scan the project root directory to obtain a routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform; the view function of the target project is determined based on the routing configuration code file; the view function is parsed by the inspection module to obtain interface parameter information of the calling interface, and the interface parameter information is stored in the database of the service platform, wherein the calling interface is an interface encapsulated internally by the service platform for calling the third-party Python application.

[0037] In this application, the routing configuration code file of the target project is automatically scanned through a preset toolkit, and the view function of the target project is quickly identified, reducing the time for manual search and configuration. The interface parameter information in the view function is automatically parsed and stored in the database of the service platform, further simplifying the API integration process, thereby achieving the improvement of the overall integration efficiency of the integrated API.

[0038] In addition, this application does not require developers to have an in-depth understanding of the business logic of each third-party Python application. They only need to focus on the interfaces and parameter information provided by them, which reduces the complexity of integration. Automated tools can handle tedious code parsing and parameter extraction, avoiding errors and omissions that may be caused by manual operations, improving the reliability and accuracy of integration, and at the same time improving the efficiency of identifying and integrating APIs. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0040] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0041] Figure 1 A flowchart of the first embodiment of the method for obtaining interface data of the present application is provided;

[0042] Figure 2 A flowchart of the second embodiment of the method for obtaining interface data of the present application is provided;

[0043] Figure 3 A schematic diagram of a brief flow of an interface data acquisition method provided in an embodiment of the present application;

[0044] Figure 4 This is a schematic diagram of the module structure of the interface data acquisition device according to an embodiment of the present application;

[0045] Figure 5 This is a schematic diagram of the device structure of the hardware operating environment involved in the interface data acquisition method in the embodiment of the present application.

[0046] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0047] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0048] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0049] The main solution of the embodiment of the present application is: when an interface scanning command is received, a preset toolkit in the project root directory of the target project is run to scan the project root directory to obtain a routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform; based on the routing configuration code file, the view function of the target project is determined; the view function is parsed by the inspection module to obtain interface parameter information of the calling interface, and the interface parameter information is stored in the database of the service platform, wherein the calling interface is an interface encapsulated inside the service platform for calling the third-party Python application.

[0050] In this embodiment, for the convenience of description, the following description is made by taking the interface data acquisition device as the execution subject.

[0051] With the development of Internet technology, service-oriented architecture has gradually become the mainstream model in software development, especially in the fields of cloud computing and microservices. In this context, API (Application Programming Interface) is an important bridge for interaction between different services, and its importance is becoming increasingly prominent. At present, most API integration methods are based on the needs of actual business scenarios. Developers need to manually understand the business logic and select appropriate APIs for integration according to business needs. However, in the actual service platform development process, there are a lot of third-party service API integration problems. The manual API integration method is highly dependent on manual operation and is inefficient when facing a large number of APIs.

[0052] The present application provides a solution that automatically scans the routing configuration code file of the target project through a preset toolkit, quickly identifies the view function of the target project, reduces the time of manual search and configuration, and further simplifies the API integration process by automatically parsing the interface parameter information in the view function and storing it in the database of the service platform, thereby improving the overall integration efficiency of the integrated API.

[0053] In addition, this application does not require developers to have an in-depth understanding of the business logic of each third-party Python application. They only need to focus on the interfaces and parameter information provided by them, which reduces the complexity of integration. Automated tools can handle tedious code parsing and parameter extraction, avoiding errors and omissions that may be caused by manual operations, improving the reliability and accuracy of integration, and at the same time improving the efficiency of identifying and integrating APIs.

[0054] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, an interface data acquisition device, etc., and the service platform is deployed on the interface data device. The following takes the interface data acquisition device as an example to illustrate this embodiment and the following embodiments.

[0055] Based on this, the present application embodiment provides an interface data acquisition method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the interface data acquisition method of the present application.

[0056] In this embodiment, the interface data acquisition method includes steps S10 to S30:

[0057] Step S10, when receiving the interface scanning command, running the preset toolkit in the project root directory of the target project to scan the project root directory to obtain the routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform;

[0058] It should be noted that the interface scanning command is a network command or software instruction used to detect and identify open interfaces in the target system or network. These interfaces are usually the endpoints of network communication, through which data exchange and instruction transmission can be carried out. By sending specific data packets or query requests, the interface scanning command can trigger the response of the target system, thereby revealing its open interfaces and services.

[0059] The target project refers to the project developed based on Python language to be integrated into the service platform. The project root directory refers to the top-level directory where the project files are located, that is, the main directory of the project. The project root directory usually contains key contents such as the project's source code, configuration files, and resource files. It is the starting point of the project structure, and all related files and directories are organized and managed based on it.

[0060] A preset toolkit is a set of preconfigured software tools or scripts used to perform specific tasks or operations. It usually includes a series of related software and libraries, as well as their dependencies and configuration information.

[0061] The routing configuration code file refers to a file used to define and configure routing information in network communication. The file defines the mapping relationship between all accessible URL paths and view functions in the project. It usually contains the configuration information of routers, switches and other devices in the network, as well as the connection relationship and routing strategy between them.

[0062] It is understandable that when the service platform receives an interface scanning command, it obtains detailed information of all interfaces in the target project by scanning the router configuration code file. The interface scanning command can be triggered by a user or system administrator, or it can be triggered according to a certain period, which is not limited here. Automated scanning can reduce the time and errors of manually searching for routing configuration files and improve efficiency.

[0063] Step S20, determining the view function of the target project based on the routing configuration code file;

[0064] A view function is a function used to process user requests and return responses in Web development. In a Web framework, a view function is usually associated with a specific URL path. When a user accesses the path, the Web server calls the corresponding view function to process the request. A view function can perform various tasks, such as verifying user identity, querying a database, generating HTML pages, etc., and finally returns a response object to the user.

[0065] After obtaining the routing configuration code files, parse these files to determine all the view functions in the target project. By analyzing the routing configuration code files, you can identify the view functions associated with each URL path and extract the names and related information of these functions.

[0066] Step S30, parsing the view function through the inspection module to obtain interface parameter information of the calling interface, and storing the interface parameter information in the database of the service platform, wherein the calling interface is an interface encapsulated inside the service platform for calling the third-party Python application.

[0067] The inspection module is a tool or library for analyzing Python code. It can read source code and extract key information such as function definitions, parameters, and return values. A calling interface refers to an interface used to call functions or services provided by other programs or modules. In software development, calling interfaces are usually used to implement communication and data exchange between modules. By calling an interface, a program can request another program to perform a specific task or return specific data. The interface usually defines key information such as input parameters, output parameters, and calling methods to ensure the correctness and reliability of the call. Interface parameter information refers to detailed information describing the parameters and their properties required for an interface call. Parameter information usually includes key content such as parameter name, type, default value, and constraints. Through the interface parameter information, developers can understand how to correctly call the interface and pass the required parameters.

[0068] After the view function is determined, the inspection module is used to parse the view function and extract the interface parameter information required to call the interface. The extracted interface parameter information is stored in the database of the service platform for subsequent query and use.

[0069] It can be understood that by automatically parsing view functions and extracting interface parameter information, the workload of manually writing and maintaining interface documents is reduced, and the interface parameter information is stored in the database, which improves the availability and maintainability of the interface and reduces interface problems caused by manual errors.

[0070] This embodiment automatically scans the routing configuration code file of the target project through a preset toolkit, quickly identifies the view function of the target project, reduces the time of manual search and configuration, and further simplifies the API integration process by automatically parsing the interface parameter information in the view function and storing it in the database of the service platform, thereby improving the overall integration efficiency of the integrated API.

[0071] In addition, this embodiment does not require developers to have an in-depth understanding of the business logic of each third-party Python application. They only need to focus on the interfaces and parameter information provided by them, which reduces the complexity of integration. Automated tools can handle tedious code parsing and parameter extraction work, avoiding errors and omissions that may be caused by manual operations, improving the reliability and accuracy of integration, and at the same time improving the efficiency of identifying and integrating APIs.

[0072] In a feasible implementation manner, the step S10: before the step of running a preset toolkit in the project root directory of the target project to scan the project root directory to obtain the routing configuration code file upon receiving the interface scanning command, further includes:

[0073] Step S01, receiving project information input by a user based on a human-computer interaction interface, and parsing the project information to determine a target project corresponding to the project information;

[0074] Before starting the interface scan, the service platform first provides a human-computer interaction interface (such as a web interface, command line interface, etc.) for the user to enter project information. The project information entered by the user may include key information such as the project name, path, type (such as a Python project), and version.

[0075] After receiving the project information input by the user, the service platform will parse and process it to determine the specific target project to which the information corresponds. This may include verification, matching and conversion of the input information to ensure that it can accurately point to an existing project that meets the scanning requirements.

[0076] Step S02, downloading a scanning toolkit from a preset server, and storing the scanning toolkit in a project root directory of the target project, and using the scanning toolkit stored in the project root directory as a preset toolkit.

[0077] After the target project is determined, the scanning toolkit is downloaded from the preset server (such as an internal server, cloud storage, etc.). The scanning toolkit is a software package containing various scanning tools and scripts for scanning and analyzing the code and configuration files of the target project. After the download is complete, the scanning toolkit is stored in the project root directory of the target project and used as the preset toolkit for subsequent scanning operations.

[0078] It can be understood that by receiving the project information input by the user and determining the target project, as well as downloading and configuring the scanning toolkit from the preset server, the system can accurately locate the target project to be scanned and provide the necessary tools and resources for subsequent scanning operations, thereby improving the accuracy and efficiency of the scanning operation, providing users with a convenient interaction method, and enhancing the usability and maintainability of the system.

[0079] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 2 The step S20: determining the view function of the target project based on the routing configuration code file comprises:

[0080] Step S201, determining a URL routing list from the routing configuration code file, and traversing each URL routing in the URL routing list to determine a routing mode of the URL routing;

[0081] In Web application development, routing configuration is the key link between user requests and backend processing functions. The routing configuration file defines the mapping relationship between URL paths and view functions, so that when a user visits a URL, the corresponding view function can be found and called to process the request.

[0082] When extracting view functions, the service platform parses all URL routes from the route configuration code file and stores them in the URL route list. URL routes are the mapping between the URLs entered by users when accessing Web applications and the backend processing functions. The service platform traverses the URL route list, processes each URL route, and determines the routing mode of each URL route.

[0083] It should be noted that the routing mode refers to the mapping relationship between the URL path and the backend processing function (i.e., view function) in a Web application. It determines how the system finds and calls the corresponding view function to process the request when a user visits a URL. The routing mode is a core component of the Web application architecture and directly affects the application's request processing flow, maintainability, and scalability. The routing mode can be a normal mode (i.e., directly mapped to a view function) or a nested mode (i.e., containing sub-routes, which may be further mapped to other view functions).

[0084] Step S202, if the routing mode is a nested mode, access the sub-routes included in the URL routing, and update the sub-routes to the URL routing, and execute the step of determining the routing mode of the URL routing;

[0085] The nested mode refers to the routing mode in which the URL path contains sub-paths, and these sub-paths may be further mapped to other view functions. In this mode, a URL path may contain multiple levels of sub-paths, and each sub-path may correspond to one or more view functions.

[0086] In the process of traversing the URL route list, if the route mode of the URL route is determined to be a nested mode, access all subroutes contained in this nested URL route, which may also be nested or normal. For each subroute, treat it as a new URL route and repeat the steps of determining the route mode until all subroutes are processed.

[0087] Step S203: If the routing mode is the normal mode, extract the view function associated with the URL routing.

[0088] Normal mode refers to the routing mode in which the URL path is directly mapped to a view function. In this mode, each URL path corresponds to a unique view function. When a user visits the URL, the system directly calls the corresponding view function to process the request.

[0089] In the process of traversing the URL routing list, if the system finds that the routing mode of a URL routing is the normal mode, it extracts the view function associated with it. The view function is a function that processes user requests and returns responses.

[0090] It can be understood that by recursively processing the nested URL routing, all levels of routing structure can be completely parsed to ensure that no view function is missed, and the view function can be automatically extracted from the target project, which not only improves efficiency but also reduces the possibility of manual intervention and errors.

[0091] Exemplarily, the recursive process of extracting the view function based on the routing configuration file may be:

[0092] Parse the URL route list from the routing configuration file and iterate over each URL route in the list. In this example, there are two URL routes: / home and / user / <userid>For / user / <userid>This nested pattern URL route visits its child routes / profile and / posts, treats / profile and / posts as new URL routes, and repeats the steps to determine the route pattern. <userid>The sub-routes list is / profile and / posts. For the nested sub-routes of / posts, access its sub-routes / <postid>Similarly, / <postid>Treat it as a new URL route and repeat the steps to determine the route pattern. For a common URL route, such as / home, / user / <userid> / profile and / user / <userid> / posts / <postid>, extract the view functions associated with it. In this example, three view functions, HomeView, UserProfileView, and UserPostView, are extracted. When all subroutes are processed, the recursive process ends.

[0093] In a feasible implementation, if the view function uses a closure or a higher-order function, since the closure can capture and save the variables of the scope in which it is created, even if the scope no longer exists when the closure is called, that is, the parameter information of the closure is not limited to the parameters explicitly declared when the function is defined, but also includes the captured variables, which makes it more complicated than parsing the parameters of ordinary functions. Since high-order functions can accept functions as parameters or return functions as results, that is, the parameters of high-order functions may actually be another function, and this function itself may have its own parameters and captured variables. Therefore, when parsing high-order functions, it is necessary to recursively parse high-order functions, resulting in greater difficulty in parsing. In this implementation, a log system can be configured in the target project to ensure that all key function calls have detailed log records; when calling a closure or a higher-order function, all the parameters passed in are recorded through the log system, and after the function is executed, the return value and any important state changes or outputs are recorded through the log system; if the view function associated with the URL route is a closure or a higher-order function, the function call record in the log file is obtained from the log system to extract the parameter information of the view function.

[0094] It should be noted that if the route or view function is dynamically generated at runtime, the view function may only be created and parsed at runtime, and the static analysis tool performs analysis without executing the code, so the static analysis tool may not be able to capture all the information of the view function. Therefore, when parsing the view function, if it is determined that there is dynamic code in the routing code in the routing code configuration file, the fixed routing code and the dynamic routing code are determined from the routing code configuration file; the fixed routing code is analyzed through static analysis to obtain the fixed route and the first view function information corresponding to the fixed route; a callback function is added to the dynamic routing code, and the dynamic routing information generated based on the dynamic routing code and the second view function information associated with the dynamic routing information are recorded through the callback function; and the first view function information and the second view function information are used as the function information of the view function.

[0095] In one embodiment, the step S10: running a preset toolkit in a project root directory of a target project to scan the project root directory to obtain a routing configuration code file includes:

[0096] Step S101, running a preset toolkit in a project root directory of a target project to open a management script code file in the project root directory, and determining a file location of a routing configuration code file in the management script code file;

[0097] Management script code files are files that declare project dependencies, build steps, and runtime environment configurations in a specific syntax or format. In management script code files, the location or reference of routing configuration code files is usually clearly specified so that build tools, deployment scripts, or other automated processes can accurately find and process these files. File location refers to a clear indication of the location or reference of routing configuration code files in a project's management script code file.

[0098] In the management script code file, the toolkit searches for specific tags, comments or code snippets to determine the file name, path or reference information of the routing configuration code file. The preset toolkit automatically processes the file, reducing the time and effort of manually searching for routing configuration code files.

[0099] Step S102, determining the relative position between the file location and the project root directory through the reference statement of the routing configuration code file, and generating the file route of the routing configuration file based on the relative position through a routing parsing method;

[0100] Relative position refers to the location of the routing configuration code file relative to the project root directory. When parsing the management script code file, the reference statement (such as path, file name, etc.) to the routing configuration code file is used to calculate the location of the routing configuration code file relative to the project root directory. Relative position is usually used to specify the location of a file or directory in the project structure instead of using an absolute path (that is, a path containing the full disk path), which can improve the portability and flexibility of the project because the relative position can remain valid regardless of the location or environment where the project is deployed.

[0101] The process of determining the relative position may be: parsing the reference statements in the management script code file, extracting the path and file name information of the routing configuration code file, and then calculating the final relative position in combination with the path of the project root directory, and there is no specific limitation here.

[0102] After finding a reference to the routing configuration code file in the management script code file, the toolkit will parse the reference statement to determine the location of the routing configuration code file relative to the project root directory. Based on the determined relative location, the toolkit will use a routing resolution method (which may be an algorithm or a set of rules) to generate a complete file route. The file route is a unique identifier pointing to the routing configuration code file, which contains the full path from the project root directory to the target file.

[0103] It can be understood that by parsing reference statements and generating file routes, the toolkit can accurately locate the location of the routing configuration code file, so that the toolkit can flexibly handle different types of files and path structures.

[0104] Step S103, opening the routing configuration code file according to the file routing.

[0105] After the file route is generated, the toolkit will open the route configuration code file according to the file route. By directly opening the file according to the file route, the toolkit can quickly access the content of the route configuration code file and provide the necessary input for subsequent steps.

[0106] In one embodiment, the step S30: the step of parsing the view function through the inspection module to obtain the interface parameter information of the calling interface includes:

[0107] Step S301, obtaining the function method and function properties of the view function through the obtain member function in the inspection module;

[0108] A member function is a function that belongs to a class or object. Getting member functions usually refers to accessing or retrieving information about these functions through some mechanism (such as reflection, introspection, etc.). Function methods usually refer to the function itself, including its name, parameter types, return type, etc. In object-oriented programming, a method usually refers to a function that belongs to an object. Function attributes refer to metadata or additional information related to a function, such as the function's definition, source code, documentation string, etc. This information is usually not directly involved in the execution of the function, but can be used for debugging, documentation generation, etc.

[0109] Through the inspection module, the view function is deeply analyzed to extract its interface parameter information as the calling interface, and the function method and function properties of the view function are accessed by using the get member function function of the inspection module.

[0110] Step S302, extracting a parameter list in the function method through a parameter acquisition function in the viewing module, wherein the parameter list includes input parameter information and output parameter information of the view function;

[0111] Get parameter function refers to the function or method used to extract function parameter information, which usually includes parameter name, type, default value, etc. The parameter list refers to the set of all parameters listed in the function definition. These parameters are passed when the function is called and used inside the function. Input parameter information refers to the parameter information received by the function, that is, the parameters passed to the function when the function is called. Output parameter information refers to the information returned by the function, that is, the result returned to the caller after the function is executed.

[0112] Use the Get Parameter Function function to extract the parameter list from the function method. The parameter list contains the input and output parameter information of the view function. The specific method of extracting the parameter list is not described here, and can be set according to actual needs.

[0113] Step S303, extracting the function definition and function source code in the function attribute through the get code function in the view module, and determining the calling method of the view function based on the function source code;

[0114] Get Code Function is a function or method used to extract the source code of a function. This usually involves accessing the definition or implementation of a function for code analysis, debugging, or optimization. The function definition is the declaration or implementation of a function, including the function's name, parameter list, return type, and the code of the function body. The function source code is the code part of the function definition, that is, the actual code that implements the function's functionality.

[0115] Use the Get Code Function function to extract the function definition and function source code. Then, by analyzing the source code (which may be parsing, abstract syntax tree generation, etc., which is not limited here), determine the calling method of the view function. Exemplarily, the specific process of extracting the calling method can be: extracting the function definition and source code; parsing the source code to generate an abstract syntax tree (AST); traversing the AST to identify nodes related to function calls (such as function call expressions); and determining the calling method of the function based on the node information.

[0116] Step S304: Use the input parameter information, the output parameter information, the function definition and the calling method as interface parameter information.

[0117] The input parameter information, output parameter information, function definition and calling method extracted in the previous steps are integrated together to form complete interface parameter information. By providing complete interface parameter information, a solid foundation is provided for interface design and implementation, and the maintainability and scalability of the code are improved.

[0118] In one embodiment, the step S30: storing the interface parameter information in a database of the service platform includes:

[0119] Step S305, converting the function definition, the calling method, the input parameter information and the output parameter information into an interface information file according to a preset text rule;

[0120] The interface parameter information (including function definition, calling method, input parameter information and output parameter information, etc.) is formatted according to a preset text rule, and an interface information file is generated. The interface information file is a structured text file that clearly expresses the various parameter information of the interface. It can be understood that the interface information file stores the various parameter information of the interface in a structured manner, making the information clearer and easier to understand. The generated interface information file conforms to the preset text rules, so it can be easily parsed and processed by other systems or tools.

[0121] It should be noted that the preset text rules are not limited here and can be set according to actual needs. For example, it can be JSON (JavaScript Object Notation, a lightweight data exchange format), XML (eXtensibleMarkup Language, a markup language), YAML (YAML Ain't Markup Language, a human-readable data serialization standard).

[0122] Step S306: storing the interface information file in the database of the service platform.

[0123] Store the interface information file in the service platform's database and insert the file content into the specified data table. The database can be a relational database (such as MySQL, PostgreSQL, etc.) or a non-relational database (such as MongoDB, Cassandra, etc.), depending on the architecture and requirements of the service platform, and is not limited here.

[0124] It is understandable that by storing the interface information file in the database, the persistent preservation of the information can be ensured, and the information will not be lost even if the system crashes or restarts. The database provides powerful query and management functions, which can easily query the interface information according to needs, or perform operations such as adding, deleting and modifying information.

[0125] For example, in order to help understand the implementation process of the interface data acquisition method obtained by combining the first embodiment with the second embodiment, a specific implementation process of the interface data acquisition method is proposed in this embodiment.

[0126] In this embodiment, by analyzing the directory structure of the project, the code files related to routing and view are found. For Django projects, first find manage.py in the current project directory, parse the url or path function call in the urls.py file, and extract the name and import path of the view function; for Flask projects, parse the file content, find all the lines using the @app.route decorator, extract the decorator parameters (routing path) and the view function name. Then use the getmembers or getsource function of the inspect module to obtain the definition and parameter information of the view function. Finally, organize the extracted view function name, routing path, parameter list and other information into a dictionary or list.

[0127] In a Django project, the urls.py file is responsible for defining URL patterns (i.e., routes) and mapping URLs to corresponding view functions. The file is usually located in the root directory of the project. After reading the file content, you can get the urlpatterns list, i.e., the url and the corresponding view function or view set. Through the resolve method, use the url as a variable to get the view function object. Use inspect.getmember to get all members of the function object, including its methods and attributes. And use inspect.getsource to get the function definition and source code.

[0128] Take the Django project as an example, refer to Figure 3 , download the toolkit (.py) file to the root directory of the Django project on the target machine according to the information filled in by the user, and run the toolkit through the command. The logic of the toolkit to implement API scanning is as follows. The data acquisition process for Python applications is:

[0129] 1. Open the manage.py file in this directory and read it line by line, search for the location of urls.py, and determine the relative position with the current directory through the reference statement, and generate the file route of urls.py through the resolve method (that is, when receiving the interface scanning command, run the preset toolkit in the project root directory of the target project to scan the project root directory to obtain the routing configuration code file).

[0130] 2. Open the urls.py file according to the file routing, get the ualpatterns list, scan the routes in the list, if it contains include, that is, the routes are nested, then continue to scan the routes in the nested structure through a recursive method until the view function method file is obtained (that is, determine the URL routing list from the routing configuration code file, and traverse each URL route in the URL routing list to determine the routing mode of the URL routing; if the routing mode is a nested mode, access the sub-routes contained in the URL routing, and update the sub-routes to the URL routing, and execute the step of determining the routing mode of the URL routing; if the routing mode is a normal mode, extract the view function associated with the URL routing).

[0131] 3. For function method files, use inspect.getmember to obtain all members of the object, including its methods and properties. For method objects, use inspect.getargspec to obtain the parameter list (that is, use the get parameter function in the inspection module to extract the parameter list in the function method).

[0132] 4. For the acquired object members, obtain the function definition and source code in string form through instance.getsource (that is, extract the function definition and function source code in the function attributes through the get code function in the inspection module, and determine the calling method of the view function based on the function source code).

[0133] 5. Generate an Excel interface document with the function definition, calling method, input parameter, and output parameter information. Scan the information in the interface document to the system database to implement API automatic import (that is, use the input parameter information, the output parameter information, the function definition, and the calling method as interface parameter information, and store the interface parameter information in the database of the service platform).

[0134] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the interface data acquisition method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0135] This application also provides an interface data acquisition device, please refer to Figure 4 , the interface data acquisition device is deployed on the service platform, and the interface data acquisition device includes:

[0136] The running module 10 is used for running a preset toolkit in a project root directory of a target project to scan the project root directory to obtain a routing configuration code file when an interface scanning command is received, wherein the target project is a project integrating a third-party Python application in the service platform;

[0137] A determination module 20, configured to determine a view function of the target project based on the routing configuration code file;

[0138] The storage module 30 is used to parse the view function through the inspection module to obtain the interface parameter information of the calling interface, and store the interface parameter information in the database of the service platform, wherein the calling interface is an interface encapsulated inside the service platform for calling the third-party Python application.

[0139] Optionally, the determining module 20 is used to:

[0140] Determine a URL routing list from the routing configuration code file, and traverse each URL routing in the URL routing list to determine a routing mode of the URL routing;

[0141] If the routing mode is a nested mode, access the sub-routes contained in the URL routing, and update the sub-routes to the URL routing, and execute the step of determining the routing mode of the URL routing;

[0142] If the routing mode is the normal mode, the view function associated with the URL routing is extracted.

[0143] Optionally, the operation module 10 is used to:

[0144] Run the preset toolkit in the project root directory of the target project to open the management script code file in the project root directory, and determine the file location of the routing configuration code file in the management script code file;

[0145] Determine the relative position between the file location and the project root directory through the reference statement of the routing configuration code file, and generate the file route of the routing configuration file based on the relative position through a routing parsing method;

[0146] Open the routing configuration code file according to the file routing.

[0147] Optionally, the storage module 30 is used to:

[0148] Obtain the function method and function properties of the view function through the obtain member function in the inspection module;

[0149] Extracting a parameter list in the function method through a parameter acquisition function in the viewing module, wherein the parameter list includes input parameter information and output parameter information of the view function;

[0150] Extracting the function definition and function source code in the function attributes through the get code function in the viewing module, and determining the calling method of the view function based on the function source code;

[0151] The input parameter information, the output parameter information, the function definition and the calling method are used as interface parameter information.

[0152] Optionally, the storage module 30 is used to:

[0153] Convert the function definition, the calling method, the input parameter information and the output parameter information into an interface information file according to a preset text rule;

[0154] The interface information file is stored in the database of the service platform.

[0155] Optionally, the device is also used for:

[0156] Receiving project information input by a user based on a human-computer interaction interface, and parsing the project information to determine a target project corresponding to the project information;

[0157] A scanning toolkit is downloaded from a preset server, and the scanning toolkit is stored in a project root directory of the target project, and the scanning toolkit stored in the project root directory is used as a preset toolkit.

[0158] The interface data acquisition device provided by the present application adopts the interface data acquisition method in the above embodiment, which can solve the technical problem of low efficiency when the service platform integrates the third-party service API. Compared with the prior art, the beneficial effects of the interface data acquisition device provided by the present application are the same as the beneficial effects of the interface data acquisition method provided by the above embodiment, and the other technical features in the interface data acquisition device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0159] The present application provides an interface data acquisition device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the interface data acquisition method in each of the above-mentioned embodiments.

[0160] Reference below Figure 5 , which shows a schematic diagram of the structure of an interface data acquisition device suitable for implementing the embodiment of the present application. The interface data acquisition device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The interface data acquisition device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0161] like Figure 5 As shown, the interface data acquisition device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the interface data acquisition device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the interface data acquisition device to communicate with other devices wirelessly or by wire to exchange data. Although the interface data acquisition device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

[0162] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0163] The interface data acquisition device provided by the present application adopts the interface data acquisition method in the above embodiment, which can solve the technical problem of low efficiency when the service platform integrates the third-party service API. Compared with the prior art, the beneficial effects of the interface data acquisition device provided by the present application are the same as the beneficial effects of the interface data acquisition method provided by the above embodiment, and the other technical features in the interface data acquisition device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0164] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0165] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0166] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the interface data acquisition method in the above-mentioned embodiment.

[0167] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0168] The computer-readable storage medium may be included in the interface data acquisition device; or may exist independently without being assembled into the interface data acquisition device.

[0169] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the interface data acquisition device, the interface data acquisition device: when receiving an interface scanning command, runs the preset toolkit in the project root directory of the target project to scan the project root directory to obtain the routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform; determines the view function of the target project based on the routing configuration code file; parses the view function through the inspection module to obtain the interface parameter information of the calling interface, and stores the interface parameter information in the database of the service platform, wherein the calling interface is an interface encapsulated inside the service platform for calling the third-party Python application.

[0170] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0171] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0172] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0173] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned interface data acquisition method, and can solve the technical problem of low efficiency when the service platform integrates third-party service APIs. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the interface data acquisition method provided by the above-mentioned embodiment, and will not be repeated here.

[0174] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned interface data acquisition method when executed by a processor.

[0175] The computer program product provided by this application can solve the technical problem of low efficiency when the service platform integrates the third-party service API. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the interface data acquisition method provided in the above embodiment, which will not be repeated here.

[0176] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.< / postid> < / userid> < / userid> < / postid> < / postid> < / userid> < / userid> < / userid>

Claims

1. A method for acquiring interface data, characterized in that: The interface data acquisition method is applied to a service platform, and the interface data acquisition method includes: When receiving the interface scanning command, running a preset toolkit in the project root directory of the target project to scan the project root directory to obtain a routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform; Determine the view function of the target project based on the routing configuration code file; The view function is parsed by the inspection module to obtain interface parameter information of the calling interface, and the interface parameter information is stored in the database of the service platform, wherein the calling interface is an interface encapsulated within the service platform for calling the third-party Python application.

2. The interface data acquisition method according to claim 1, characterized in that: The step of determining the view function of the target project based on the routing configuration code file includes: Determine a URL routing list from the routing configuration code file, and traverse each URL routing in the URL routing list to determine a routing mode of the URL routing; If the routing mode is a nested mode, access the sub-routes contained in the URL routing, and update the sub-routes to the URL routing, and execute the step of determining the routing mode of the URL routing; If the routing mode is the normal mode, the view function associated with the URL routing is extracted.

3. The interface data acquisition method according to claim 1, characterized in that: The step of scanning the project root directory by a preset toolkit in the project root directory of the running target project to obtain the routing configuration code file comprises: Run the preset toolkit in the project root directory of the target project to open the management script code file in the project root directory, and determine the file location of the routing configuration code file in the management script code file; Determine the relative position between the file location and the project root directory through the reference statement of the routing configuration code file, and generate the file route of the routing configuration file based on the relative position through a routing parsing method; Open the routing configuration code file according to the file routing.

4. The interface data acquisition method according to claim 1, characterized in that: The step of parsing the view function through the inspection module to obtain interface parameter information of the calling interface includes: Obtain the function method and function properties of the view function through the obtain member function in the inspection module; Extracting a parameter list in the function method through a parameter acquisition function in the viewing module, wherein the parameter list includes input parameter information and output parameter information of the view function; Extracting the function definition and function source code in the function attributes through the get code function in the viewing module, and determining the calling method of the view function based on the function source code; The input parameter information, the output parameter information, the function definition and the calling method are used as interface parameter information.

5. The interface data acquisition method according to claim 4, characterized in that: The step of storing the interface parameter information in a database of the service platform comprises: Convert the function definition, the calling method, the input parameter information and the output parameter information into an interface information file according to a preset text rule; The interface information file is stored in the database of the service platform.

6. The interface data acquisition method according to any one of claims 1 to 5, characterized in that: Before the step of running a preset toolkit in the project root directory of the target project to scan the project root directory to obtain the routing configuration code file upon receiving the interface scanning command, the method further includes: Receiving project information input by a user based on a human-computer interaction interface, and parsing the project information to determine a target project corresponding to the project information; A scanning toolkit is downloaded from a preset server, and the scanning toolkit is stored in a project root directory of the target project, and the scanning toolkit stored in the project root directory is used as a preset toolkit.

7. An interface data acquisition device, characterized in that: The interface data acquisition device is deployed on the service platform, and the interface data acquisition device includes: A running module, for, upon receiving an interface scanning command, running a preset toolkit in a project root directory of a target project to scan the project root directory to obtain a routing configuration code file, wherein the target project is a project integrating a third-party Python application in the service platform; A determination module, used to determine the view function of the target project based on the routing configuration code file; A storage module is used to parse the view function through the inspection module to obtain interface parameter information of the calling interface, and store the interface parameter information in the database of the service platform, wherein the calling interface is an interface encapsulated inside the service platform for calling the third-party Python application.

8. An interface data acquisition device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the interface data acquisition method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the interface data acquisition method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the interface data acquisition method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Communication control method and device

    CN121098659A