Method and system for generating interface codes open to outside

By generating business codes for the entity layer, dao layer, dto layer, service layer, controller layer and UI layer, and performing signature verification and QPS restrictions when interface requests are made, the problem of cumbersome development of external open interfaces in the existing technology is solved and realized It provides fast and safe interface generation, improving development efficiency and security.

CN118733055AInactive Publication Date: 2024-10-01WEIFANG HUACHUANG INFORMATION TECHNOLOGY CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411224463.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-10-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The development process of external open interfaces in the existing technology is cumbersome and time-consuming, requiring writing a large amount of repeated code, and the interfaces are not standardized and there is no unified standard, resulting in low development efficiency.

Method used

By generating business codes for the entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on database tables and configurations, and performing signature verification and QPS restrictions when interface requests are made, fast and safe external open interface generation is achieved.

Benefits of technology

It significantly reduces the workload of manually writing duplicate codes, improves development efficiency, ensures the security and identity legitimacy of the interface, and simplifies the process of opening the interface to the outside world.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733055A_ABST
    Figure CN118733055A_ABST
Patent Text Reader

Abstract

The invention relates to the field of computers, and particularly discloses a method and a system for generating an interface code open to the outside. The method comprises the following steps: generating a service code comprising an entity layer, a dao layer, a dto layer, a service layer, a controller layer and a UI layer based on a database table and configuration; generating an API (Application Program Interface) which is open to the outside and is in a RESTful style on the basis of the database table and configuration; wherein when the generated external open interface is requested, signature verification and QPS limitation are carried out. According to the invention, the security and identity legality of the external interface are ensured through signature verification; malicious attacks are prevented through QPS limitation; automatic code generation is realized, and the workload of manually writing repeated codes is reduced; the development efficiency is improved, and the time of developers is saved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and system for generating an externally open interface code. Background Art

[0002] With the rapid development of the Internet, more and more companies and developers need to open their services and applications to the outside world to achieve better interconnection and cooperation. However, the development process of open interfaces is usually cumbersome and time-consuming, requiring the writing of a large amount of repeated code, and the interfaces are not standardized and have no unified standards. In order to solve this technical problem, a method and system for generating open interface code is proposed. Summary of the invention

[0003] In order to solve the technical problems existing in the above-mentioned prior art, the present invention provides a method for generating code for an externally open interface, which can quickly and automatically generate the code required for the externally open interface, and ensure the security and identity legitimacy when the interface is called through signature verification. The method of the present invention focuses on simplifying and standardizing the process of opening the interface to the outside world, significantly reducing the workload of manually writing repetitive codes, and is suitable for various application scenarios that require the rapid construction of a safe and reliable external interface.

[0004] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions: In a first aspect, in an embodiment provided by the present invention, a method for generating an externally open interface code is provided, the method comprising the following steps: Generate business codes of entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on database tables and configurations; Generate secure and standardized external open interfaces based on database tables and configurations; When the generated external open interface is requested, signature verification and QPS restriction are performed.

[0005] The present invention directly generates business codes including entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on database tables and configurations, and generates a safe and standardized external open interface based on the database tables and configurations; wherein, when the generated external open interface is requested, signature verification and QPS restriction are performed; the present invention ensures the security and identity legitimacy of the external interface through signature verification; automatically generates code, reduces the workload of manually writing repeated code, improves development efficiency, and saves developers' time.

[0006] As a further solution of the present invention, the generated open interface performs request signature verification each time a request is made, including the following steps: Database table analysis: analyze the database table structure and understand the fields, types, primary keys and foreign key relationships of the database tables; Design a corresponding entity class for each table, and the entity class attributes correspond to the database table fields one by one; Use Beetl template engine, define template files, and replace variables when generating code; Use JDBC to connect to the database and read the database metadata; Convert the read metadata into a model for template filling; Use the metadata model to fill in the variables in the template and generate specific code; Generate Entity, DAO, DTO, Service, and Controller layer codes; Format the generated code to make it conform to coding standards.

