WO2016192556A1 - Interface invoking method, device and terminal - Google Patents

Interface invoking method, device and terminal Download PDF

Info

Publication number
WO2016192556A1
WO2016192556A1 PCT/CN2016/083359 CN2016083359W WO2016192556A1 WO 2016192556 A1 WO2016192556 A1 WO 2016192556A1 CN 2016083359 W CN2016083359 W CN 2016083359W WO 2016192556 A1 WO2016192556 A1 WO 2016192556A1
Authority
WO
WIPO (PCT)
Prior art keywords
interface
parameter
call
identifier
target
Prior art date
Application number
PCT/CN2016/083359
Other languages
French (fr)
Chinese (zh)
Inventor
刘争辉
Original Assignee
北京金山安全软件有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京金山安全软件有限公司 filed Critical 北京金山安全软件有限公司
Publication of WO2016192556A1 publication Critical patent/WO2016192556A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication

Definitions

  • the present invention relates to the field of computer technologies, and in particular, to an interface calling method, apparatus, and terminal.
  • the browser has become one of the necessary application software on the mobile terminal.
  • the browser kernel interprets and renders the webpage syntax.
  • the browser kernel provides some standard interfaces for the client script to use or call. Therefore, by loading the client script in the webpage and interpreting and executing the client script by the browser, the dynamic display effect of the webpage can be realized, and the interaction of the webpage is enhanced. Sex. For example: implement special display effects of page elements, respond to user actions, validate form data, and more.
  • the embodiment of the invention provides an interface calling method, device and terminal, which can improve the development efficiency of the extended interface.
  • an embodiment of the present invention provides an interface calling method, including:
  • the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser;
  • the data type of the output parameter is a preset first data type
  • the method further includes:
  • Formatting the first parameter, and the data type of the converted first parameter is a preset second data type
  • the method further includes:
  • the determining, according to the calling manner and the interface parameter, The first parameter in the input parameters of the target interface function includes:
  • the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
  • the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
  • the request according to the second parameter, The result of the call returned to the client script includes:
  • the second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier
  • the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result, and then The output result is returned to the client script as a result of the call of the interface call request.
  • the method further includes:
  • the callback information is saved in the callback database, where the callback information includes the request identifier and a callback function identified by the preset parameter;
  • Determining the target callback function corresponding to the request identifier including:
  • the callback function specified by the callback information is determined as a target callback function.
  • the second parameter is returned to the call result of the interface call request corresponding to the request identifier to After the client script, the method further includes:
  • the determining, by the interface identifier, the calling manner of the target interface includes:
  • the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
  • the calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
  • an interface calling apparatus including:
  • a receiving module configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser;
  • a mode determining module configured to determine, according to the interface identifier, a calling mode of the target interface
  • a parameter determining module configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier
  • a calling module configured to invoke the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function;
  • An obtaining module configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
  • a returning module configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  • the data type of the output parameter is a preset first data type
  • the device further includes:
  • a first conversion module configured to perform format conversion on the first parameter, and the data type of the converted first parameter is a pre- The second data type set;
  • the second conversion module is configured to perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
  • the parameter determining module is specifically configured to:
  • the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
  • the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
  • the returning module includes:
  • An asynchronous return unit if the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result And returning the output result to the client script as a result of the call of the interface call request.
  • the device further includes:
  • a saving module configured to save the callback information to the callback database if the calling mode is an asynchronous call, where the callback information includes the request identifier and a callback function identified by the preset parameter;
  • the synchronous return unit is specifically configured to:
  • the callback function specified by the callback information is determined as a target callback function.
  • the device further includes:
  • a deleting module configured to delete the callback information corresponding to the request identifier in the callback database.
  • the mode determining module is specifically configured to:
  • the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
  • the calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
  • an embodiment of the present invention provides an interface calling apparatus, including at least one processor and a memory storing instructions executable by at least one processor.
  • At least one processor is configured to: receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser; Determining, by the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier; Calling the target interface function as the input parameter of the target interface function, and acquiring an output parameter returned after calling the target interface function, where the output parameter includes the request identifier and the a second parameter, based on the second parameter, returning a call result of the interface call request corresponding to the request identifier to the client script.
  • an embodiment of the present invention provides an interface calling device, including: an interface registrar, configured to record registration information of an interface, where registration information of the interface includes an interface identifier and a calling mode of the interface, and an interface database for storing Interface information of each interface; a request request database for storing the call request identifier and calling mode; a parameter converter for receiving an interface call request of the client script, the interface call request carrying a target that the client script needs to call An interface identifier and an interface parameter corresponding to the interface, where the target interface is one of the extended interfaces provided by the browser; determining, according to the interface identifier, a calling mode of the target interface; according to the calling mode and the interface parameter, Determining, by the interface proxy, the first parameter in the input parameter of the target interface function corresponding to the interface identifier; the interface proxy is configured to obtain the call information required by the interface call request, where the call information includes a request identifier, an interface identifier, and a first parameter And calling mode; and reconstructing
  • an embodiment of the present invention provides a terminal, including the interface calling device according to the second aspect, the third aspect, or the fourth aspect.
  • an embodiment of the present invention provides a computer readable storage medium having instructions stored therein, and when a processor of a terminal executes the instruction, the terminal executes an interface calling method as described above.
  • an embodiment of the present invention provides a computer program that, when run on a processor, performs the above The interface call method.
  • the interface call request is received, and the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser; Determining, by the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier; Calling the target interface function as the input parameter of the target interface function, and acquiring an output parameter returned after calling the target interface function, where the output parameter includes the request identifier and the a second parameter, based on the second parameter, returning a call result of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when developers develop an extension interface, it is only necessary to develop an interface function corresponding to the extension interface, which can improve the development efficiency of the extension interface.
  • Figure 1a is a schematic diagram of an interface call provided by the prior method
  • FIG. 1 is a schematic flowchart of an interface calling method according to an embodiment of the present invention.
  • Figure 1b is a schematic diagram of an interface call provided in Figure 1;
  • FIG. 2 is another schematic flowchart of an interface calling method according to an embodiment of the present invention.
  • FIG. 3 is a schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention.
  • FIG. 4 is another schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention.
  • FIG. 4a is a schematic structural view of one of the return modules provided in FIG. 4;
  • FIG. 5 is still another schematic structural diagram of an interface calling apparatus according to an embodiment of the present disclosure.
  • FIG. 6 is a schematic structural diagram of a terminal according to an embodiment of the present disclosure.
  • FIG. 7 is still another schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention.
  • the embodiment of the present invention provides an interface calling method, device, and terminal.
  • the interface calling method, device, and terminal provided by the embodiment of the present invention are respectively described in detail in conjunction with FIG.
  • FIG. 1 is a schematic flowchart of a method for invoking an interface according to an embodiment of the present invention.
  • the method may include the following steps.
  • S101 Receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser.
  • the method described in the embodiment of the present invention may be used in a browser on a terminal or a browser-like product.
  • the terminal may be a terminal such as a computer, an IPAD, a mobile phone, or other smart device.
  • the embodiment of the invention does not impose any limitation.
  • the browser provides a large number of interfaces to the webpage for the client script to be loaded in the webpage, and the browser interprets and executes the client script. For example, when the browser receives the interface call request of the client script, the browser runs the interface function corresponding to the target interface specified by the information according to the information carried by the interface call request, thereby implementing the corresponding function. Therefore, in the process of loading the webpage, if the client script in the webpage needs to invoke the extension interface provided by the browser, the browser receives the interface call request.
  • S102 Determine, according to the interface identifier, a calling manner of the target interface.
  • the calling mode of the interface includes a synchronous call and an asynchronous call.
  • the synchronous call is a blocking call, and the caller waits for the callee to return after executing, and belongs to a one-way call;
  • the asynchronous call is a two-way call, similar to The processing mechanism of the message or event, the caller only has an operation request, and returns immediately after the callee finishes executing.
  • the callee actively calls the callback function (callback) provided by the caller to return the execution result to the call. Therefore, asynchronous calls can improve the efficiency of the browser executing web pages.
  • the calling mode of the interface is preset according to the function implemented by the extended interface.
  • the subsequent operations can be performed without the return result of the interface A.
  • the calling mode of the interface A can be set to be asynchronously invoked, thereby the interface parameters of the interface A.
  • There is a parameter indicating the callback function which is independent of the specific function that the interface needs to implement, and is used to return the running result of the interface. For example, if the client script invokes interface B and the return result of interface B is the premise of subsequent operations, the call mode of interface B can be set to synchronous call.
  • the interface information of the extended interface may be recorded in the preset interface database, where the interface information includes an interface identifier and a calling mode, and the interface identifier may be an interface name of the interface function, or may be an interface name.
  • the other identifiers of the one-to-one correspondence are not limited in the embodiment of the present invention; the calling modes include synchronous calling and asynchronous calling.
  • Table 1 is a schematic diagram of storage of an interface database according to an embodiment of the present invention.
  • the call mode corresponding to the interface whose interface identifier is "recordHistory” and “downloadUrl” is called asynchronously, and the interface whose interface identifier is "playAudio" corresponds to the calling mode. Called for synchronization. Therefore, in the embodiment of the present invention, the calling mode of the target interface corresponding to the interface identifier may be queried from the interface database according to the interface identifier carried in the interface call request.
  • the interface parameter carried in the interface call request may include a parameter that identifies a calling mode of the target interface.
  • the first parameter in the interface parameter is used to indicate the calling mode of the target interface.
  • the "1" is used to indicate the synchronous call, and the "0" is used to indicate the asynchronous call.
  • the parameter indicating the calling mode of the target interface can also be The parameter at the other position in the interface parameter indicates that the specific value of the calling mode may be other characters, which is not limited in the embodiment of the present invention.
  • the calling mode of the target interface may be determined according to the specific value of the first parameter in the interface parameter.
  • the calling mode of the target interface corresponding to the interface identifier may be determined to be synchronously invoked; If it is "0", it can be determined that the calling mode corresponding to the interface identifier is asynchronously called.
  • the specific form of the parameter of the calling mode of the calibration target interface is not limited, and the calibration rule may be agreed in advance.
  • the calling mode of the target interface corresponding to the interface identifier may be determined according to the interface parameter carried in the interface call request. To facilitate the description of the subsequent steps, the first embodiment of the present invention is taken as an example.
  • S103 Determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier.
  • the asynchronous call requires the caller to provide a parameter identifying the callback function, and the callee returns the execution result of the target interface function through the callback function after the execution is completed.
  • the synchronous call is the result of the caller returning directly to the target interface function after execution. Therefore, if the calling mode is asynchronous, the interface parameter carried by the interface calling request has a preset parameter that identifies a callback function, and the preset parameter is provided by the caller, and the called party is responsible for calling the preset parameter.
  • the callback function for the identity.
  • the manner in which the client script invokes the interface is normalized, for example, the script indicating the synchronous call and the asynchronous call may be as shown in the code 1.
  • the embodiment of the present invention normalizes the specification of the script call interface, wherein the number of interface parameters (arg1, arg2, etc.) and the data type are set according to actual needs.
  • the last parameter in the interface parameter can be used to represent the parameter of the callback function.
  • the embodiment of the present invention does not limit, and the agreement is reached in advance.
  • the callback function in the asynchronous call is used to notify the client script of the result of the call.
  • the specification of the callback function is also listed in code 1. It accepts an input parameter, and the type of the input parameter can be a common data type supported by the script. For example: Object object.
  • the first parameter in the input parameter of the target interface function corresponding to the target interface may be directly determined according to the interface parameter carried in the interface call request. If the calling mode is asynchronous, the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the interface parameter carried in the interface call request, and the other parameters of the interface parameter except the preset parameter are Set parameters to identify the callback function, and each preset parameter corresponds to a callback function.
  • S104 Call the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function.
  • the request identifier of the interface call request may be determined before the target interface function is invoked by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function. Further, considering that the browser processes the webpage, there may be a case of processing multiple interface call requests at the same time. Therefore, the request identifier is used to calibrate each interface call request of the client script call interface, and the request identifier corresponds to The interface invokes all the information associated with the request, the information including the interface identifier of the interface call request, the interface parameter, the call result, and the like, thereby tracking each interface call request and the call result by the request identifier.
  • determining the request identifier of the interface call request where the request identifier may be automatically allocated when the browser kernel receives the interface call request. It can be seen that a request identifier uniquely aligns an interface call request, and the request identifier is associated with an interface identifier and an interface parameter carried in the interface call request.
  • the design mode of the interface function is normalized, that is, each interface function receives one request identifier as one of the parameters of the input parameter, and the request identifier is also used as one of the parameters of the output parameter.
  • the request identifier is one of the input parameters of the interface function, that is, the input parameter includes the request identifier and the first parameter;
  • the request identifier is one of the parameters of the output parameter of the interface function, that is, the output parameter includes the request identifier and the The second parameter, the request identifier and the second parameter association.
  • the output parameter of the interface function is obtained, and the output parameter includes a request identifier and a second parameter, and the request result identifies the call result of the interface call request by the second parameter associated with the request identifier.
  • the request identifier and the first parameter are used as input parameters of the target interface function corresponding to the target interface, and the target interface function is invoked, that is, the target interface function is run.
  • S105 Acquire an output parameter returned after calling the target interface function, where the output parameter includes the request identifier and the second parameter.
  • the output parameter of the interface function includes a request identifier and a second parameter, where the second parameter is a parameter used by the interface function to implement the interface function and is returned to the client script, and the request identifier is used to identify the second parameter.
  • the parameter is the result of the call to the request of the interface of the client script.
  • an output parameter returned after the target interface function is invoked is obtained, where the output parameter includes the request identifier and the second parameter.
  • the second parameter is directly returned to the calling as the calling result of the interface calling request corresponding to the request identifier.
  • a party wherein the request identifier is associated with the second parameter.
  • the calling mode is an asynchronous call
  • the caller since the caller can continue to perform subsequent operations without waiting for the callee to return the call result, the call result is returned to the caller through the callback function. Therefore, the called party uses the second parameter as an input parameter of the callback function, and returns the call result of the interface call request corresponding to the request identifier to the caller by calling the callback function, wherein the request identifier is associated with the second parameter, and the callback is The function is a preset parameter that is calibrated in the interface parameter carried by the interface request request corresponding to the request identifier. Understandably, the caller is a client-side script and the callee is a browser. Thus, the result of the call of the interface call request is returned to the client script, and the call of the interface is completed.
  • FIG. 1b is a schematic diagram of an interface call provided in FIG.
  • the interface middle layer receives the interface call request, and the interface call request carries the target interface that the client script needs to call.
  • Interface identifier and interface parameters wherein the target interface is an extension provided by the browser Any expansion interface in the port; the target interface function corresponding to the target interface is invoked by the above method, and the running result of the target interface function is returned to the client script as a result of the call of the interface call request.
  • the developer when developing the extended interface, the developer only needs to develop a corresponding interface function for the extended interface, and it is not necessary to design a set of the interface for each extended interface. Method to reduce workload and improve development efficiency.
  • an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser.
  • Determining, according to the interface identifier, a calling mode of the target interface determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • FIG. 2 is another schematic flowchart of an interface calling method according to an embodiment of the present invention.
  • the method may include the following steps.
  • S201 Receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke.
  • S202 Determine, according to the interface identifier, a calling manner of the target interface.
  • the calling interface to be called is determined according to the interface call request, and the calling mode of the target interface is determined, and the calling manner includes a synchronous call and an asynchronous call.
  • the interface information of each interface is pre-stored in the interface database, and the interface information includes an interface identifier and a calling mode.
  • the interface identifier is used to query the interface information corresponding to the interface identifier, and the interface information includes the interface identifier and the calling mode, and the interface information is included in the interface database.
  • the calling mode corresponding to the interface identifier is determined as the calling mode of the target interface.
  • the calling mode of the target interface may also be calibrated in the interface parameter of the interface call request when the client script calls the target interface.
  • the embodiment of the present invention is not limited.
  • determining the calling mode of the target interface may be: querying, according to the interface identifier, the interface information corresponding to the interface identifier from the preset interface database, where the interface information includes the interface identifier and the calling mode; The calling mode corresponding to the interface identifier that is queried in the interface database is determined as the calling mode of the target interface.
  • S203 Determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier.
  • the asynchronous call requires the client script to carry a parameter identifying the callback function in the interface parameter.
  • the parameter identifying the callback function is referred to as a preset parameter.
  • the last parameter in the interface parameter of the asynchronous call may be used to store the preset parameter.
  • the preset parameter may be set to other positions in the interface parameter according to a pre-agreed.
  • the preset parameter that identifies the callback function in the interface parameter is obtained, and the callback information is saved in a preset callback database, where the callback information includes the request identifier and
  • the callback function identified by the preset parameter may further include other information such as an environment variable required to run the callback function, and the embodiment of the present invention is not limited. Therefore, when the subsequent step (for example, step S208) returns the result of the asynchronous call, the target callback function corresponding to the request identifier is queried from the callback database according to the request identifier in the output parameter returned after the target interface function is called.
  • a script representing a synchronous call and an asynchronous call may be as shown in code 1 in the above embodiment.
  • the interface parameters synchronously called are the parameters required by the target interface function corresponding to the target interface, and the preset parameters (callback) used to represent the callback function in the interface parameters of the asynchronous interface are not required in the target interface function corresponding to the target interface.
  • the preset parameters calledback
  • the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the calling mode of the target interface and the interface parameter.
  • the interface parameter carried in the interface call request is determined as the first parameter in the input parameter of the target interface function corresponding to the target interface; if the calling mode is asynchronous, the interface call request is carried.
  • the other parameters of the interface parameter except the preset parameter are determined as the first parameter of the input parameter of the target interface function, wherein the preset parameter is used to identify a callback function, and each preset parameter corresponds to a callback function.
  • S204 Perform format conversion on the first parameter, and the data type of the converted first parameter is a preset second data type.
  • the design of the interface function is standardized, and the interface module is designed using the same specification regardless of the browser kernel.
  • the design specification of the interface function can be as shown in the code 2.
  • the developer When adding the interface function, the developer only needs to implement the corresponding function according to the specification. It is worth noting that the code 2 is merely an example, and the present invention is not limited to this example.
  • id represents the request identifier corresponding to the interface call request
  • kv_map saves the parameters passed in the script
  • the id is a request identifier for tracking the interface call request and the call result;
  • the data type of the first parameter kv_map of the interface function is a preset second data type, and the second data type may be a predefined
  • the KeyValueMap type or the Value type is not limited in the embodiment of the present invention.
  • the embodiment of the present invention takes the second data type as the KeyValueMap type as an example, but it should be noted that the second data type is not limited to the KeyValueMap type.
  • KeyValueMap or Value is a data type, like a storage box, can be used to store a variety of different types of data, such as: integers, floating-point numbers, strings, and so on.
  • the KeyValueMap is a key-value mapping table, and the mapping table stores a one-to-one correspondence between a key and a value.
  • the key can be a number (the order of the parameters) ) or string (the name of the parameter), the value (Value) is the specific value of a key in the parameter.
  • the determined first parameter is format converted, and the data type of the converted first parameter is a preset second data type. That is, before calling the target interface function corresponding to the target interface, it is necessary to convert the first parameter passed in by the script, such as converting the first parameter into a KeyValueMap object.
  • the interface specification provided by the client script may be: function recordHistory(url,date,callback), One parameter indicates the URL of the incoming web page (url, assumed to be http: ⁇ www. Kunststoffao.cn), and the second parameter indicates the time that the incoming access is required (time, assumed to be 2014-07-20 20:00) : 00), the last parameter is a script function object, the parameter is not used as a parameter of the calling interface function, but is used to notify the script after the interface function is successfully operated. Therefore, the first parameter determined according to the interface parameter in step S103 does not include This parameter. After the first parameter is converted, the first parameter of the converted KeyValueMap type is as shown in Table 2. Table 2 is a schematic diagram of a second data type provided by the embodiment of the present invention.
  • the step can be adopted. Converting the first parameter to the same data type parameter, the data type of the input parameter of the interface function is unified. Therefore, developers only need to design an interface function when developing a set of interfaces for the multi-core browser.
  • S205 Call the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function.
  • the request identifier of the interface call request may be determined before the target interface function is invoked by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function.
  • the request identifier of the interface call request may be determined. Considering that in the process of loading the webpage, the browser may handle multiple interface call requests at the same time. Therefore, the request identifier is used to calibrate each interface call request of the client script call interface, and the request identifier corresponds to the corresponding interface call. All the requested information is associated, the information includes the interface identifier of the interface call request, the interface parameter, the call result, and the like, so that each interface call request and the call result are tracked by the request identifier.
  • determining the request identifier of the interface call request where the request identifier may be automatically allocated when the browser kernel receives the interface call request. It can be seen that a request identifier uniquely aligns an interface call request, and the request identifier is associated with an interface identifier and an interface parameter carried in the interface call request.
  • the related information of the interface is saved in a preset interface database, where the interface related information includes an interface identifier and an interface function, and the interface identifier may be an interface name. If the developer has provided the target interface specified by the interface call request, the interface identifier carried in the interface call request can find a unique interface function matching the interface identifier in the preset information base. In the embodiment of the present invention, according to the interface identifier carried in the interface call request, whether the interface function matching the interface identifier exists in the interface database is queried.
  • the browser provides the target interface specified by the interface identifier, and searches for the target interface function according to the request identifier corresponding to the interface call request and the converted first parameter; if not, the browser does not provide the target interface function.
  • the target interface returns the default error message.
  • the request identifier and the first parameter converted in step S204 are used as input parameters of the found target interface function, and the target interface function is invoked.
  • the request identifier and the converted first parameter are substituted into the found target interface function, and the found target interface function is run or executed. Therefore, for different browser kernels, after adopting the embodiment of the present invention, a unified specification call interface function can be adopted, and different browser kernels call the interface in the same manner, the efficiency of calling the interface is high, and the execution efficiency of the webpage is also improved.
  • S206 Obtain an output parameter that is returned after the target interface function is invoked, where the output parameter includes the request identifier and a second parameter, and the data type of the output parameter is a preset first data type.
  • the output parameter returned after the target interface function is invoked is obtained, where the output parameter includes the request identifier and the second parameter, and the data type of the output parameter is a preset first Data class Type, where the second parameter is used to represent the result of the operation of the target interface function.
  • the first data type may be a predefined data type for accepting any type of data, or may be a general data type in a database that is included in the programming language, and the data type may receive data of any data type.
  • the KeyValueMap type or the Value type is not limited in the embodiment of the present invention.
  • the code 2 or the embodiment of the present invention takes the first data type as the Value type as an example, but the embodiment of the present invention does not limit the first data type to the Value type. Therefore, when developers develop extension interfaces for different browser kernels, they only need to design an interface function according to the specification. It is not necessary to design an interface function for different browser kernels, and there is no need to design the interface method corresponding to the interface function. Not only can it reduce development costs, but also improve development efficiency.
  • the data type of the second parameter may be a preset first data type
  • the data type of the output parameter of the interface function is a structure
  • the structure includes a request identifier and a second parameter.
  • S207 Perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
  • the second parameter in the output parameter returned after the acquired target interface function is formatted, and the data type of the converted second parameter is a preset third data type.
  • the third data type may be a pre-defined data structure type for accepting any type of data, or may be a general data type in the client-side scripting language, for example, an Object object.
  • the embodiment of the present invention is not limited.
  • the result of the call returned to the client script is normalized to improve the execution efficiency of the script.
  • the format conversion may not be performed for the second parameter, and the step S208 is performed by skipping this step.
  • the second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier in the output parameter according to the calling mode of the target interface.
  • the calling mode of the target interface is a synchronous call
  • the second parameter or the formatted second parameter is returned to the client script as the calling result of the interface call request corresponding to the request identifier;
  • the calling mode is an asynchronous call
  • the request identifier is determined according to the request identifier.
  • the target target callback function takes the second parameter or the formatted second parameter as an input parameter of the target callback function, runs the target callback function to obtain an output result, and further calls the output result as the interface.
  • the result of the requested call is returned to the client script.
  • the manner of determining the target callback function corresponding to the request identifier may be: querying, according to the request identifier, a callback corresponding to the request identifier from the callback database Information; the callback function specified by the callback information is determined as a target callback function.
  • the callback information is stored with other information for running the target callback function, the current environment variable is set according to the information to ensure that the target callback function is normally run, and the result of the call is notified to the client script.
  • the callback information corresponding to the request identifier in the callback database is deleted. Thereby, the amount of data is reduced, and the query efficiency of the target callback function is improved.
  • an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser.
  • Determining, according to the interface identifier, a calling mode of the target interface determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • the device embodiment of the present invention is the same as the method embodiment of the present invention, and is used to perform the method described in the method embodiment of the present invention.
  • the device embodiment of the present invention only shows a part related to the device embodiment of the present invention.
  • details of the technical details please refer to the description of the method embodiment of the present invention, and details are not described herein again.
  • FIG. 3 is a schematic structural diagram of an interface invoking device according to an embodiment of the present invention.
  • the device may include: a receiving module 101, a mode determining module 102, a parameter determining module 103, and a call.
  • the receiving module 101 is configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that is required to be invoked by the client script, where the target interface is any one of the extended interfaces provided by the browser. extension port.
  • the mode determining module 102 is configured to determine, according to the interface identifier, a calling manner of the target interface.
  • the parameter determining module 103 is configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the target interface.
  • the calling module 104 is configured to invoke the target interface function by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function.
  • the obtaining module 105 is configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter.
  • the returning module 106 is configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  • an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser.
  • Determining, according to the interface identifier, a calling mode of the target interface determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • FIG. 4 is another schematic structural diagram of an interface invoking device according to an embodiment of the present invention.
  • the device may include: a receiving module 201, a mode determining module 202, and a parameter determining module 203.
  • the receiving module 201 is configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser.
  • the mode determining module 202 is configured to determine, according to the interface identifier, a calling manner of the target interface.
  • the parameter determining module 203 is configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the target interface.
  • the calling module 204 is configured to invoke the target interface function by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function.
  • the obtaining module 205 is configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter.
  • the returning module 206 is configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  • the data type of the output parameter is a preset first data type.
  • the first conversion module 207 is configured to perform format conversion on the first parameter, and the data type of the converted first parameter is a preset second data type.
  • the second conversion module 208 is configured to perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
  • the saving module 301 is configured to save the callback information to the callback database if the calling mode is an asynchronous call, where the callback information includes the request identifier and a callback function identified by the preset parameter.
  • the deleting module 302 is configured to delete the callback information corresponding to the request identifier in the callback database.
  • the parameter determining module 203 is specifically configured to:
  • the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
  • the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
  • the return module 206 includes: a synchronous return unit 2061 and an asynchronous return unit 2062, as shown in FIG. 4a, which is a schematic structural diagram of one of the return modules provided in FIG.
  • the synchronization returning unit 2061 if the calling mode is a synchronous call, returning the second parameter to the client script as a result of calling the interface call request corresponding to the request identifier;
  • the asynchronous return unit 2062 if the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output As a result, the output result is returned to the client script as a result of the call of the interface call request.
  • the synchronization return unit 2061 is specifically configured to:
  • the callback function specified by the callback information is determined as a target callback function.
  • the mode determining module 202 is specifically configured to:
  • the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
  • the calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
  • an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser.
  • Determining, according to the interface identifier, a calling mode of the target interface determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • FIG. 5 is a schematic diagram of another structure of an interface calling device according to an embodiment of the present invention.
  • the device may include: a parameter converter 301, an interface proxy 302, and an interface forwarder 303.
  • the interface calling device may further include a callback database 308 and a callback 309.
  • the developer needs to provide the interface registrar 305 with the registration information such as the interface identifier and the calling mode of the interface.
  • the interface identifier is assumed to be the interface name, and the specific implementation of the interface function is provided in the main process.
  • the interface registrar 305 records the registration information, and after the browser creates the rendering process, sends the registration information to the rendering process by means of inter-process communication, and the rendering process caches the registration information in the interface database 306, thereby, the interface database
  • the interface information of each interface is recorded in 306.
  • the storage format of the interface database can be as shown in Table 1.
  • the callback database 308 is configured to store the request identifier of the asynchronous call and the callback function carried in the interface call request calibrated by the request identifier when the calling mode is asynchronous, so that the callback 309 can query the callback database 308 according to the request identifier.
  • the request identifies the corresponding target callback function, and returns the call result to the script by calling the target callback function.
  • the call request database 307 is configured to store the requested identifier and the calling mode, so that the interface notifier 304 obtains the output parameter after the target interface function is completed, and then queries the request database 307 according to the request identifier in the output parameter.
  • the calling mode corresponds to the calling mode.
  • the output parameter is directly sent to the interface proxy 302; if it is an asynchronous call, the output parameter is sent to the callback 309.
  • the interface calling device can be used in a single-process browser or in a multi-process browser, but for convenience of description, a multi-process browser is taken as an example.
  • the browser mostly appears as a multi-process during the running process, and the multi-process includes at least a rendering process and a main process, wherein the rendering process is used to process the rendering of the webpage content, the main process is used to process the user interface and manage all other Process Wait. Since the rendering process can only execute web pages and cannot perform other operations, the implementation of the extended interface (ie, the implementation of the interface function) must be provided in the main process. For convenience of description, assuming that the browser starts the rendering process and the main process during the running process, in the interface calling process of implementing the client script, the rendering process receives an interface call request of the client script, and the interface call request carries the client.
  • the parameter converter 301 receives the interface call request of the client script 201, and the interface call request carries the interface identifier and the interface parameter corresponding to the target interface that the client script 201 needs to call, and the target interface is browsed.
  • the parameter converter 301 queries the interface database 306 for the interface information corresponding to the interface identifier. If the interface does not exist, the interface is incorrectly called, and the default error information is directly returned. If yes, the interface name corresponding to the interface identifier is determined. This interface identifies the calling mode of the corresponding target interface. Further, the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the calling mode and the interface parameter.
  • the parameter converter 301 performs format conversion on the first parameter, and the data type of the converted first parameter is a preset second data type, for example, a KeyValueMap type or a Value type.
  • the interface proxy 302 obtains the call information required for the interface call request from the parameter converter 301, or the parameter converter 301 sends the call information to the interface proxy 302, where the call information includes the request identifier of the interface call request, The interface name, the first parameter, and the calling mode. If the calling mode is asynchronous, the calling information further includes a callback function. Of course, the request identifier may also be determined or generated by the interface proxy 302. Specifically, the embodiment of the present invention is not limited. If the calling mode is an asynchronous call, the interface proxy 302 adds the request identifier and the callback function corresponding to the request identifier to the callback database 308 according to the acquired call information.
  • the target callback function corresponding to the request identifier is queried from the callback database 308 according to the request identifier in the output parameter.
  • the interface proxy 302 sends an interface call request to the interface forwarder 303 located in the main process, which may be as shown in code 4.
  • the code of the client script calling the target interface can be: recordHistory('http: ⁇ www. Kunststoffao.cn' , '2014-07-20 20:00:00', onRecordHistoryDone), we can see that the first parameters include "http: ⁇ www. Kunststoffao.cn", "2014-07-20 20:00:00", callback function
  • the function name is onRecordHistoryDone.
  • the parameter converter 301 receives the interface call request of the client script to call the target interface recordHistory, determines the request identifier of the interface call request, and the calling mode of the target interface; And calling the mode and the interface parameter to determine a first parameter of the input parameter of the target interface function corresponding to the target interface.
  • the parameter converter 303 performs format conversion on the first parameter, and the first parameter after the format conversion can be as shown in Table 2.
  • the interface proxy 302 can add information such as a request identifier (request_id) identifying the interface call request, a callback function object (here, the onRecordHistoryDone function), and an environment variable required to normally execute the callback function to the callback database 308, ensuring that the callback can The result of the call is successfully returned to the script based on the information stored in the callback database 308.
  • the interface proxy 302 reconstructs the interface call request according to the acquired call information, and sends the interface call request to the interface forwarder 303 in the browser main process by means of inter-process communication.
  • the call request of the interface may be like a code. As shown in FIG. 4, the call request of the interface may carry a request identifier request_id, an interface name interface, a first parameter arguments, and a call mode sync, where the data type of the first parameter is a preset second data type.
  • the code 4 describes the call request of the asynchronous interface.
  • the request_id is used to identify the interface call request, the interface indicates that the interface identifier corresponding to the target interface is to be called, and the argument type obtained by the parameter converter 301 is preset.
  • the first parameter of the first data type, sync is used to indicate the calling mode of the target interface.
  • the interface proxy 302 sends the call request of the constructed interface to the interface in the browser main process by means of inter-process communication. Transponder 303. If the calling mode is a synchronous call, after the interface proxy 302 sends a call request to the interface forwarder 303, the interface proxy 302 suspends execution until the browser main process finishes executing and passes the return value. If the calling mode is an asynchronous call, after the interface proxy 302 sends the call request to the interface forwarder 303, the interface proxy 302 returns immediately, so that the rendering process can continue to perform other operations, and the execution efficiency of the webpage is high.
  • the interface forwarder 303 After receiving the call request sent by the interface proxy, the interface forwarder 303 adds the request identifier and the calling manner that identifies the call request to the call request database 307 according to the call information carried in the call request, thereby being located in the main process.
  • the call request database 307 stores the correspondence between each request identifier and the calling mode of the target interface specified by the call request.
  • the interface forwarder 303 queries the interface registrar 305 to query the target interface function corresponding to the interface name, obtains the location of the target interface function 401 corresponding to the target interface, and uses the request identifier request_id and the first parameter argument as the queried query.
  • the input parameter of the target interface function 401 is called, and the implementation of the target interface function may be an asynchronous implementation or a synchronous implementation.
  • the interface function After the interface function is finished, it needs to return the running result, such as whether the operation is successful, the data to be read, etc., and the data is the output parameter of the interface function, and the data type of the output parameter is the preset first data type. Such as KeyValueMap type or Value type.
  • the output parameter is passed to the interface notifier 304, where the output parameter includes the request identifier and the second parameter, and the second parameter is the call result of the interface call request corresponding to the request identifier.
  • the interface notifier 304 looks up the corresponding call request and calling mode in the call request database 307 according to the request identifier.
  • the interface notifier 304 sends the request identifier and the second parameter to the interface proxy 302, so that the interface proxy 302 continues to perform other operations after receiving the output parameter of the target interface function returned by the interface notifier 304.
  • the parameter converter 301 performs format conversion on the second parameter of the output parameter, and the data type of the converted second parameter is a preset third data type, for example, an Object object inside the script, and further, returns a corresponding identifier of the request identifier. The result is called to the script and the synchronous call is completed. After the synchronization call is completed, the corresponding item in the call request database 307 is deleted according to the request identifier, thereby reducing the amount of data and improving the query efficiency.
  • the interface proxy 302 will return to the interface forwarder 303 after sending the call request of the interface, and continue to execute other parts of the script.
  • the return result of the calling interface needs to be returned by calling the callback function specified by the request. Therefore, the interface notifier 304 sends the request identifier and the second parameter to the callback 309 in the rendering process after the asynchronous call is made to the target interface corresponding to the request identifier from the call request database 307 according to the request identifier in the output parameter.
  • the caller 309 uses the request identifier to query the target callback function corresponding to the request identifier from the callback database 308, and at the same time, invokes the parameter converter 301 to format convert the second parameter, and the data type of the converted second parameter is preset.
  • the third data type for example, the Object object of the script, uses the converted second parameter as an input parameter of the target callback function, runs the target callback function provided by the script, and returns the result of the call, and the asynchronous interface call is completed. After the asynchronous call is completed, the corresponding items in the call request database 307 and the callback database 308 are deleted according to the request identifier, thereby reducing the amount of data and improving the query efficiency.
  • an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by a browser.
  • Determining, according to the interface identifier, a calling mode of the target interface determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface;
  • the interface calls the request identifier and the first parameter as input parameters of the target interface function, and invokes the target interface function; and obtains an output parameter returned after calling the target interface function, where the output parameter includes Determining the request identifier and the second parameter; and returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • FIG. 6 is a schematic structural diagram of a terminal according to an embodiment of the present invention.
  • the terminal 10 includes the interface calling device as described above.
  • the terminal may include: a smart phone, a computer, a tablet computer, a notebook computer, a palmtop computer, and a terminal device such as a mobile Internet device (MID) or a PAD.
  • MID mobile Internet device
  • PAD PAD
  • the embodiment of the present invention is not limited.
  • the terminal 10 includes any interface calling device as described above, and the terminal receives an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke.
  • the target interface is one of the extended interfaces provided by the browser; determining the calling mode of the target interface according to the interface identifier; determining the input of the target interface function corresponding to the target interface according to the calling mode and the interface parameter a first parameter of the parameter; calling the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, calling the target interface function; and obtaining an output returned after calling the target interface function a parameter, the output parameter includes the request identifier and the second parameter; and based on the second parameter, returning an invocation result of the interface call request corresponding to the request identifier to the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • FIG. 7 is a schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention, for performing an interface calling method disclosed in an embodiment of the present invention, where the apparatus may include: at least one processor 401, for example, The CPU, at least one network interface 404 or other user interface 403, memory 405, at least one communication bus 402. Communication bus 402 is used to implement connection communication between these components.
  • the user interface 403 can optionally include a USB interface and other standard interfaces and wired interfaces.
  • Network interface 404 can optionally include a Wi-Fi interface as well as other wireless interfaces.
  • the memory 405 may include a high speed RAM memory and may also include a non-volatile memory such as at least one disk memory.
  • the memory 405 can optionally include at least one located far from the foregoing The storage device of the processor 401. As shown in FIG. 7, an operating system 4051 and an application 4052 may be included in the memory 405 as a computer storage medium.
  • the memory 405 stores the following elements, executable modules or data structures, or a subset thereof, or their extension set:
  • An operating system 4051 including various system programs for implementing various basic services and processing hardware-based tasks;
  • the application 4052 includes various setting programs of a data block parameter setting program of the target network data, a partitioning program of the target data block, a comparison program of the target data block and the data block in the database, and a deletion program of the target data block, and the like. To achieve a variety of application services.
  • the processor 401 is configured to invoke a program stored in the memory 405 to perform the following operations:
  • the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser;
  • the data type of the output parameter is a preset first data type
  • the method further includes: performing the following operations:
  • Formatting the first parameter, and the data type of the converted first parameter is a preset second data type
  • the processor 401 performs the obtaining the output parameter returned after the calling of the target interface function, and after the output parameter includes the operation of the request identifier and the second parameter, the method further includes:
  • the processor 401 performs the operation of determining the first parameter of the input parameters of the target interface function according to the calling mode and the interface parameter, including: performing the following operations:
  • the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
  • the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
  • the processor 401 performs the returning, according to the second parameter, a result of calling the interface call request corresponding to the request identifier to the client script, and the following operations are performed:
  • the second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier
  • the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result, and then The output result is returned to the client script as a result of the call of the interface call request.
  • the method further includes:
  • the callback information is saved in the callback database, where the callback information includes the request identifier and a callback function identified by the preset parameter;
  • the processor 401 performs the operation of determining the target callback function corresponding to the request identifier, including performing the following operations:
  • the callback function specified by the callback information is determined as a target callback function.
  • the method further includes:
  • the processor 401 performs an operation of determining a calling manner of the target interface according to the interface identifier, including performing the following operations:
  • the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
  • the calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
  • an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is an extension provided by the browser.
  • Determining, according to the interface identifier, a calling mode of the target interface determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the requested identifier of the interface and the first parameter as input parameters of the target interface function, and calling the target interface function; Obtaining an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter; and returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the Describe the client script.
  • the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
  • modules or units in all the embodiments of the present invention may be implemented by a general-purpose integrated circuit, such as a CPU (Central Processing Unit) or an ASIC (Application Specific Integrated Circuit).
  • a CPU Central Processing Unit
  • ASIC Application Specific Integrated Circuit
  • a "computer-readable medium” can be any apparatus that can contain, store, communicate, propagate, or transport a program for use in an instruction execution system, apparatus, or device, or in conjunction with the instruction execution system, apparatus, or device.
  • a more specific example (non-exhaustive list) of computer readable media includes the following: electrical connections having one or more wires (electrical Sub-device), portable computer case (magnetic device), random access memory (RAM), read only memory (ROM), erasable editable read only memory (EPROM or flash memory), fiber optic device, and portable CD Read only memory (CDROM).
  • the computer readable medium may even be a paper or other suitable medium on which the program can be printed, as it may be optically scanned, for example by paper or other medium, followed by editing, interpretation or, if appropriate, other suitable The method is processed to obtain the program electronically and then stored in computer memory.
  • each functional unit in each embodiment of the present invention may be integrated into one processing module, or each unit may exist physically separately, or two or more units may be integrated into one module.
  • the above integrated modules can be implemented in the form of hardware or in the form of software functional modules.
  • the integrated modules, if implemented in the form of software functional modules and sold or used as stand-alone products, may also be stored in a computer readable storage medium.
  • the above mentioned storage medium may be a read only memory, a magnetic disk or an optical disk or the like.

