Business processing method, device, equipment, storage medium and program
By maintaining the identity and storage address of the business interface in the preset file and using the address query code in the business interface, the code maintainability problem caused by URL dispersion is solved, the separation of URL data and interface logic is achieved, and the business is improved Maintainability of the code.
Patent Information
- Application Number
- CN202111148534.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-28
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2041-09-28
AI Technical Summary
In the client's business code, URLs are scattered in multiple locations, resulting in low maintainability of the code and difficult to manage and maintain uniformly.
By maintaining the identification of each service interface and its corresponding storage address in the preset file, and including address query code in the service interface, the separation of URL data and interface logic is achieved, and the storage address is avoided from passing it into the service interface in the form of incoming parameters. This improves the maintainability of the code.
It realizes the unified management of URL data and the separation of interface logic, improves the maintainability of business code, and simplifies the query and maintenance process of URL-related information.
Smart Images

Figure CN114201241B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a business processing method, device, equipment, storage medium and program. Background Art
[0002] Some applications based on the World Wide Web (Web) adopt a client (also called front-end) + server (also called back-end) system architecture. The client can send a business request to the server to obtain business data from the server.
[0003] Usually, a series of application programming interfaces (APIs) are provided on the client side, and the client's business module sends business requests to the server side by calling the API interface. Specifically, a corresponding API interface is written for each business type, and the API interface has input parameters: a uniform resource locator (URL) and a callback function. The URL indicates the storage address of the target data to be obtained on the server side, and the callback function indicates the processing logic for the obtained target data. When the business module needs to process a certain business, it calls the API interface corresponding to the type of the business, and passes the URL and callback function to the API interface to implement business processing.
[0004] However, the inventors found in the process of implementing the present application that in the client's business code, the API interface is usually called wherever a communication with the server is needed, and the URL and callback function are passed to the API interface. This causes the URL to be scattered in the business code, making the code less maintainable. Summary of the invention
[0005] The present application provides a business processing method, apparatus, device, storage medium and program to improve the maintainability of business codes.
[0006] In a first aspect, the present application provides a business processing method, including:
[0007] Obtaining a pending business, where the pending business is used to request to obtain target data from a server;
[0008] Determine a service interface according to the service type of the service to be processed, wherein the service interface includes an address query code;
[0009] According to the address query code and the identifier of the service interface, obtaining a first storage address of the target data on the server in a preset file, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface;
[0010] The target data is obtained from the server according to the first storage address and the service interface.
[0011] In a possible implementation, the service interface includes a request function; and obtaining the target data from the server according to the first storage address and the service interface includes:
[0012] Determine, according to the first storage address, input parameter information corresponding to the request function, the input parameter information including the first storage address;
[0013] According to the input parameter information corresponding to the request function, a request message is sent to the server through the request function, and the target data sent by the server is received.
[0014] In a possible implementation, the request function includes an acquisition function; the first storage address includes a storage path and a data acquisition method; sending a request message to the server through the request function, and receiving the target data sent by the server, includes:
[0015] Obtain the data query conditions corresponding to the business to be processed;
[0016] Determine the address input parameter and configuration information input parameter corresponding to the acquisition function according to the data acquisition method, the storage path and the data query condition;
[0017] In the request function, according to the address input parameter and the configuration information input parameter corresponding to the acquisition function, a request message is sent to the server through the acquisition function, and the target data sent by the server is received.
[0018] In a possible implementation, the data acquisition mode is a first acquisition mode; and according to the data acquisition mode, the storage path, and the data query condition, determining the address input parameter and the configuration information input parameter corresponding to the acquisition function includes:
[0019] Determine the address input parameter according to the data query condition and the storage path, wherein the address input parameter includes the data query condition and the storage path;
[0020] The preset configuration information is determined as the configuration information input parameter.
[0021] In a possible implementation, the data acquisition method is the second acquisition method; determining the address input parameter and the configuration information input parameter corresponding to the request function according to the data acquisition method, the storage path and the data query condition, including:
[0022] Determine the storage path as the address input parameter;
[0023] Obtain preset configuration information, and add the data query condition to the preset configuration information to obtain the configuration information input parameter.
[0024] In a possible implementation, according to the address input parameter and the configuration information input parameter corresponding to the acquisition function, sending a request message to the server through the acquisition function, and receiving the target data sent by the server include:
[0025] The address input parameter and the configuration information input parameter are input into the acquisition function, and the acquisition function is executed to send a request message to the server and receive the target data sent by the server.
[0026] In a possible implementation, the request function further includes a format conversion function and a verification function, and the acquisition function, the format conversion function and the verification function are chain-connected; after receiving the target data, the method further includes:
[0027] In the request function, the target data is format converted by the format conversion function to obtain the data to be verified;
[0028] In the request function, the data to be verified is verified through the format conversion function.
[0029] In a possible implementation, the request function further includes an anomaly detection function, and the verification function and the anomaly detection function are chain-connected; the method further includes:
[0030] In the request function, an exception detection process is performed by the exception detection function.
[0031] In a second aspect, the present application provides a service processing device, including:
[0032] A first acquisition module is used to acquire a pending business, where the pending business is used to request to acquire target data from a server;
[0033] A determination module, used to determine a service interface according to the service type of the service to be processed, wherein the service interface includes an address query code;
[0034] A second acquisition module, configured to acquire, from a preset file, a first storage address of the target data on the server according to the address query code and the identifier of the service interface, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface;
[0035] A third acquisition module is used to acquire the target data from the server according to the first storage address and the service interface.
[0036] In a possible implementation, the business interface includes a request function; and the third acquisition module is specifically used to:
[0037] Determine, according to the first storage address, input parameter information corresponding to the request function, the input parameter information including the first storage address;
[0038] According to the input parameter information corresponding to the request function, a request message is sent to the server through the request function, and the target data sent by the server is received.
[0039] In a possible implementation, the request function includes an acquisition function; the first storage address includes a storage path and a data acquisition method; and the third acquisition module is specifically used to:
[0040] Obtain the data query conditions corresponding to the business to be processed;
[0041] Determine the address input parameter and configuration information input parameter corresponding to the acquisition function according to the data acquisition method, the storage path and the data query condition;
[0042] In the request function, according to the address input parameter and the configuration information input parameter corresponding to the acquisition function, a request message is sent to the server through the acquisition function, and the target data sent by the server is received.
[0043] In a possible implementation, the data acquisition method is a first acquisition method; and the third acquisition module is specifically used for:
[0044] Determine the address input parameter according to the data query condition and the storage path, wherein the address input parameter includes the data query condition and the storage path;
[0045] The preset configuration information is determined as the configuration information input parameter.
[0046] In a possible implementation, the data acquisition method is the second acquisition method; and the third acquisition module is specifically used for:
[0047] Determine the storage path as the address input parameter;
[0048] Obtain preset configuration information, and add the data query condition to the preset configuration information to obtain the configuration information input parameter.
[0049] In a possible implementation, the third acquisition module is specifically used to:
[0050] The address input parameter and the configuration information input parameter are input into the acquisition function, and the acquisition function is executed to send a request message to the server and receive the target data sent by the server.
[0051] In a possible implementation, the request function further includes a format conversion function and a verification function, and the acquisition function, the format conversion function and the verification function are chain-connected; after receiving the target data, the third acquisition module is further used to:
[0052] In the request function, the target data is format converted by the format conversion function to obtain the data to be verified;
[0053] In the request function, the data to be verified is verified through the format conversion function.
[0054] In a possible implementation, the request function further includes an anomaly detection function, and the verification function and the anomaly detection function are chain-connected; and the third acquisition module is further used for:
[0055] In the request function, an exception detection process is performed by the exception detection function.
[0056] In a third aspect, the present application provides an electronic device, comprising: a memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to implement the method as described in any one of the first aspects.
[0057] In a fourth aspect, the present application provides a computer-readable storage medium, comprising: a computer program, wherein when the computer program is executed by a processor, the method as described in any one of the first aspects is implemented.
[0058] In a fifth aspect, the present application provides a computer program product, comprising: a computer program, wherein when the computer program is executed by a processor, the method as described in any one of the first aspects is implemented.
[0059] The present application provides a business processing method, device, equipment, storage medium and program, the method comprising: obtaining a pending business, the pending business is used to request to obtain target data from a server; determining a business interface according to the business type of the pending business, the business interface including an address query code; obtaining a first storage address of the target data on the server in a preset file according to the address query code and the identifier of the business interface, the preset file including identifiers of multiple business interfaces and storage addresses corresponding to the identifiers of each business interface; obtaining the target data from the server according to the first storage address and the business interface. In the present application scheme, by maintaining the identifier of each business interface and its corresponding storage address in a preset file, and including an address query code in the business interface, when calling the business interface, the storage address of the target data on the server can be queried in the preset file through the address query code in the business interface, without having to pass the storage address into the business interface in the form of an input parameter, thereby realizing the separation of URL data and interface logic, facilitating unified management of URL data, and improving the maintainability of business code. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0061] Figure 1 A schematic diagram of a system architecture involved in an embodiment of the present application;
[0062] Figure 2 A schematic diagram of an application scenario of an embodiment of the present application;
[0063] Figure 3 A flowchart of a business processing method provided in an embodiment of the present application;
[0064] Figure 4 A schematic diagram of the process of generating a service interface provided in an embodiment of the present application;
[0065] Figure 5 The file organization diagram of the API module provided in the embodiment of the present application;
[0066] Figure 6 A flowchart of another business processing method provided in an embodiment of the present application;
[0067] Figure 7 A flowchart of another business processing method provided in an embodiment of the present application;
[0068] Figure 8 A schematic diagram of the structure of a service processing device provided in an embodiment of the present application;
[0069] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0070] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0071] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0072] To facilitate understanding, the terms and concepts involved in the embodiments of the present application are first explained.
[0073] (1) Uniform Resource Locator (URL): Each information resource has a unified and unique address on the Internet, which is the URL address. In this embodiment, the URL of the target data refers to the storage address of the target data on the server.
[0074] (2) Callback function: refers to a function that is passed as a parameter. The usage mechanism of the callback function is as follows: define a callback function; the party providing the function implementation registers the function pointer of the callback function to the caller during initialization; when a specific event or condition occurs, the caller uses the function pointer to call the callback function to process the event.
[0075] (3) Ajax: Asynchronous Javascript And XML (Extensible Markup Language, XML) is a technology based on the XMLHttpRequest API to implement network requests. Using Ajax technology, web applications can quickly present incremental updates on the user interface without reloading (refreshing) the entire page, which enables the program to respond to user operations more quickly. Among them, XMLHttpRequest is an object used to interact with the server.
[0076] (4) Promise: It is an asynchronous programming specification that uses the method encapsulated by the promise specification and can support chain calls.
[0077] (5) The fetch method refers to an interface for obtaining resources in the browser. It natively supports the promise specification and obtains resources asynchronously across the network in a simple and reasonable way.
[0078] (6) get and post refer to the two methods of interaction between the client and the server. get refers to requesting data from a specified resource, and post refers to submitting data to be processed by a specified resource.
[0079] Figure 1 Schematic diagram of a system architecture involved in the embodiment of the present application. Figure 1 As shown, the system architecture 100 may include: a terminal device 101, a network 102 and a server 103. The network 102 is used to provide a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired and wireless communication links. The terminal device 101 is a variety of electronic devices that support Internet access, including but not limited to: handheld terminals (such as mobile phones, pads, etc.), laptops, desktop computers, vehicle terminals, smart wearable devices, etc. The terminal device 101 may be installed with a browser or a client of a web application. The server 303 is used to provide services to the terminal device 101, for example, the server may be the server of a web application. The server 303 may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability of traditional physical hosts. The server may also be a server of a distributed system, or a server combined with a blockchain.
[0080] It should be understood that Figure 1 The number of terminal devices, networks, and servers in the embodiment is only for illustration. Any number of terminal devices, networks, and servers may be provided according to actual needs.
[0081] Figure 2 Schematic diagram of an application scenario of an embodiment of the present application. Figure 2 As shown, the terminal device can send a service request message to the server. The service request message is used to request to obtain target data from the server. The terminal device can also receive target data from the server. After receiving the target data, the terminal device processes and / or displays the target data.
[0082] Continue to see Figure 2 The terminal device is provided with an API interface. The process of the terminal device sending a service request message to the server and the terminal device receiving target data from the server can be realized by calling the API interface.
[0083] In the related art, a corresponding API interface is written for each business type. The API interface has input parameters: uniform resource locator (URL) and callback function. The URL indicates the storage address of the target data to be obtained on the server side, and the callback function indicates the processing logic of the obtained target data. When the business module needs to process a certain business, the API interface corresponding to the type of the business is called, and the URL and callback function are passed to the API interface to implement business processing.
[0084] However, the inventors found in the process of implementing the present application that in the client's business code, the API interface is usually called wherever communication with the server is needed, and the URL and callback function are passed to the API interface. In this way, when there are a large number of API interfaces, the URLs are scattered in the business code, making the code maintainability low.
[0085] In order to solve the above technical problems, the embodiments of the present application provide a business processing method, device, equipment, storage medium, and program. In the scheme of the present application, a correspondence between each API interface and each URL is established, and the correspondence is stored in a preset file. When a certain API interface needs to be called, the preset file is queried by code inside the API interface to obtain the corresponding URL. In this way, the separation of URL data and interface logic is achieved, which facilitates the unified management of URL data and improves the maintainability of business code.
[0086] The technical solution of the present application is described in detail with specific embodiments below. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments.
[0087] Figure 3The flowchart of a service processing method provided in an embodiment of the present application is shown in FIG. The method of this embodiment can be executed by a terminal device. Figure 3 As shown, the method of this embodiment includes:
[0088] S301: Obtain a pending business, where the pending business is used to request to obtain target data from a server.
[0089] Exemplarily, the terminal device can obtain pending services according to user operations. For example, if the terminal device detects that the user clicks the login button, the pending service is a login service, which is used to request to obtain the login verification result from the server. If the terminal device detects that the user clicks a certain product, the pending service is to obtain product information, which is used to request to obtain the relevant information of the product from the server.
[0090] Exemplarily, the terminal device may also obtain the pending service according to the current service processing logic. For example, if the current service processing logic requires the use of user information, the pending service is obtaining user information, which is used to request to obtain relevant information of the current user from the server.
[0091] S302: Determine a service interface according to the service type of the service to be processed, wherein the service interface includes an address query code.
[0092] In the embodiment of the present application, different business types correspond to different business interfaces. Therefore, the business interface to be called can be determined according to the business type of the business to be processed.
[0093] S303: According to the address query code and the identifier of the service interface, obtain the first storage address of the target data on the server from a preset file, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface.
[0094] Specifically, multiple business interface identifiers and storage addresses corresponding to the multiple business interface identifiers are predefined in the preset file, wherein the storage address corresponding to each business interface identifier refers to the storage address of the target data required to be acquired by the business interface on the server.
[0095] As an example, the corresponding relationship stored in the preset file is shown in Table 1.
[0096] Table 1
[0097] Business interface identifier Storage address Interface A (e.g. GetUser) URL1 Interface B (e.g. Login) URL2 Interface C (e.g. GetGoods) URL3 …… ……
[0098] In this way, according to the identification of the business interface, the first storage address (i.e., URL address) of the target data required for the business to be processed on the server can be obtained in the preset file through the address query code. For example, if the business interface corresponding to the business to be processed is interface A, the first storage address is determined to be URL1, if the business interface corresponding to the business to be processed is interface B, the first storage address is determined to be URL2, and if the business interface corresponding to the business to be processed is interface C, the first storage address is determined to be URL3.
[0099] By centrally maintaining URL-related information in a preset file, it is easy to query, modify, and maintain URL-related information in scenarios with a large number of business interfaces, thereby improving the maintainability of business codes.
[0100] S304: Acquire the target data from the server according to the first storage address and the service interface.
[0101] Specifically, after the first storage address is determined, the target data can be obtained from the server according to the first storage address in the service interface.
[0102] As an example, the process of a terminal device performing business processing through a business interface is as follows: the terminal device obtains the business to be processed and determines the business interface according to the type of the business to be processed. For example, if the type of the business to be processed is to obtain user information, it is determined that interface A needs to be called. The terminal device calls interface A, which includes an address query code and an interaction code. The address query code can be used to obtain a first storage address (i.e., URL) in a preset file according to the identifier of interface A. The interaction code can be used to obtain target data from a server according to the first storage address.
[0103] The difference between the business interface in the embodiment of the present application and the business interface in the aforementioned related art is that the business interface in the embodiment of the present application no longer uses a URL as an input parameter, but includes an address query code in the business interface. Among them, the address query code can be used to query the preset file to obtain the first storage address (i.e., URL) of the server for the target data required by the business interface. In this way, when the terminal device calls the business interface, there is no need to pass in the URL as an input parameter for the business interface in the calling code. Thereby, it is possible to avoid the URL being scattered in multiple locations of the business code.
[0104] The business processing method provided in the embodiment of the present application includes: obtaining a pending business, wherein the pending business is used to request to obtain target data from a server; determining a business interface according to the business type of the pending business, wherein the business interface includes an address query code; obtaining a first storage address of the target data on the server in a preset file according to the address query code and the identifier of the business interface, wherein the preset file includes identifiers of multiple business interfaces and storage addresses corresponding to the identifiers of each business interface; obtaining the target data from the server according to the first storage address and the business interface. In the embodiment of the present application, by maintaining the identifier of each business interface and its corresponding storage address in a preset file, and including an address query code in the business interface, when calling the business interface, the storage address of the target data on the server can be queried in the preset file through the address query code in the business interface, without having to pass the storage address into the business interface as an input parameter, thereby realizing the separation of URL data and interface logic, facilitating unified management of URL data, and improving the maintainability of business code.
[0105] The above embodiment describes the process of using the service interface to perform service processing. The following describes the generation method of the service interface in conjunction with a specific example.
[0106] Figure 4 The following is a schematic diagram of the process of generating a service interface provided in the embodiment of the present application. Figure 4 As shown in FIG. 1 , the process of generating a business interface includes: encapsulating a request function, generating a preset file, and generating a business interface. The following will introduce each of them.
[0107] S401: Encapsulation request function
[0108] For ease of description, in this embodiment, it is assumed that the name of the request function is request, and the request function can be encapsulated according to the following steps (1) to (4).
[0109] (1) Create a request function.
[0110] This function has three input parameters: url, query and isLoading. Among them, url is the request object type, and the url object includes: storage path path, data acquisition method method and other parameters. Among them, the data acquisition method method can be get method or post method. Query is the data query condition, which is a parameter sent to the server and is used to query the target data in the data stored in the storage path path. isLoading indicates whether to enable the loading prompt effect in the page.
[0111] (2) Set configuration information input parameters
[0112] In this embodiment, the terminal device and the server communicate based on the browser fetch method. The first input parameter of the fetch method is the storage path path, which can be passed in by the input parameter url of the request function. The second input parameter of the fetch method is the configuration information input parameter config. The purpose of this step is to construct the configuration information input parameter config so as to pass it into the fetch method.
[0113] Specifically, declare a config variable in the request function body, and configure basic properties such as mothod, headers, credentials, and body in config. For the mothod property in the config variable, its value is read from the input parameter url.method of the request function; if the value of url.method is an empty string or undefined, set the value of mothod in config to get. For the headers property in the config variable, declare a headers variable, call newHeaders() and assign the return value of new Headers() to the headers variable, and then assign the headers variable to the headers property of config. The value of headers in config will be dynamically set later based on the data acquisition method. For the credentials property in the config variable, set the value of credentials to the include string, which is used to carry cookies when sending requests.
[0114] (3) Processing the data query condition query
[0115] In the request function body, determine the data acquisition method in the url object. If the data acquisition method is get, concatenate the data query condition query to the storage path path of the url object, and the concatenated storage path path is passed as the first input parameter of the fetch function. If the data acquisition method is post, the data query condition query needs to be added to the body attribute of config.
[0116] For example, if the data acquisition method is post, declare a data variable and set the value to an empty array. Then use the Object.keys method to get the array of all query keys, then call the forEach method to traverse, package the query data into a key=value string and push it into the data array, then call the join method and pass in an & character to connect the string and assign it to the body attribute of config. If the value of the url's mothod is the string get, then process the data query condition query into a key=value string and connect it with the & character, add a ? string to the path attribute of the url and splice it in.
[0117] (4) Call the fetch method
[0118] Before calling the fetch method, you need to add a return keyword, which is the key to chaining and combining with other promises. Then pass url.path as the first parameter of the fetch method and config as the second parameter of the fetch method.
[0119] Since fetch itself is a method that supports promise, the return value can be obtained through the .then method chain. The then method takes function A as an input parameter. In function A, you can define a res as a type parameter to receive the target data returned by the server, and call the native json method of res to convert the target data into json format and return it using return.
[0120] Continue to chain call the next then method, which takes function B as a parameter. In function B, res is used as a type parameter to receive the target data passed by the previous then. Then the code value of res is judged to execute the logic of success or failure. Usually, the code value is agreed with the backend. For example, the code of the interface is 0000 to indicate that the result is returned correctly, and a combination of 4 digits other than 0000 indicates that the result is not returned correctly. If it is returned correctly, the data is placed in the data attribute of res. If it is not returned correctly, the prompt information is placed in the msg attribute of res.
[0121] Then, use the if conditional statement to judge the code. If it is 0000, then use return directly to return the data of res; if it is not 0000, call the reject method of Promise and pass in res.
[0122] Continue to chain and add a catch method. The catch method is called when any error occurs, including the above-mentioned active call to the reject method of Promise to trigger. The catch method receives function C as an input parameter, and uses a type parameter err in function C to obtain the relevant data of the error. Use the if conditional statement to determine whether there is specific error prompt data in the msg of err. If so, use a pop-up window to display it to the user. If there is no error prompt data, you can output the default error prompt information, such as "An unknown error occurred, please try again later." Finally, call the reject method of Promise through the keyword return and pass in the msg under err. The use of the return keyword for calling is to provide error information to developers so that developers can further handle the error logic. For example, developers usually need to do a local loading effect, so when they know that there is an error in the server, they can stop loading.
[0123] As an example, the above chain call example is as follows, that is, each function involved in the chain call is connected in sequence by .
[0124] fetch(url.path,config).then(A).then(B).catch(C)
[0125] In this embodiment, by collecting the communication method based on the fetch method, the request function supports chain function calls, and the fetch method can be used in combination with other methods that support promises, greatly enhancing the expansion capability of the code. In addition, the fetch method uses JSON as the main data format for communication, which simplifies the communication steps and makes the implementation more convenient.
[0126] S402: Generate preset file
[0127] In the embodiment of the present application, the preset file stores the identifiers of different service interfaces and the storage address corresponding to the identifier of each service interface. Assume that the preset file is the url.js file.
[0128] (1) Create a url.js file and create a urls object in the url.js file. For each business type, add the identifier of the business interface corresponding to the business type in the urls object. For example, for the business type of obtaining user information, add the identifier of the business interface "getUser" in the urls object, and add the storage path path (for example, URL1) and data acquisition method method (for example, get or post) for "getUser". For the login business type, add the identifier of the business interface "login" in the urls object, and add the storage path path (for example, URL2) and data acquisition method method (for example, get or post) for "login". Of course, in addition to the above-mentioned storage path and data acquisition method, the identifier of each business interface can also have other attributes, which is not limited in this embodiment.
[0129] (2) Define a variable origin in the url.js file, and then assign the server domain name to the variable origin. Use the for in method to traverse the urls object, obtain the value of the storage path of the current active object in the loop, concatenate the domain name origin in front, and then assign it to the path attribute.
[0130] In this way, when adding the storage path attribute to the identifier of each business interface in step (1), only the relative path can be added. By means of the above step (2), domain name information can be uniformly added to each path in url.js, thereby making it easier to maintain the path in the url.js file.
[0131] (3) Use the export default statement to export the urls variable. The exported urls variable can be introduced into other business modules for use.
[0132] It should be noted that there is no order distinction between the above S401 and S402.
[0133] S403: Generate business interface
[0134] In the above S401, the encapsulation of the request function is completed, and in the above S402, the generation of the urls variable is completed. Next, the two can be bound to generate the final business interface for developers to call.
[0135] (1) Create an api.js file and use the import statement to introduce the request method and urls variable. Create an apis variable in the api.js file and assign it an empty object.
[0136] (2) Call the keys method of Object and pass in the urls variable, then call the forEach method in a chained manner, set a type parameter key in the forEach method, and assign a function to it through apis[key]. The function receives the query and isLoading fields as input parameters. This function is also the business interface that is finally exposed to developers. Through the above process, various business interfaces can be generated, such as apis.getUser, apis.login, apis.getGoods, etc.
[0137] Exemplarily, in order to make the use of the business interface more flexible and convenient, the number of input parameters of the business interface can be 0 to 2. Use the if statement inside the business interface to judge the data type of the input parameter. If the data type of the input parameter is object, it means that the caller has passed the data query condition query. In this case, use return to return and call the request method, and pass in urls[k] and query in sequence. If the data type of the input parameter is a boolean value, it means that the caller did not pass the data query condition query, but only passed isLoading. In this case, use return to return and call the request method, and pass in urls[k], {} and isLoading in sequence. If the number of input parameters is 0, call the request method and pass in urls[k].
[0138] By judging the number and data type of the input parameters of the business interface, the input parameters of the request method can be dynamically determined to generate a business interface that meets the developer's calling requirements.
[0139] (3) Use the export default statement to export the apis variable. The exported apis variable can be introduced into the business model for calling.
[0140] For example, when each business module needs to call a business interface, it can import the apis variable through the import statement, and call the corresponding business interface when it needs to communicate with the server. For example, if the terminal device needs to obtain user data, it can call apis.getUser; if the terminal device needs to log in, it can call apis.login. When calling any of the above interfaces, you only need to pass in query and / or isLoading, without passing in the url object.
[0141] Figure 5 The file organization structure diagram of the API module provided in the embodiment of this application. Figure 4The processing process shown generates the API module and the file organization structure in the API module Figure 5 As shown, it includes: req.js, urls.js, and api.js. Among them, the req.js file includes the request function encapsulated in S401. The urls.js file includes the urls object, and the api.js file includes the apis object. The content in the api.js file is the business interface that is finally exposed to the developer.
[0142] In this embodiment, since the request method is encapsulated based on the fetch method, and the fetch method natively supports promise, it can be used in combination with any third-party method with promise, making the method flexible in application and easy to expand.
[0143] The business interface based on ajax technology in the above-mentioned related technologies needs to pass in the url and callback function when in use. When there are many business logics, it is necessary to constantly nest other functions in the callback function, resulting in a very deep nesting of callback functions. For example, the business logic of the user clicking the submit button needs to call the api interface three times, and these three interface calls have data dependencies. For example, the c interface depends on the data of the b interface, and the b interface depends on the data of the a interface. Then, it is necessary to put the b request function in the callback function of the a interface, and put the c request function in the callback function of the b interface. It can be seen that when the interface dependencies are more, such a nested relationship leads to worse code readability. In the embodiment of the present application, by adopting a communication method based on fetch, chain function calls are supported in the request function, and the fetch method can be used in combination with other methods that support promises, which greatly enhances the expansion capability of the code and improves the readability of the code.
[0144] In addition, the business interface based on ajax technology in the above-mentioned related technology is independent, and the callback function is called once for each request. When multiple interfaces are called, the multiple interfaces are independent of each other during execution. For example, when handling errors, developers need to add binding error handling code to each interface separately, so this code is not shared. In the embodiment of the present application, the interface call logic based on the fetch method is encapsulated through the then method, catch method, etc. to reduce code redundancy and improve code readability and maintainability.
[0145] The following is an introduction to the service processing method provided by the present application in conjunction with a more specific embodiment.
[0146] Figure 6 A flowchart of another service processing method provided in an embodiment of the present application. Figure 6 As shown, the method of this embodiment includes:
[0147] S601: Obtain a pending business, where the pending business is used to request to obtain target data from a server.
[0148] S602: Determine a service interface according to the service type of the service to be processed, wherein the service interface includes an address query code and a request function.
[0149] S603: According to the address query code and the identifier of the service interface, obtain the first storage address of the target data on the server from a preset file, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface.
[0150] Optionally, the preset file may be the urls.js file in the above embodiment.
[0151] Optionally, the request function may be the request function in the above embodiment.
[0152] Optionally, the address query code may be urls[k], where k indicates an identifier of a service interface. urls[k] represents the first storage address of the target data in the server.
[0153] S604: Determine input parameter information corresponding to the request function according to the first storage address, where the input parameter information includes the first storage address.
[0154] S605: According to the input parameter information corresponding to the request function, a request message is sent to the server through the request function, and the target data sent by the server is received.
[0155] For example, in the business interface, urls[k] is passed as the first input parameter to the request function, and the request function is executed to send a request message to the server and receive target data from the server.
[0156] Optionally, depending on actual business processing requirements, the input parameter information corresponding to the request function may include other parameters in addition to the first storage address, such as data query conditions (such as query parameters), loading effect prompt parameters (such as isLoading parameters), etc.
[0157] Figure 7 A flowchart of another service processing method provided in an embodiment of the present application is shown below. Figure 7 As shown, the method of this embodiment includes:
[0158] S701: Obtain a pending business, where the pending business is used to request to obtain target data from a server.
[0159] S702: Determine a business interface according to the business type of the business to be processed, wherein the business interface includes an address query code and a request function, wherein the request function includes an acquisition function, a format conversion function, a verification function and an anomaly detection function, and the acquisition function, the format conversion function, the verification function and the anomaly detection function are chain-connected.
[0160] Optionally, the address query code may be urls[k], where k indicates an identifier of a service interface. urls[k] represents the first storage address of the target data in the server.
[0161] Optionally, the request function may be the request function in the above embodiment.
[0162] Optionally, the acquisition function may be the fetch function in the above embodiment.
[0163] Optionally, the format conversion function may be the first then function in the above embodiment.
[0164] Optionally, the verification function may be the second then function in the above embodiment.
[0165] Optionally, the anomaly detection function may be the catch function in the above embodiment.
[0166] Exemplarily, the acquisition function, the format conversion function, the verification function and the anomaly detection function may be chained in the following manner (function parameters are omitted in the following example):
[0167] fetch().then().then().catch()
[0168] S703: According to the address query code and the identifier of the business interface, obtain the first storage address of the target data on the server in a preset file, wherein the first storage address includes a storage path and a data acquisition method; the preset file includes identifiers of multiple business interfaces and the storage address corresponding to the identifier of each business interface.
[0169] The data acquisition method is a first acquisition method or a second acquisition method. The first acquisition method may be get, and the second acquisition method may be post.
[0170] Optionally, the preset file may be the urls.js file in the above embodiment.
[0171] S704: Obtain data query conditions corresponding to the business to be processed.
[0172] The data query condition is used to filter and query the data stored in the first storage address of the server to obtain the target data.
[0173] S705: Determine the address input parameter and configuration information input parameter corresponding to the acquisition function according to the data acquisition method, the storage path and the data query condition.
[0174] The address input parameter refers to the first input parameter path of the fetch function, and the configuration information input parameter refers to the second input parameter config of the fetch function.
[0175] Optionally, if the data acquisition method is the first acquisition method get, the address input parameter is determined according to the data query condition and the storage path, and the address input parameter includes the data query condition and the storage path; and the preset configuration information is determined as the configuration information input parameter.
[0176] For example, the data query condition query is concatenated with the storage path path, and the concatenated result is determined as the address input parameter.
[0177] Optionally, if the data acquisition method is the second acquisition method post, the storage path is determined as the address input parameter; the preset configuration information is obtained, and the data query condition is added to the preset configuration information to obtain the configuration information input parameter.
[0178] For example, add data query conditions to the body attribute of config.
[0179] S706: In the request function, according to the address input parameter and the configuration information input parameter corresponding to the acquisition function, a request message is sent to the server through the acquisition function, and the target data sent by the server is received.
[0180] Optionally, the address input parameter and the configuration information input parameter are input into the acquisition function, and the acquisition function is executed to send a request message to the server and receive the target data sent by the server.
[0181] For example, the address input parameter path and the configuration information input parameter config are used as input parameters of the fetch function, and the fetch function is executed, thereby sending a request message to the server and receiving the target data sent by the server.
[0182] S707: In the request function, the target data is format converted by the format conversion function to obtain data to be verified.
[0183] Exemplarily, the target data is converted into data to be verified in JSON format through the first then function after the fetch function.
[0184] S708: In the request function, verify the data to be verified through the format conversion function.
[0185] Exemplarily, the second then function after the fetch function verifies the data to be verified to determine whether the server returns the data correctly.
[0186] S709: In the request function, perform anomaly detection processing through the anomaly detection function.
[0187] Exemplarily, the exceptions during the execution of the business interface are captured and processed through the catch function.
[0188] It should be understood that Figure 6 and Figure 7 The technical effects of the illustrated embodiment are similar to those of the aforementioned embodiment and will not be elaborated here.
[0189] Figure 8 Schematic diagram of the structure of a service processing device provided in an embodiment of the present application. The device of this embodiment may be in the form of software and / or hardware. Figure 8 As shown, the service processing device 800 provided in this embodiment may include: a first acquisition module 801 , a determination module 802 , a second acquisition module 803 and a third acquisition module 804 .
[0190] The first acquisition module 801 is used to acquire a pending business, where the pending business is used to request to acquire target data from a server;
[0191] A determination module 802, configured to determine a service interface according to a service type of the service to be processed, wherein the service interface includes an address query code;
[0192] A second acquisition module 803 is used to acquire, according to the address query code and the identifier of the service interface, a first storage address of the target data on the server in a preset file, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface;
[0193] The third acquisition module 804 is used to acquire the target data from the server according to the first storage address and the service interface.
[0194] In a possible implementation, the business interface includes a request function; and the third acquisition module 804 is specifically used to:
[0195] Determine, according to the first storage address, input parameter information corresponding to the request function, the input parameter information including the first storage address;
[0196] According to the input parameter information corresponding to the request function, a request message is sent to the server through the request function, and the target data sent by the server is received.
[0197] In a possible implementation, the request function includes an acquisition function; the first storage address includes a storage path and a data acquisition method; and the third acquisition module 804 is specifically used to:
[0198] Obtain the data query conditions corresponding to the business to be processed;
[0199] Determine the address input parameter and configuration information input parameter corresponding to the acquisition function according to the data acquisition method, the storage path and the data query condition;
[0200] In the request function, according to the address input parameter and the configuration information input parameter corresponding to the acquisition function, a request message is sent to the server through the acquisition function, and the target data sent by the server is received.
[0201] In a possible implementation, the data acquisition method is the first acquisition method; the third acquisition module 804 is specifically used for:
[0202] Determine the address input parameter according to the data query condition and the storage path, wherein the address input parameter includes the data query condition and the storage path;
[0203] The preset configuration information is determined as the configuration information input parameter.
[0204] In a possible implementation, the data acquisition method is the second acquisition method; the third acquisition module 804 is specifically used for:
[0205] Determine the storage path as the address input parameter;
[0206] Obtain preset configuration information, and add the data query condition to the preset configuration information to obtain the configuration information input parameter.
[0207] In a possible implementation, the third acquisition module 804 is specifically configured to:
[0208] The address input parameter and the configuration information input parameter are input into the acquisition function, and the acquisition function is executed to send a request message to the server and receive the target data sent by the server.
[0209] In a possible implementation, the request function further includes a format conversion function and a verification function, and the acquisition function, the format conversion function and the verification function are chain-connected; after receiving the target data, the third acquisition module 804 is further used to:
[0210] In the request function, the target data is format converted by the format conversion function to obtain the data to be verified;
[0211] In the request function, the data to be verified is verified through the format conversion function.
[0212] In a possible implementation, the request function further includes an anomaly detection function, and the verification function and the anomaly detection function are chain-connected; and the third acquisition module 804 is further used to:
[0213] In the request function, an exception detection process is performed by the exception detection function.
[0214] The business processing device provided in this embodiment can be used to execute the business processing method provided by any of the above method embodiments. Its implementation principles and technical effects are similar and will not be described in detail here.
[0215] Fig. 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application, and the electronic device may be a terminal device. Fig. 9 As shown, the electronic device 900 provided in this embodiment includes: a processor 901 and a memory 902 .
[0216] The memory 902 is used to store computer programs; the processor 901 is used to execute the computer programs stored in the memory to implement one or more steps of the business processing method in the above embodiment. For details, please refer to the relevant description in the above method embodiment, the implementation principle and technical effect are similar, and this embodiment will not be repeated here.
[0217] Optionally, the memory 902 may be independent or integrated with the processor 901 .
[0218] When the memory 902 is a device independent of the processor 901 , the electronic device 900 may further include: a bus 903 for connecting the memory 902 and the processor 901 .
[0219] An embodiment of the present application also provides a computer-readable storage medium, which includes a computer program. The computer program is used to implement one or more steps in the business processing method provided in any of the above method embodiments. The implementation principle and technical effects are similar and will not be repeated here.
[0220] An embodiment of the present application also provides a chip, including: a memory and a processor, wherein the memory stores a computer program, and the processor runs the computer program to execute one or more steps of the business processing method provided by any of the above method embodiments. The implementation principles and technical effects are similar and will not be repeated here.
[0221] An embodiment of the present application also provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements one or more steps of the business processing method provided by any of the above method embodiments. Its implementation principles and technical effects are similar and will not be repeated here.
[0222] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0223] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0224] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0225] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor (English: processor) to perform some steps of the method described in each embodiment of the present application.
[0226] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the application may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0227] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0228] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0229] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0230] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic device or a main control device.
[0231] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0232] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A business processing method, characterized in that: Applied to terminal equipment, including: Acquire a pending business, where the pending business is used to request to acquire target data from a server; the target data is data corresponding to a corresponding user operation in the pending business; Determine a service interface according to the service type of the service to be processed, wherein the service interface includes an address query code; According to the address query code and the identifier of the service interface, obtaining a first storage address of the target data on the server in a preset file, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface; Acquire the target data from the server according to the first storage address and the service interface; The business interface includes a request function; the request function includes an acquisition function; acquiring the target data from the server according to the first storage address and the business interface, including: Determine input parameter information corresponding to the request function according to the first storage address, the input parameter information includes the first storage address; the first storage address includes a storage path and a data acquisition method; Obtain the data query conditions corresponding to the business to be processed; Determine the address input parameter and configuration information input parameter corresponding to the acquisition function according to the data acquisition method, the storage path and the data query condition; In the request function, according to the address input parameter and the configuration information input parameter corresponding to the acquisition function, a request message is sent to the server through the acquisition function, and the target data sent by the server is received.
2. The method according to claim 1, characterized in that The data acquisition method is a first acquisition method; according to the data acquisition method, the storage path and the data query condition, determining the address input parameter and the configuration information input parameter corresponding to the acquisition function includes: Determine the address input parameter according to the data query condition and the storage path, wherein the address input parameter includes the data query condition and the storage path; The preset configuration information is determined as the configuration information input parameter.
3. The method according to claim 1, characterized in that The data acquisition method is the second acquisition method; according to the data acquisition method, the storage path and the data query condition, determining the address input parameter and the configuration information input parameter corresponding to the request function, including: Determine the storage path as the address input parameter; Obtain preset configuration information, and add the data query condition to the preset configuration information to obtain the configuration information input parameter.
4. The method according to any one of claims 1 to 3, characterized in that: According to the address input parameter and the configuration information input parameter corresponding to the acquisition function, a request message is sent to the server through the acquisition function, and the target data sent by the server is received, including: The address input parameter and the configuration information input parameter are input into the acquisition function, and the acquisition function is executed to send a request message to the server and receive the target data sent by the server.
5. The method according to any one of claims 1 to 3, characterized in that: The request function also includes a format conversion function and a verification function, and the acquisition function, the format conversion function and the verification function are chain-connected; After receiving the target data, the method further includes: In the request function, the target data is format converted by the format conversion function to obtain data to be verified; In the request function, the data to be verified is verified through the format conversion function.
6. The method according to claim 5, characterized in that The request function also includes an anomaly detection function, and the verification function and the anomaly detection function are chain-connected; the method also includes: In the request function, an exception detection process is performed by the exception detection function.
7. A service processing device, characterized in that: include: A first acquisition module, used to acquire a pending business, wherein the pending business is used to request to acquire target data from a server; The target data is data corresponding to the user operation corresponding to the service to be processed; A determination module, used to determine a service interface according to the service type of the service to be processed, wherein the service interface includes an address query code; A second acquisition module, configured to acquire, from a preset file, a first storage address of the target data on the server according to the address query code and the identifier of the service interface, wherein the preset file includes identifiers of multiple service interfaces and a storage address corresponding to the identifier of each service interface; a third acquisition module, configured to acquire the target data from the server according to the first storage address and the service interface; The third acquisition module is specifically used to: determine the input parameter information corresponding to the request function according to the first storage address, the input parameter information includes the first storage address; the business interface includes a request function; the request function includes an acquisition function; the first storage address includes a storage path and a data acquisition method; obtain the data query condition corresponding to the business to be processed; determine the address input parameter and configuration information input parameter corresponding to the acquisition function according to the data acquisition method, the storage path and the data query condition; within the request function, according to the address input parameter and configuration information input parameter corresponding to the acquisition function, send a request message to the server through the acquisition function, and receive the target data sent by the server.
8. An electronic device, characterized in that: include: A memory and a processor, wherein the memory is used to store a computer program, and the processor runs the computer program to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: include: A computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product, characterized in that include: A computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Conversion method and device for dynamic interface, terminal equipment and storage medium
CN108021710A
Interface calling method, storage medium and related equipment
CN111400072A