[0007] As a further solution of the present invention, the generated open interface performs request signature verification each time a request is made, including the following steps: Construct a signature parameter set, which includes the parameters required by the interface and the time and key ID in the required request header; Remove data with null and empty parameter values; Sort the keys of all parameters in ascending order of ASCII code; Concatenate the sorted parameters to form a signature string; Perform HmacSHA1 digest on the signature string and encrypt it with Base64; Perform signature verification on the signature string.

[0008] As a further solution of the present invention, the signature verification of the signature string includes: Use a key pair, RSA2 key, or verification-free key to verify the signature.

[0009] As a further solution of the present invention, the generated open interface performs request signature verification each time a protocol request is made, including: The generated open interface performs request signature verification every time an HTTP or HTTPS protocol request is made.

[0010] As a further solution of the present invention, the encryption algorithm used in requesting signature verification is HmacSHA1 digest or Base64 encryption.

[0011] In a second aspect, in another embodiment provided by the present invention, a system for generating code for an open interface is provided, the system comprising: a code generation module, an interface generation module and a security verification module.

[0012] The code generation module is configured to generate business code for the entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on the database table and configuration; The interface generation module is configured to generate a secure and standardized externally open interface based on the database table and configuration; The security verification module is configured to perform signature verification and QPS restriction when the generated externally open interface is requested.

[0013] The technical solution provided by the present invention has the following beneficial effects: The present invention generates business codes of entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on database tables and configurations, and generates a safe and standardized external open interface based on the database tables and configurations; when the generated external open interface is requested, signature verification and QPS restriction are performed; the present invention ensures the security and identity legitimacy of the external interface through signature verification; automatically generates code, reduces the workload of manually writing repeated code, improves development efficiency, and saves developers' time.

[0014] These and other aspects of the present invention will be more clearly understood in the following description of the embodiments. It should be understood that the above general description and the following detailed description are only exemplary and explanatory and cannot limit the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] 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 in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can be obtained based on these drawings without paying creative work.

[0016] Figure 1 The present invention is a flowchart of a method for generating an externally open interface code according to an embodiment of the present invention.

[0017] Figure 2 The present invention is a flowchart of performing request signature verification each time a request is made to the open interface generated in the method for generating an open interface code according to an embodiment of the present invention.

[0018] Figure 3 The present invention is a structural block diagram of an open interface code generation system according to an embodiment of the present invention.

[0019] In the figure: 100 - code generation module, 200 - interface generation module, 300 - security verification module. DETAILED DESCRIPTION

[0020] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not 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.

[0021] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0022] It should be understood that the terms used in this specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the specification of the present invention and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.

[0023] Specifically, the embodiments of the present invention are further described below in conjunction with the accompanying drawings.

[0024] See also Figure 1 , Figure 1 is a flow chart of a method for generating an externally open interface code provided by an embodiment of the present invention, such as Figure 1 As shown, the method for generating an open interface code includes steps S10 to S30.

[0025] S10. Generate business code including entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on database table and configuration. The business code includes entity layer, dao layer, dto layer, service layer, controller layer and UI layer, so that the addition, deletion, modification and query operations of database table can be realized, and corresponding data transfer object (DTO) and service layer interface are provided.

[0026] In the embodiment of the present invention, the S10, generating business code including entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on the database table and configuration, comprises the following steps: Step 1: Analyze the database table structure and understand the fields, types, primary keys, foreign keys and other relationships of the database table.

[0027] Step 2: Design a corresponding entity class for each table, and the entity class attributes correspond one-to-one to the database table fields.

[0028] In the embodiment of the present invention, the entity class of each table design contains annotations corresponding to the database table fields, which are used to identify the type, length, whether it can be empty, and primary key or foreign key attributes of the field.