Abstract

Disclosed in embodiments of the present invention are an interface invoking method and terminal. The method comprises: receiving an interface invoking request, the interface invoking request carrying an interface identifier and an interface parameter corresponding to a target interface required to be invoked by a client script; determining, according to the interface identifier, an invoking mode of the target interface; determining, according to the invoking mode and the interface parameter, a first parameter in input parameters of a target interface function corresponding to the target interface; invoking the target interface function by utilizing a request identifier of the interface invoking request and the first parameter as the input parameters of the target interface function; acquiring output parameters returned after invoking the target interface function, the output parameters comprising the request identifier and a second parameter; and returning, based on the second parameter, an invoking result of the interface invoking request corresponding to the request identifier to the client script. The embodiments of the present invention improve a development efficiency of an expansion interface.

Description

接口调用方法、装置及终端Interface calling method, device and terminal
相关申请的交叉引用Cross-reference to related applications
本申请基于申请号为201510289070.8,申请日为2015年5月29日的中国专利申请提出,并要求该中国专利申请的优先权,该中国专利申请的全部内容在此引入本申请作为参考。The present application is based on a Chinese patent application filed on Jan. 29, 2015, the entire disclosure of which is hereby incorporated by reference.
技术领域Technical field
本发明涉及计算机技术领域,尤其涉及一种接口调用方法、装置及终端。The present invention relates to the field of computer technologies, and in particular, to an interface calling method, apparatus, and terminal.
背景技术Background technique
随着互联网技术的发展,浏览器已成为移动终端上必备的应用软件之一,通过移动终端上的浏览器浏览网页时,浏览器内核对网页语法进行解释并渲染。通常,浏览器内核提供一些标准接口供客户端脚本使用或调用,因此,通过在网页中加载客户端脚本,由浏览器解释执行该客户端脚本,可以实现网页的动态展示效果,增强网页的交互性。例如:实现页面元素的特殊显示效果、响应用户动作、验证表单数据等等。With the development of Internet technology, the browser has become one of the necessary application software on the mobile terminal. When browsing the webpage through the browser on the mobile terminal, the browser kernel interprets and renders the webpage syntax. Generally, the browser kernel provides some standard interfaces for the client script to use or call. Therefore, by loading the client script in the webpage and interpreting and executing the client script by the browser, the dynamic display effect of the webpage can be realized, and the interaction of the webpage is enhanced. Sex. For example: implement special display effects of page elements, respond to user actions, validate form data, and more.
然而,浏览器内核本身提供的标准接口有限,因此,为满足Web网页的开发需求,开发人员需根据需要开发出更多的扩展接口,以供Web网页的客户端脚本调用。目前,由于开发扩展接口的标准不统一,并没有一种统一来处理客户端脚本调用任意扩展接口的接口调用方法,因此,开发人员在开发扩展接口时,不仅需要针对该扩展接口所提供的功能设计一个接口函数,而且还需要针对该扩展接口设计出客户端脚本调用该接口的处理方法。例如:现有的接口开发方法如图1a所示,开发接口A和接口B时,除开发出接口A的接口函数和接口B的接口函数外,还需针对接口A开发一套脚本调用接口A时的调用方法和针对接口B开发一套脚本调用接口B时的调用方法,导致开发效率低。However, the standard interface provided by the browser kernel itself is limited. Therefore, in order to meet the development needs of Web pages, developers need to develop more extension interfaces as needed for client-side scripting of Web pages. At present, because the standards for developing extended interfaces are not uniform, there is no unified interface calling method for handling client-side scripts to call any extended interface. Therefore, when developing an extended interface, developers need not only the functions provided by the extended interface. Design an interface function, and also need to design a processing method for the interface to call the interface for the extended interface. For example, the existing interface development method is shown in Figure 1a. When developing interface A and interface B, in addition to developing the interface function of interface A and the interface function of interface B, it is necessary to develop a script call interface A for interface A. The calling method and the calling method when developing a set of scripts for interface B to invoke interface B result in low development efficiency.
发明内容Summary of the invention
本发明实施例提供一种接口调用方法、装置及终端,可以提高扩展接口的开发效率。The embodiment of the invention provides an interface calling method, device and terminal, which can improve the development efficiency of the extended interface.
第一方面,本发明实施例提供一种接口调用方法,包括:In a first aspect, an embodiment of the present invention provides an interface calling method, including:
接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;Receiving an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser;
根据所述接口标识,确定所述目标接口的调用方式;Determining, according to the interface identifier, a calling manner of the target interface;
根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数 中的第一参数;Determining, according to the calling mode and the interface parameter, an input parameter of a target interface function corresponding to the interface identifier The first parameter in ;
将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, and calling the target interface function;
获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;Obtaining an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。And returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
在第一方面的第一种可能的实现方式中,所述输出参数的数据类型为预设的第一数据类型;In a first possible implementation manner of the first aspect, the data type of the output parameter is a preset first data type;
所述根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数之后,所述方法还包括:After the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the calling mode and the interface parameter, the method further includes:
将所述第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型;Formatting the first parameter, and the data type of the converted first parameter is a preset second data type;
所述获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数之后,所述方法还包括:After the obtaining the output parameter that is returned after the target interface function is invoked, after the output parameter includes the request identifier and the second parameter, the method further includes:
将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。Converting the second parameter into a format, and the data type of the converted second parameter is a preset third data type.
结合第一方面或第一方面的第一种可能的实现方式,在第一方面的第二种可能的实现方式中,所述根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数包括:With reference to the first aspect or the first possible implementation manner of the first aspect, in a second possible implementation manner of the first aspect, the determining, according to the calling manner and the interface parameter, The first parameter in the input parameters of the target interface function includes:
若所述调用方式为同步调用,将所述接口参数确定为所述目标接口函数的输入参数中的第一参数;If the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
若所述调用方式为异步调用,将所述接口参数中除预设参数外的其它参数确定为所述目标接口函数的输入参数中的第一参数,所述预设参数用于标识回调函数。If the calling mode is an asynchronous call, the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
结合第一方面或第一方面的第一种可能的实现方式,在第一方面的第三种可能的实现方式中,所述基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本包括:With reference to the first aspect, or the first possible implementation manner of the first aspect, in a third possible implementation manner of the first aspect, the request, according to the second parameter, The result of the call returned to the client script includes:
若所述调用方式为同步调用,将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本;If the calling mode is a synchronous call, the second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier;
若所述调用方式为异步调用,确定所述请求标识对应的目标回调函数,并将所述第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给所述客户端脚本。If the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result, and then The output result is returned to the client script as a result of the call of the interface call request.
结合第一方面的第三种可能的实现方式,在第一方面的第四种可能的实现方式中,所述 根据所述接口标识,确定所述目标接口的调用方式之后,所述方法还包括:In conjunction with the third possible implementation of the first aspect, in a fourth possible implementation of the first aspect, After determining the calling mode of the target interface according to the interface identifier, the method further includes:
若所述调用方式为异步调用,将回调信息保存至回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数;If the calling mode is an asynchronous call, the callback information is saved in the callback database, where the callback information includes the request identifier and a callback function identified by the preset parameter;
所述确定所述请求标识对应的目标回调函数,包括:Determining the target callback function corresponding to the request identifier, including:
若所述调用方式为异步调用,根据所述请求标识从所述回调数据库中查询所述请求标识对应的回调信息;If the calling mode is an asynchronous call, query the callback information corresponding to the request identifier from the callback database according to the request identifier;
将所述回调信息指定的回调函数确定为目标回调函数。The callback function specified by the callback information is determined as a target callback function.
结合第一方面的第四种可能的实现方式,在第一方面的第五种可能的实现方式中,所述将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本之后,所述方法还包括:In conjunction with the fourth possible implementation of the first aspect, in a fifth possible implementation manner of the first aspect, the second parameter is returned to the call result of the interface call request corresponding to the request identifier to After the client script, the method further includes:
删除所述回调数据库中所述请求标识对应的回调信息。Deleting the callback information corresponding to the request identifier in the callback database.
结合第一方面或第一方面的第一种可能的实现方式,在第一方面的第六种可能的实现方式中,所述根据所述接口标识,确定所述目标接口的调用方式包括:With reference to the first aspect, or the first possible implementation manner of the first aspect, in a sixth possible implementation manner of the first aspect, the determining, by the interface identifier, the calling manner of the target interface includes:
根据所述接口标识,从预设的接口数据库中查询所述接口标识对应的接口信息,所述接口信息包括接口标识和调用方式;Querying, according to the interface identifier, the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
将所述接口数据库中该接口标识对应的调用方式确定为所述目标接口的调用方式。The calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
第二方面,本发明实施例提供一种接口调用装置,包括:In a second aspect, an embodiment of the present invention provides an interface calling apparatus, including:
接收模块,用于接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;a receiving module, configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser;
方式确定模块,用于根据所述接口标识,确定所述目标接口的调用方式;a mode determining module, configured to determine, according to the interface identifier, a calling mode of the target interface;
参数确定模块,用于根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;a parameter determining module, configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier;
调用模块,用于将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;a calling module, configured to invoke the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function;
获取模块,用于获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;An obtaining module, configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
返回模块,用于基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。And a returning module, configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
在第二方面的第一种可能的实现方式中,所述输出参数的数据类型为预设的第一数据类型,所述装置还包括:In a first possible implementation manner of the second aspect, the data type of the output parameter is a preset first data type, and the device further includes:
第一转换模块,用于将所述第一参数进行格式转换,转换后的第一参数的数据类型为预 设的第二数据类型;a first conversion module, configured to perform format conversion on the first parameter, and the data type of the converted first parameter is a pre- The second data type set;
第二转换模块,用于将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。The second conversion module is configured to perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
结合第二方面或第二方面的第一种可能的实现方式,在第二方面的第二种可能的实现方式中,所述参数确定模块具体用于:With reference to the second aspect or the first possible implementation manner of the second aspect, in the second possible implementation manner of the second aspect, the parameter determining module is specifically configured to:
若所述调用方式为同步调用,将所述接口参数确定为所述目标接口函数的输入参数中的第一参数;If the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
若所述调用方式为异步调用,将所述接口参数中除预设参数外的其它参数确定为所述目标接口函数的输入参数中的第一参数,所述预设参数用于标识回调函数。If the calling mode is an asynchronous call, the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
结合第二方面或第二方面的第一种可能的实现方式,在第二方面的第三种可能的实现方式中,所述返回模块包括:In conjunction with the second aspect, or the first possible implementation of the second aspect, in a third possible implementation of the second aspect, the returning module includes:
同步返回单元,若所述调用方式为同步调用,将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本;Synchronizing the returning unit, if the calling mode is a synchronous call, returning the second parameter to the client script as a result of calling the interface call request corresponding to the request identifier;
异步返回单元,若所述调用方式为异步调用,确定所述请求标识对应的目标回调函数,并将所述第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给所述客户端脚本。An asynchronous return unit, if the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result And returning the output result to the client script as a result of the call of the interface call request.
结合第二方面的第三种可能的实现方式,在第二方面的第四种可能的实现方式中,所述装置还包括:In conjunction with the third possible implementation of the second aspect, in a fourth possible implementation of the second aspect, the device further includes:
保存模块,用于若所述调用方式为异步调用,将回调信息保存至回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数;a saving module, configured to save the callback information to the callback database if the calling mode is an asynchronous call, where the callback information includes the request identifier and a callback function identified by the preset parameter;
所述同步返回单元具体用于:The synchronous return unit is specifically configured to:
若所述调用方式为异步调用,根据所述请求标识从所述回调数据库中查询所述请求标识对应的回调信息;If the calling mode is an asynchronous call, query the callback information corresponding to the request identifier from the callback database according to the request identifier;
将所述回调信息指定的回调函数确定为目标回调函数。The callback function specified by the callback information is determined as a target callback function.
结合第二方面的第四种可能的实现方式,在第二方面的第五种可能的实现方式中,所述装置还包括:In conjunction with the fourth possible implementation of the second aspect, in a fifth possible implementation of the second aspect, the device further includes:
删除模块,用于删除所述回调数据库中所述请求标识对应的回调信息。And a deleting module, configured to delete the callback information corresponding to the request identifier in the callback database.
结合第二方面或第二方面的第五种可能的实现方式,在第二方面的第六种可能的实现方式中,所述方式确定模块具体用于:With reference to the second aspect, or the fifth possible implementation manner of the second aspect, in the sixth possible implementation manner of the second aspect, the mode determining module is specifically configured to:
根据所述接口标识,从预设的接口数据库中查询所述接口标识对应的接口信息,所述接口信息包括接口标识和调用方式; Querying, according to the interface identifier, the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
将所述接口数据库中该接口标识对应的调用方式确定为所述目标接口的调用方式。The calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
第三方面,本发明实施例提供一种接口调用装置,包括至少一个处理器和存储至少一个处理器可执行的指令的存储器。至少一个处理器用于:接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定所述目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。In a third aspect, an embodiment of the present invention provides an interface calling apparatus, including at least one processor and a memory storing instructions executable by at least one processor. At least one processor is configured to: receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser; Determining, by the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier; Calling the target interface function as the input parameter of the target interface function, and acquiring an output parameter returned after calling the target interface function, where the output parameter includes the request identifier and the a second parameter, based on the second parameter, returning a call result of the interface call request corresponding to the request identifier to the client script.
第四方面,本发明实施例提供一种接口调用装置,包括:接口注册器,用于记录接口的注册信息,所述接口的注册信息包括接口的接口标识和调用方式;接口数据库,用于存储各个接口的接口信息;调用请求数据库,用于存储调用的请求标识和调用方式;参数转换器,用于接收客户端脚本的接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定所述目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;接口代理,用于获取所述接口调用请求所需的调用信息,所述调用信息包括请求标识、接口标识、第一参数和调用方式;并且根据获取到的所述调用信息重构接口调用请求;接口转发器,接收所述接口代理发送的重构的所述接口调用请求;将所述接口调用请求中的请求标识和调用方式添加至所述调用请求数据库;根据所述接口标识查询所述接口注册器以获取所述接口标识对应的目标接口函数,获取所述目标接口对应的目标接口函数的位置,将所述请求标识和第一参数作为查询到的目标接口函数的输入参数,调用所述目标接口函数;接口通知器,用于获取目标接口函数运行完毕后的输出参数,所述输出参数包括所述请求标识和第二参数,所述第二参数为所述请求标识对应的接口调用请求的调用结果;根据所述请求标识在所述调用请求数据库中查找对应的调用请求和调用方式;以及若所述调用方式为同步调用,将所述输出参数发送给所述接口代理In a fourth aspect, an embodiment of the present invention provides an interface calling device, including: an interface registrar, configured to record registration information of an interface, where registration information of the interface includes an interface identifier and a calling mode of the interface, and an interface database for storing Interface information of each interface; a request request database for storing the call request identifier and calling mode; a parameter converter for receiving an interface call request of the client script, the interface call request carrying a target that the client script needs to call An interface identifier and an interface parameter corresponding to the interface, where the target interface is one of the extended interfaces provided by the browser; determining, according to the interface identifier, a calling mode of the target interface; according to the calling mode and the interface parameter, Determining, by the interface proxy, the first parameter in the input parameter of the target interface function corresponding to the interface identifier; the interface proxy is configured to obtain the call information required by the interface call request, where the call information includes a request identifier, an interface identifier, and a first parameter And calling mode; and reconstructing the interface according to the obtained call information Receiving, by the interface forwarder, the reconstructed interface call request sent by the interface proxy; adding a request identifier and a calling manner in the interface call request to the call request database; and querying according to the interface identifier Obtaining, by the interface registrar, a target interface function corresponding to the interface identifier, acquiring a location of a target interface function corresponding to the target interface, and using the request identifier and the first parameter as input parameters of the queried target interface function, Calling the target interface function; the interface notifier is configured to obtain an output parameter after the target interface function is completed, the output parameter includes the request identifier and the second parameter, and the second parameter is corresponding to the request identifier The result of the call of the interface call request; searching for the corresponding call request and the calling mode in the call request database according to the request identifier; and sending the output parameter to the interface proxy if the calling mode is a synchronous call
第五方面,本发明实施例提供一种终端,其特征在于,包括如第二方面、第三方面或第四方面所述的接口调用装置。According to a fifth aspect, an embodiment of the present invention provides a terminal, including the interface calling device according to the second aspect, the third aspect, or the fourth aspect.
第六方面,本发明实施例提供一种计算机可读存储介质,具有存储于其中的指令,当终端的处理器执行该指令时,终端执行如上所述的接口调用方法。In a sixth aspect, an embodiment of the present invention provides a computer readable storage medium having instructions stored therein, and when a processor of a terminal executes the instruction, the terminal executes an interface calling method as described above.
第七方面,本发明实施例提供一种计算机程序,当其在处理器上运行时,执行如上所述 的接口调用方法。In a seventh aspect, an embodiment of the present invention provides a computer program that, when run on a processor, performs the above The interface call method.
本发明实施例中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定所述目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,可以提高扩展接口的开发效率。In the embodiment of the present invention, the interface call request is received, and the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser; Determining, by the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier; Calling the target interface function as the input parameter of the target interface function, and acquiring an output parameter returned after calling the target interface function, where the output parameter includes the request identifier and the a second parameter, based on the second parameter, returning a call result of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when developers develop an extension interface, it is only necessary to develop an interface function corresponding to the extension interface, which can improve the development efficiency of the extension interface.
附图说明DRAWINGS
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly described below. It is obvious that the drawings in the following description are some embodiments of the present invention, Those skilled in the art can also obtain other drawings based on these drawings without paying any creative work.
图1a是现有方法提供的一种接口调用的示意图;Figure 1a is a schematic diagram of an interface call provided by the prior method;
图1是本发明实施例提供的一种接口调用方法的流程示意图;1 is a schematic flowchart of an interface calling method according to an embodiment of the present invention;
图1b是图1提供的一种接口调用的示意图;Figure 1b is a schematic diagram of an interface call provided in Figure 1;
图2是本发明实施例提供的一种接口调用方法的另一流程示意图;2 is another schematic flowchart of an interface calling method according to an embodiment of the present invention;
图3是本发明实施例提供的一种接口调用装置的结构示意图;3 is a schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention;
图4是本发明实施例提供的一种接口调用装置的另一结构示意图;4 is another schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention;
图4a是图4提供的其中一种返回模块的结构示意图;4a is a schematic structural view of one of the return modules provided in FIG. 4;
图5是本发明实施例提供的一种接口调用装置的又一结构示意图;FIG. 5 is still another schematic structural diagram of an interface calling apparatus according to an embodiment of the present disclosure;
图6是本发明实施例提供的一种终端的结构示意图;FIG. 6 is a schematic structural diagram of a terminal according to an embodiment of the present disclosure;
图7是本发明实施例提供的一种接口调用装置的再一结构示意图。FIG. 7 is still another schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention.
具体实施方式detailed description
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅是本发明的一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例, 都属于本发明保护的范围。The technical solutions in the embodiments of the present invention are clearly and completely described in the following with reference to the accompanying drawings in the embodiments of the present invention. It is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts, All fall within the scope of protection of the present invention.
本发明实施例提供了一种接口调用方法、装置及终端,下面将结合附图1-附图7对本发明实施例提供的一种接口调用方法、装置及终端分别进行详细介绍。The embodiment of the present invention provides an interface calling method, device, and terminal. The interface calling method, device, and terminal provided by the embodiment of the present invention are respectively described in detail in conjunction with FIG.
请参见图1,图1是本发明实施例提供的一种接口调用方法的流程示意图,在本发明实施例中,该方法可以包括以下步骤。Referring to FIG. 1, FIG. 1 is a schematic flowchart of a method for invoking an interface according to an embodiment of the present invention. In the embodiment of the present invention, the method may include the following steps.
S101:接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一。S101: Receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser.
在本发明实施例中所描述的方法可以用于终端上的浏览器或类似于浏览器的产品中,所述终端可以是计算机、IPAD、手机等终端,也可以是其它智能设备,具体的,本发明实施例不作任何限制。The method described in the embodiment of the present invention may be used in a browser on a terminal or a browser-like product. The terminal may be a terminal such as a computer, an IPAD, a mobile phone, or other smart device. Specifically, The embodiment of the invention does not impose any limitation.
通常,为丰富网页的动态展示效果,增强网页与用户的交互性,浏览器向网页提供了大量接口,供网页中加载的客户端脚本调用,浏览器解释、执行该客户端脚本。例如:浏览器接收到客户端脚本的接口调用请求时,根据该接口调用请求携带的信息运行该信息所指定的目标接口对应的接口函数,从而实现相应的功能。因此,浏览器在加载网页的过程中,若网页中的客户端脚本需要调用浏览器提供的扩展接口,则接收接口调用请求。Generally, in order to enrich the dynamic display effect of the webpage and enhance the interaction between the webpage and the user, the browser provides a large number of interfaces to the webpage for the client script to be loaded in the webpage, and the browser interprets and executes the client script. For example, when the browser receives the interface call request of the client script, the browser runs the interface function corresponding to the target interface specified by the information according to the information carried by the interface call request, thereby implementing the corresponding function. Therefore, in the process of loading the webpage, if the client script in the webpage needs to invoke the extension interface provided by the browser, the browser receives the interface call request.
S102:根据所述接口标识,确定所述目标接口的调用方式。S102: Determine, according to the interface identifier, a calling manner of the target interface.
接口的调用方式包括同步调用和异步调用,其中,同步调用是一种阻塞式调用,调用方要等待被调用方执行完毕后才返回,属于单向调用;异步调用是一种双向调用,类似于消息或事件的处理机制,调用方仅发生操作请求,不等被调用方执行完毕而立即返回,被调用方在执行完毕后主动调用调用方提供的回调函数(callback),将执行结果返回给调用方,因此,异步调用可以提升浏览器执行网页的效率。通常,开发人员开发出扩展接口的接口函数后,会根据扩展接口所实现的功能预先设置该接口的调用方式。例如,假设客户端脚本调用接口A时,无需接口A的返回结果即可执行后续操作,则为提高网页的运行效率,可以将接口A的调用方式设置为异步调用,从而,接口A的接口参数中存在一个表示回调函数的参数,该参数与接口需要实现的具体功能无关,用于返回接口的运行结果。再例如,假设客户端脚本调用接口B时,接口B的返回结果为后续操作的前提,则可以将接口B的调用方式设置为同步调用。The calling mode of the interface includes a synchronous call and an asynchronous call. The synchronous call is a blocking call, and the caller waits for the callee to return after executing, and belongs to a one-way call; the asynchronous call is a two-way call, similar to The processing mechanism of the message or event, the caller only has an operation request, and returns immediately after the callee finishes executing. After the execution, the callee actively calls the callback function (callback) provided by the caller to return the execution result to the call. Therefore, asynchronous calls can improve the efficiency of the browser executing web pages. Usually, after the developer develops the interface function of the extended interface, the calling mode of the interface is preset according to the function implemented by the extended interface. For example, if the client script invokes the interface A, the subsequent operations can be performed without the return result of the interface A. To improve the running efficiency of the web page, the calling mode of the interface A can be set to be asynchronously invoked, thereby the interface parameters of the interface A. There is a parameter indicating the callback function, which is independent of the specific function that the interface needs to implement, and is used to return the running result of the interface. For example, if the client script invokes interface B and the return result of interface B is the premise of subsequent operations, the call mode of interface B can be set to synchronous call.
作为一种示例,可以是预设的接口数据库中记录有扩展接口的接口信息,所述接口信息包括接口标识和调用方式,所述接口标识可以是接口函数的接口名称,也可以是与接口名称一一对应的其它标识符,具体的,本发明实施例不作限制;调用方式包括同步调用和异步调用。为方便说明,假设接口标识为接口名称,所提供的扩展接口有3个,则接口数据库的存 储形式可以如表1所示,表1是本发明实施例提供一种接口数据库的存储示意。As an example, the interface information of the extended interface may be recorded in the preset interface database, where the interface information includes an interface identifier and a calling mode, and the interface identifier may be an interface name of the interface function, or may be an interface name. The other identifiers of the one-to-one correspondence are not limited in the embodiment of the present invention; the calling modes include synchronous calling and asynchronous calling. For the convenience of description, suppose the interface identifier is the interface name, and there are three extension interfaces provided, then the interface database is saved. The storage format can be as shown in Table 1. Table 1 is a schematic diagram of storage of an interface database according to an embodiment of the present invention.
表1Table 1
Figure PCTCN2016083359-appb-000001
Figure PCTCN2016083359-appb-000001
从表1可知,在浏览器所提供的扩展接口中,接口标识分别为“recordHistory”和“downloadUrl”的接口所对应的调用方式为异步调用,接口标识为“playAudio”的接口所对应的调用方式为同步调用。因此,本发明实施例中,可以根据接口调用请求中所携带的接口标识,从接口数据库中查询出所述接口标识对应的目标接口的调用方式。As shown in Table 1, in the extended interface provided by the browser, the call mode corresponding to the interface whose interface identifier is "recordHistory" and "downloadUrl" is called asynchronously, and the interface whose interface identifier is "playAudio" corresponds to the calling mode. Called for synchronization. Therefore, in the embodiment of the present invention, the calling mode of the target interface corresponding to the interface identifier may be queried from the interface database according to the interface identifier carried in the interface call request.
作为另一种示例,也可以是接口调用请求所携带的接口参数中包含有标识目标接口的调用方式的参数。例如:可以假设接口参数中的第一个参数用来表示目标接口的调用方式,用“1”表示同步调用,用“0”表示异步调用,当然,表示目标接口的调用方式的参数也可以是接口参数中位于其它位置处的参数,表示调用方式的具体数值也可以是其它字符,本发明实施例不作限制。但基于该假设,可以根据接口参数中第一个参数的具体数值确定目标接口的调用方式,若获取到该参数为“1”,则可以确定接口标识对应的目标接口的调用方式为同步调用;若为“0”,则可以确定接口标识对应的目标接口的调用方式为异步调用。值得说明的是,本发明实施例对标定目标接口的调用方式的参数的具体形式不作限制,预先约定好标定规则即可。本发明实施例中,可以根据接口调用请求中所携带的接口参数,确定所述接口标识对应的目标接口的调用方式。为方便后续步骤的说明,本发明实施例以第一种示例为例。As another example, the interface parameter carried in the interface call request may include a parameter that identifies a calling mode of the target interface. For example, it can be assumed that the first parameter in the interface parameter is used to indicate the calling mode of the target interface. The "1" is used to indicate the synchronous call, and the "0" is used to indicate the asynchronous call. Of course, the parameter indicating the calling mode of the target interface can also be The parameter at the other position in the interface parameter indicates that the specific value of the calling mode may be other characters, which is not limited in the embodiment of the present invention. However, based on the assumption, the calling mode of the target interface may be determined according to the specific value of the first parameter in the interface parameter. If the parameter is set to "1", the calling mode of the target interface corresponding to the interface identifier may be determined to be synchronously invoked; If it is "0", it can be determined that the calling mode corresponding to the interface identifier is asynchronously called. It should be noted that, in the embodiment of the present invention, the specific form of the parameter of the calling mode of the calibration target interface is not limited, and the calibration rule may be agreed in advance. In the embodiment of the present invention, the calling mode of the target interface corresponding to the interface identifier may be determined according to the interface parameter carried in the interface call request. To facilitate the description of the subsequent steps, the first embodiment of the present invention is taken as an example.
S103:根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数。S103: Determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier.
由于浏览器在分别处理异步调用和同步调用的接口调用请求时存在差异,异步调用需调用方提供一个标识回调函数的参数,被调用方在执行完毕后通过该回调函数返回目标接口函数的执行结果;同步调用是被调用方在执行完毕后直接返回目标接口函数的执行结果。因此,若调用方式为异步调用,则接口调用请求所携带的接口参数中存在一个标识回调函数(callback)的预设参数,该预设参数由调用方提供,被调用方负责调用该预设参数标识的回调函数。 Since the browser has a difference in handling the asynchronous call and the synchronous call of the interface call request, the asynchronous call requires the caller to provide a parameter identifying the callback function, and the callee returns the execution result of the target interface function through the callback function after the execution is completed. The synchronous call is the result of the caller returning directly to the target interface function after execution. Therefore, if the calling mode is asynchronous, the interface parameter carried by the interface calling request has a preset parameter that identifies a callback function, and the preset parameter is provided by the caller, and the called party is responsible for calling the preset parameter. The callback function for the identity.
本发明实施例中,规范化客户端脚本调用接口的方式,例如,表示同步调用和异步调用的脚本可以如代码1所示。In the embodiment of the present invention, the manner in which the client script invokes the interface is normalized, for example, the script indicating the synchronous call and the asynchronous call may be as shown in the code 1.
代码1Code 1
//同步调用,操作结果通过返回值获得/ / Synchronous call, the result of the operation is obtained by the return value
function syncInterface(arg1,arg2,......);Function syncInterface(arg1, arg2,...);
//异步调用,操作结果通过回调函数callback获得/ / Asynchronous call, the result of the operation is obtained through callback function callback
function asyncInterface(arg1,arg2,......,callback);Function asyncInterface(arg1, arg2, ..., callback);
//回调函数规范/ / callback function specification
function asyncCallback(Object);Function asyncCallback(Object);
从代码1可以看出,本发明实施例规范化了脚本调用接口的规范,其中,接口参数(arg1、arg2等)的个数和数据类型根据实际需求设定。在异步调用中,可以将接口参数中的最后一个参数用来表示回调函数的参数,当然,也可以是接口参数中位于其它位置处的参数,具体的,本发明实施例不作限制,预先达成约定即可。异步调用中的回调函数用于将调用结果通知给客户端脚本,其中,回调函数的规范也在代码1中列出,它接受一个输入参数,输入参数的类型可以是脚本支持的通用数据类型,例如:Object对象。As can be seen from the code 1, the embodiment of the present invention normalizes the specification of the script call interface, wherein the number of interface parameters (arg1, arg2, etc.) and the data type are set according to actual needs. In the asynchronous call, the last parameter in the interface parameter can be used to represent the parameter of the callback function. Of course, it can also be the parameter at the other position in the interface parameter. Specifically, the embodiment of the present invention does not limit, and the agreement is reached in advance. Just fine. The callback function in the asynchronous call is used to notify the client script of the result of the call. The specification of the callback function is also listed in code 1. It accepts an input parameter, and the type of the input parameter can be a common data type supported by the script. For example: Object object.
本发明实施例中,若调用方式为同步调用,则根据接口调用请求携带的接口参数,可以直接确定该接口参数为目标接口对应的目标接口函数的输入参数中的第一参数。若调用方式为异步调用,则根据接口调用请求携带的接口参数,确定该接口参数中除预设参数外的其它参数为目标接口对应的目标接口函数的输入参数中的第一参数,其中,预设参数用于标识回调函数,每个预设参数对应一个回调函数。In the embodiment of the present invention, if the calling mode is a synchronous call, the first parameter in the input parameter of the target interface function corresponding to the target interface may be directly determined according to the interface parameter carried in the interface call request. If the calling mode is asynchronous, the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the interface parameter carried in the interface call request, and the other parameters of the interface parameter except the preset parameter are Set parameters to identify the callback function, and each preset parameter corresponds to a callback function.
S104:将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数。S104: Call the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function.
具体实现中,在将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数之前,可以确定所述接口调用请求的请求标识。进一步的,考虑到浏览器在加载网页的过程中,会存在同时处理多项接口调用请求的情况,因此,采用请求标识来标定客户端脚本调用接口的每项接口调用请求,该请求标识与其对应的接口调用请求的所有信息关联,所述信息包括该接口调用请求的接口标识、接口参数、调用结果等,从而,通过请求标识来跟踪每项接口调用请求及调用结果。本发明实施例中,接收到接口调用请求后,确定该接口调用请求的请求标识,其中,请求标识可以是浏览器内核接收到接口调用请求时自动分配的。可知,一个请求标识唯一标定一项接口调用请求,且请求标识与该项接口调用请求所携带的接口标识和接口参数关联。 In a specific implementation, before the target interface function is invoked by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, the request identifier of the interface call request may be determined. Further, considering that the browser processes the webpage, there may be a case of processing multiple interface call requests at the same time. Therefore, the request identifier is used to calibrate each interface call request of the client script call interface, and the request identifier corresponds to The interface invokes all the information associated with the request, the information including the interface identifier of the interface call request, the interface parameter, the call result, and the like, thereby tracking each interface call request and the call result by the request identifier. In the embodiment of the present invention, after receiving the interface call request, determining the request identifier of the interface call request, where the request identifier may be automatically allocated when the browser kernel receives the interface call request. It can be seen that a request identifier uniquely aligns an interface call request, and the request identifier is associated with an interface identifier and an interface parameter carried in the interface call request.
本发明实施例中,将接口函数的设计方式进行规范化,即每个接口函数接收一个请求标识作为输入参数的其中一个参数,且将该请求标识也作为输出参数的其中一个参数。例如:将请求标识作为接口函数的输入参数的其中一个参数,即输入参数包括请求标识和第一参数;将该请求标识作为接口函数的输出参数的其中一个参数,即输出参数包括请求标识和第二参数,请求标识和第二参数关联。从而,接口函数执行完毕后,获取该接口函数的输出参数,输出参数包括请求标识和第二参数,通过请求标识区分该请求标识关联的第二参数为哪项接口调用请求的调用结果。In the embodiment of the present invention, the design mode of the interface function is normalized, that is, each interface function receives one request identifier as one of the parameters of the input parameter, and the request identifier is also used as one of the parameters of the output parameter. For example, the request identifier is one of the input parameters of the interface function, that is, the input parameter includes the request identifier and the first parameter; the request identifier is one of the parameters of the output parameter of the interface function, that is, the output parameter includes the request identifier and the The second parameter, the request identifier and the second parameter association. Therefore, after the execution of the interface function is completed, the output parameter of the interface function is obtained, and the output parameter includes a request identifier and a second parameter, and the request result identifies the call result of the interface call request by the second parameter associated with the request identifier.
具体实现中,将请求标识和第一参数作为目标接口对应的目标接口函数的输入参数,调用该目标接口函数,即运行该目标接口函数。In a specific implementation, the request identifier and the first parameter are used as input parameters of the target interface function corresponding to the target interface, and the target interface function is invoked, that is, the target interface function is run.
S105:获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数。S105: Acquire an output parameter returned after calling the target interface function, where the output parameter includes the request identifier and the second parameter.
本发明实施例中,接口函数的输出参数包括请求标识和第二参数,其中,第二参数为该接口函数实现接口功能后用来返回给客户端脚本的参数,请求标识用来标识该第二参数为客户端脚本的哪项接口调用请求的调用结果。In the embodiment of the present invention, the output parameter of the interface function includes a request identifier and a second parameter, where the second parameter is a parameter used by the interface function to implement the interface function and is returned to the client script, and the request identifier is used to identify the second parameter. The parameter is the result of the call to the request of the interface of the client script.
具体实现中,目标接口函数运行完毕后,获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数。In a specific implementation, after the target interface function is completed, an output parameter returned after the target interface function is invoked is obtained, where the output parameter includes the request identifier and the second parameter.
S106:基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。S106: Return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
作为一种示例,若调用方式为同步调用,由于调用方需等待被调用方返回调用结果后才执行后续操作,因此,将第二参数作为请求标识对应的接口调用请求的调用结果直接返回给调用方,其中,请求标识与该第二参数关联。As an example, if the calling mode is a synchronous call, since the calling party needs to wait for the called party to return the calling result and then perform the subsequent operation, the second parameter is directly returned to the calling as the calling result of the interface calling request corresponding to the request identifier. a party, wherein the request identifier is associated with the second parameter.
作为另一种示例,若调用方式为异步调用,由于调用方无需等待被调用方返回调用结果后即可继续执行后续操作,调用结果通过回调函数返回给调用方。因此,被调用方将第二参数作为回调函数的输入参数,通过调用该回调函数的方式返回请求标识对应的接口调用请求的调用结果给调用方,其中,请求标识与该第二参数关联,回调函数为请求标识对应的接口调用请求所携带的接口参数中标定的预设参数。可以理解的,调用方为客户端脚本,被调用方为浏览器。从而,将接口调用请求的调用结果返回给客户端脚本,完成接口的调用。As another example, if the calling mode is an asynchronous call, since the caller can continue to perform subsequent operations without waiting for the callee to return the call result, the call result is returned to the caller through the callback function. Therefore, the called party uses the second parameter as an input parameter of the callback function, and returns the call result of the interface call request corresponding to the request identifier to the caller by calling the callback function, wherein the request identifier is associated with the second parameter, and the callback is The function is a preset parameter that is calibrated in the interface parameter carried by the interface request request corresponding to the request identifier. Understandably, the caller is a client-side script and the callee is a browser. Thus, the result of the call of the interface call request is returned to the client script, and the call of the interface is completed.
为方便说明,可以将本发明方法理解为接口中间层,如图1b所示,图1b是图1提供的一种接口调用的示意图。浏览器在执行网页的过程中,若网页中的客户端脚本需要调用浏览器提供的扩展接口,则接口中间层接收接口调用请求,该接口调用请求中携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,其中,目标接口为浏览器所提供的扩展接 口中的任一扩展接口;采用上述方法调用目标接口对应的目标接口函数,并将该目标接口函数的运行结果作为该接口调用请求的的调用结果返回给客户端脚本。从而,通过该接口中间层统一处理接口的调用流程,开发人员在开发扩展接口时,只需针对扩展接口开发出对应的接口函数即可,无需针对每个扩展接口都设计一套该接口的调用方法,降低工作量,提高开发效率。For convenience of description, the method of the present invention can be understood as an interface intermediate layer, as shown in FIG. 1b, and FIG. 1b is a schematic diagram of an interface call provided in FIG. In the process of executing the webpage, if the client script in the webpage needs to invoke the extension interface provided by the browser, the interface middle layer receives the interface call request, and the interface call request carries the target interface that the client script needs to call. Interface identifier and interface parameters, wherein the target interface is an extension provided by the browser Any expansion interface in the port; the target interface function corresponding to the target interface is invoked by the above method, and the running result of the target interface function is returned to the client script as a result of the call of the interface call request. Therefore, through the intermediate layer of the interface to uniformly process the calling process of the interface, when developing the extended interface, the developer only needs to develop a corresponding interface function for the extended interface, and it is not necessary to design a set of the interface for each extended interface. Method to reduce workload and improve development efficiency.
在本发明实施例描述的接口调用方法中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。In the interface calling method described in the embodiment of the present invention, an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
请参见图2,图2是本发明实施例提供的一种接口调用方法的另一流程示意图,在本发明实施例中,该方法可以包括以下步骤。Referring to FIG. 2, FIG. 2 is another schematic flowchart of an interface calling method according to an embodiment of the present invention. In the embodiment of the present invention, the method may include the following steps.
S201:接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数。S201: Receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke.
S202:根据所述接口标识,确定所述目标接口的调用方式。S202: Determine, according to the interface identifier, a calling manner of the target interface.
具体实现中,根据接口调用请求所要调用的目标接口,确定该目标接口的调用方式,所述调用方式包括同步调用和异步调用。通常,各接口的接口信息预先存储在接口数据库中,所述接口信息包括接口标识和调用方式。当浏览器接收到该接口调用请求时,根据该接口调用请求中携带的接口标识,从接口数据库中查询该接口标识对应的接口信息,接口信息包括接口标识和调用方式;从而,将接口数据库中该接口标识对应的调用方式确定为目标接口的调用方式。当然,目标接口的调用方式也可以是客户端脚本调用该目标接口时,在接口调用请求的接口参数中标定,具体的,本发明实施例不作限制。In a specific implementation, the calling interface to be called is determined according to the interface call request, and the calling mode of the target interface is determined, and the calling manner includes a synchronous call and an asynchronous call. Generally, the interface information of each interface is pre-stored in the interface database, and the interface information includes an interface identifier and a calling mode. When the browser receives the interface call request, the interface identifier is used to query the interface information corresponding to the interface identifier, and the interface information includes the interface identifier and the calling mode, and the interface information is included in the interface database. The calling mode corresponding to the interface identifier is determined as the calling mode of the target interface. Certainly, the calling mode of the target interface may also be calibrated in the interface parameter of the interface call request when the client script calls the target interface. Specifically, the embodiment of the present invention is not limited.
但作为一种优选的实施方式,确定目标接口的调用方式可以是根据接口标识,从预设的接口数据库中查询该接口标识对应的接口信息,所述接口信息包括接口标识和调用方式;将从接口数据库中所查询到的该接口标识对应的调用方式确定为所述目标接口的调用方式。 However, as a preferred implementation manner, determining the calling mode of the target interface may be: querying, according to the interface identifier, the interface information corresponding to the interface identifier from the preset interface database, where the interface information includes the interface identifier and the calling mode; The calling mode corresponding to the interface identifier that is queried in the interface database is determined as the calling mode of the target interface.
S203:根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数。S203: Determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier.
本发明实施例中,异步调用需客户端脚本在接口参数中携带一个标识回调函数的参数,为方便描述,将标识回调函数的参数称为预设参数。例如,可以将异步调用的接口参数中的最后一个参数用来存放预设参数,当然,也可以根据预先约定设置预设参数在接口参数中的其它位置,具体的,本发明实施例不作限制。在一种实现方式中,若确定出调用方式为异步调用,获取接口参数中标识回调函数的预设参数,将回调信息保存至预设的回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数,当然,回调信息还可以包括运行该回调函数时所需的环境变量等其它信息,具体的,本发明实施例不作限制。从而,方便后续步骤(例如,步骤S208)返回异步调用的调用结果时,根据调用目标接口函数后返回的输出参数中的请求标识,从该回调数据库中查询该请求标识对应的目标回调函数。In the embodiment of the present invention, the asynchronous call requires the client script to carry a parameter identifying the callback function in the interface parameter. For convenience of description, the parameter identifying the callback function is referred to as a preset parameter. For example, the last parameter in the interface parameter of the asynchronous call may be used to store the preset parameter. Of course, the preset parameter may be set to other positions in the interface parameter according to a pre-agreed. In an implementation manner, if it is determined that the calling mode is an asynchronous call, the preset parameter that identifies the callback function in the interface parameter is obtained, and the callback information is saved in a preset callback database, where the callback information includes the request identifier and The callback function identified by the preset parameter, of course, the callback information may further include other information such as an environment variable required to run the callback function, and the embodiment of the present invention is not limited. Therefore, when the subsequent step (for example, step S208) returns the result of the asynchronous call, the target callback function corresponding to the request identifier is queried from the callback database according to the request identifier in the output parameter returned after the target interface function is called.
作为一种示例,表示同步调用和异步调用的脚本可以如上述实施例中的代码1所示。可知,同步调用的接口参数均为目标接口对应的目标接口函数所需要的参数,异步接口的接口参数中用来表示回调函数的预设参数(callback)在目标接口对应的目标接口函数中不需要,但在目标接口函数运行完毕后,需要调用该预设参数所表示的回调函数,返回调用结果。本发明实施例中,根据目标接口的调用方式和接口参数来确定目标接口对应的目标接口函数的输入参数中的第一参数。具体实现中,若调用方式为同步调用,将接口调用请求中携带的接口参数确定为目标接口对应的目标接口函数的输入参数中的第一参数;若调用方式为异步调用,将接口调用请求携带的接口参数中除预设参数外的其它参数确定为目标接口函数的输入参数中的第一参数,其中,预设参数用于标识回调函数,每个预设参数对应一个回调函数。As an example, a script representing a synchronous call and an asynchronous call may be as shown in code 1 in the above embodiment. It can be seen that the interface parameters synchronously called are the parameters required by the target interface function corresponding to the target interface, and the preset parameters (callback) used to represent the callback function in the interface parameters of the asynchronous interface are not required in the target interface function corresponding to the target interface. However, after the target interface function finishes running, you need to call the callback function represented by the preset parameter to return the call result. In the embodiment of the present invention, the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the calling mode of the target interface and the interface parameter. In the specific implementation, if the calling mode is a synchronous call, the interface parameter carried in the interface call request is determined as the first parameter in the input parameter of the target interface function corresponding to the target interface; if the calling mode is asynchronous, the interface call request is carried. The other parameters of the interface parameter except the preset parameter are determined as the first parameter of the input parameter of the target interface function, wherein the preset parameter is used to identify a callback function, and each preset parameter corresponds to a callback function.
S204:将所述第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型。S204: Perform format conversion on the first parameter, and the data type of the converted first parameter is a preset second data type.
由于目前的浏览器大多为多核浏览器,即浏览器中包括两个或两个以上的浏览器内核,现有方法在针对多核浏览器开发扩展接口时,需针对每一种浏览器内核都设计一个与该扩展接口所要实现的功能相同的接口函数,不仅开发成本高,而且由于不同的浏览器内核对接口函数的设计规范不一样,不同的浏览器内核针对相同的接口标识所调用的接口函数不同,导致接口调用流程复杂,从而,调用接口的效率低。Since most browsers today are multi-core browsers, that is, two or more browser kernels are included in the browser, the existing methods are designed for each browser kernel when developing an extension interface for a multi-core browser. An interface function that is the same as the function to be implemented by the extension interface not only has high development cost, but also because different browser kernels have different design specifications for interface functions, and different browser kernels identify interface functions called for the same interface identifier. Differently, the interface calling process is complicated, and thus the calling interface is inefficient.
本发明实施例中,将接口函数的设计规范化,不管针对什么样的浏览器内核,均采用相同的规范来设计接口函数。例如,接口函数的设计规范可以如代码2所示,在添加接口函数时,开发人员只需根据该规范来实现相应的功能即可。值得说明的是,代码2仅为示例,本发明并不限于该示例。 In the embodiment of the present invention, the design of the interface function is standardized, and the interface module is designed using the same specification regardless of the browser kernel. For example, the design specification of the interface function can be as shown in the code 2. When adding the interface function, the developer only needs to implement the corresponding function according to the specification. It is worth noting that the code 2 is merely an example, and the present invention is not limited to this example.
//接口函数规范,id表示与接口调用请求对应的请求标识,kv_map保存脚本传入的参数/ / Interface function specification, id represents the request identifier corresponding to the interface call request, kv_map saves the parameters passed in the script
Value InterfaceFunction(int id,KeyValueMap kv_map);Value InterfaceFunction(int id,KeyValueMap kv_map);
在该规范中,id为请求标识,用于跟踪该接口调用请求及调用结果;接口函数的第一参数kv_map的数据类型为预设的第二数据类型,所述第二数据类型可以是预先定义的用于接纳任何类型数据的数据结构类型,也可以是编程语言自带的数据库中的通用数据类型,该数据类型可以接收任何数据类型的数据。例如:KeyValueMap类型或Value类型,具体的,本发明实施例不作限制。为方便说明,本发明实施例以第二数据类型为KeyValueMap类型为例,但应当说明的是,并不限制第二数据类型为KeyValueMap类型。其中,KeyValueMap或Value是一种数据类型,该类型像储物箱一样,可以用来保存多种不同类型的数据,例如:整数、浮点数、字符串等等。具体的,KeyValueMap是一种键-值(Key-Value)映射表,该映射表中保存了键(Key)和值(Value)的一一对应关系,键(Key)可以是数字(参数的顺序)或字符串(参数的名称),值(Value)是参数中对应某个键的具体值。In the specification, the id is a request identifier for tracking the interface call request and the call result; the data type of the first parameter kv_map of the interface function is a preset second data type, and the second data type may be a predefined The type of data structure used to accept any type of data, or a generic data type in a database that comes with the programming language, which can receive data of any data type. For example, the KeyValueMap type or the Value type is not limited in the embodiment of the present invention. For convenience of description, the embodiment of the present invention takes the second data type as the KeyValueMap type as an example, but it should be noted that the second data type is not limited to the KeyValueMap type. Among them, KeyValueMap or Value is a data type, like a storage box, can be used to store a variety of different types of data, such as: integers, floating-point numbers, strings, and so on. Specifically, the KeyValueMap is a key-value mapping table, and the mapping table stores a one-to-one correspondence between a key and a value. The key can be a number (the order of the parameters) ) or string (the name of the parameter), the value (Value) is the specific value of a key in the parameter.
本发明实施例中,将所确定的第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型。即在调用目标接口对应的目标接口函数前需要把脚本传递进来的第一参数进行转换,如将第一参数转换成一个KeyValueMap对象等。In the embodiment of the present invention, the determined first parameter is format converted, and the data type of the converted first parameter is a preset second data type. That is, before calling the target interface function corresponding to the target interface, it is necessary to convert the first parameter passed in by the script, such as converting the first parameter into a KeyValueMap object.
为方便说明,假设客户端脚本欲调用一个添加网页历史记录的接口,且该接口的调用方式为异步调用,则客户端脚本提供的接口规范可以为:function recordHistory(url,date,callback),第一个参数表示需要传入网页的网址(url,假定为http:\\www.liebao.cn),第二个参数表示需要传入访问的时间(time,假定为2014-07-20 20:00:00),最后一个参数为脚本函数对象,该参数不作为调用接口函数的参数,而用于在接口函数操作成功后通知脚本,因此,步骤S103根据接口参数所确定的第一参数不包括将该参数。将所确定的第一参数进行格式转换后,得到转换后的KeyValueMap类型的第一参数可以如表2所示,表2是本发明实施例提供的一种第二数据类型的示意。For convenience of description, suppose the client script wants to call an interface that adds the history of the webpage, and the calling mode of the interface is asynchronous, the interface specification provided by the client script may be: function recordHistory(url,date,callback), One parameter indicates the URL of the incoming web page (url, assumed to be http:\\www.liebao.cn), and the second parameter indicates the time that the incoming access is required (time, assumed to be 2014-07-20 20:00) : 00), the last parameter is a script function object, the parameter is not used as a parameter of the calling interface function, but is used to notify the script after the interface function is successfully operated. Therefore, the first parameter determined according to the interface parameter in step S103 does not include This parameter. After the first parameter is converted, the first parameter of the converted KeyValueMap type is as shown in Table 2. Table 2 is a schematic diagram of a second data type provided by the embodiment of the present invention.
表2Table 2
Figure PCTCN2016083359-appb-000002
Figure PCTCN2016083359-appb-000002
从而,保证不同的浏览器内核接收到客户端脚本的接口调用请求后,均可以通过本步骤 将第一参数转换为数据类型相同的参数,对接口函数的输入参数的数据类型实现了统一,因此,开发人员针对多核浏览器开发一套接口时只需设计一个接口函数。Therefore, after ensuring that different browser kernels receive the interface call request of the client script, the step can be adopted. Converting the first parameter to the same data type parameter, the data type of the input parameter of the interface function is unified. Therefore, developers only need to design an interface function when developing a set of interfaces for the multi-core browser.
S205:将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数。S205: Call the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function.
具体实现中,在将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数之前,可以确定所述接口调用请求的请求标识。考虑到浏览器在加载网页的过程中,会存在同时处理多项接口调用请求的情况,因此,采用请求标识来标定客户端脚本调用接口的每项接口调用请求,该请求标识与其对应的接口调用请求的所有信息关联,所述信息包括该接口调用请求的接口标识、接口参数、调用结果等,从而,通过请求标识来跟踪每项接口调用请求及调用结果。本发明实施例中,接收到接口调用请求后,确定该接口调用请求的请求标识,其中,请求标识可以是浏览器内核接收到接口调用请求时自动分配的。可知,一个请求标识唯一标定一项接口调用请求,且请求标识与该项接口调用请求所携带的接口标识和接口参数关联。In a specific implementation, before the target interface function is invoked by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, the request identifier of the interface call request may be determined. Considering that in the process of loading the webpage, the browser may handle multiple interface call requests at the same time. Therefore, the request identifier is used to calibrate each interface call request of the client script call interface, and the request identifier corresponds to the corresponding interface call. All the requested information is associated, the information includes the interface identifier of the interface call request, the interface parameter, the call result, and the like, so that each interface call request and the call result are tracked by the request identifier. In the embodiment of the present invention, after receiving the interface call request, determining the request identifier of the interface call request, where the request identifier may be automatically allocated when the browser kernel receives the interface call request. It can be seen that a request identifier uniquely aligns an interface call request, and the request identifier is associated with an interface identifier and an interface parameter carried in the interface call request.
通常,开发人员开发出一套扩展接口后,将该接口的相关信息保存在预设的接口数据库中,其中,接口的相关信息包括接口标识和接口函数,所述接口标识可以是接口名称。若开发人员已提供了接口调用请求所指定的目标接口,则由接口调用请求中携带的接口标识可以在预设的信息库中查找到一个唯一的与该接口标识匹配的接口函数。本发明实施例中,根据接口调用请求中携带的接口标识,查询接口数据库中是否存在与所述接口标识匹配的接口函数。若存在,说明浏览器提供该接口标识所指定的目标接口,根据接口调用请求对应的请求标识和转换后的第一参数运行所查找到的目标接口函数;若不存在,说明浏览器不提供该目标接口,则返回预设的错误信息。Generally, after the developer develops a set of extended interfaces, the related information of the interface is saved in a preset interface database, where the interface related information includes an interface identifier and an interface function, and the interface identifier may be an interface name. If the developer has provided the target interface specified by the interface call request, the interface identifier carried in the interface call request can find a unique interface function matching the interface identifier in the preset information base. In the embodiment of the present invention, according to the interface identifier carried in the interface call request, whether the interface function matching the interface identifier exists in the interface database is queried. If yes, the browser provides the target interface specified by the interface identifier, and searches for the target interface function according to the request identifier corresponding to the interface call request and the converted first parameter; if not, the browser does not provide the target interface function. The target interface returns the default error message.
若查询到接口数据库中存在与接口标识匹配的目标接口函数,则将请求标识和步骤S204中转换后的第一参数作为所查找到的目标接口函数的输入参数,调用该目标接口函数。换句话说,将请求标识和转换后的第一参数代入所查找到的目标接口函数中,运行或执行所查找到的目标接口函数。从而,针对不同的浏览器内核,采用本发明实施例后,可以采用统一的规范调用接口函数,不同的浏览器内核调用接口的方式相同,调用接口的效率高,网页的执行效率也得到提高。If the target interface function matching the interface identifier exists in the interface database, the request identifier and the first parameter converted in step S204 are used as input parameters of the found target interface function, and the target interface function is invoked. In other words, the request identifier and the converted first parameter are substituted into the found target interface function, and the found target interface function is run or executed. Therefore, for different browser kernels, after adopting the embodiment of the present invention, a unified specification call interface function can be adopted, and different browser kernels call the interface in the same manner, the efficiency of calling the interface is high, and the execution efficiency of the webpage is also improved.
S206:获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数,所述输出参数的数据类型为预设的第一数据类型。S206: Obtain an output parameter that is returned after the target interface function is invoked, where the output parameter includes the request identifier and a second parameter, and the data type of the output parameter is a preset first data type.
调用目标接口对应的目标接口函数后,获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数,所述输出参数的数据类型为预设的第一数据类 型,其中,第二参数用来表示目标接口函数的运行结果。具体实现中,所述第一数据类型可以是预先定义的用于接纳任何类型数据的数据类型,也可以是编程语言自带的数据库中的通用数据类型,该数据类型可以接收任何数据类型的数据。例如:KeyValueMap类型或Value类型,具体的,本发明实施例不作限制。为方便说明,代码2或本发明实施例中以第一数据类型为Value类型为例,但本发明实施例并不限制第一数据类型为Value类型。从而,开发人员针对不同的浏览器内核开发扩展接口时,只需根据规范设计一个接口函数,无需针对不同的浏览器内核分别设计一个接口函数,且无需设计该接口函数对应的接口的调用方法,不仅可以减少开发成本,而且提高开发效率。After the target interface function corresponding to the target interface is invoked, the output parameter returned after the target interface function is invoked is obtained, where the output parameter includes the request identifier and the second parameter, and the data type of the output parameter is a preset first Data class Type, where the second parameter is used to represent the result of the operation of the target interface function. In a specific implementation, the first data type may be a predefined data type for accepting any type of data, or may be a general data type in a database that is included in the programming language, and the data type may receive data of any data type. . For example, the KeyValueMap type or the Value type is not limited in the embodiment of the present invention. For convenience of description, the code 2 or the embodiment of the present invention takes the first data type as the Value type as an example, but the embodiment of the present invention does not limit the first data type to the Value type. Therefore, when developers develop extension interfaces for different browser kernels, they only need to design an interface function according to the specification. It is not necessary to design an interface function for different browser kernels, and there is no need to design the interface method corresponding to the interface function. Not only can it reduce development costs, but also improve development efficiency.
值得说明的是,在具体实现中,也可以是第二参数的数据类型为预设的第一数据类型,接口函数的输出参数的数据类型为结构体,该结构体包括请求标识和第二参数。例如,以第一数据类型为Value类型为例,结构体的规范可以如代码3所示。It should be noted that, in a specific implementation, the data type of the second parameter may be a preset first data type, and the data type of the output parameter of the interface function is a structure, and the structure includes a request identifier and a second parameter. . For example, taking the first data type as the Value type as an example, the specification of the structure can be as shown in the code 3.
代码3Code 3
Figure PCTCN2016083359-appb-000003
Figure PCTCN2016083359-appb-000003
S207:将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。S207: Perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
作为一种优选的实施方式,将所获取到的调用目标接口函数后返回的输出参数中的第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。其中,第三数据类型可以是预先定义的用于接纳任何类型数据的数据结构类型,也可以是客户端脚本语言中的通用数据类型,例如,Object对象,具体的,本发明实施例不作限制。从而,对返回给客户端脚本的调用结果进行规范化处理,提高脚本的执行效率。值得说明的是,也可以不针对第二参数进行格式转换,跳过本步骤而执行步骤S208。As a preferred implementation manner, the second parameter in the output parameter returned after the acquired target interface function is formatted, and the data type of the converted second parameter is a preset third data type. The third data type may be a pre-defined data structure type for accepting any type of data, or may be a general data type in the client-side scripting language, for example, an Object object. Specifically, the embodiment of the present invention is not limited. Thus, the result of the call returned to the client script is normalized to improve the execution efficiency of the script. It should be noted that the format conversion may not be performed for the second parameter, and the step S208 is performed by skipping this step.
S208:基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。S208: Return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
根据目标接口的调用方式,将第二参数作为该输出参数中的请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。具体实现中,若目标接口的调用方式为同步调用,将第二参数或经格式转换后的第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本;若所述调用方式为异步调用,根据所述请求标识,确定该请求标识对 应的目标回调函数,将第二参数或经格式转换后的第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给客户端脚本。The second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier in the output parameter according to the calling mode of the target interface. In a specific implementation, if the calling mode of the target interface is a synchronous call, the second parameter or the formatted second parameter is returned to the client script as the calling result of the interface call request corresponding to the request identifier; The calling mode is an asynchronous call, and the request identifier is determined according to the request identifier. The target target callback function takes the second parameter or the formatted second parameter as an input parameter of the target callback function, runs the target callback function to obtain an output result, and further calls the output result as the interface. The result of the requested call is returned to the client script.
在一种实施例中,若调用方式为异步调用,则确定所述请求标识对应的目标回调函数的方式可以是:根据所述请求标识,从所述回调数据库中查询所述请求标识对应的回调信息;将所述回调信息指定的回调函数确定为目标回调函数。同时,若获取到该回调信息中存储有运行该目标回调函数的其它信息,则根据这些信息设置当前的环境变量,保证正常运行该目标回调函数,将调用结果通知给客户端脚本。In an embodiment, if the calling mode is an asynchronous call, the manner of determining the target callback function corresponding to the request identifier may be: querying, according to the request identifier, a callback corresponding to the request identifier from the callback database Information; the callback function specified by the callback information is determined as a target callback function. At the same time, if the callback information is stored with other information for running the target callback function, the current environment variable is set according to the information to ensure that the target callback function is normally run, and the result of the call is notified to the client script.
作为一种可行的实施方式,将调用结果返回给客户端脚本后,删除所述回调数据库中所述请求标识对应的回调信息。从而,降低数据量,提高目标回调函数的查询效率。As a feasible implementation manner, after the result of the call is returned to the client script, the callback information corresponding to the request identifier in the callback database is deleted. Thereby, the amount of data is reduced, and the query efficiency of the target callback function is improved.
在本发明实施例描述的接口调用方法中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。In the interface calling method described in the embodiment of the present invention, an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
下面为本发明装置实施例,本发明装置实施例与本发明方法实施例属于同一构思,用于执行本发明方法实施例中描述的方法。为了便于说明,本发明装置实施例仅示出与本发明装置实施例相关的部分,具体技术细节未揭示的,请参照本发明方法实施例的描述,此处不再一一赘述。The following is an embodiment of the device of the present invention. The device embodiment of the present invention is the same as the method embodiment of the present invention, and is used to perform the method described in the method embodiment of the present invention. For the convenience of the description, the device embodiment of the present invention only shows a part related to the device embodiment of the present invention. For details of the technical details, please refer to the description of the method embodiment of the present invention, and details are not described herein again.
请参见图3,图3是本发明实施例提供的一种接口调用装置的结构示意图,在本发明实施例中,该装置可以包括:接收模块101、方式确定模块102、参数确定模块103、调用模块104、获取模块105和返回模块106。Referring to FIG. 3, FIG. 3 is a schematic structural diagram of an interface invoking device according to an embodiment of the present invention. In the embodiment of the present invention, the device may include: a receiving module 101, a mode determining module 102, a parameter determining module 103, and a call. Module 104, acquisition module 105, and return module 106.
接收模块101,用于接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口中的任一扩展接口。 The receiving module 101 is configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that is required to be invoked by the client script, where the target interface is any one of the extended interfaces provided by the browser. extension port.
方式确定模块102,用于根据所述接口标识,确定所述目标接口的调用方式。The mode determining module 102 is configured to determine, according to the interface identifier, a calling manner of the target interface.
参数确定模块103,用于根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数。The parameter determining module 103 is configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the target interface.
调用模块104,用于将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数。The calling module 104 is configured to invoke the target interface function by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function.
获取模块105,用于获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数。The obtaining module 105 is configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter.
返回模块106,用于基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。The returning module 106 is configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
在本发明实施例描述的接口调用装置中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。In the interface invoking device described in the embodiment of the present invention, an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
请参见图4,图4是本发明实施例提供的一种接口调用装置的另一结构示意图,在本发明实施例中,该装置可以包括:接收模块201、方式确定模块202、参数确定模块203、调用模块204、获取模块205、返回模块206、第一转换模块207、第二转换模块208、保存模块301和删除模块302。Referring to FIG. 4, FIG. 4 is another schematic structural diagram of an interface invoking device according to an embodiment of the present invention. In the embodiment of the present invention, the device may include: a receiving module 201, a mode determining module 202, and a parameter determining module 203. The calling module 204, the obtaining module 205, the returning module 206, the first converting module 207, the second converting module 208, the saving module 301, and the deleting module 302.
接收模块201,用于接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一。The receiving module 201 is configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser.
方式确定模块202,用于根据所述接口标识,确定所述目标接口的调用方式。The mode determining module 202 is configured to determine, according to the interface identifier, a calling manner of the target interface.
参数确定模块203,用于根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数。The parameter determining module 203 is configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the target interface.
调用模块204,用于将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数。 The calling module 204 is configured to invoke the target interface function by using the request identifier of the interface call request and the first parameter as an input parameter of the target interface function.
获取模块205,用于获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数。The obtaining module 205 is configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter.
返回模块206,用于基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。The returning module 206 is configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
在一种实施例中,所述输出参数的数据类型为预设的第一数据类型。In an embodiment, the data type of the output parameter is a preset first data type.
第一转换模块207,用于将所述第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型。The first conversion module 207 is configured to perform format conversion on the first parameter, and the data type of the converted first parameter is a preset second data type.
第二转换模块208,用于将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。The second conversion module 208 is configured to perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
保存模块301,用于若所述调用方式为异步调用,将回调信息保存至回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数。The saving module 301 is configured to save the callback information to the callback database if the calling mode is an asynchronous call, where the callback information includes the request identifier and a callback function identified by the preset parameter.
删除模块302,用于删除所述回调数据库中所述请求标识对应的回调信息。The deleting module 302 is configured to delete the callback information corresponding to the request identifier in the callback database.
在另一种实施例中,参数确定模块203具体用于:In another embodiment, the parameter determining module 203 is specifically configured to:
若所述调用方式为同步调用,将所述接口参数确定为所述目标接口函数的输入参数中的第一参数;If the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
若所述调用方式为异步调用,将所述接口参数中除预设参数外的其它参数确定为所述目标接口函数的输入参数中的第一参数,所述预设参数用于标识回调函数。If the calling mode is an asynchronous call, the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
在另一种实施例中,返回模块206包括:同步返回单元2061和异步返回单元2062,如图4a所示,图4a是图4提供的其中一种返回模块的结构示意图。In another embodiment, the return module 206 includes: a synchronous return unit 2061 and an asynchronous return unit 2062, as shown in FIG. 4a, which is a schematic structural diagram of one of the return modules provided in FIG.
同步返回单元2061,若所述调用方式为同步调用,将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本;The synchronization returning unit 2061, if the calling mode is a synchronous call, returning the second parameter to the client script as a result of calling the interface call request corresponding to the request identifier;
异步返回单元2062,若所述调用方式为异步调用,确定所述请求标识对应的目标回调函数,并将所述第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给客户端脚本。The asynchronous return unit 2062, if the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output As a result, the output result is returned to the client script as a result of the call of the interface call request.
在另一种实施例中,同步返回单元2061具体用于:In another embodiment, the synchronization return unit 2061 is specifically configured to:
根据所述请求标识,从所述回调数据库中查询所述请求标识对应的回调信息;Querying the callback information corresponding to the request identifier from the callback database according to the request identifier;
将所述回调信息指定的回调函数确定为目标回调函数。The callback function specified by the callback information is determined as a target callback function.
在另一种实施例中,方式确定模块202具体用于:In another embodiment, the mode determining module 202 is specifically configured to:
根据所述接口标识,从预设的接口数据库中查询所述接口标识对应的接口信息,所述接口信息包括接口标识和调用方式;Querying, according to the interface identifier, the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
将所述接口数据库中该接口标识对应的调用方式确定为所述目标接口的调用方式。 The calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
在本发明实施例描述的接口调用装置中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。In the interface invoking device described in the embodiment of the present invention, an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by the browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, calling the target interface function; and obtaining an output parameter returned after calling the target interface function, where the output parameter includes the Determining the identifier and the second parameter; and returning, according to the second parameter, the result of the call of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
请参见图5,图5是本发明实施例提供的一种接口调用装置的又一结构示意图,在本发明实施例中,该装置可以包括:参数转换器301、接口代理302、接口转发器303、接口通知器304、接口注册器305、接口数据库306和调用请求数据库307。Referring to FIG. 5, FIG. 5 is a schematic diagram of another structure of an interface calling device according to an embodiment of the present invention. In the embodiment of the present invention, the device may include: a parameter converter 301, an interface proxy 302, and an interface forwarder 303. The interface notifier 304, the interface registrar 305, the interface database 306, and the call request database 307.
具体实现中,若接口调用指令所指定的目标接口的调用方式为异步调用,则该接口调用装置还可以包括回调数据库308和回调器309。开发人员在添加接口时,需要向接口注册器305提供接口的接口标识和调用方式等注册信息,为方便说明,假定接口标识为接口名称,其中,接口函数的具体实现在主进程中提供。接口注册器305记录这些注册信息,并在浏览器创建渲染进程后,把这些注册信息通过进程间通信的方式发送给渲染进程,渲染进程把这些注册信息缓存在接口数据库306中,从而,接口数据库306中记录有各接口的接口信息,例如,接口数据库的存储形式可以如表1所示。回调数据库308用于调用方式为异步调用时,存储该异步调用的请求标识和该请求标识所标定的接口调用请求中携带的回调函数,从而,回调器309可以根据请求标识去回调数据库308中查询该请求标识对应的目标回调函数,通过调用该目标回调函数的方式向脚本返回调用结果。调用请求数据库307用于存储调用的请求标识和调用方式,从而,接口通知器304获取到目标接口函数运行完毕后的输出参数后,根据该输出参数中的请求标识去调用请求数据库307中查询该请求标识对应的调用方式,若为同步调用,则直接将输出参数发送给接口代理302;若为异步调用,则将输出参数发送给回调器309。值得说明的是,该接口调用装置可以用于单进程的浏览器中,也可以用于多进程的浏览器中,但为方便说明,以多进程的浏览器为例。In a specific implementation, if the calling mode of the target interface specified by the interface calling instruction is an asynchronous call, the interface calling device may further include a callback database 308 and a callback 309. When adding an interface, the developer needs to provide the interface registrar 305 with the registration information such as the interface identifier and the calling mode of the interface. For convenience of explanation, the interface identifier is assumed to be the interface name, and the specific implementation of the interface function is provided in the main process. The interface registrar 305 records the registration information, and after the browser creates the rendering process, sends the registration information to the rendering process by means of inter-process communication, and the rendering process caches the registration information in the interface database 306, thereby, the interface database The interface information of each interface is recorded in 306. For example, the storage format of the interface database can be as shown in Table 1. The callback database 308 is configured to store the request identifier of the asynchronous call and the callback function carried in the interface call request calibrated by the request identifier when the calling mode is asynchronous, so that the callback 309 can query the callback database 308 according to the request identifier. The request identifies the corresponding target callback function, and returns the call result to the script by calling the target callback function. The call request database 307 is configured to store the requested identifier and the calling mode, so that the interface notifier 304 obtains the output parameter after the target interface function is completed, and then queries the request database 307 according to the request identifier in the output parameter. The calling mode corresponds to the calling mode. If it is a synchronous call, the output parameter is directly sent to the interface proxy 302; if it is an asynchronous call, the output parameter is sent to the callback 309. It should be noted that the interface calling device can be used in a single-process browser or in a multi-process browser, but for convenience of description, a multi-process browser is taken as an example.
通常,浏览器在运行过程中大多表现为多进程,所述多进程至少包括渲染进程和主进程,其中,渲染进程用于处理网页内容的渲染,主进程用于处理用户界面和管理所有其它的进程 等。由于渲染进程只能执行网页,而不能执行其它操作,因此,扩展接口的具体实现(即接口函数的实现)必须在主进程中提供。为方便说明,假设浏览器在运行过程中启动了渲染进程和主进程,则在实现客户端脚本的接口调用流程中,渲染进程接收客户端脚本的接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口中的任一扩展接口。由于渲染进程本身不可以运行目标接口对应的目标接口函数,因此,根据客户端脚本传入的接口标识和接口参数,重新构造接口调用请求,向主进程发送该接口调用请求,从而,由主进程运行该接口调用请求所指定的目标接口函数,并将运行结果返回给渲染进程和/或客户端脚本,实现脚本的调用。Generally, the browser mostly appears as a multi-process during the running process, and the multi-process includes at least a rendering process and a main process, wherein the rendering process is used to process the rendering of the webpage content, the main process is used to process the user interface and manage all other Process Wait. Since the rendering process can only execute web pages and cannot perform other operations, the implementation of the extended interface (ie, the implementation of the interface function) must be provided in the main process. For convenience of description, assuming that the browser starts the rendering process and the main process during the running process, in the interface calling process of implementing the client script, the rendering process receives an interface call request of the client script, and the interface call request carries the client. The interface identifier and the interface parameter corresponding to the target interface that the terminal script needs to call, and the target interface is any one of the extended interfaces provided by the browser. Since the rendering process itself cannot run the target interface function corresponding to the target interface, the interface call request is reconstructed according to the interface identifier and the interface parameter passed in the client script, and the interface call request is sent to the main process, thereby, by the main process Run the interface to call the target interface function specified by the request, and return the running result to the rendering process and / or client script to implement the script call.
本发明实施例中,参数转换器301接收客户端脚本201的接口调用请求,所述接口调用请求携带有客户端脚本201需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接之一。参数转换器301查询接口数据库306中是否存在该接口标识对应的接口信息,若不存在,则说明接口调用错误,直接返回预设的错误信息;若存在,则确定该接口标识对应的接口名称和该接口标识对应的目标接口的调用方式。进一步的,根据该调用方式和所述接口参数确定目标接口对应的目标接口函数的输入参数中的第一参数。参数转换器301对第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型,例如,KeyValueMap类型或Value类型。In the embodiment of the present invention, the parameter converter 301 receives the interface call request of the client script 201, and the interface call request carries the interface identifier and the interface parameter corresponding to the target interface that the client script 201 needs to call, and the target interface is browsed. One of the extensions provided by the device. The parameter converter 301 queries the interface database 306 for the interface information corresponding to the interface identifier. If the interface does not exist, the interface is incorrectly called, and the default error information is directly returned. If yes, the interface name corresponding to the interface identifier is determined. This interface identifies the calling mode of the corresponding target interface. Further, the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the calling mode and the interface parameter. The parameter converter 301 performs format conversion on the first parameter, and the data type of the converted first parameter is a preset second data type, for example, a KeyValueMap type or a Value type.
接口代理302(Interface Proxy)从参数转换器301处获取接口调用请求所需的调用信息,或者是参数转换器301将调用信息发送给接口代理302,所述调用信息包括接口调用请求的请求标识、接口名称、第一参数和调用方式,若调用方式为异步调用,所述调用信息还包括回调函数。当然,所述请求标识也可以是接口代理302确定的或生成的,具体的,本发明实施例不作限制。若调用方式为异步调用,则接口代理302根据所获取到的调用信息,将请求标识和与该请求标识对应的回调函数添加至回调数据库308中。以便回调器309接收到主进程中的接口通知器304返回的目标接口函数的输出参数后,根据该输出参数中的请求标识从回调数据库308中查询该请求标识对应的目标回调函数。同时,接口代理302向位于主进程中的接口转发器303发送接口调用请求,所述接口调用请求可以如代码4所示。The interface proxy 302 (Interface Proxy) obtains the call information required for the interface call request from the parameter converter 301, or the parameter converter 301 sends the call information to the interface proxy 302, where the call information includes the request identifier of the interface call request, The interface name, the first parameter, and the calling mode. If the calling mode is asynchronous, the calling information further includes a callback function. Of course, the request identifier may also be determined or generated by the interface proxy 302. Specifically, the embodiment of the present invention is not limited. If the calling mode is an asynchronous call, the interface proxy 302 adds the request identifier and the callback function corresponding to the request identifier to the callback database 308 according to the acquired call information. After the caller 309 receives the output parameter of the target interface function returned by the interface notifier 304 in the main process, the target callback function corresponding to the request identifier is queried from the callback database 308 according to the request identifier in the output parameter. At the same time, the interface proxy 302 sends an interface call request to the interface forwarder 303 located in the main process, which may be as shown in code 4.
例如,若需要调用的目标接口的调用方式为异步调用,假设目标接口的接口名称为recordHistory,则客户端脚本调用该目标接口的代码可以为:recordHistory('http:\\www.liebao.cn','2014-07-20 20:00:00',onRecordHistoryDone),可知,第一参数包括“http:\\www.liebao.cn”、“2014-07-20 20:00:00”,回调函数的函数名称为onRecordHistoryDone。因此,参数转换器301接收客户端脚本调用目标接口recordHistory的接口调用请求,确定所述接口调用请求的请求标识和所述目标接口的调用方式;根据所述 调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数。参数转换器303对第一参数进行格式转换,格式转换后的第一参数可以如表2所示。接口代理302可以将标识该接口调用请求的请求标识(request_id)、回调函数对象(这里是onRecordHistoryDone函数)以及正常执行该回调函数所需的环境变量等信息添加到回调数据库308中,保证回调器可以根据回调数据库308中保存的信息将调用结果成功返回给脚本。同时,接口代理302根据所获取到的调用信息重新构造接口调用请求,并通过进程间通信的方式将该接口调用请求发送给浏览器主进程中的接口转发器303,接口的调用请求可以如代码4所示,该接口的调用请求可以携带请求标识request_id、接口名称interface、第一参数arguments和调用方式sync,其中,第一参数的数据类型为预设的第二数据类型。For example, if the calling interface to be called is called asynchronously, assuming the interface name of the target interface is recordHistory, the code of the client script calling the target interface can be: recordHistory('http:\\www.liebao.cn' , '2014-07-20 20:00:00', onRecordHistoryDone), we can see that the first parameters include "http:\\www.liebao.cn", "2014-07-20 20:00:00", callback function The function name is onRecordHistoryDone. Therefore, the parameter converter 301 receives the interface call request of the client script to call the target interface recordHistory, determines the request identifier of the interface call request, and the calling mode of the target interface; And calling the mode and the interface parameter to determine a first parameter of the input parameter of the target interface function corresponding to the target interface. The parameter converter 303 performs format conversion on the first parameter, and the first parameter after the format conversion can be as shown in Table 2. The interface proxy 302 can add information such as a request identifier (request_id) identifying the interface call request, a callback function object (here, the onRecordHistoryDone function), and an environment variable required to normally execute the callback function to the callback database 308, ensuring that the callback can The result of the call is successfully returned to the script based on the information stored in the callback database 308. At the same time, the interface proxy 302 reconstructs the interface call request according to the acquired call information, and sends the interface call request to the interface forwarder 303 in the browser main process by means of inter-process communication. The call request of the interface may be like a code. As shown in FIG. 4, the call request of the interface may carry a request identifier request_id, an interface name interface, a first parameter arguments, and a call mode sync, where the data type of the first parameter is a preset second data type.
代码4中举例描述了异步接口的调用请求,其中,request_id用来标识接口调用请求,interface表示要调用目标接口对应的接口标识,arguments是经过参数转换器301转换后得到的数据类型为预设的第一数据类型的第一参数,sync用来表示目标接口的调用方式。The code 4 describes the call request of the asynchronous interface. The request_id is used to identify the interface call request, the interface indicates that the interface identifier corresponding to the target interface is to be called, and the argument type obtained by the parameter converter 301 is preset. The first parameter of the first data type, sync is used to indicate the calling mode of the target interface.
代码4Code 4
Figure PCTCN2016083359-appb-000004
Figure PCTCN2016083359-appb-000004
若需要调用的目标接口为同步接口,则接口调用请求中的参数sync为true,同理,接口代理302通过进程间通信的方式把所构造的接口的调用请求发送给浏览器主进程中的接口转发器303。若调用方式为同步调用,则接口代理302向接口转发器303发送调用请求后,接口代理302会暂停执行,直到浏览器主进程执行完成并传递返回值后才继续。若调用方式为异步调用,则接口代理302向接口转发器303发送调用请求后,接口代理302会立即返回,从而,渲染进程可以继续执行其它操作,网页的执行效率高。 If the target interface to be called is a synchronous interface, the parameter sync in the interface call request is true. Similarly, the interface proxy 302 sends the call request of the constructed interface to the interface in the browser main process by means of inter-process communication. Transponder 303. If the calling mode is a synchronous call, after the interface proxy 302 sends a call request to the interface forwarder 303, the interface proxy 302 suspends execution until the browser main process finishes executing and passes the return value. If the calling mode is an asynchronous call, after the interface proxy 302 sends the call request to the interface forwarder 303, the interface proxy 302 returns immediately, so that the rendering process can continue to perform other operations, and the execution efficiency of the webpage is high.
接口转发器303接收到接口代理发送的调用请求后,根据该调用请求中所携带的调用信息,将标识该调用请求的请求标识和调用方式添加至调用请求数据库307中,从而,位于主进程中的调用请求数据库307保存有各请求标识与调用请求所指定的目标接口的调用方式之间的对应关系。接口转发器303根据接口标识去接口注册器305中查询与该接口名称对应的目标接口函数,获取目标接口对应的目标接口函数401的位置,将请求标识request_id和第一参数arguments作为所查询到的目标接口函数401的输入参数,调用该目标接口函数,其中,目标接口函数的实现方式可以是异步实现方式也可以是同步实现方式。After receiving the call request sent by the interface proxy, the interface forwarder 303 adds the request identifier and the calling manner that identifies the call request to the call request database 307 according to the call information carried in the call request, thereby being located in the main process. The call request database 307 stores the correspondence between each request identifier and the calling mode of the target interface specified by the call request. The interface forwarder 303 queries the interface registrar 305 to query the target interface function corresponding to the interface name, obtains the location of the target interface function 401 corresponding to the target interface, and uses the request identifier request_id and the first parameter argument as the queried query. The input parameter of the target interface function 401 is called, and the implementation of the target interface function may be an asynchronous implementation or a synchronous implementation.
通常,接口函数运行完毕后,需要返回运行结果,如操作是否成功,要求读取的数据等等,这些数据为接口函数的输出参数,该输出参数的数据类型为预设的第一数据类型,如KeyValueMap类型或Value类型等。那么,目标接口函数在执行完毕后,会把输出参数传递给接口通知器304,其中,输出参数包括请求标识和第二参数,第二参数为所述请求标识对应的接口调用请求的调用结果,从而,接口通知器304根据请求标识在调用请求数据库307中查找所对应的调用请求和调用方式。Usually, after the interface function is finished, it needs to return the running result, such as whether the operation is successful, the data to be read, etc., and the data is the output parameter of the interface function, and the data type of the output parameter is the preset first data type. Such as KeyValueMap type or Value type. Then, after the execution of the target interface function, the output parameter is passed to the interface notifier 304, where the output parameter includes the request identifier and the second parameter, and the second parameter is the call result of the interface call request corresponding to the request identifier. Thus, the interface notifier 304 looks up the corresponding call request and calling mode in the call request database 307 according to the request identifier.
若调用方式为同步调用,则接口通知器304将请求标识和第二参数发送给接口代理302,从而,接口代理302接收到接口通知器304返回的目标接口函数的输出参数后,继续执行其它操作。参数转换器301对输出参数中的第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型,例如,脚本内部的Object对象,进而,返回该请求标识对应的调用结果给脚本,同步调用完成。在同步调用完成后,根据请求标识删除调用请求数据库307中的对应项,从而降低数据量,提高查询效率。If the calling mode is a synchronous call, the interface notifier 304 sends the request identifier and the second parameter to the interface proxy 302, so that the interface proxy 302 continues to perform other operations after receiving the output parameter of the target interface function returned by the interface notifier 304. . The parameter converter 301 performs format conversion on the second parameter of the output parameter, and the data type of the converted second parameter is a preset third data type, for example, an Object object inside the script, and further, returns a corresponding identifier of the request identifier. The result is called to the script and the synchronous call is completed. After the synchronization call is completed, the corresponding item in the call request database 307 is deleted according to the request identifier, thereby reducing the amount of data and improving the query efficiency.
若调用方式为同步调用,接口代理302给接口转发器303发送接口的调用请求后会立即返回,继续执行脚本的其它部分。而调用接口的返回结果需要通过调用请求所指定的回调函数来返回。因此,接口通知器304根据输出参数中的请求标识从调用请求数据库307中查询得该请求标识对应的目标接口为异步调用后,将请求标识和第二参数发送给渲染进程中的回调器309,回调器309采用该请求标识从回调数据库308中查询该请求标识对应的目标回调函数,同时,调用参数转换器301将第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型,例如,脚本的Object对象,将转换后的第二参数作为目标回调函数的输入参数,运行脚本提供的目标回调函数,从而,返回调用结果,异步接口调用完成。在异步调用完成后,根据请求标识删除调用请求数据库307和回调数据库308中的对应项,从而降低数据量,提高查询效率。If the calling mode is a synchronous call, the interface proxy 302 will return to the interface forwarder 303 after sending the call request of the interface, and continue to execute other parts of the script. The return result of the calling interface needs to be returned by calling the callback function specified by the request. Therefore, the interface notifier 304 sends the request identifier and the second parameter to the callback 309 in the rendering process after the asynchronous call is made to the target interface corresponding to the request identifier from the call request database 307 according to the request identifier in the output parameter. The caller 309 uses the request identifier to query the target callback function corresponding to the request identifier from the callback database 308, and at the same time, invokes the parameter converter 301 to format convert the second parameter, and the data type of the converted second parameter is preset. The third data type, for example, the Object object of the script, uses the converted second parameter as an input parameter of the target callback function, runs the target callback function provided by the script, and returns the result of the call, and the asynchronous interface call is completed. After the asynchronous call is completed, the corresponding items in the call request database 307 and the callback database 308 are deleted according to the request identifier, thereby reducing the amount of data and improving the query efficiency.
在本发明实施例描述的接口调用装置中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供 的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。In the interface invoking device described in the embodiment of the present invention, an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is provided by a browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; The interface calls the request identifier and the first parameter as input parameters of the target interface function, and invokes the target interface function; and obtains an output parameter returned after calling the target interface function, where the output parameter includes Determining the request identifier and the second parameter; and returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
请参见图6,图6是本发明实施例提供的一种终端的结构示意图,在本发明实施例中,终端10包括如上所述的接口调用装置。在本发明实施例中,所述终端可以包括:智能手机、电脑、平板电脑、笔记本电脑、掌上电脑以及移动互联网设备(MID)、PAD等终端设备。具体的,本发明实施例不作限制。Referring to FIG. 6, FIG. 6 is a schematic structural diagram of a terminal according to an embodiment of the present invention. In the embodiment of the present invention, the terminal 10 includes the interface calling device as described above. In the embodiment of the present invention, the terminal may include: a smart phone, a computer, a tablet computer, a notebook computer, a palmtop computer, and a terminal device such as a mobile Internet device (MID) or a PAD. Specifically, the embodiment of the present invention is not limited.
值得说明的是,终端10包括如上所述的任意一种接口调用装置,该终端接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。It is to be noted that the terminal 10 includes any interface calling device as described above, and the terminal receives an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke. The target interface is one of the extended interfaces provided by the browser; determining the calling mode of the target interface according to the interface identifier; determining the input of the target interface function corresponding to the target interface according to the calling mode and the interface parameter a first parameter of the parameter; calling the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, calling the target interface function; and obtaining an output returned after calling the target interface function a parameter, the output parameter includes the request identifier and the second parameter; and based on the second parameter, returning an invocation result of the interface call request corresponding to the request identifier to the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
请参见图7,图7是本发明实施例提供的一种接口调用装置的再一结构示意图,用于执行本发明实施例公开的接口调用方法,该装置可以包括:至少一个处理器401,例如CPU,至少一个网络接口404或者其他用户接口403,存储器405,至少一个通信总线402。通信总线402用于实现这些组件之间的连接通信。其中,用户接口403可选的可以包括USB接口以及其他标准接口、有线接口。网络接口404可选的可以包括Wi-Fi接口以及其他无线接口。存储器405可能包含高速RAM存储器,也可能还包括非不稳定的存储器(non-volatile memory),例如至少一个磁盘存储器。存储器405可选的可以包含至少一个位于远离前述处 理器401的存储装置。如图7所示,作为一种计算机存储介质的存储器405中可以包括操作系统4051及应用程序4052。Referring to FIG. 7, FIG. 7 is a schematic structural diagram of an interface calling apparatus according to an embodiment of the present invention, for performing an interface calling method disclosed in an embodiment of the present invention, where the apparatus may include: at least one processor 401, for example, The CPU, at least one network interface 404 or other user interface 403, memory 405, at least one communication bus 402. Communication bus 402 is used to implement connection communication between these components. The user interface 403 can optionally include a USB interface and other standard interfaces and wired interfaces. Network interface 404 can optionally include a Wi-Fi interface as well as other wireless interfaces. The memory 405 may include a high speed RAM memory and may also include a non-volatile memory such as at least one disk memory. The memory 405 can optionally include at least one located far from the foregoing The storage device of the processor 401. As shown in FIG. 7, an operating system 4051 and an application 4052 may be included in the memory 405 as a computer storage medium.
在一些实施方式中,存储器405存储了如下的元素,可执行模块或者数据结构,或者他们的子集,或者他们的扩展集:In some implementations, the memory 405 stores the following elements, executable modules or data structures, or a subset thereof, or their extension set:
操作系统4051,包含各种系统程序,用于实现各种基础业务以及处理基于硬件的任务;An operating system 4051, including various system programs for implementing various basic services and processing hardware-based tasks;
应用程序4052,包含目标网络数据的数据分块参数的设置程序、目标数据块的划分程序、目标数据块与数据库中的数据块的比较程序以及目标数据块的删除程序等各种应用程序,用于实现各种应用业务。The application 4052 includes various setting programs of a data block parameter setting program of the target network data, a partitioning program of the target data block, a comparison program of the target data block and the data block in the database, and a deletion program of the target data block, and the like. To achieve a variety of application services.
具体地,处理器401用于调用存储器405中存储的程序,执行以下操作:Specifically, the processor 401 is configured to invoke a program stored in the memory 405 to perform the following operations:
接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;Receiving an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser;
根据所述接口标识,确定所述目标接口的调用方式;Determining, according to the interface identifier, a calling manner of the target interface;
根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;Determining, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the target interface;
将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, and calling the target interface function;
获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;Obtaining an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。And returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
在一种实施例中,所述输出参数的数据类型为预设的第一数据类型;In an embodiment, the data type of the output parameter is a preset first data type;
处理器401执行所述根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数的操作之后,还包括执行以下操作:After the processor 401 performs the operation of determining the first parameter in the input parameter of the target interface function corresponding to the target interface according to the calling mode and the interface parameter, the method further includes: performing the following operations:
将所述第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型;Formatting the first parameter, and the data type of the converted first parameter is a preset second data type;
处理器401执行所述获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数的操作之后,还包括执行以下操作:The processor 401 performs the obtaining the output parameter returned after the calling of the target interface function, and after the output parameter includes the operation of the request identifier and the second parameter, the method further includes:
将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。Converting the second parameter into a format, and the data type of the converted second parameter is a preset third data type.
在一种实施例中,处理器401执行所述根据所述调用方式和所述接口参数,确定所述目标接口函数的输入参数中的第一参数的操作,包括执行以下操作:In an embodiment, the processor 401 performs the operation of determining the first parameter of the input parameters of the target interface function according to the calling mode and the interface parameter, including: performing the following operations:
若所述调用方式为同步调用,将所述接口参数确定为所述目标接口函数的输入参数中的第一参数; If the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
若所述调用方式为异步调用,将所述接口参数中除预设参数外的其它参数确定为所述目标接口函数的输入参数中的第一参数,所述预设参数用于标识回调函数。If the calling mode is an asynchronous call, the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
在一种实施例中,处理器401执行所述基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本,包括执行以下操作:In an embodiment, the processor 401 performs the returning, according to the second parameter, a result of calling the interface call request corresponding to the request identifier to the client script, and the following operations are performed:
若所述调用方式为同步调用,将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本;If the calling mode is a synchronous call, the second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier;
若所述调用方式为异步调用,确定所述请求标识对应的目标回调函数,并将所述第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给客户端脚本。If the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result, and then The output result is returned to the client script as a result of the call of the interface call request.
在一种实施例中,处理器401执行所述根据所述接口标识,确定所述目标接口的调用方式的操作之后,还包括执行以下操作:In an embodiment, after the performing, by the processor 401, the operation of determining the calling manner of the target interface according to the interface identifier, the method further includes:
若所述调用方式为异步调用,将回调信息保存至回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数;If the calling mode is an asynchronous call, the callback information is saved in the callback database, where the callback information includes the request identifier and a callback function identified by the preset parameter;
其中,处理器401执行所述确定所述请求标识对应的目标回调函数的操作,包括执行以下操作:The processor 401 performs the operation of determining the target callback function corresponding to the request identifier, including performing the following operations:
若所述调用方式为异步调用,根据所述请求标识从所述回调数据库中查询所述请求标识对应的回调信息;If the calling mode is an asynchronous call, query the callback information corresponding to the request identifier from the callback database according to the request identifier;
将所述回调信息指定的回调函数确定为目标回调函数。The callback function specified by the callback information is determined as a target callback function.
在一种实施例中,处理器401执行所述将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本的操作之后,还包括执行以下操作:In an embodiment, after the processor 401 performs the operation of returning the second parameter as the result of the call of the interface call request corresponding to the request identifier to the client script, the method further includes:
删除所述回调数据库中所述请求标识对应的回调信息。Deleting the callback information corresponding to the request identifier in the callback database.
在一种实施例中,处理器401执行根据所述接口标识,确定所述目标接口的调用方式的操作,包括执行以下操作:In an embodiment, the processor 401 performs an operation of determining a calling manner of the target interface according to the interface identifier, including performing the following operations:
根据所述接口标识,从预设的接口数据库中查询所述接口标识对应的接口信息,所述接口信息包括接口标识和调用方式;Querying, according to the interface identifier, the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
将所述接口数据库中该接口标识对应的调用方式确定为所述目标接口的调用方式。The calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
在本发明实施例描述的技术方案中,接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数;将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数; 获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。采用本发明实施例,通过规范化接口函数的设计和接口调用,浏览器可以采用统一的接口调用方法来实现客户端脚本对任一扩展接口的调用。从而,开发人员开发扩展接口时,只需开发该扩展接口对应的接口函数,提高开发效率。In the technical solution described in the embodiment of the present invention, an interface call request is received, where the interface call request carries an interface identifier and an interface parameter corresponding to a target interface that the client script needs to invoke, and the target interface is an extension provided by the browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the target interface; Calling the requested identifier of the interface and the first parameter as input parameters of the target interface function, and calling the target interface function; Obtaining an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter; and returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the Describe the client script. By adopting the embodiment of the present invention, through the design of the normalized interface function and the interface call, the browser can adopt a unified interface calling method to implement the call of the client script to any extended interface. Therefore, when a developer develops an extension interface, it is only necessary to develop an interface function corresponding to the extension interface to improve development efficiency.
在本说明书的描述中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不一定是必须针对相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。In the description of the present specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" and the like means a specific feature described in connection with the embodiment or example. A structure, material or feature is included in at least one embodiment or example of the invention. In the present specification, the schematic representation of the above terms does not necessarily have to be for the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in a suitable manner in any one or more embodiments or examples. In addition, various embodiments or examples described in the specification, as well as features of various embodiments or examples, may be combined and combined.
本领域的技术人员可以将本说明书中描述的不同实施例以及不同实施例的特征进行结合和组合。本发明所有实施例中的模块或单元,可以通过通用集成电路,例如CPU(Central Processing Unit,中央处理器),或通过ASIC(Application Specific Integrated Circuit,专用集成电路)来实现。Those skilled in the art can combine and combine the different embodiments described in the specification and the features of the different embodiments. The modules or units in all the embodiments of the present invention may be implemented by a general-purpose integrated circuit, such as a CPU (Central Processing Unit) or an ASIC (Application Specific Integrated Circuit).
本发明所有实施例方法中的步骤可以根据实际需要进行顺序调整、合并和删减;本发明所有实施例装置中的模块或单元可以根据实际需要进行合并、划分和删减。The steps in the method of all the embodiments of the present invention may be sequentially adjusted, combined, and deleted according to actual needs; the modules or units in all the embodiments of the present invention may be combined, divided, and deleted according to actual needs.
流程图中或在此以其他方式描述的任何过程或方法描述可以被理解为,表示包括一个或更多个用于实现特定逻辑功能或过程的步骤的可执行指令的代码的模块、片段或部分,并且本发明的优选实施方式的范围包括另外的实现,其中可以不按所示出或讨论的顺序,包括根据所涉及的功能按基本同时的方式或按相反的顺序,来执行功能,这应被本发明的实施例所属技术领域的技术人员所理解。Any process or method description in the flowcharts or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a particular logical function or process. And the scope of the preferred embodiments of the invention includes additional implementations, in which the functions may be performed in a substantially simultaneous manner or in an opposite order depending on the functions involved, in the order shown or discussed. It will be understood by those skilled in the art to which the embodiments of the present invention pertain.
在流程图中表示或在此以其他方式描述的逻辑和/或步骤,例如,可以被认为是用于实现逻辑功能的可执行指令的定序列表,可以具体实现在任何计算机可读介质中,以供指令执行系统、装置或设备(如基于计算机的系统、包括处理器的系统或其他可以从指令执行系统、装置或设备取指令并执行指令的系统)使用,或结合这些指令执行系统、装置或设备而使用。就本说明书而言,"计算机可读介质"可以是任何可以包含、存储、通信、传播或传输程序以供指令执行系统、装置或设备或结合这些指令执行系统、装置或设备而使用的装置。计算机可读介质的更具体的示例(非穷尽性列表)包括以下:具有一个或多个布线的电连接部(电 子装置),便携式计算机盘盒(磁装置),随机存取存储器(RAM),只读存储器(ROM),可擦除可编辑只读存储器(EPROM或闪速存储器),光纤装置,以及便携式光盘只读存储器(CDROM)。另外,计算机可读介质甚至可以是可在其上打印所述程序的纸或其他合适的介质,因为可以例如通过对纸或其他介质进行光学扫描,接着进行编辑、解译或必要时以其他合适方式进行处理来以电子方式获得所述程序,然后将其存储在计算机存储器中。The logic and/or steps represented in the flowchart or otherwise described herein, for example, may be considered as an ordered list of executable instructions for implementing logical functions, and may be embodied in any computer readable medium, Used in conjunction with, or in conjunction with, an instruction execution system, apparatus, or device (eg, a computer-based system, a system including a processor, or other system that can fetch instructions and execute instructions from an instruction execution system, apparatus, or device) Or use with equipment. For the purposes of this specification, a "computer-readable medium" can be any apparatus that can contain, store, communicate, propagate, or transport a program for use in an instruction execution system, apparatus, or device, or in conjunction with the instruction execution system, apparatus, or device. A more specific example (non-exhaustive list) of computer readable media includes the following: electrical connections having one or more wires (electrical Sub-device), portable computer case (magnetic device), random access memory (RAM), read only memory (ROM), erasable editable read only memory (EPROM or flash memory), fiber optic device, and portable CD Read only memory (CDROM). In addition, the computer readable medium may even be a paper or other suitable medium on which the program can be printed, as it may be optically scanned, for example by paper or other medium, followed by editing, interpretation or, if appropriate, other suitable The method is processed to obtain the program electronically and then stored in computer memory.
本技术领域的普通技术人员可以理解实现上述实施例方法携带的全部或部分步骤是可以通过程序来指令相关的硬件完成,所述的程序可以存储于一种计算机可读存储介质中,该程序在执行时,包括方法实施例的步骤之一或其组合。One of ordinary skill in the art can understand that all or part of the steps carried by the method of implementing the above embodiments can be completed by a program to instruct related hardware, and the program can be stored in a computer readable storage medium. When executed, one or a combination of the steps of the method embodiments is included.
此外,在本发明各个实施例中的各功能单元可以集成在一个处理模块中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。所述集成的模块如果以软件功能模块的形式实现并作为独立的产品销售或使用时,也可以存储在一个计算机可读取存储介质中。In addition, each functional unit in each embodiment of the present invention may be integrated into one processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above integrated modules can be implemented in the form of hardware or in the form of software functional modules. The integrated modules, if implemented in the form of software functional modules and sold or used as stand-alone products, may also be stored in a computer readable storage medium.
上述提到的存储介质可以是只读存储器,磁盘或光盘等。尽管上面已经示出和描述了本发明的实施例,可以理解的是,上述实施例是示例性的,不能理解为对本发明的限制,本领域的普通技术人员在本发明的范围内可以对上述实施例进行变化、修改、替换和变型。The above mentioned storage medium may be a read only memory, a magnetic disk or an optical disk or the like. Although the embodiments of the present invention have been shown and described, it is understood that the above-described embodiments are illustrative and are not to be construed as limiting the scope of the invention. The embodiments are subject to variations, modifications, substitutions and variations.
以上所揭露的仅为本发明的较佳实施例而已,当然不能以此来限定本发明之权利范围,本领域普通技术人员可以理解实现上述实施例的全部或部分流程,并依本发明权利要求所作的等同变化,仍属于发明所涵盖的范围。 The above is only the preferred embodiment of the present invention, and the scope of the present invention is not limited thereto, and those skilled in the art can understand all or part of the process of implementing the above embodiments, and according to the claims of the present invention. Equivalent changes made are still within the scope of the invention.

