Method and device for converting universal API (Application Program Interface) for interaction
Access H5 pages or API interfaces through the browser, enter page elements and button information, and use JSOUP and Hutool tool classes to generate general API interfaces, which solves the problem of converting H5 page or interface data, realizes efficient multi-end data sharing and display, and improves improve the utilization efficiency of data resources.
Patent Information
- Application Number
- CN202411266865.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-11
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-09-11
AI Technical Summary
Existing technology is difficult to effectively convert H5 page or interface data into a universal interface, resulting in data sharing being restricted by network or hardware problems, and the lack of efficient multi-terminal data sharing solutions.
Access the H5 page or API interface through the browser, enter the page element information and button information, use JSOUP and Hutool tool classes to parse and call the interface, generate a general API interface, and achieve rapid display and sharing of data.
It simplifies the data display process, reduces the complexity of information acquisition, optimizes the utilization of data resources, realizes rapid sharing and convenient interaction of H5 page and API interface data, and improves the value and utilization efficiency of data resources.
Smart Images

Figure CN118779554A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of Internet technology, and specifically provides a method and device for converting into a universal API interface for interaction. Background Art
[0002] The present invention discloses a method and device for configuring page crawling rules, which relate to the field of computer technology. The main purpose is to automatically generate page crawling rules and improve the generation speed of crawling rules. The main technical scheme of the present invention is: selecting a page element to be crawled from a page that needs to be configured with crawling rules; generating path information of the page element according to attribute information corresponding to the page element to be crawled; generating a regular expression matching the content of the page element to be crawled by setting a regular expression template matching the page element to be crawled; configuring the page crawling rules of the page to be crawled according to the display rules of the page element to be crawled in the page to be crawled and the position information of the page element to be crawled in the page to be crawled.
[0003] The present invention relates to a data sharing method for realizing set protocol conversion in an API manner, comprising the steps of: API service entry; wherein the entry method at least includes: quickly importing RESTful through a Swagger document, or quickly importing WebService through a WSDL document, or manually entering an API service; determining the service type to which the entered API service belongs, and converting the corresponding API service interface information format from a second format that is not the first format to a first format; wherein the first format is a RESTful format, and the second format is a format other than the first format; performing service joint debugging on the API service after the interface information format is converted, to ensure that the service can be called normally after formal release; wherein the service joint debugging method at least includes associating a plug-in and a custom proxy address; performing a joint debugging test after the service joint debugging, and publishing the service after the test passes.
[0004] In the prior art, how to convert H5 page or interface data into a universal interface and realize data sharing through technical means, thereby eliminating data sharing barriers caused by network or hardware problems and realizing the possibility of multi-terminal data sharing, is an urgent problem to be solved by technical personnel in this field. Summary of the invention
[0005] The present invention aims at the above-mentioned deficiencies of the prior art and provides a method for converting into a universal API interface for interaction with high practicality.
[0006] A further technical task of the present invention is to provide a device that is reasonably designed, safe and applicable and is converted into a universal API interface for interaction.
[0007] The technical solution adopted by the present invention to solve its technical problem is: A method for converting to a general API interface for interaction, the steps are as follows: S1. Enter the application based on the shared resources; S2. Determine whether the resource to be shared is an H5 page or an API interface; S3. If the resource is an H5 page, the browser accesses the H5 page link and finds the elements to be shared and the interfaces to be used by viewing the source code; S4. If the resource is an API interface, the front end enters the first page as the homepage of the application; S5. Enter the button information in the first page, and enter the page code of the second page in the goto field of the button; S6. The third party displays the result page according to the page information and button information returned by the general interface.
[0008] Furthermore, in step S3, the browser accesses the H5 page link, finds the elements to be shared and the interfaces to be used by viewing the source code, enters a page in the front end with reference to the shared H5 page, and enters the element information to be displayed in the entered page.
[0009] Furthermore, the element information includes attribute name, attribute type, associated ID, default value, prompt information, attribute length, verification rule, selector, sorting, whether required, whether read-only, whether crawled, whether enabled, whether to pass data, whether to obtain data and remarks.
[0010] Furthermore, when entering the element information to be displayed in the entered page, it further includes: (1) If the value of a page element is a fixed value, fill it in the default field and the backend will return the default value as the value; (2) If the value of the element is crawled through a shared H5 page, enter the crawling expression, and the backend will crawl the corresponding content of the H5 page through the relevant methods of JSOUP and return it as the value; (3) If the value of an element is obtained through an API interface, you need to enter the basic information of the API interface first, and then enter the corresponding interface ID in the field. The backend will find the corresponding interface information through the associated ID, call the interface through the Hutool tool class, and return the return result of the interface as the value.
[0011] Furthermore, in step S4, the front end enters the first page as the home page of the application, and adds corresponding page element information to the entered page according to the parameters required by the interface. The element information needs to enter whether to pass the data identifier, and the third party determines whether to pass it as a parameter when calling the next page based on the field information.
[0012] Furthermore, in step S4, the front end enters the second page as the result page of the application, and according to the result returned by the interface, adds the corresponding page element information to the result page entered in the previous step. The back end obtains the interface return value through the Hutool tool class, and uses the configured parsing method name to implement the parsing of the interface result through Java's reflection mechanism, and assigns the final result to the value attribute of the element.
[0013] Furthermore, in step S6, the third party parses the page information and button information returned by the universal interface to its own page according to the standard, clicks the button to trigger the call of the universal interface again, parses the data to the second page according to the standard, and displays the result page.
[0014] A device for converting into a universal API interface for interaction, comprising: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is used to call the machine-readable program to execute a method of converting into a universal API interface for interaction.
[0015] Compared with the prior art, the method and device for converting to a universal API interface for interaction of the present invention has the following outstanding beneficial effects: The present invention simplifies the process of data display, reduces the complexity of obtaining information, and effectively optimizes the use of data resources. It not only realizes the rapid display and sharing of H5 page and API interface data, but also provides a more convenient and efficient data interaction method for all parties, realizes multi-terminal data sharing, and further improves the value and utilization efficiency of data resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the embodiments of the present invention 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, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0017] Attached Figure 1 It is a method of converting application information into a common API interface for interaction. Attached Figure 2 It is a schematic diagram of the backend processing flow in a method of converting to a general API interface for interaction; Attached Figure 3 It is a diagram of the third-party call process in a method that is converted into a general API interface for interaction. DETAILED DESCRIPTION
[0018] In order to enable those skilled in the art to better understand the solution of the present invention, the present invention is further described in detail below in conjunction with specific implementation methods. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0019] A best embodiment is given below: like Figure 1-3 As shown, a method of converting into a general API interface for interaction in this embodiment fixes the content returned by the general interface into a Json structure, and the structure includes a set of HTML tags, a set of HTML buttons, and key-value pairs of basic information descriptions. The third party parses the label and button information of the interface according to the rules through the return results of the interface, and then displays it on its own page to achieve resource sharing.
[0020] To implement this process, you need to first enter the content that the H5 page needs to display into the system through the front-end system, such as element information and button information. The back-end code determines whether the entered element tag attribute is crawled. If it is crawled, the Document object is obtained through the corresponding method of JSOUP according to the path configured on the page.
[0021] Then, the Document is parsed according to the configured expression, and the value is assigned to the value attribute of the field to complete the assignment of the field attribute; if the element tag attribute is not crawled, a default value is given for the fixed value, and for the value obtained by the interface, the background uses the interface template configured in the front end and the Hutool tool class to implement the interface call. According to the configured parsing method name, the interface result is parsed through Java's reflection mechanism, and the final result is assigned to the value attribute of the element.
[0022] Finally, all element information is returned, and the data sharing of H5 pages or interfaces can be realized through a common interface.
[0023] The specific steps are as follows: S1. Enter the application based on the shared resources (refer to Figure 1 Application Information Table); S2. Determine whether the resource to be shared is an H5 page or an API interface; S3. If the resource is an H5 page; Further including: S3-1. Use the browser to access the H5 page link and find the elements to be shared and the interfaces to be used by viewing the source code. S3-2. Enter a page on the front end by referring to the shared H5 page (reference Figure 1 Page basic information table); S3-3. Refer to the shared H5 page and enter the element information to be displayed in the page entered in the previous step (reference Figure 1 Page element information table); (1) If the value of a page element is a fixed value, fill it in the default field and the backend will return the default value as the value; (2) If the value of the element is crawled through a shared H5 page, enter the crawling expression, and the backend will crawl the corresponding content of the H5 page through the relevant methods of JSOUP and return it as the value; (3) If the value of an element is obtained through an interface, you need to first enter the basic information of the interface, including the interface address, request method, interface parameters, parameter passing method, etc., and then enter the corresponding interface ID in the field. The backend will find the corresponding interface information through the associated ID, call the interface through the Hutool tool class, and return the return result of the interface as the value.
[0024] S4. If the resource is an API interface, the front end enters the first page as the homepage of the application; Further including: S4-1. Enter the first page as the homepage of the application on the front end; S4-2. According to the parameters required by the interface, add the corresponding page element information to the page entered in the previous step. The element information here needs to enter whether to pass the data identifier. The third party determines whether to pass it as a parameter when calling the next page based on the field information; S4-3, the front end enters the second page as the result page of the application; S4-4. According to the result returned by the interface, add the corresponding page element information to the result page entered in the previous step. The backend obtains the interface return value through the Hutool tool class, and implements the parsing of the interface result through the configured parsing method name and Java's reflection mechanism, and assigns the final result to the value attribute of the element.
[0025] S5. Enter the button information in the first page, and enter the page code of the second page in the goto field of the button; S6. The third party displays the result page according to the page information and button information returned by the general interface; The third party parses the page information and button information returned by the general interface into its own page according to the standard. After clicking the button, the general interface is called again, and the data is parsed into the second page according to the standard to display the result page.
[0026] Based on the above method, a device for converting into a universal API interface for interaction in this embodiment includes: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is used to call the machine-readable program to execute a method of converting into a universal API interface for interaction.
[0027] The above-mentioned specific implementations are only specific cases of the present invention. The patent protection scope of the present invention includes but is not limited to the above-mentioned specific implementations. Any technical solutions that comply with the claims of the present invention and any appropriate changes or substitutions made by ordinary technicians in the relevant technical field shall fall within the patent protection scope of the present invention.
[0028] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method of converting to a general API interface for interaction, It is characterized in that The steps are as follows: S1. Enter the application based on the shared resources; S2. Determine whether the resource to be shared is an H5 page or an API interface; S3. If the resource is an H5 page, the browser accesses the H5 page link and finds the elements to be shared and the interfaces to be used by viewing the source code; S4. If the resource is an API interface, the front end enters the first page as the homepage of the application; S5. Enter the button information in the first page, and enter the page code of the second page in the goto field of the button; S6. The third party displays the result page according to the page information and button information returned by the general interface.
2. A method for converting to a general API interface for interaction according to claim 1, It is characterized in that In step S3, the browser accesses the H5 page link, finds the elements to be shared and the interfaces to be used by viewing the source code, enters a page on the front end with reference to the shared H5 page, and enters the element information to be displayed in the entered page.
3. A method for converting to a general API interface for interaction according to claim 2, It is characterized in that The element information includes attribute name, attribute type, associated ID, default value, prompt information, attribute length, verification rule, selector, sorting, whether required, whether read-only, whether crawled, whether enabled, whether to pass data, whether to obtain data and remarks.
4. A method for converting to a general API interface for interaction according to claim 3, It is characterized in that When entering the element information to be displayed in the entered page, it further includes: (1) If the value of a page element is a fixed value, fill it in the default field and the backend will return the default value as the value; (2) If the value of the element is crawled through a shared H5 page, enter the crawling expression, and the backend will crawl the corresponding content of the H5 page through the relevant methods of JSOUP and return it as the value; (3) If the value of an element is obtained through an API interface, you need to enter the basic information of the API interface first, and then enter the corresponding interface ID in the field. The backend will find the corresponding interface information through the associated ID, call the interface through the Hutool tool class, and return the return result of the interface as the value.
5. A method for converting to a general API interface for interaction according to claim 4, It is characterized in that In step S4, the front end enters the first page as the home page of the application, and adds corresponding page element information to the entered page according to the parameters required by the interface. The element information needs to enter whether to pass the data identifier. The third party determines whether to pass it as a parameter when calling the next page based on the field information.
6. A method for converting to a general API interface for interaction according to claim 5, It is characterized in that In step S4, the front end enters the second page as the result page of the application. According to the result returned by the interface, the corresponding page element information is added to the result page entered in the previous step. The back end obtains the interface return value through the Hutool tool class, and uses the configured parsing method name to implement the parsing of the interface result through Java's reflection mechanism, and assigns the final result to the value attribute of the element.
7. A method for converting to a general API interface for interaction according to claim 6, It is characterized in that In step S6, the third party parses the page information and button information returned by the universal interface to its own page according to the standard, clicks the button to trigger the call of the universal interface again, parses the data to the second page according to the standard, and displays the result page.
8. A device for converting to a universal API interface for interaction, It is characterized in that include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to call the machine-readable program to execute the method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Internal control management system capable of applying response type shared application architecture
CN107301048A
Interactive selected web crawler establishment method and system based on page elements
CN107609150A
Page returning method and device, equipment and storage medium
CN113468443A
Method and device for generating dynamic page data and storage medium
CN115291868A
Page loading method and device, electronic equipment, server and storage medium
CN115525848A