[0029] Step 3: Use the Beetl template engine to define the template file and replace the variables when generating the code.

[0030] In the embodiment of the present invention, the Beetl template engine used can adaptively and dynamically generate a code framework according to the database table structure, including but not limited to the initial structure of the Entity, DAO, DTO, Service, and Controller layer codes.

[0031] Step 4: Use JDBC to connect to the database and read the database metadata.

[0032] In the embodiment of the present invention, when JDBC is used to connect to the database and read metadata, a connection pool technology is adopted to improve the efficiency and response speed of the database connection.

[0033] Step 5: Convert the read metadata into a model that can be used for template filling.

[0034] In an embodiment of the present invention, the model converted into the read metadata includes type mapping of database table fields and identification of relationships between fields (such as primary keys and foreign keys) to ensure that the generated code correctly reflects the database structure.

[0035] Step 6: Use the metadata model to fill in the variables in the template and generate specific code.

[0036] In the embodiment of the present invention, when a metadata model is used to fill a template, an exception handling mechanism is automatically added through predefined rules to enhance the robustness and security of the generated code.

[0037] Step 7. Generate Entity, DAO, DTO, Service, and Controller layer codes.

[0038] In the embodiment of the present invention, the generated Service layer code includes a transaction management mechanism to ensure the consistency and integrity of database operations.

[0039] Entity layer: Generates entity classes, including fields and getter / setter methods.

[0040] DAO layer: Generates data access objects, including CRUD operation methods.

[0041] DTO layer: Generates data transfer objects for data exchange between the service layer and the controller.

[0042] Service layer: Generates business logic interface and its implementation, and calls DAO layer.

[0043] Controller layer: generates controllers, processes HTTP requests, and calls the Service layer.

[0044] Generate UI layer code: Generate VUE-based front-end code based on the generated content.

[0045] Step 8: Format the generated code to make it conform to the coding standards.

[0046] S20. Generate a secure and standardized external open interface based on database tables and configurations; In the embodiment of the present invention, the step S20 of generating a secure and standardized externally open interface based on the database table and configuration includes the following steps: Step 1: When generating business code, generate an external interface for adding, deleting, modifying and checking interfaces in the REST directory; Step 2: Unify the prefix of the external interface to provide a unified entry for subsequent verification requests; Step 3: Automatically generate the documentation and error codes corresponding to the interface.

[0047] S30. When the generated externally open interface is requested, signature verification and QPS restriction are performed, so as to ensure the security of the access request and the legitimacy of the identity.