Claims (20)

  1. 一种接口调用方法,其特征在于,包括:An interface calling method, comprising:
    接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;Receiving an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser;
    根据所述接口标识,确定所述目标接口的调用方式;Determining, according to the interface identifier, a calling manner of the target interface;
    根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;Determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of the target interface function corresponding to the interface identifier;
    将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, and calling the target interface function;
    获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;Obtaining an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
    基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。And returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  2. 如权利要求1所述的方法,其特征在于,所述输出参数的数据类型为预设的第一数据类型;The method according to claim 1, wherein the data type of the output parameter is a preset first data type;
    所述根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数之后,所述方法还包括:After the first parameter in the input parameter of the target interface function corresponding to the target interface is determined according to the calling mode and the interface parameter, the method further includes:
    将所述第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型;Formatting the first parameter, and the data type of the converted first parameter is a preset second data type;
    所述获取调用所述目标接口函数后返回的输出参数之后,所述方法还包括:After the obtaining the output parameter returned after the target interface function is invoked, the method further includes:
    将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。Converting the second parameter into a format, and the data type of the converted second parameter is a preset third data type.
  3. 如权利要求1或2所述的方法,其特征在于,所述根据所述调用方式和所述接口参数,确定所述目标接口对应的目标接口函数的输入参数中的第一参数包括:The method according to claim 1 or 2, wherein the determining, according to the calling mode and the interface parameter, the first parameter in the input parameter of the target interface function corresponding to the target interface comprises:
    若所述调用方式为同步调用,将所述接口参数确定为所述目标接口函数的输入参数中的第一参数;If the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
    若所述调用方式为异步调用,将所述接口参数中除预设参数外的其它参数确定为所述目标接口函数的输入参数中的第一参数,所述预设参数用于标识回调函数。If the calling mode is an asynchronous call, the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
  4. 如权利要求1至3中任一项所述的方法,其特征在于,所述基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本包括:The method according to any one of claims 1 to 3, wherein the returning the call result of the interface call request corresponding to the request identifier to the client script based on the second parameter comprises:
    若所述调用方式为同步调用,将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本; If the calling mode is a synchronous call, the second parameter is returned to the client script as a result of the call of the interface call request corresponding to the request identifier;
    若所述调用方式为异步调用,确定所述请求标识对应的目标回调函数,并将所述第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给所述客户端脚本。If the calling mode is an asynchronous call, determining a target callback function corresponding to the request identifier, and using the second parameter as an input parameter of the target callback function, running the target callback function to obtain an output result, and then The output result is returned to the client script as a result of the call of the interface call request.
  5. 如权利要求4所述的方法,其特征在于,所述根据所述接口标识,确定所述目标接口的调用方式之后,所述方法还包括:The method according to claim 4, wherein after the determining the calling mode of the target interface according to the interface identifier, the method further includes:
    若所述调用方式为异步调用,将回调信息保存至回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数;If the calling mode is an asynchronous call, the callback information is saved in the callback database, where the callback information includes the request identifier and a callback function identified by the preset parameter;
    所述确定所述请求标识对应的目标回调函数,包括:Determining the target callback function corresponding to the request identifier, including:
    若所述调用方式为异步调用,根据所述请求标识从所述回调数据库中查询所述请求标识对应的回调信息;If the calling mode is an asynchronous call, query the callback information corresponding to the request identifier from the callback database according to the request identifier;
    将所述回调信息指定的回调函数确定为目标回调函数。The callback function specified by the callback information is determined as a target callback function.
  6. 如权利要求5所述的方法,其特征在于,所述将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本之后,所述方法还包括:The method according to claim 5, wherein after the returning the second parameter as the result of the call of the interface call request corresponding to the request identifier to the client script, the method further includes:
    删除所述回调数据库中所述请求标识对应的回调信息。Deleting the callback information corresponding to the request identifier in the callback database.
  7. 如权利要求1至6中任一项所述的方法,其特征在于,所述根据所述接口标识,确定所述目标接口的调用方式包括:The method according to any one of claims 1 to 6, wherein the determining the calling manner of the target interface according to the interface identifier comprises:
    根据所述接口标识,从预设的接口数据库中查询所述接口标识对应的接口信息,所述接口信息包括接口标识和调用方式;Querying, according to the interface identifier, the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
    将所述接口数据库中该接口标识对应的调用方式确定为所述目标接口的调用方式。The calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
  8. 一种接口调用装置,其特征在于,包括:An interface calling device, comprising:
    接收模块,用于接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;a receiving module, configured to receive an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is one of the extended interfaces provided by the browser;
    方式确定模块,用于根据所述接口标识,确定所述目标接口的调用方式;a mode determining module, configured to determine, according to the interface identifier, a calling mode of the target interface;
    参数确定模块,用于根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;a parameter determining module, configured to determine, according to the calling manner and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier;
    调用模块,用于将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;a calling module, configured to invoke the request identifier of the interface call request and the first parameter as an input parameter of the target interface function, and invoke the target interface function;
    获取模块,用于获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;An obtaining module, configured to obtain an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
    返回模块,用于基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。 And a returning module, configured to return, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  9. 如权利要求8所述的装置,其特征在于,所述输出参数的数据类型为预设的第一数据类型,所述装置还包括:The device according to claim 8, wherein the data type of the output parameter is a preset first data type, and the device further comprises:
    第一转换模块,用于将所述第一参数进行格式转换,转换后的第一参数的数据类型为预设的第二数据类型;a first conversion module, configured to perform format conversion on the first parameter, where the data type of the converted first parameter is a preset second data type;
    第二转换模块,用于将所述第二参数进行格式转换,转换后的第二参数的数据类型为预设的第三数据类型。The second conversion module is configured to perform format conversion on the second parameter, and the data type of the converted second parameter is a preset third data type.
  10. 如权利要求8或9所述的装置,其特征在于,所述参数确定模块具体用于:The device according to claim 8 or 9, wherein the parameter determining module is specifically configured to:
    若所述调用方式为同步调用,将所述接口参数确定为所述目标接口函数的输入参数中的第一参数;If the calling mode is a synchronous call, determining the interface parameter as the first parameter in the input parameter of the target interface function;
    若所述调用方式为异步调用,将所述接口参数中除预设参数外的其它参数确定为所述目标接口函数的输入参数中的第一参数,所述预设参数用于标识回调函数。If the calling mode is an asynchronous call, the other parameters of the interface parameter except the preset parameter are determined as the first parameter in the input parameter of the target interface function, and the preset parameter is used to identify the callback function.
  11. 如权利要求8至10中任一项所述的装置,其特征在于,所述返回模块包括:The apparatus according to any one of claims 8 to 10, wherein the returning module comprises:
    同步返回单元,用于若所述调用方式为同步调用,将所述第二参数作为所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本;以及a synchronization return unit, configured to return the second parameter as a result of the call of the interface call request corresponding to the request identifier to the client script if the calling mode is a synchronous call;
    异步返回单元,用于若所述调用方式为异步调用,确定所述请求标识对应的目标回调函数,并将所述第二参数作为所述目标回调函数的输入参数,运行所述目标回调函数得到输出结果,进而将所述输出结果作为所述接口调用请求的调用结果返回给客户端脚本。An asynchronous return unit, configured to: if the calling mode is an asynchronous call, determine a target callback function corresponding to the request identifier, and use the second parameter as an input parameter of the target callback function, and run the target callback function to obtain The result is output, and the output result is returned to the client script as a result of the call of the interface call request.
  12. 如权利要求8至11中任一项所述的装置,其特征在于,还包括:The apparatus according to any one of claims 8 to 11, further comprising:
    保存模块,用于若所述调用方式为异步调用,将回调信息保存至回调数据库中,所述回调信息包括所述请求标识和所述预设参数所标识的回调函数,a saving module, configured to save the callback information to the callback database if the calling mode is an asynchronous call, where the callback information includes the request identifier and a callback function identified by the preset parameter,
    所述同步返回单元用于:The synchronous return unit is used to:
    根据所述请求标识从所述回调数据库中查询所述请求标识对应的回调信息;Querying the callback information corresponding to the request identifier from the callback database according to the request identifier;
    将所述回调信息指定的回调函数确定为目标回调函数。The callback function specified by the callback information is determined as a target callback function.
  13. 如权利要求12所述的装置,其特征在于,还包括:The device of claim 12, further comprising:
    删除模块,用于删除所述回调数据库中所述请求标识对应的回调信息。And a deleting module, configured to delete the callback information corresponding to the request identifier in the callback database.
  14. 如权利要求8至13中任一项所述的装置,其特征在于,所述方式确定模块用于:The apparatus according to any one of claims 8 to 13, wherein the mode determining module is configured to:
    根据所述接口标识,从预设的接口数据库中查询所述接口标识对应的接口信息,所述接口信息包括接口标识和调用方式;Querying, according to the interface identifier, the interface information corresponding to the interface identifier from a preset interface database, where the interface information includes an interface identifier and a calling mode;
    将所述接口数据库中该接口标识对应的调用方式确定为所述目标接口的调用方式。The calling mode corresponding to the interface identifier in the interface database is determined as the calling mode of the target interface.
  15. 一种接口调用装置,其特征在于,包括:An interface calling device, comprising:
    接口注册器,用于记录接口的注册信息,所述接口的注册信息包括接口的接口标识和调 用方式;An interface registrar, configured to record registration information of the interface, where the registration information of the interface includes an interface identifier and an interface Way of use;
    接口数据库,用于存储各个接口的接口信息;An interface database for storing interface information of each interface;
    调用请求数据库,用于存储调用的请求标识和调用方式;Calling the request database for storing the request identifier and calling mode of the call;
    参数转换器,用于接收客户端脚本的接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;根据所述接口标识,确定所述目标接口的调用方式;根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数中的第一参数;The parameter converter is configured to receive an interface call request of the client script, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to invoke, and the target interface is an extended interface provided by the browser. Determining, according to the interface identifier, a calling mode of the target interface; determining, according to the calling mode and the interface parameter, a first parameter in an input parameter of a target interface function corresponding to the interface identifier;
    接口代理,用于获取所述接口调用请求所需的调用信息,所述调用信息包括请求标识、接口标识、第一参数和调用方式;并且根据获取到的所述调用信息重构接口调用请求;An interface proxy, configured to acquire the call information required by the interface call request, where the call information includes a request identifier, an interface identifier, a first parameter, and a calling manner; and reconstruct an interface call request according to the obtained call information;
    接口转发器,接收所述接口代理发送的重构的所述接口调用请求;将所述接口调用请求中的请求标识和调用方式添加至所述调用请求数据库;根据所述接口标识查询所述接口注册器以获取所述接口标识对应的目标接口函数,获取所述目标接口对应的目标接口函数的位置,将所述请求标识和第一参数作为查询到的目标接口函数的输入参数,调用所述目标接口函数;The interface forwarder receives the reconstructed interface call request sent by the interface proxy, adds a request identifier and a calling manner in the interface call request to the call request database, and queries the interface according to the interface identifier. The registrar acquires the target interface function corresponding to the interface identifier, obtains the location of the target interface function corresponding to the target interface, and uses the request identifier and the first parameter as input parameters of the queried target interface function, and invokes the Target interface function;
    接口通知器,用于获取目标接口函数运行完毕后的输出参数,所述输出参数包括所述请求标识和第二参数,所述第二参数为所述请求标识对应的接口调用请求的调用结果;根据所述请求标识在所述调用请求数据库中查找对应的调用请求和调用方式;以及若所述调用方式为同步调用,将所述输出参数发送给所述接口代理。An interface notifier, configured to obtain an output parameter after the target interface function is completed, where the output parameter includes the request identifier and the second parameter, where the second parameter is a call result of the interface call request corresponding to the request identifier; And searching for a corresponding call request and a calling mode in the call request database according to the request identifier; and sending the output parameter to the interface proxy if the calling mode is a synchronous call.
  16. 如权利要求15所述的接口调用装置,其特征在于,还包括:The interface calling device of claim 15, further comprising:
    回调数据库,用于若调用方式为异步调用,存储所述异步调用的请求标识和所述请求标识所标定的接口调用请求中携带的回调函数;a callback database, configured to store a request identifier of the asynchronous call and a callback function carried in the interface call request calibrated by the request identifier if the calling mode is an asynchronous call;
    回调器,用于根据所述请求标识查询所述回调数据库以获取所述请求标识对应的目标回调函数,并通过调用所述目标回调函数的方式向所述客户端脚本返回调用结果。The callback is configured to query the callback database according to the request identifier to obtain a target callback function corresponding to the request identifier, and return a call result to the client script by calling the target callback function.
  17. 一种接口调用装置,其特征在于,包括:An interface calling device, comprising:
    至少一个处理器;At least one processor;
    存储器,用于存储所述至少一个处理器可执行的指令;a memory for storing instructions executable by the at least one processor;
    所述至少一个处理器用于:The at least one processor is configured to:
    接收接口调用请求,所述接口调用请求携带有客户端脚本需要调用的目标接口对应的接口标识和接口参数,所述目标接口为浏览器所提供的扩展接口之一;Receiving an interface call request, where the interface call request carries an interface identifier and an interface parameter corresponding to the target interface that the client script needs to call, and the target interface is one of the extended interfaces provided by the browser;
    根据所述接口标识,确定所述目标接口的调用方式;Determining, according to the interface identifier, a calling manner of the target interface;
    根据所述调用方式和所述接口参数,确定所述接口标识对应的目标接口函数的输入参数 中的第一参数;Determining, according to the calling mode and the interface parameter, an input parameter of a target interface function corresponding to the interface identifier The first parameter in ;
    将所述接口调用请求的请求标识和所述第一参数作为所述目标接口函数的输入参数,调用所述目标接口函数;Calling the request identifier of the interface call request and the first parameter as input parameters of the target interface function, and calling the target interface function;
    获取调用所述目标接口函数后返回的输出参数,所述输出参数包括所述请求标识和第二参数;Obtaining an output parameter returned after the target interface function is invoked, where the output parameter includes the request identifier and the second parameter;
    基于所述第二参数,将所述请求标识对应的接口调用请求的调用结果返回给所述客户端脚本。And returning, according to the second parameter, a call result of the interface call request corresponding to the request identifier to the client script.
  18. 一种终端,其特征在于,包括如权利要求8-17任一项所述的接口调用装置。A terminal characterized by comprising the interface calling device according to any one of claims 8-17.
  19. 一种计算机可读存储介质,具有存储于其中的指令,当终端的处理器执行所述指令时,所述终端执行如权利要求1-7中任一项所述的接口调用方法。A computer readable storage medium having instructions stored therein, the terminal executing the interface calling method of any one of claims 1-7 when the processor of the terminal executes the instructions.
  20. 一种计算机程序,当其在处理器上运行时,执行如权利要求1-7中任一项所述的接口调用方法。 A computer program that, when run on a processor, performs the interface invocation method of any one of claims 1-7.
