Disclosure of Invention
The embodiment of the application provides an interface interaction method and device, which at least solve the technical problem of low interaction efficiency caused by the need of developing a docking code in the interface interaction process.
According to one aspect of the embodiment of the application, an interface interaction method is provided, which comprises the steps that a target engine receives request information transmitted by an origin server, the request information at least comprises request data and interface interaction rules, the request data are converted into target data in a first target format required by a target interface based on the interface interaction rules, the target data are processed according to the requirements of the target interface, the processed target data are obtained, the processed target data are sent to the origin server through the target interface, response data returned by the origin server are received, and the response data are sent to the origin server according to a second target format in the interface interaction rules.
Optionally, the method comprises the steps of converting the request data into target data in a first target format required by a target interface based on the interface interaction rule, wherein the method comprises the steps of determining a mapping relation between a first field in the request data and a second field in the response data, extracting the first target format from the interface interaction rule, and converting the request data and the mapping relation into the target data according to the first target format, wherein data values of the target data are assembled according to a node path, and preset characters in the node path are used for representing hierarchical relations among the target data fields.
Optionally, after obtaining the target data, the method further comprises determining address information of the target interface from the interface interaction rules.
Optionally, processing the target data according to the requirement of the target interface to obtain processed target data, wherein the requirement at least comprises one of encrypting the target data, constructing a signature value for a data value corresponding to the target data, generating an anti-replay value for the data value corresponding to the target data, extracting a corresponding processing mode from the interface interaction rule according to the requirement of the target interface, and processing the target data to obtain the processed target data.
Optionally, extracting a corresponding processing mode from the interface interaction rule according to the requirement of the target interface, and processing the target data to obtain processed target data, wherein the processing mode comprises the steps of selecting an encryption rule from the interaction rule to encrypt the target data when the requirement of the target interface is to encrypt the target data, selecting an encryption rule from the interaction rule to encrypt the data corresponding to the target data to obtain a corresponding signature value when the requirement of the target interface is to construct the signature value for the data corresponding to the target data, and selecting an encryption rule from the interaction rule to encrypt the data corresponding to the target data to obtain the corresponding signature value when the requirement of the target interface is to generate an anti-replay value for the data corresponding to the target data, and selecting a target algorithm to generate the corresponding anti-replay value from the interaction rule.
Optionally, the sending the processed target data to the target server through the target interface includes sending the processed target data to the target interface through a preset action, and transmitting the processed target data to the target server through the target interface.
Optionally, the response data is sent to the source server according to a second target format in the interface interaction rule, and the method comprises the steps of extracting data values corresponding to the target data in the response data according to a mapping relation, completing analysis of the response data according to a node path mode, and sending the response data after analysis to the source server according to the second target format required by the source server in the interface interaction rule.
According to another aspect of the embodiment of the application, the interface interaction device further provides an interface interaction device, which comprises a receiving module, a processing module and a response module, wherein the receiving module is used for receiving request information transmitted by an origin server, the request information at least comprises request data and interface interaction rules, the processing module is used for converting the request data into target data in a first target format required by a target interface based on the interface interaction rules, processing the target data according to the requirements of the target interface to obtain processed target data, sending the processed target data to the origin server through the target interface, and the response module is used for receiving response data returned by the origin server and sending the response data to the origin server according to a second target format in the interface interaction rules.
According to still another aspect of the embodiment of the present application, there is further provided a nonvolatile storage medium, in which a program is stored, where a device in which the nonvolatile storage medium is controlled to execute the above-described interface interaction method when the program runs.
According to still another aspect of the embodiment of the present application, there is also provided a computer device including a memory and a processor, where the processor is configured to execute a program stored in the memory, and the program executes the interface interaction method.
In the embodiment of the application, a target engine is adopted to receive request information transmitted by an origin server, the request information at least comprises request data and interface interaction rules, the request data is converted into target data in a first target format required by a target interface based on the interface interaction rules, the target data is processed according to the requirements of the target interface, the processed target data is obtained and is transmitted to the target server through the target interface, response data returned by the target server is received, the response data is transmitted to the origin server according to a second target format in the interface interaction rules, the request data is converted into the target data in the first target format required by the target interface through the target engine, the target data is transmitted to the target server through the target interface after the target data is processed according to the requirements of the target interface, the response data is returned, the aim of avoiding programming a butt joint code is achieved, and the technical effect of improving the interface interaction efficiency is achieved, and the technical problem of low interaction efficiency caused by the need of developing the butt joint code in the interface interaction process is solved.
Detailed Description
In order that those skilled in the art will better understand the present application, a technical solution in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be noted that the steps illustrated in the flowcharts of the figures may be performed in a computer system such as a set of computer executable instructions, and that although a logical order is illustrated in the flowcharts, in some cases the steps illustrated or described may be performed in an order other than that illustrated herein.
The method embodiments provided by the embodiments of the present application may be performed in a mobile terminal, a computer terminal, or similar computing device. Fig. 1 shows a block diagram of a hardware architecture of a computer terminal (or mobile device) for implementing an interface interaction method. As shown in fig. 1, the computer terminal 10 (or mobile device 10) may include one or more (102 a, 102b are shown here), 102 n), a processor 102 (the processor 102 may include, but is not limited to, a microprocessor MCU or a processing device such as a programmable logic device FPGA), a memory 104 for storing data, and a transmission module 106 for communication functions. Among other things, a display, an input/output interface (I/O interface), a Universal Serial BUS (USB) port (which may be included as one of the ports of the BUS BUS), a network interface, a power supply, and/or a camera. It will be appreciated by those of ordinary skill in the art that the configuration shown in fig. 1 is merely illustrative and is not intended to limit the configuration of the electronic device described above. For example, the computer terminal 10 may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
It should be noted that the one or more processors 102 and/or other data processing circuits described above may be referred to generally herein as "data processing circuits. The data processing circuit may be embodied in whole or in part in software, hardware, firmware, or any other combination. Furthermore, the data processing circuitry may be a single stand-alone processing module, or incorporated, in whole or in part, into any of the other elements in the computer terminal 10 (or mobile device). As referred to in embodiments of the application, the data processing circuit acts as a processor control (e.g., selection of the path of the variable resistor termination connected to the interface).
The memory 104 may be used to store software programs and modules of application software, such as program instructions/data storage devices corresponding to the interface interaction method in the embodiment of the present application, and the processor 102 executes the software programs and modules stored in the memory 104, thereby executing various functional applications and data processing, that is, implementing the interface interaction method described above. Memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the computer terminal 10 via a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission means 106 is arranged to receive or transmit data via a network. The specific examples of the network described above may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC) that can connect to other network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module for communicating with the internet wirelessly.
The display may be, for example, a touch screen type Liquid Crystal Display (LCD) that may enable a user to interact with a user interface of the computer terminal 10 (or mobile device).
In the above operating environment, the embodiment of the present application provides an interface interaction method, as shown in fig. 2, where the method includes the following steps:
step S202, a target engine receives request information transmitted by a source server, wherein the request information at least comprises request data and interface interaction rules;
step S204, converting the request data into target data in a first target format required by a target interface based on the interface interaction rule, processing the target data according to the requirement of the target interface to obtain processed target data, and sending the processed target data to a target server through the target interface;
step S206, receiving response data returned by the target server, and sending the response data to the source server according to a second target format in the interface interaction rule.
Through the steps, the target data can be transmitted to the target server through the target interface and the response data is returned, so that the aim of avoiding writing the docking code is fulfilled, the technical effect of improving the interface interaction efficiency is realized, and the technical problem of low interaction efficiency caused by the fact that the docking code needs to be developed in the interface interaction process is solved.
In the related art, the interface interaction has two forms, namely an interface formulated by adopting a REST API form and an interface formulated by adopting a WEB SERVICE form, and in order to improve the safety of interface interaction in industrial application, in the process of executing interface interaction by adopting the two technologies, a signature value and an encryption and decryption mechanism of a certain rule are added besides the formats of appointed request data and response data so as to ensure the safety of interface call. The interface interaction generally adopts GET, POST, PUT, DELETE and other request modes, the formats of request data and response data generally adopt XML, JSON, INI and other formats, the signature mechanism generally orders the request parameters and request heads transmitted by the interface according to a certain rule to form a character string, and encryption is performed by adopting MD5, SHA256 and other algorithms agreed on the two sides to generate a signature value, wherein the encryption and decryption mechanism generally adopts symmetric encryption and decryption, asymmetric encryption and decryption, national encryption and decryption, digital envelope encryption and decryption and other algorithms to execute encryption and decryption of data contents.
In step S204, a first target format, including but not limited to JSON format, XML format, INI format or other custom canonical format, the interaction rules include but are not limited to request protocol, domain name, interface address, request data format, request mode and interface signature mode.
Steps S202 to S206 are described below by specific examples.
In an optional mode, the method for converting the request data into the target data in the first target format required by the target interface based on the interface interaction rule comprises the steps of determining a mapping relation between a first field in the request data and a second field in the response data, extracting the first target format from the interface interaction rule, and converting the request data and the mapping relation into the target data according to the first target format, wherein data values of the target data are assembled according to a node path mode, and preset characters in the node path are used for representing hierarchical relations among the target data fields.
Specifically, a request data assembler in the target engine is utilized to assemble the request data required by the target interface according to the specified specification. The method comprises the steps of encrypting request data and a request data head by using an encryption device through a specified encryption algorithm, assembling the request data by using a format assembler through a first target format (XML, JSON, INI or a self-defined format), and assembling corresponding data values by using a node path.
In the assembly process, matching is performed according to the mapping relation of the data fields of the two interactive sides of the interface, and the structure assembly is completed according to the node path expression.
It should be noted that, the node path expression adopts a preset character "," represents a hierarchical relationship between fields, for example, "x.y.z" represents a z field under a y level under an x level.
The request header assembler is utilized to add custom request header.
In some embodiments of the present application, after obtaining the target data, address information of the target interface needs to be determined from the interface interaction rule.
In an actual application scenario, a protocol setter in the target engine, which designates an interface request mode, and a domain name setter, which designates an interface domain name, may be adopted.
Processing the target data according to the requirements of the target interface, and obtaining the processed target data comprises the following specific steps:
the method comprises the steps of determining the requirements of the target interface, wherein the requirements at least comprise one of encrypting the target data, constructing a signature value for a data value corresponding to the target data, generating an anti-replay value for the data value corresponding to the target data, extracting a corresponding processing mode from the interface interaction rule according to the requirements of the target interface, and processing the target data to obtain the processed target data.
In an alternative manner, in the case that the target interface requires that the target data is encrypted, an encryption rule is selected from the interaction rules to encrypt the target data, for example, a parameter sequencer in a target engine is used to perform sequencing on the request data according to a specified field name ascending order, a field name reverse order or a custom mode, and serialize the sequenced request data into a character string.
Under the condition that the requirement of the target interface is to construct a signature value for a data value corresponding to the target data, an encryption rule is selected from the interaction rule to encrypt the data value corresponding to the target data to obtain a corresponding signature value, for example, a request data body is encrypted by a designated encryption algorithm for a request data head to generate the signature value, and an optional interface signature mode is that after the request data is arranged in ascending order according to a text dictionary sequence, the request data is spliced into a character string form of 'a=xx & b=xx', MD5 encoding is adopted to generate the signature value, and a signature parameter is added in a parameter list to serve as the signature value, and other different modes can be used, which are not repeated herein.
And under the condition that the requirement of the target interface is to generate an anti-replay value for the data value corresponding to the target data, selecting a target algorithm from the interaction rule to generate the corresponding anti-replay value, for example, adopting UUID values, time stamps, snowflake IDs and other algorithms to generate unique values for anti-replay processing.
And sending the processed target data to the target interface through a preset action, and transmitting the processed target data to the target server through the target interface.
The preset actions include GET, PUT, POST, DELETE and the like.
The response data is sent to the source server according to a second target format in the interface interaction rule, and the method specifically comprises the steps of extracting data values corresponding to the target data in the response data according to a mapping relation, completing analysis of the response data according to a node path mode, and sending the response data after analysis to the source server according to the second target format required by the source server in the interface interaction rule.
For example, a format parser in the target engine is used for parsing response data by adopting XML, JSON, INI or a self-defined format to form a grammar tree, a node path is used for extracting corresponding data values, matching is performed according to the mapping relation of data fields of the two interaction sides of an interface in the parsing process, structural parsing is completed according to a node path expression, the node path expression adopts a hierarchy relation between fields, such as 'x.y.z' represents a z field under a y level under the x level, a decryptor in the target engine is used for decrypting response data bodies by adopting a designated decryption algorithm on response data heads, and a structural reconstructor in the target engine is used for packaging the obtained plaintext response data values into a second target format (XML, JSON, INI or a self-defined data structure) and returning.
It should be noted that, the multiple processors in the target engine may each provide an extended method library, for example, an encryptor corresponding to an encryption algorithm library, a decryptor corresponding to a decryption algorithm library, a DES, AES, RSA, SM, a digital envelope encryption and decryption algorithm, a format assembler corresponding to a format assembling method, a XML, JSON, INI, YML and a custom text format generating method, and a signature constructor corresponding to a signature algorithm library, a MD5, SHA256 and a custom signature generating method.
The method in the method library corresponding to each processor is endowed with a unique identification, and the identification is defined in the interface interaction rule and used for matching corresponding processing logic.
The embodiment of the application provides an interface interaction device, as shown in fig. 3, which comprises a receiving module 30, a processing module 32 and a sending module 34, wherein the receiving module is used for receiving request information transmitted by an origin server, the request information at least comprises request data and interface interaction rules, the processing module 32 is used for converting the request data into target data in a first target format required by a target interface based on the interface interaction rules, processing the target data according to the requirements of the target interface to obtain processed target data, sending the processed target data to the origin server through the target interface, and the sending module 34 is used for receiving response data returned by the origin server and sending the response data to the origin server according to a second target format in the interface interaction rules.
The processing module 32 includes a conversion sub-module, an address sub-module and a processing sub-module, wherein the conversion sub-module is configured to determine a mapping relationship between a first field in the request data and a second field in the response data, extract the first target format from the interface interaction rule, and convert the request data and the mapping relationship into the target data according to the first target format, where data values of the target data are assembled according to a node path, and preset characters in the node path are used to represent a hierarchical relationship between the target data fields.
And the address sub-module is used for determining the address information of the target interface from the interface interaction rule.
The processing sub-module is used for determining the requirement of the target interface, wherein the requirement at least comprises one of encrypting the target data, constructing a signature value for a data value corresponding to the target data, generating an anti-replay value for the data value corresponding to the target data, extracting a corresponding processing mode from the interface interaction rule according to the requirement of the target interface, and processing the target data to obtain the processed target data.
The processing sub-module comprises a processing unit and a sending unit, wherein the processing unit is used for selecting an encryption rule from the interaction rule to encrypt the target data when the target interface is required to encrypt the target data, selecting the encryption rule from the interaction rule to encrypt the data value corresponding to the target data to obtain a corresponding signature value when the target interface is required to construct the signature value for the data value corresponding to the target data, and selecting a target algorithm from the interaction rule to generate the corresponding anti-replay value when the target interface is required to generate the anti-replay value for the data value corresponding to the target data.
And the sending unit is used for sending the processed target data to the target interface through a preset action and transmitting the processed target data to the target server through the target interface.
The response module 34 includes a response sub-module, which is configured to extract a data value corresponding to the target data in the response data according to a mapping relationship, complete analysis of the response data according to a node path, and send the response data after the analysis to the source server according to a second target format required by the source server in the interface interaction rule.
According to still another aspect of the embodiment of the present application, there is further provided a nonvolatile storage medium, in which a program is stored, where a device in which the nonvolatile storage medium is controlled to execute the above-described interface interaction method when the program runs.
According to still another aspect of the embodiment of the present application, there is also provided a computer device including a memory and a processor, where the processor is configured to execute a program stored in the memory, and the program executes the interface interaction method described above.
It should be noted that each module in the interface interaction device may be a program module (for example, a set of program instructions for implementing a specific function), or may be a hardware module, and for the latter, it may be expressed in a form, but is not limited to, that each module is expressed in a form of one processor, or the functions of each module are implemented by one processor.
The foregoing embodiment numbers of the present application are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
In the foregoing embodiments of the present application, the descriptions of the embodiments are emphasized, and for a portion of this disclosure that is not described in detail in this embodiment, reference is made to the related descriptions of other embodiments.
In the several embodiments provided in the present application, it should be understood that the disclosed technology may be implemented in other manners. The above-described embodiments of the apparatus are merely exemplary, and the division of units may be a logic function division, and there may be another division manner in actual implementation, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some interfaces, units or modules, or may be in electrical or other forms.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed over a plurality of units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be essentially or a part contributing to the related art or all or part of the technical solution may be embodied in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods of the embodiments of the present application. The storage medium includes a U disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a removable hard disk, a magnetic disk, or an optical disk, etc. which can store the program code.
The foregoing is merely a preferred embodiment of the present application and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present application, which are intended to be comprehended within the scope of the present application.