[0048] In the embodiment of the present invention, when the generated external open interface is requested in S30, signature verification and QPS restriction are performed, so as to ensure the security of the access request and the legitimacy of the identity, including the following steps: Step 1: The system will assign a set of key ID and key KEY to each user who requests the interface; Step 2: Construct a signature parameter set, which includes the parameters required by the interface (such as name, description, creation time, etc.) and the C-Date and C-Secret that must be transmitted when requesting the interface (C-Date is the time in the request header, and C-Secret is the user's secret key ID); Step 3: Remove data with null and empty parameter values; Step 4: Sort the keys of all parameters in ascending order of ASCII code; Step 5: Concatenate the sorted parameters to form a signature string; Step 6: Perform HmacSHA1 digest on the signature string and encrypt it with Base64; Step 7: Verify the signature string.

[0049] Step 8: When making a request, the request amount will be limited according to the preset QPS limit value.

[0050] In an embodiment of the present invention, the signature verification of the signature string includes: Use a key pair for signature verification, or use an RSA2 key for signature verification, or use a signature-free method for verification.

[0051] In an embodiment of the present invention, the generated open interface performs request signature verification each time a request is made, including: The generated open interface performs request signature verification every time an HTTP or HTTPS protocol request is made.

[0052] In an embodiment of the present invention, the open interface can be called by a key pair, an RSA2 key or a signature-free method.

[0053] In an embodiment of the present invention, the encryption algorithm used in requesting signature verification is HmacSHA1 digest and Base64 encryption.

[0054] When requesting signature verification, ensure the confidentiality and security of the key pair, RSA2 key, or signature-free method when verifying the identity of the access requester.

[0055] The present invention generates business codes of entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on database tables and configurations, and generates a safe and standardized external open interface based on database tables and configurations; when the generated external open interface is requested, signature verification and QPS restriction are performed; the present invention ensures the security and identity legitimacy of the external interface through signature verification; automatically generates code, reduces the workload of manually writing repeated code, improves development efficiency, and saves developers' time.

[0056] It should be understood that, although described in a certain order, these steps are not necessarily performed in sequence in the above order. Unless there is clear explanation in this article, the execution of these steps does not have strict order restriction, and these steps can be performed in other orders. Moreover, a part of the steps of the present embodiment may include a plurality of steps or a plurality of stages, and these steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a part of the steps or stages in other steps or other steps.

[0057] In one embodiment, see Figure 2 As shown, in an embodiment of the present invention, an externally open interface code generation system is also provided, which includes a code generation module 100, an interface generation module 200 and a security verification module 300.

[0058] The code generation module 100 is configured to generate business codes of entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on database tables and configurations.

[0059] The interface generation module 200 is configured to generate a secure and standardized externally open interface based on the database table and configuration.

[0060] The security verification module 300 is configured to perform signature verification and QPS restriction when the generated externally open interface is requested.

[0061] See also Figure 2 , Figure 2 FIG. 1 is a flowchart of performing request signature verification each time a request is made to the externally-opened interface generated in the externally-opened interface code generation method according to an embodiment of the present invention, such as Figure 2 As shown, the generated open interface performs request signature verification each time a request is made, including the following steps: Step 1: Construct a signature parameter set, which includes the parameters required by the interface and the required C-Date and C-Secret (C-Date is the time in the request header, and C-Secret is the user's secret key ID); Step 2: Remove data with null and empty parameter values; Step 3: Sort the keys of all parameters in ascending order of ASCII code; Step 4: Concatenate the sorted parameters to form a signature string; Step 5: Perform HmacSHA1 digest and Base64 encryption on the signature string; Step 6: Verify the signature string.

[0062] In an embodiment of the present invention, the signature verification of the signature string includes: Use a key pair for signature verification, or use an RSA2 key for signature verification, or use a signature-free method for verification.

[0063] The invention discloses an externally open interface code generation system, which generates business codes of entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on database tables and configurations; generates a safe and standardized externally open interface based on database tables and configurations; performs signature verification and QPS restriction when the generated externally open interface is requested; the invention ensures the security and identity legitimacy of the external interface through signature verification; generates codes automatically, reduces the workload of manually writing repeated codes, improves development efficiency and saves developers' time.

[0064] The present invention is implemented based on computer equipment, and the computer equipment includes user equipment and network equipment. The user equipment includes but is not limited to computers, smart phones, PDAs, etc. The network equipment includes but is not limited to a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of computers or network servers based on cloud computing (Cloud Computing), wherein cloud computing is a kind of distributed computing, a super virtual computer consisting of a group of loosely coupled computer sets. The computer equipment can be operated alone to implement the present invention, or it can be connected to the network and implement the present invention through interactive operations with other computer equipment in the network. The network where the computer equipment is located includes but is not limited to the Internet, wide area network, metropolitan area network, local area network, VPN network, etc.

[0065] It should be further understood that the term “and / or” used in the present specification and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0066] It should be understood that, as used herein, the singular form "a" or "an" is intended to include the plural form as well, unless the context clearly supports an exception. It should also be understood that, as used herein, "and / or" refers to any and all possible combinations of one or more of the items listed in association. The serial numbers of the embodiments disclosed in the above embodiments of the present invention are for description only and do not represent the advantages and disadvantages of the embodiments.

[0067] A person skilled in the art should understand that the discussion of any of the above embodiments is only exemplary and is not intended to imply that the scope of the disclosure of the embodiments of the present invention (including the claims) is limited to these examples; under the concept of the embodiments of the present invention, the technical features in the above embodiments or different embodiments can also be combined, and there are many other changes in different aspects of the above embodiments of the present invention, which are not provided in detail for the sake of simplicity. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the embodiments of the present invention should be included in the protection scope of the embodiments of the present invention.

Claims

1. A method for generating an open interface code, characterized in that: Applied to business code generation and security verification of the system's external open interfaces, the method includes: Generate business code including entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on database tables and configurations; Generate secure and standardized external open interfaces based on database tables and configurations; When the generated external open interface is requested, signature verification and QPS restriction are performed.

2. The method for generating an open interface code according to claim 1, characterized in that: Generate business code including entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on database tables and configurations, including: Database table analysis: analyze the database table structure and understand the fields, types, primary keys and foreign key relationships of the database tables; Design a corresponding entity class for each table, and the entity class attributes correspond to the database table fields one by one; Use Beetl template engine, define template files, and replace variables when generating code; Use JDBC to connect to the database and read the database metadata; Convert the read metadata into a model for template filling; Use the metadata model to fill in the variables in the template and generate specific code; Generate Entity, DAO, DTO, Service, and Controller layer codes; Format the generated code to make it conform to coding standards.

3. The method for generating an open interface code according to claim 2, characterized in that: Generate business code including entity layer, dao layer, dto layer, service layer, controller layer and UI layer based on database tables and configurations, including: When using JDBC to connect to the database and read metadata, use connection pool technology to improve the efficiency and response speed of database connections; The Beetl template engine used can adaptively generate code frameworks dynamically according to the database table structure, including but not limited to the initial structure of the Entity, DAO, DTO, Service, and Controller layer codes; When using metadata models to fill templates, exception handling mechanisms are automatically added through predefined rules to enhance the robustness and security of generated code; The generated Service layer code includes a transaction management mechanism to ensure the consistency and integrity of database operations; The entity class designed for each table contains annotations corresponding to the database table fields, which are used to identify the field type, length, whether it can be null, and primary key or foreign key properties; The model converted from the read metadata includes type mapping of database table fields and identification of relationships between fields to ensure that the generated code correctly reflects the database structure.

4. The method for generating an open interface code according to claim 1, wherein: The method of generating a secure and standardized external open interface based on database tables and configurations includes: When generating business code, the add, delete, modify and query interface will also be generated as an external interface under the REST directory.

5. The method for generating an open interface code according to claim 1, characterized in that: When the generated external open interface is requested, signature verification and QPS restriction are performed, including: The system will assign a set of key ID and key KEY to each user who requests the interface; When the user requests the interface, he must pass the C-Date and key ID; The encryption algorithm used in signature verification is HmacSHA1 digest and Base64 encryption; The generated open interface will limit the request volume and perform signature verification according to the preset QPS limit value each time the HTTP or HTTPS protocol is requested.

6. An open interface code generation system, characterized in that: The system includes: a code generation module, an interface generation module and a safety verification module; The code generation module is configured to generate business codes of entity layer, dao layer, dto layer, service layer, controller layer and ui layer based on database tables and configurations; The interface generation module is configured to generate a secure and standardized externally open interface based on the database table and configuration; The security verification module is configured to perform signature verification and QPS restriction when the generated externally open interface is requested.

Citation Information

Patent Citations

  • Code generation method, device, electronic equipment and medium

    CN110989999A

  • Software code generation method and device, computer equipment and storage medium

    CN111061475A

  • Method for quickly constructing service calling and middle-platform API gateway

    CN112367321A

  • Code generation method and device, electronic equipment and storage medium

    CN114579109A

  • Data processing method, system and device, equipment and medium

    CN117390644A