PCT/CN2016/083359 2015-05-29 2016-05-25 Interface invoking method, device and terminal WO2016192556A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510289070.8A CN104866383B (en) 2015-05-29 2015-05-29 Interface calling method and device and terminal
CN201510289070.8 2015-05-29

Publications (1)

Publication Number Publication Date
WO2016192556A1 true WO2016192556A1 (en) 2016-12-08

Family

ID=53912231

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/083359 WO2016192556A1 (en) 2015-05-29 2016-05-25 Interface invoking method, device and terminal

Country Status (2)

Country Link
CN (1) CN104866383B (en)
WO (1) WO2016192556A1 (en)

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109274656A (en) * 2018-09-04 2019-01-25 平安普惠企业管理有限公司 Interface parameters decryption method, device, computer equipment and storage medium
CN110333914A (en) * 2019-04-12 2019-10-15 上海连尚网络科技有限公司 A kind of method and apparatus for performance objective operation
CN110737428A (en) * 2019-10-21 2020-01-31 Oppo广东移动通信有限公司 Hidl-based universal interface design method, device, terminal and readable storage medium
CN110968296A (en) * 2019-12-03 2020-04-07 政采云有限公司 Data acquisition method, device, equipment and readable storage medium
CN111124873A (en) * 2018-10-31 2020-05-08 北京国双科技有限公司 Method and device for returning Mock data
CN111310007A (en) * 2020-02-11 2020-06-19 北京达佳互联信息技术有限公司 Webpage interface query method and device, electronic equipment and storage medium
CN111552578A (en) * 2020-04-30 2020-08-18 成都新潮传媒集团有限公司 Third-party interface calling method and device
CN114840276A (en) * 2022-04-15 2022-08-02 北京百度网讯科技有限公司 Object calling method, device, equipment, storage medium and program product
CN115080006A (en) * 2021-03-15 2022-09-20 武汉斗鱼网络科技有限公司 Data calling method and related equipment
CN115208936A (en) * 2022-05-26 2022-10-18 锐凌无线有限责任公司 Remote calling method, system, device, electronic equipment and storage medium
CN115225812A (en) * 2022-06-01 2022-10-21 合肥移瑞通信技术有限公司 Camera control method and device, electronic equipment and storage medium
CN115499291A (en) * 2022-09-14 2022-12-20 平安壹钱包电子商务有限公司 Method and device for processing service zero-drop alarm information and storage medium
CN115865886A (en) * 2022-11-28 2023-03-28 灵犀科技有限公司 Cross-network data interaction method and device based on HTTP
CN117270831A (en) * 2023-11-17 2023-12-22 天津华来科技股份有限公司 Protocol class synchronization and cooperative program call compatible implementation method
CN110780929B (en) * 2019-09-18 2024-05-03 华为技术有限公司 Method for calling hardware interface and electronic equipment

