A method, apparatus, electronic device, and storage medium for converting parameter formats.
By selecting a target template to convert the format of business parameters, the problem of low transmission efficiency caused by differences in data formats between different servers is solved, achieving efficient data transmission and improved code quality.
Patent Information
- Application Number
- CN202211715636.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2042-12-29
AI Technical Summary
Different servers have different data formats, which leads to low data transmission efficiency. Existing technologies involve a lot of code format conversion, resulting in high time costs and affecting transmission efficiency.
By receiving the target interface call request from the server, selecting the target template in the template database, and converting the business parameters according to the target template, a response parameter file is generated without modifying the code.
It improves parameter transmission efficiency, reduces code modification time, and enhances code quality and transmission efficiency.
Smart Images

Figure CN116126321B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data processing, and more particularly to a method, apparatus, electronic device, and storage medium for converting parameter formats. Background Technology
[0002] With the continuous development of computer software technology, different services transmit information through corresponding interfaces on the server side. However, the interfaces and parameter types of different servers are usually different. This can lead to data import and export failures between different servers due to different data formats.
[0003] In related technologies, a large amount of code is used to convert the format of the data to be transmitted. This results in an excessively large amount of code and requires a lot of time to transmit data, thus affecting the efficiency of data transmission. Summary of the Invention
[0004] This invention provides a method, apparatus, electronic device, and storage medium for converting parameter formats, in order to solve the technical problem of low data transmission efficiency.
[0005] To achieve the above objectives, the present invention adopts the following technical solution:
[0006] In a first aspect, the present invention provides a method for converting parameter formats, comprising:
[0007] Receive the target interface call request sent by the first server. The target interface call request carries the business information of the target business and at least one business parameter.
[0008] Based on the business information of the target business, a target template is selected from the template database, which stores multiple preset templates.
[0009] Convert at least one business parameter according to the target template to generate a response parameter file;
[0010] The response parameter file is returned to the first server.
[0011] In this embodiment, a target template is selected based on the business information of the target business, and the business parameters are formatted according to the target template to obtain a response parameter file. In this way, when calling the interface, it is only necessary to select the matching target template from the template database and convert the business parameters into the correct format. No code modification is required, which reduces a lot of time costs, improves code quality, and increases parameter transmission efficiency.
[0012] In one possible implementation, the preset template includes a request parameter template and a response parameter template, and the target template includes a target request parameter template and a target response parameter template. The step of converting at least one business parameter according to the target template to generate a response parameter file includes:
[0013] Convert at least one business parameter according to the target request parameter template to generate a request parameter file;
[0014] Send the request parameter file to the second server;
[0015] Upon receiving the request parameter file on the second server, at least one response parameter is generated;
[0016] At least one response parameter is converted to the target response parameter template to generate a response parameter file.
[0017] In this embodiment, since the target template includes a target request parameter template and a target response parameter template, at least one business parameter needs to be converted into a request parameter file according to the target request parameter template. This request parameter file is then sent to the second server. After receiving the request parameter file, the second server converts at least one response parameter into a response parameter file according to the target response parameter template. This ensures that the received parameter files are compatible with the server, reducing the time wasted due to code modifications and improving parameter transmission efficiency.
[0018] In one possible implementation, the step of converting at least one business parameter according to the target request parameter template to generate a request parameter file includes:
[0019] The target request parameter template is parsed to obtain multiple template nodes;
[0020] For each template node, determine the template node type corresponding to the template node;
[0021] Based on the template node type corresponding to each template node and at least one business parameter, a request parameter file is obtained.
[0022] In this embodiment, the target request parameter template is first parsed to obtain multiple template nodes. Based on the type of each template node and at least one business parameter, the request parameter file is obtained. In this way, the nodes in the template can be accurately matched with the business parameters, reducing the occurrence of parameter matching errors and improving the accuracy of parameter conversion.
[0023] In one possible implementation, obtaining the request parameter file based on the template node type corresponding to each template node and at least one business parameter includes:
[0024] When the template node type is a leaf node, retrieve the business parameters corresponding to the leaf node;
[0025] The business parameters corresponding to the leaf nodes are assembled to obtain the request parameter file.
[0026] In this embodiment, if the template node type is a leaf node, the business parameters corresponding to the leaf node can be directly obtained and assembled to obtain the request parameter file. In this way, the business parameters are only obtained and assembled when the template node type is a leaf node, which reduces the occurrence of parameter assembly errors and improves the accuracy of request parameter file determination.
[0027] In one possible implementation, obtaining the request parameter file based on the template node type corresponding to each template node and at least one business parameter includes:
[0028] If the template node type is an object, query the node parameters corresponding to the object;
[0029] Assemble the node parameters corresponding to the object to obtain the first parameter;
[0030] Based on the first parameter, the object is parsed and returned to the step of determining the template node type corresponding to the template node, until the template node type is determined to be a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated.
[0031] In this embodiment, if the template node type is an object, the node parameters corresponding to the object are queried and assembled for object parsing, until the template node type is a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated. This reduces the occurrence of parameter assembly errors and improves the accuracy of request parameter file determination.
[0032] In one possible implementation, obtaining the request parameter file based on the template node type corresponding to each template node and at least one business parameter includes:
[0033] If the template node type is an array, iterate through the array;
[0034] Given that the array contains objects, assemble the node parameters corresponding to the objects in the array to obtain the second parameter;
[0035] Based on the second parameter, the object is parsed and returned to the step of determining the template node type corresponding to the template node, until the template node type is determined to be a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated.
[0036] In this implementation, if the template node type is an array, the entire array needs to be traversed. If the array contains objects, parameters are assembled and objects are parsed until the template node type is a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated. This reduces the occurrence of parameter assembly errors and improves the accuracy of the request parameter file determination.
[0037] In one possible implementation, the method further includes:
[0038] If the array contains a subarray, assemble the node parameters corresponding to the subarray in the array;
[0039] Treat the subarray as an array and return to the step of traversing the array until the array no longer contains the subarray, at which point the entire traversal process is considered complete.
[0040] In this embodiment, if the array contains subarrays, the node parameters corresponding to the subarrays are assembled, and the subarrays are treated as arrays. The process is then returned to the step of traversing the array until the array no longer contains subarrays, at which point the entire traversal process is considered complete. This reduces the occurrence of parameter assembly errors and improves the accuracy of the request parameter file determination.
[0041] Secondly, the present invention provides a parameter format conversion device, comprising:
[0042] The receiving module is used to receive the target interface call request sent by the first server. The target interface call request carries the business information of the target business and at least one business parameter.
[0043] The selection module is used to select a target template from the template database based on the business information of the target business. The template database stores multiple preset templates.
[0044] The conversion module is used to convert at least one business parameter according to the target template and generate a response parameter file.
[0045] The return module is used to return the response parameter file to the first server.
[0046] In one possible implementation, the preset template includes a request parameter template and a response parameter template, the target template includes a target request parameter template and a target response parameter template, and the conversion module is specifically used for:
[0047] Convert at least one business parameter according to the target request parameter template to generate a request parameter file;
[0048] Send the request parameter file to the second server;
[0049] Upon receiving the request parameter file on the second server, at least one response parameter is generated;
[0050] At least one response parameter is converted to the target response parameter template to generate a response parameter file.
[0051] In one possible implementation, the conversion module is specifically used for:
[0052] The target request parameter template is parsed to obtain multiple template nodes;
[0053] For each template node, determine the template node type corresponding to the template node;
[0054] Based on the template node type corresponding to each template node and at least one business parameter, a request parameter file is obtained.
[0055] In one possible implementation, the conversion module is specifically used for:
[0056] When the template node type is a leaf node, retrieve the business parameters corresponding to the leaf node;
[0057] The business parameters corresponding to the leaf nodes are assembled to obtain the request parameter file.
[0058] In one possible implementation, the conversion module is specifically used for:
[0059] If the template node type is an object, query the node parameters corresponding to the object;
[0060] Assemble the node parameters corresponding to the object to obtain the first parameter;
[0061] Based on the first parameter, the object is parsed and returned to the step of determining the template node type corresponding to the template node, until the template node type is determined to be a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated.
[0062] In one possible implementation, the conversion module is specifically used for:
[0063] If the template node type is an array, iterate through the array;
[0064] Given that the array contains objects, assemble the node parameters corresponding to the objects in the array to obtain the second parameter;
[0065] Based on the second parameter, the object is parsed and returned to the step of determining the template node type corresponding to the template node, until the template node type is determined to be a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated.
[0066] In one possible implementation, the conversion module is specifically used for:
[0067] If the array contains a subarray, assemble the node parameters corresponding to the subarray in the array;
[0068] Treat the subarray as an array and return to the step of traversing the array until the array no longer contains the subarray, at which point the entire traversal process is considered complete.
[0069] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and when the machine-readable instructions are executed by the processor, the parameter format conversion method described in any of the above possible embodiments is performed.
[0070] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the parameter format conversion method described in any of the above possible embodiments.
[0071] For a detailed description of the second to fourth aspects and their various implementations in this application, please refer to the detailed description in the first aspect and its various implementations; and for a detailed description of the beneficial effects of the second to fourth aspects and their various implementations, please refer to the beneficial effect analysis in the first aspect and its various implementations, which will not be repeated here.
[0072] These or other aspects of this application will become more readily apparent in the following description. Attached Figure Description
[0073] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0074] Figure 1 A flowchart illustrating a parameter format conversion method provided in an embodiment of this application;
[0075] Figure 2aThis is a schematic diagram of an interface for displaying multiple preset templates, provided as an embodiment of this application.
[0076] Figure 2b This is a schematic diagram of an interface for template parameters corresponding to a preset template, provided as an embodiment of this application.
[0077] Figure 3 This is a flowchart illustrating a method for generating a response parameter file provided in an embodiment of this application.
[0078] Figure 4 This is a flowchart illustrating a method for format conversion of business parameters provided in an embodiment of this application.
[0079] Figure 5a This is a schematic diagram illustrating a template for displaying target request parameters provided in an embodiment of this application;
[0080] Figure 5b This is a schematic diagram illustrating the node attributes corresponding to template nodes in a target request parameter template, provided as an embodiment of this application.
[0081] Figure 5c This is a schematic diagram illustrating the display of template attributes provided in an embodiment of this application;
[0082] Figure 6 This is a flowchart illustrating a method for generating a request parameter file, provided in an embodiment of this application.
[0083] Figure 7 This is a flowchart illustrating another method for generating a request parameter file provided in an embodiment of this application.
[0084] Figure 8a This is a schematic diagram illustrating a template for displaying target response parameters provided in an embodiment of this application;
[0085] Figure 8b This is a schematic diagram illustrating the node attributes corresponding to template nodes in a target response parameter template, provided as an embodiment of this application.
[0086] Figure 9 A schematic diagram of a parameter format conversion device provided in an embodiment of this application;
[0087] Figure 10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0088] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0089] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, unless otherwise stated, "a plurality of" means two or more.
[0090] Research has found that when importing or exporting data between different servers, data transmission may fail due to different data formats. Related technologies typically involve a large amount of code to convert the format of the data to be transmitted, which results in an excessively large amount of code and requires a significant amount of time for data transmission, thus affecting data transmission efficiency.
[0091] To address the aforementioned issues, this application provides a parameter format conversion method, comprising: receiving a target interface call request sent by a first server, the target interface call request carrying business information of a target business and at least one business parameter; selecting a target template from a template database based on the business information of the target business, the template database storing multiple preset templates; converting at least one business parameter according to the target template to generate a response parameter file; and returning the response parameter file to the first server.
[0092] In this embodiment, a target template is selected based on the business information of the target business, and the business parameters are formatted according to the target template to obtain a response parameter file. Thus, when calling the interface, it is only necessary to select a matching target template from the template database and format the business parameters, without modifying the code, which reduces a lot of time costs, improves code quality, and improves parameter transmission efficiency.
[0093] To facilitate understanding of this embodiment, a parameter format conversion method disclosed in this disclosure will first be described in detail. The execution subject of the parameter format conversion method provided in this disclosure is generally an electronic device with certain computing power, such as a server. The server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data, and artificial intelligence platforms.
[0094] In some possible implementations, the conversion of this parameter format can be achieved by the processor calling computer-readable instructions stored in memory.
[0095] The following describes the parameter format conversion method provided in the embodiments of this disclosure.
[0096] See Figure 1 The diagram shown is a flowchart of a parameter format conversion method provided in an embodiment of this disclosure. The method includes the following steps S101 to S104:
[0097] S101, receive a target interface call request sent by the first server. The target interface call request carries business information of the target business and at least one business parameter.
[0098] Here, the target interface call request refers to the call request sent by the first server to the target interface. It can be understood that the first server is the calling end, and this first server can communicate with the second server to send the call request to the second server. For example, the first server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data, and artificial intelligence platforms.
[0099] For example, the target interface can be an Application Programming Interface (API). An API is a collection of definitions, procedures, and protocols that enable communication between computer software.
[0100] Specifically, the target interface call request carries business information about the target business and at least one business parameter. The business information includes the business type and business name; for example, the business type could be "query," and the business name could be "roleAssume." The business parameter is the business parameter generated by the target business.
[0101] S102, Based on the business information of the target business, select the target template from the template database. The template database stores multiple preset templates.
[0102] Specifically, upon receiving a target interface call request, a target template can be selected from the template database based on the business information of the target service carried in the target interface call request. This template database stores multiple preset templates, each including a request parameter template and a response parameter template. The request parameter template is used to convert the format of the request parameters in the business parameters, and the response parameter template is used to convert the format of the response parameters.
[0103] Accordingly, the preset templates are pre-set by administrators based on the mapping relationships of conversion rules. For example, see... Figure 2a The diagram illustrates an interface for displaying multiple preset templates according to an embodiment of this application. Each preset template includes a template sequence, template name, business type, business name, usage status, and rule ID. For example, taking template sequence 6 as an example, the template name corresponding to template sequence 6 is quan, the business type is query, the business name is roleAssume, the usage status is normal, and the rule ID is 6. The usage status includes normal and abnormal states. If the usage status is normal, it means the template can be used normally; if the usage status is abnormal, it means the template has been deactivated and is unavailable. It should be noted that in this embodiment, one template corresponds to one rule ID, but in practice, multiple templates of different business types can correspond to the same rule ID; the specific implementation is not limited.
[0104] In one possible implementation, in response to a trigger operation on any of a plurality of preset templates, the detailed content corresponding to the triggered preset template is displayed. Specifically, if the administrator clicks... Figure 2a The text identifier "Template Sequence 6" will then display something like this. Figure 2b The detailed page shown includes all template parameters contained in template sequence 6. Administrators can trigger the "delete", "save", or "edit" flags to modify or delete the templates as needed. This allows administrators to modify templates in real time and view template content periodically, providing convenience for administrators.
[0105] For example, if the business type of the target business is query and the business name of the target business is roleAssume, the target template can be determined as the quan template corresponding to template sequence 6 from multiple preset templates in the template database.
[0106] S103, convert at least one business parameter according to the target template to generate a response parameter file.
[0107] Specifically, after determining the target template, the business parameters carried in the target interface call request can be formatted according to the target template to obtain the response parameter file.
[0108] It is understandable that, since the preset template includes both request parameter templates and response parameter templates, and the target template is one of multiple preset templates, the target template includes both a target request parameter template and a target response parameter template. For details, see [link to relevant documentation]. Figure 3 The diagram shown is a flowchart of a method for generating a response parameter file according to an embodiment of this application, including the following steps S1031 to S1034:
[0109] S1031, Convert at least one business parameter according to the target request parameter template to generate a request parameter file.
[0110] Specifically, after determining the target template, at least one business parameter can be formatted according to the target request parameter template included in the target template to generate a request parameter file. It should be noted that the specific method for formatting the business parameters will be described in detail later.
[0111] S1032, send the request parameter file to the second server.
[0112] Specifically, after obtaining the request parameter file, it needs to be sent to the second server. The second server is the called party; for example, it can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud storage, big data, and artificial intelligence platforms.
[0113] S1033, upon receiving the request parameter file on the second server, generate at least one response parameter.
[0114] Specifically, after receiving the request parameter file, the second server will generate at least one response parameter.
[0115] S1034, Convert at least one response parameter according to the target response parameter template to generate a response parameter file.
[0116] Specifically, after generating at least one response parameter, the format of the at least one response parameter can be converted according to the target response parameter template included in the target template to generate a response parameter file. This ensures that the received parameter files are compatible with the server, reducing time wasted due to code modifications and improving parameter transmission efficiency.
[0117] It is understood that the method of format conversion for response parameters is the same as that for business parameters. Therefore, in this embodiment, only the format conversion of business parameters will be described in detail, and the format conversion method for response parameters will not be described in detail.
[0118] S104, return the response parameter file to the first server.
[0119] It is understandable that the calling process between different servers usually involves the calling end sending a call request to the called end, and then the called end generating a response parameter file based on the request parameter file and returning the response parameter file to the calling end. In this way, the complete process from request to response can be realized. Therefore, after generating the response parameter file, the second server needs to return the response parameter file to the first server to complete the entire process from request to response.
[0120] In this embodiment, a target template is selected based on the business information of the target business, and the business parameters are formatted according to the target template to obtain a response parameter file. Thus, when calling the interface, it is only necessary to select a matching target template from the template database and format the business parameters, without modifying the code, which reduces a lot of time costs, improves code quality, and improves parameter transmission efficiency.
[0121] In one possible implementation, see S1031 above. Figure 4 The diagram shown is a flowchart of a method for format conversion of business parameters provided in an embodiment of this application, including the following steps S10311 to S10313:
[0122] S10311, parse the target request parameter template to obtain multiple template nodes.
[0123] Specifically, after obtaining the target request parameter template, it needs to be parsed to obtain multiple template nodes. It can be understood that a template contains multiple template nodes, and the system needs to parse the template to accurately convert the parameter format during parameter transformation.
[0124] For example, see Figure 5aThe diagram shown is a schematic of a target request parameter template provided in an embodiment of this application. The target request parameter template includes multiple template nodes, which can be ROOT (root node), lang (folder), content (content file), queryCommodityPriceForms (query commodity price list), CommodityAttrs (commodity attribute), Node Type (node type), etc.
[0125] Accordingly, in response to a triggering operation on any template node, the node attributes of the triggered template node are displayed, for example, if Figure 5a When the "CommodityAttrs" template node is triggered, it will display something like this: Figure 5b The `CommodityAttrs` node attributes include: node name, node type, value type, data value key, mapping TAG, mapping identifier key, whether required, default, value retrieval script, A2O_KEY, and A2O_VKEY. Specifically, the node name is `CommodityAttrs`, the node type is `OBJ`, the value type is `arrary2obj`, the data value key is `_FD.productPrties`, the mapping TAG is `N`, the requirement is `N`, the A2O_KEY is `propertyCode`, and the A2O_VKEY is `propertyValue`.
[0126] In one possible implementation, the template attributes corresponding to the template node can also be displayed, specifically, such as... Figure 5c The diagram illustrates a display of template attributes provided in an embodiment of this application. The template attributes include a template sequence, rule type, template description, input parameter format, output parameter format, URL address, POST type, method Func, HTTP category, parameter Func, and parameter log. Specifically, the template sequence corresponding to the "CommodityAttrs" template node is 41, the rule type is json, the template description is aliqrypriceRds, the URL address is http: / / 172.29.7.102 / com, the POST type is post, the method Func is httpMethodInvoke, the HTTP category is http, the parameter Func is cmppMethodParam, and the parameter log is INFO. It can be understood that the URL address is the peer's reference address.
[0127] S10312, For each template node, determine the template node type corresponding to the template node.
[0128] Specifically, after obtaining multiple template nodes, it is necessary to determine the template node type corresponding to each template node. Template node types include objects (OBJ), arrays, and leaf nodes.
[0129] S10313. Based on the template node type corresponding to each template node and at least one business parameter, obtain the request parameter file.
[0130] Specifically, after obtaining the template node type corresponding to each template node, a request parameter file can be obtained based on the template node type and at least one business parameter. This allows for precise mapping of nodes in the template to business parameters, reducing parameter matching errors and improving the accuracy of parameter conversion.
[0131] In one possible implementation, see Figure 6 The diagram shown is a flowchart of a method for generating a request parameter file according to an embodiment of this application, including the following steps S201 to S206:
[0132] S201. For each template node, determine the template node type corresponding to the template node; if the template node type is a leaf node, proceed to step S202; if the template node type is an object, proceed to step S204.
[0133] For example, if the template node type is a leaf node, then the business parameters corresponding to the leaf node need to be obtained; if the template node type is an object, then the node parameters corresponding to the object need to be queried.
[0134] S202, if the template node type is a leaf node, obtain the business parameters corresponding to the leaf node.
[0135] Specifically, after determining that the template node type is a leaf node, it is necessary to obtain the business parameters corresponding to the leaf node.
[0136] For example, the business parameters corresponding to the leaf node can be obtained by retrieving the original data. Here, the original data refers to all business parameters contained in the first server. Alternatively, the business parameters corresponding to the leaf node can be obtained by calling an API. They can also be obtained by mapping and parsing data. Furthermore, they can be obtained using a script. Any method that allows the retrieval of the business parameters corresponding to the leaf node is acceptable and is not limited in its specific implementation.
[0137] S203, assemble the business parameters corresponding to the leaf nodes to obtain the request parameter file.
[0138] Specifically, after obtaining the business parameters corresponding to the leaf node, these parameters are assembled to obtain the request parameter file. In this way, business parameters are only obtained and assembled when the template node type is a leaf node, reducing the occurrence of parameter assembly errors and improving the accuracy of request parameter file determination.
[0139] S204, if the template node type is an object, query the node parameters corresponding to the object.
[0140] Specifically, after determining that the template node type is an object, it is necessary to query the node parameters corresponding to that object.
[0141] S205, Assemble the node parameters corresponding to the object to obtain the first parameter.
[0142] Specifically, after retrieving the node parameters corresponding to the object, these node parameters need to be assembled to obtain the first parameter. The first parameter includes the node parameters corresponding to the object.
[0143] S206, parse the object based on the first parameter.
[0144] Specifically, after obtaining the first parameter, the object needs to be parsed based on it. After parsing, the template node type for each template node is redefined until the template node type is a leaf node. Based on the business parameters corresponding to the leaf nodes, a request parameter file is generated. This reduces the occurrence of parameter assembly errors and improves the accuracy of the request parameter file determination.
[0145] For example, objects can be parsed recursively. Recursion involves breaking down a large, complex problem into smaller, similar problems for each subsequent solution. This reduces the amount of code in the program.
[0146] In another possible implementation, see Figure 7 The diagram shown is a flowchart of another method for generating a request parameter file provided in an embodiment of this application, including the following steps S301 to S309:
[0147] S301, For each template node, determine the template node type corresponding to the template node; if the template node type is a leaf node, then execute step S302; if the template node type is an array, then execute step S204.
[0148] For example, if the template node type is a leaf node, then it is necessary to obtain the business parameters corresponding to the leaf node; if the template node type is an array, then it is necessary to traverse the entire array.
[0149] S302, when the template node type is a leaf node, obtain the business parameters corresponding to the leaf node.
[0150] This step and Figure 6 Step S202 is similar and will not be repeated here.
[0151] S303 assembles the business parameters corresponding to the leaf nodes to obtain the request parameter file.
[0152] This step and Figure 6 Step S203 is similar and will not be repeated here.
[0153] S304, when the template node type is an array, traverse the array.
[0154] Specifically, after determining that the template node type is an array, the main task is to traverse the entire array.
[0155] S305, determine the contents of the array; if the array contains subarrays, proceed to step S306; if the array contains objects, proceed to step S308.
[0156] Specifically, during the traversal of the entire array, it is necessary to determine the contents of the array; if the array contains subarrays, the node parameters corresponding to the subarrays in the array need to be assembled; if the array contains objects, the node parameters corresponding to the objects in the array need to be assembled.
[0157] S306, if it is determined that the array contains a subarray, assemble the node parameters in the array that correspond to the subarray.
[0158] Specifically, after determining that the array contains subarrays, it is necessary to assemble the node parameters in the array that correspond to the subarrays.
[0159] S307, treat the subarray as an array.
[0160] Specifically, after assembling the node parameters corresponding to the subarrays in the array, the subarrays are redefined as arrays, and the arrays are traversed again until they no longer contain the subarrays, at which point the entire traversal process ends. This reduces the occurrence of parameter assembly errors and improves the accuracy of determining the request parameter file.
[0161] S308, if it is determined that the array contains an object, assemble the node parameters corresponding to the object in the array to obtain the second parameter.
[0162] Specifically, after determining that the array contains objects, it is necessary to assemble the node parameters corresponding to the objects in the array to obtain the second parameter.
[0163] S309, parse the object based on the second parameter.
[0164] Specifically, after obtaining the second parameter, the object needs to be parsed based on it. After parsing, the template node type for each template node is redefined until the template node type is a leaf node. Based on the business parameters corresponding to the leaf nodes, a request parameter file is generated. This reduces the occurrence of parameter assembly errors and improves the accuracy of the request parameter file determination.
[0165] For example, see Figure 8a The diagram shown is a schematic of a target response parameter template provided in an embodiment of this application. The target response parameter template includes multiple template nodes, which can be ROOT (root node), RSP_DATA (data), moduleResultList (template result list), itemPriceResults (unit price result), originalPrice (original price), totalPrice (total price), etc. RSP represents the response file.
[0166] Accordingly, in response to a triggering operation on any template node, the node attributes of the triggered template node are displayed, for example, if Figure 8a When the "originalPrice" template node is triggered, it will display something like this: Figure 8b The `originalPrice` node has the following attributes: node name, node type, value type, data value key, mapping TAG, mapping identifier key, whether it is required, default value, and value retrieval script. Specifically, the node name is `originalPrice`, the node type is `NODE`, the value type is `string`, the data value key is `_FD.originalPrice`, the mapping TAG is `N`, and whether it is required is `N`.
[0167] The following code example illustrates how to convert parameter formats.
[0168] The request parameters carried by the target API call are as follows:
[0169]
[0170]
[0171] Specifically, the target template can be determined based on the "busiCode" (business code) and "serviceType" (business type) in the request parameters. For example, the target template is shown below:
[0172]
[0173]
[0174] Accordingly, the code for formatting the request parameters based on the target template is shown below:
[0175]
[0176] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0177] Based on the same inventive concept, this disclosure also provides a parameter format conversion device corresponding to the parameter format conversion method. Since the principle of the device in this disclosure for solving the problem is similar to the parameter format conversion method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0178] Reference Figure 9 The diagram shown is a structural schematic of a parameter format conversion device provided in an embodiment of this application. The parameter format conversion device 900 includes:
[0179] The receiving module 901 is used to receive a target interface call request sent by the first server. The target interface call request carries business information of the target business and at least one business parameter.
[0180] The selection module 902 is used to select a target template from the template database based on the business information of the target business. The template database stores multiple preset templates.
[0181] The conversion module 903 is used to convert at least one business parameter according to the target template to generate a response parameter file.
[0182] Return module 904 is used to return the response parameter file to the first server.
[0183] In one possible implementation, the preset template includes a request parameter template and a response parameter template, and the target template includes a target request parameter template and a target response parameter template. The conversion module 903 is specifically used for:
[0184] Convert at least one business parameter according to the target request parameter template to generate a request parameter file;
[0185] Send the request parameter file to the second server;
[0186] Upon receiving the request parameter file on the second server, at least one response parameter is generated;
[0187] At least one response parameter is converted to the target response parameter template to generate a response parameter file.
[0188] In one possible implementation, the conversion module 903 is specifically used for:
[0189] The target request parameter template is parsed to obtain multiple template nodes;
[0190] For each template node, determine the template node type corresponding to the template node;
[0191] Based on the template node type corresponding to each template node and at least one business parameter, a request parameter file is obtained.
[0192] In one possible implementation, the conversion module 903 is specifically used for:
[0193] When the template node type is a leaf node, retrieve the business parameters corresponding to the leaf node;
[0194] The business parameters corresponding to the leaf nodes are assembled to obtain the request parameter file.
[0195] In one possible implementation, the conversion module 903 is specifically used for:
[0196] If the template node type is an object, query the node parameters corresponding to the object;
[0197] Assemble the node parameters corresponding to the object to obtain the first parameter;
[0198] Based on the first parameter, the object is parsed and returned to the step of determining the template node type corresponding to the template node, until the template node type is determined to be a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated.
[0199] In one possible implementation, the conversion module 903 is specifically used for:
[0200] If the template node type is an array, iterate through the array;
[0201] Given that the array contains objects, assemble the node parameters corresponding to the objects in the array to obtain the second parameter;
[0202] Based on the second parameter, the object is parsed and returned to the step of determining the template node type corresponding to the template node, until the template node type is determined to be a leaf node. Based on the business parameters corresponding to the leaf node, a request parameter file is generated.
[0203] In one possible implementation, the conversion module 903 is specifically used for:
[0204] If the array contains a subarray, assemble the node parameters corresponding to the subarray in the array;
[0205] Treat the subarray as an array and return to the step of traversing the array until the array no longer contains the subarray, at which point the entire traversal process is considered complete.
[0206] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0207] Based on the same technical concept, embodiments of this application also provide an electronic device. (Refer to...) Figure 10 The diagram shown is a structural schematic of an electronic device 1000 provided in an embodiment of this application, including a processor 1001, a memory 1002, and a bus 1003. The memory 1002 stores execution instructions and includes a main memory 10021 and an external memory 10022. The main memory 10021, also called internal memory, is used to temporarily store computational data in the processor 1001 and data exchanged with external memory 10022 such as a hard disk. The processor 1001 exchanges data with the external memory 10022 through the main memory 10021.
[0208] In this embodiment, the memory 1002 is specifically used to store application code that executes the solution of this application, and its execution is controlled by the processor 1001. That is, when the electronic device 1000 is running, the processor 1001 communicates with the memory 1002 through the bus 1003, so that the processor 1001 executes the application code stored in the memory 1002, and then executes the method disclosed in any of the foregoing embodiments.
[0209] The memory 1002 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0210] Processor 1001 may be an integrated circuit chip with signal processing capabilities. The aforementioned processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor.
[0211] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 1000. In other embodiments of this application, the electronic device 1000 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
[0212] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the parameter format conversion method described in the above method embodiments. The storage medium can be either volatile or non-volatile computer-readable storage.
[0213] This application also provides a computer program product that carries program code. The instructions included in the program code can be used to execute the parameter format conversion method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0214] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0215] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0216] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0217] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0218] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
[0219] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.
Claims
1. A method of converting a parameter format, characterized by, The method comprises: receiving a target interface call request sent by a first service end, the target interface call request carrying service information of a target service and at least one service parameter; selecting a target template from a template database based on the service information of the target service, the template database storing a plurality of preset templates; the target template comprising a target request parameter template and a target response parameter template, and the preset template comprising a request parameter template and a response parameter template; format-converting the at least one service parameter according to the target template to generate a response parameter file; returning the response parameter file to the first service end; wherein the format-converting the at least one service parameter according to the target template to generate a response parameter file comprises: parsing the target request parameter template to obtain a plurality of template nodes; determining a template node type corresponding to each template node; obtaining a request parameter file based on the template node type corresponding to each template node and the at least one service parameter; sending the request parameter file to a second service end; generating at least one response parameter in a case where the second service end receives the request parameter file; format-converting the at least one response parameter according to the target response parameter template to generate the response parameter file; wherein the obtaining a request parameter file based on the template node type corresponding to each template node and the at least one service parameter comprises: in a case where the template node type is a leaf node, obtaining a service parameter corresponding to the leaf node; assembling the service parameter corresponding to the leaf node to obtain the request parameter file; in a case where the template node type is an object, querying a node parameter corresponding to the object; assembling the node parameter corresponding to the object to obtain a first parameter; based on the first parameter, parsing the object and returning to the step of determining the template node type corresponding to each template node, until it is determined that the template node type is a leaf node, and the request parameter file is generated based on the service parameter corresponding to the leaf node; in a case where the template node type is an array, traversing the array; in a case where it is determined that the array contains an object, assembling parameters of nodes corresponding to the object in the array to obtain a second parameter; based on the second parameter, parsing the object and returning to the step of determining the template node type corresponding to each template node, until it is determined that the template node type is a leaf node, and the request parameter file is generated based on the service parameter corresponding to the leaf node.
2. The method of converting a parameter format according to claim 1, wherein, The method further comprises: in a case where it is determined that the array contains a sub-array, assembling node parameters corresponding to the sub-array in the array; taking the sub-array as the array and returning to the step of traversing the array until it is determined that the array does not contain the sub-array, and determining that the entire traversal process is completed.
3. A conversion apparatus of a parameter format, characterized by, The method comprises: The receiving module is configured to receive a target interface call request sent by a first server, the target interface call request carrying service information of a target service and at least one service parameter; The selecting module is configured to select a target template from a template database based on the service information of the target service, the template database storing a plurality of preset templates; The target template includes a target request parameter template and a target response parameter template, and the preset template includes a request parameter template and a response parameter template; The converting module is configured to convert the at least one service parameter according to the target template to generate a response parameter file; The returning module is configured to return the response parameter file to the first server; The converting module is specifically configured to: parse the target request parameter template to obtain a plurality of template nodes; determine a template node type corresponding to each template node; obtain a request parameter file based on the template node type corresponding to each template node and the at least one service parameter; send the request parameter file to a second server; generate at least one response parameter in a case where the request parameter file is received by the second server; convert the at least one response parameter according to the target response parameter template to generate the response parameter file; The converting module is specifically configured to: in a case where the template node type is a leaf node, obtain a service parameter corresponding to the leaf node; assemble the service parameter corresponding to the leaf node to obtain the request parameter file; in a case where the template node type is an object, query a node parameter corresponding to the object; assemble the node parameter corresponding to the object to obtain a first parameter; based on the first parameter, parse the object, and return to the step of determining the template node type corresponding to each template node until it is determined that the template node type is a leaf node, and the request parameter file is generated based on the service parameter corresponding to the leaf node; in a case where the template node type is an array, traverse the array; in a case where it is determined that the array includes an object, assemble parameters of nodes corresponding to the object in the array to obtain a second parameter; based on the second parameter, parse the object, and return to the step of determining the template node type corresponding to each template node until it is determined that the template node type is a leaf node, and the request parameter file is generated based on the service parameter corresponding to the leaf node.
4. An electronic device, comprising: comprise: a processor, a memory and a bus, the memory storing machine readable instructions executable by the processor, the processor and the memory being in communication through the bus when the electronic device is running, the machine readable instructions being executed by the processor to perform the parameter format conversion method of any one of claims 1 to 2.
5. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, which is executed by the processor to perform the parameter format conversion method of any one of claims 1 to 2.
Citation Information
Patent Citations
Data conversion method and device, storage medium and electronic equipment
CN113779121A
Message processing method and device, electronic equipment and storage medium
CN115242631A