Families Citing this family (30)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104866383B (en) * 2015-05-29 2018-11-23 北京金山安全软件有限公司 Interface calling method and device and terminal
CN106649078B (en) * 2015-11-02 2019-06-25 阿里巴巴集团控股有限公司 Application interface test method and device
CN107135073B (en) * 2016-02-26 2021-05-25 北京京东尚科信息技术有限公司 Interface calling method and device
CN106412009A (en) * 2016-08-29 2017-02-15 郑州悉知信息科技股份有限公司 Interface calling method and device
CN107194014B (en) * 2017-07-04 2021-05-28 贵州数据宝网络科技有限公司 Data source calling method and device
CN109426570A (en) * 2017-08-29 2019-03-05 阿里巴巴集团控股有限公司 A kind of acquisition methods of data, device and equipment
CN108009026A (en) * 2017-10-27 2018-05-08 深圳市买买提乐购金融服务有限公司 Interface call method, third party's data access platform and computer-readable medium
CN107809332A (en) * 2017-11-10 2018-03-16 中国民生银行股份有限公司 Compound interface configures and compound interface call method, device
CN109871285A (en) * 2017-12-05 2019-06-11 北京嘀嘀无限科技发展有限公司 Dynamic adjusting method, device, server, mobile terminal and readable storage medium storing program for executing
CN108650093A (en) * 2018-03-30 2018-10-12 深圳市富途网络科技有限公司 A kind of interface realizing method based on idempotence
CN108874557B (en) * 2018-05-24 2022-03-22 广东睿江云计算股份有限公司 Front-end interface processing method and system
CN110618875A (en) * 2018-06-20 2019-12-27 北京三快在线科技有限公司 Communication method, distributed system, electronic device, and storage medium
CN109218841B (en) * 2018-08-17 2021-01-01 武汉斗鱼网络科技有限公司 Barrage message transmission method, device, equipment and storage medium
CN109445960B (en) * 2018-10-18 2021-03-02 腾讯科技(深圳)有限公司 Application routing method, device and storage medium
CN109446261A (en) * 2018-10-31 2019-03-08 北京酷我科技有限公司 It is a kind of to mix the method and its system for calling data based on multiple interfaces
CN111142960B (en) * 2018-11-02 2023-11-14 中国电信股份有限公司 Interface providing method, device and system
CN109710426A (en) * 2018-12-24 2019-05-03 珠海豹趣科技有限公司 A kind of inter-process communication methods and relevant device
CN110413423A (en) * 2019-07-23 2019-11-05 腾讯科技(深圳)有限公司 Data processing method, relevant apparatus, equipment and storage medium
CN111190950B (en) * 2019-10-31 2021-12-31 腾讯科技(深圳)有限公司 Asset retrieval method and device
CN112925589B (en) * 2019-12-06 2023-10-17 深圳市雅阅科技有限公司 Calling method and device of expansion interface
CN111158794B (en) * 2019-12-19 2023-03-31 苏州浪潮智能科技有限公司 OpenStack-oriented API (application program interface) combination optimization method and device
CN111030111A (en) * 2019-12-30 2020-04-17 广东电网有限责任公司电力调度控制中心 Method, device, system and medium for configuring stable control section parameters of power system
CN111274453A (en) * 2020-01-14 2020-06-12 北京市商汤科技开发有限公司 Data operation method, system, electronic device and computer readable storage medium
CN111428171B (en) * 2020-03-23 2023-06-30 郑州悉知信息科技股份有限公司 Interface call processing method and system
CN113448742B (en) * 2020-03-25 2023-11-03 北京京东振世信息技术有限公司 Interface data acquisition method and device
CN111581578B (en) * 2020-05-09 2022-11-29 郑州悉知信息科技股份有限公司 Interface request processing method and device
CN112667371A (en) * 2020-12-07 2021-04-16 深圳市远行科技股份有限公司 Asynchronous task processing method, device, equipment and storage medium
CN112395024B (en) * 2020-12-09 2021-12-24 上海益世界信息技术集团有限公司 Interface calling method and related device
CN113452721A (en) * 2021-08-30 2021-09-28 湖南高至科技有限公司 Network interaction function optimization system, method, computer equipment and medium
CN113934476B (en) * 2021-10-15 2022-08-19 中电金信软件有限公司 Logic calling method and device and electronic equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103177040A (en) * 2011-12-26 2013-06-26 腾讯科技(深圳)有限公司 Method and device for calling functions of webpage application
CN103309728A (en) * 2012-03-12 2013-09-18 腾讯科技(深圳)有限公司 Asynchronous request processing method and equipment
CN104281455A (en) * 2014-10-11 2015-01-14 北京金山安全软件有限公司 Interface calling method and device and terminal
CN104866383A (en) * 2015-05-29 2015-08-26 北京金山安全软件有限公司 Interface calling method and device and terminal

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7020867B2 (en) * 2001-03-23 2006-03-28 S2 Technologies, Inc. System and method for automatically generating code templates for communication via a predefined communication interface
US8019839B2 (en) * 2009-05-11 2011-09-13 Accenture Global Services Limited Enhanced network adapter framework
CN103226474B (en) * 2013-05-10 2016-09-28 北京奇虎科技有限公司 Exchange method between page script and browser program, Apparatus and system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103177040A (en) * 2011-12-26 2013-06-26 腾讯科技(深圳)有限公司 Method and device for calling functions of webpage application
CN103309728A (en) * 2012-03-12 2013-09-18 腾讯科技(深圳)有限公司 Asynchronous request processing method and equipment
CN104281455A (en) * 2014-10-11 2015-01-14 北京金山安全软件有限公司 Interface calling method and device and terminal
CN104866383A (en) * 2015-05-29 2015-08-26 北京金山安全软件有限公司 Interface calling method and device and terminal

Cited By (25)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109274656A (en) * 2018-09-04 2019-01-25 平安普惠企业管理有限公司 Interface parameters decryption method, device, computer equipment and storage medium
CN109274656B (en) * 2018-09-04 2022-04-22 平安普惠企业管理有限公司 Interface parameter decryption method and device, computer equipment and storage medium
CN111124873A (en) * 2018-10-31 2020-05-08 北京国双科技有限公司 Method and device for returning Mock data
CN110333914A (en) * 2019-04-12 2019-10-15 上海连尚网络科技有限公司 A kind of method and apparatus for performance objective operation
CN110333914B (en) * 2019-04-12 2023-09-15 上海连尚网络科技有限公司 Method and device for executing target operation
CN110780929B (en) * 2019-09-18 2024-05-03 华为技术有限公司 Method for calling hardware interface and electronic equipment
CN110737428A (en) * 2019-10-21 2020-01-31 Oppo广东移动通信有限公司 Hidl-based universal interface design method, device, terminal and readable storage medium
CN110737428B (en) * 2019-10-21 2023-08-15 Oppo广东移动通信有限公司 Hidl-based universal interface design method, device, terminal and readable storage medium
CN110968296A (en) * 2019-12-03 2020-04-07 政采云有限公司 Data acquisition method, device, equipment and readable storage medium
CN110968296B (en) * 2019-12-03 2023-07-25 政采云有限公司 Data acquisition method, device, equipment and readable storage medium
CN111310007B (en) * 2020-02-11 2023-07-07 北京达佳互联信息技术有限公司 Webpage interface query method and device, electronic equipment and storage medium
CN111310007A (en) * 2020-02-11 2020-06-19 北京达佳互联信息技术有限公司 Webpage interface query method and device, electronic equipment and storage medium
CN111552578A (en) * 2020-04-30 2020-08-18 成都新潮传媒集团有限公司 Third-party interface calling method and device
CN111552578B (en) * 2020-04-30 2023-08-04 成都新潮传媒集团有限公司 Third party interface calling method and device
CN115080006A (en) * 2021-03-15 2022-09-20 武汉斗鱼网络科技有限公司 Data calling method and related equipment
CN114840276A (en) * 2022-04-15 2022-08-02 北京百度网讯科技有限公司 Object calling method, device, equipment, storage medium and program product
CN115208936A (en) * 2022-05-26 2022-10-18 锐凌无线有限责任公司 Remote calling method, system, device, electronic equipment and storage medium
CN115225812A (en) * 2022-06-01 2022-10-21 合肥移瑞通信技术有限公司 Camera control method and device, electronic equipment and storage medium
CN115225812B (en) * 2022-06-01 2024-04-09 合肥移瑞通信技术有限公司 Camera control method and device, electronic equipment and storage medium
CN115499291A (en) * 2022-09-14 2022-12-20 平安壹钱包电子商务有限公司 Method and device for processing service zero-drop alarm information and storage medium
CN115499291B (en) * 2022-09-14 2024-04-02 平安壹钱包电子商务有限公司 Processing method and device for service zero-drop alarm information and storage medium
CN115865886A (en) * 2022-11-28 2023-03-28 灵犀科技有限公司 Cross-network data interaction method and device based on HTTP
CN115865886B (en) * 2022-11-28 2023-07-18 灵犀科技有限公司 HTTP-based cross-network data interaction method and device
CN117270831A (en) * 2023-11-17 2023-12-22 天津华来科技股份有限公司 Protocol class synchronization and cooperative program call compatible implementation method
CN117270831B (en) * 2023-11-17 2024-02-23 天津华来科技股份有限公司 Protocol class synchronization and cooperative program call compatible implementation method

Also Published As

Publication number Publication date
CN104866383B (en) 2018-11-23
CN104866383A (en) 2015-08-26

Similar Documents

Publication Publication Date Title
WO2016192556A1 (en) Interface invoking method, device and terminal
WO2019104973A1 (en) Cross-language invoking method, server, and storage medium
WO2019104975A1 (en) Dubbo framework–based remote invoking method, server, and storage medium
US8978023B2 (en) Canonical mechanism for securely assembling features into a mobile application
US20180196665A1 (en) Managing, using, and updating application resources
WO2018161813A1 (en) Resource loading method and device
WO2016177341A1 (en) Interface calling method and device, and terminal
US9781262B2 (en) Methods and apparatus for voice-enabling a web application
JP6182160B2 (en) Dynamic code insertion into a running process
WO2013097592A1 (en) Script loading technology
US10157612B2 (en) Methods and apparatus for voice-enabling a web application
US20140040746A1 (en) Methods and apparatus for voiced-enabling a web application
JP6016808B2 (en) Method and server system for implementing web access
CN113468448A (en) Page rendering method and device
WO2018035799A1 (en) Data query method, application and database servers, middleware, and system
WO2015021809A1 (en) Dynamic language code execution method and apparatus
US10594764B2 (en) Request cache to improve web applications performance
US11930096B2 (en) Systems and methods for rendering interactive web pages
US20140040745A1 (en) Methods and apparatus for voiced-enabling a web application
CN110109983B (en) Method and device for operating Redis database
US9606844B2 (en) Remotely-hosted interactive client-server session
US9854047B2 (en) Service pool for multi-tenant applications
WO2019024520A1 (en) Page presentation method, electronic device and non-volatile computer readable storage medium
US11556608B2 (en) Caching for single page web applications
WO2022078057A1 (en) Method and apparatus for publishing application package, method and apparatus for applying application package, and medium, server and device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16802479

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 27.03.2018)

122 Ep: pct application non-entry in european phase

Ref document number: 16802479

Country of ref document: EP

Kind code of ref document: A1