CN117149469A - Method, device, equipment and storage medium for calling host function by H5 page - Google Patents

Method, device, equipment and storage medium for calling host function by H5 page Download PDF

Info

Publication number
CN117149469A
CN117149469A CN202311420175.3A CN202311420175A CN117149469A CN 117149469 A CN117149469 A CN 117149469A CN 202311420175 A CN202311420175 A CN 202311420175A CN 117149469 A CN117149469 A CN 117149469A
Authority
CN
China
Prior art keywords
function
target
page
configuration data
host
Prior art date
Legal status (The legal status 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 status listed.)
Granted
Application number
CN202311420175.3A
Other languages
Chinese (zh)
Other versions
CN117149469B (en
Inventor
刘鹤
徐政钧
牛小菁
王浩洋
刘逸雄
潘建东
肖钢
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Securities Co Ltd
Original Assignee
China Securities Co Ltd
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 China Securities Co Ltd filed Critical China Securities Co Ltd
Priority to CN202311420175.3A priority Critical patent/CN117149469B/en
Publication of CN117149469A publication Critical patent/CN117149469A/en
Application granted granted Critical
Publication of CN117149469B publication Critical patent/CN117149469B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

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
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/541Client-server
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/544Remote
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The embodiment of the application provides a method, a device, equipment and a storage medium for calling a host function by an H5 page. The method for calling the host function by the H5 page comprises the steps of determining description information of a target host where the H5 page is located, and taking the description information as target description information; acquiring configuration data corresponding to the target description information from a configuration center as target configuration data; determining a communication mode between the H5 page and the target host terminal based on the communication mode in the target configuration data; and responding to the detection that the user sends out page operation on realizing any function on the H5 page, and realizing the call of the function by utilizing the target configuration data based on the communication mode. Therefore, the scheme can realize the function calling of the same H5 interface to different host terminals without lengthy codes.

Description

Method, device, equipment and storage medium for calling host function by H5 page
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a method, an apparatus, a device, and a storage medium for calling a host function by an H5 page.
Background
The H5 page may be in the host side, so as to serve as a function page of the host side, and the host side may be, for example, an APP of the mobile terminal, or may be an intelligent device for implementing a specific function, for example, an intelligent customer service device of a business hall.
The user can perform various page operations on the H5 page, such as page returning, page sharing, page jumping and camera calling; accordingly, the H5 page typically requires invoking a host-side function in response to either page operation. Because the communication modes of different host terminals, the names of methods for calling functions of the host terminals, related parameters and the like may be different, when the same H5 page is applied in different host terminals, different calling modes need to be set for different host terminals, so that the code of a development project corresponding to the H5 page is tedious, and the maintenance is not facilitated.
Therefore, a method for calling host functions by using an H5 page is urgently needed to realize the calling of functions of different hosts by using the same H5 interface without lengthy codes.
Disclosure of Invention
The embodiment of the application aims to provide a method, a device, equipment and a storage medium for calling functions of a host side by an H5 page, so that the functions of different host sides can be called by the same H5 interface without lengthy codes. The specific technical scheme is as follows:
In a first aspect of the present application, there is first provided a method for calling a host function by an H5 page, where the method includes:
determining description information of a target host end where the H5 page is located, and taking the description information as target description information;
acquiring configuration data corresponding to the target description information from a configuration center as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs corresponding to various functions to be called, and the function list corresponding to the API injection mode comprises method names and parameters corresponding to various functions to be called;
determining a communication mode between the H5 page and the target host terminal based on the communication mode in the target configuration data;
Responding to the detection that a user sends out page operation about realizing any function on the H5 page, if the determined communication mode is an interception mode and the version of the target host terminal accords with the version requirement in the target configuration data, sending a call request carrying the URL corresponding to the function to the target host terminal based on the URL corresponding to the function in the target configuration data, so that the target host terminal intercepts and analyzes the call request and then calls the function according to the URL in the call request;
and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
In a second aspect of the present application, there is also provided an apparatus for calling a host function by an H5 page, where the apparatus includes:
the first determining module is used for determining description information of a target host end where the H5 page is located and taking the description information as target description information;
the acquisition module is used for acquiring configuration data corresponding to the target description information from a configuration center and taking the configuration data as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs corresponding to various functions to be called, and the function list corresponding to the API injection mode comprises method names and parameters corresponding to various functions to be called;
The second determining module is used for determining the communication mode between the H5 page and the target host end based on the communication mode in the target configuration data;
the calling module is used for responding to the fact that a user sends out page operation about realizing any function on the H5 page, if the determined communication mode is an interception mode and the version of the target host terminal accords with the version requirement in the target configuration data, a calling request carrying the URL corresponding to the function is sent to the target host terminal based on the URL corresponding to the function in the target configuration data, so that the target host terminal intercepts and analyzes the calling request and then calls the function according to the URL in the calling request;
and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
In yet another aspect of the present application, there is also provided an electronic device including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory perform communication with each other through the communication bus;
A memory for storing a computer program;
and the processor is used for realizing the method for calling the host function by the H5 page when executing the program stored in the memory.
In still another aspect of the implementation of the present application, there is further provided a computer readable storage medium, where a computer program is stored, where the computer program when executed by a processor implements a method for calling a host function by an H5 page as described in any one of the above.
The embodiment of the application also provides a computer program product containing instructions, which when run on a computer, cause the computer to execute the method for calling the host-side function by the H5 page.
The embodiment of the application has the beneficial effects that:
according to the method for calling the host function by the H5 page, the description information of the target host where the H5 page is located is determined to be used as target description information, the communication mode of the H5 page and the target host is determined based on the communication mode in the target configuration data, the page operation on any function is sent out by a user on the H5 page in response to detection, if the determined communication mode is an interception mode and the version of the target host meets the version requirement in the target configuration data, a call request carrying the URL corresponding to the function is sent to the target host based on the URL corresponding to the function in the target configuration data, so that the target host intercepts and analyzes the call request, and then calls the function according to the URL in the call request; and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
In the scheme of the application, for the same H5 page, the configuration data of each host end can be pre-stored in the configuration center based on the description information of each host end, when the H5 page is accessed to the target host end, the configuration data corresponding to the target host end is acquired from the configuration center, and then the function of the target host end can be invoked by using the acquired configuration data. Therefore, when the same H5 page is accessed to different host terminals, different calling modes are not required to be set for the different host terminals, and the function calling of the same H5 interface to the different host terminals can be realized under the condition that lengthy codes are not required.
Drawings
In order to more clearly illustrate the embodiments of the application or the technical solutions in the prior art, the drawings used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the application, and other embodiments may be obtained according to these drawings to those skilled in the art.
FIG. 1 is a schematic flow chart of a method for calling host function by an H5 page according to an embodiment of the present application;
FIG. 2 is a schematic diagram of an interaction relationship provided in an embodiment of the present application;
FIG. 3 is a schematic diagram of an H5 page acquiring configuration data from a configuration center according to an embodiment of the present application;
FIG. 4 is a flowchart illustrating another method for H5 page calling host function according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of an apparatus for H5 page calling host function according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. Based on the embodiments of the present application, all other embodiments obtained by the person skilled in the art based on the present application are included in the scope of protection of the present application.
In order to realize the call of the same H5 interface to functions of different hosts without lengthy codes, the embodiment of the application provides a method, a device, equipment and a storage medium for calling the functions of the hosts by the H5 page.
The following first describes a method for calling host-side functions by using an H5 page provided by the embodiment of the present application. The method for calling the host function by the H5 page provided by the embodiment of the application is applied to the H5 page. In a specific application, the host end of the H5 page can be APP, applet, intelligent equipment and the like; the application is not limited in this regard. The method for calling the host function by the H5 page provided by the embodiment of the application can be applied to the scene of calling the host function by the H5 page, and is particularly suitable for the scene that the same H5 page needs to be accessed to different host ends. An H5 page is a page written in HTML5 language (a language descriptive way of building web content).
The method for calling the host function by the H5 page provided by the embodiment of the application comprises the following steps:
determining description information of a target host end where the H5 page is located, and taking the description information as target description information;
acquiring configuration data corresponding to the target description information from a configuration center as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs (Universal Resource Locator, uniform resource locators) corresponding to all functions to be called, and the function list corresponding to the API (APPlication Programming Interface, application program interface) injection mode comprises method names and parameters corresponding to all functions to be called;
Determining a communication mode between the H5 page and the target host terminal based on the communication mode in the target configuration data;
responding to the detection that a user sends out page operation about realizing any function on the H5 page, if the determined communication mode is an interception mode and the version of the target host terminal accords with the version requirement in the target configuration data, sending a call request carrying the URL corresponding to the function to the target host terminal based on the URL corresponding to the function in the target configuration data, so that the target host terminal intercepts and analyzes the call request and then calls the function according to the URL in the call request;
and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
According to the method for calling the host function by the H5 page, the description information of the target host where the H5 page is located is determined to be used as target description information, the communication mode of the H5 page and the target host is determined based on the communication mode in the target configuration data, the page operation on any function is sent out by a user on the H5 page in response to detection, if the determined communication mode is an interception mode and the version of the target host meets the version requirement in the target configuration data, a call request carrying the URL corresponding to the function is sent to the target host based on the URL corresponding to the function in the target configuration data, so that the target host intercepts and analyzes the call request, and then calls the function according to the URL in the call request; and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
In the scheme of the application, for the same H5 page, the configuration data of each host end can be pre-stored in the configuration center based on the description information of each host end, when the H5 page is accessed to the target host end, the configuration data corresponding to the target host end is acquired from the configuration center, and then the function of the target host end can be invoked by using the acquired configuration data. Therefore, when the same H5 page is accessed to different host terminals, different calling modes are not required to be set for the different host terminals, and the function calling of the same H5 interface to the different host terminals can be realized under the condition that lengthy codes are not required.
An exemplary description of a method for calling host-side functions by using an H5 page according to an embodiment of the present application is provided below with reference to the accompanying drawings. As shown in fig. 1, a method for calling host-side functions by using an H5 page provided by the embodiment of the present application may include the following steps:
s101, determining description information of a target host end where an H5 page is located, and taking the description information as target description information;
the description information of the target host end where the H5 page is located is used as a basis for obtaining configuration data from a configuration center, and the description information of the target host end may be information for describing a type, a name, a device type where the target host end is located, and the like of the target host end. For example, when the target host is an APP, the description information may be a type of the APP, for example, the APP is an APP of An Zhuoduan or an APP of an IOS, or may be a type of a device where the APP is located, for example, the device where the APP is located is an android. When the target host is an intelligent device for implementing a specific function, the description information may be a type and/or a name of the intelligent device.
Typically, a webview component of the host (a component in the host for parsing and executing an H5 page) is used as a carrier of the H5 page, where the H5 page runs in the webview component. Therefore, a specific manner of determining the description information of the target host end where the H5 page is located may be that the H5 page obtains a user agent (user client) character string from webview corresponding to the H5 page, where the user agent character string includes information such as a type and a name of the target host end and/or a type of equipment where the target host end is located. Therefore, the userAgent character string can be directly used as target description information, or the type and name of the target host end obtained by analyzing the userAgent character string and/or information such as the type of equipment where the target host end is located can be used as target description information.
S102, acquiring configuration data corresponding to the target description information from a configuration center as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs corresponding to various functions to be called, and the function list corresponding to the API injection mode comprises method names and parameters corresponding to various functions to be called;
The URL corresponding to any function is the URL required to be accessed when the function is realized, and the method name and the parameter corresponding to any function are the method name and the parameter of the method required to be called when the function is realized.
By way of example, the functions may be opening a new H5 page, returning to a previous H5 page, sharing a current H5 page, opening a camera, and adjusting a sound.
The interception mode can be realized by intercepting the URL SCHEME (URL protocol). The host may define a set of protocols, method names, parameters, and callback information, and bind the defined protocols, method names, parameters, and callback functions to a specific URL (Universal Resource Locator, uniform resource locator). The H5 page transmits the URL to the host end by accessing the URL agreed with the host end and carrying corresponding parameters and callback information. Then, the host end intercepts and analyzes the URL, and executes a method corresponding to the URL to realize corresponding functions, so that interaction between the host end and the H5 page can be realized.
The API injection mode can be realized by injecting the API onto a global scope window object in an H5 page. After the host side injects the API into the window object, the H5 page can call the function of the host side by calling the injected API, so that the interaction between the host side and the H5 page is realized.
The configuration data corresponding to the target description information is obtained from a configuration center, specifically, a request for characterizing to obtain the configuration data corresponding to the target description information is sent to the configuration center, and the specific request form is not limited by the application.
Under the condition, when the analysis result obtained by analyzing the userAgent character string is taken as target description information, namely, the type, the name and/or the equipment type of the target host end are taken as target description information, the analysis result is taken as a parameter in the request; under the condition that the userAgent character string is used as target description information, the userAgent character string is used as a parameter in the request, and after the configuration center obtains the request, the configuration center analyzes the userAgent character string to obtain information such as the type and name of the target host end and/or the type of equipment where the target host end is located. The configuration center may return configuration data corresponding to the target host according to the type and name of the target host and/or the type of the device in which the target host is located.
For any host, the method used when the host realizes the same function is the same, but the specific parameters can be changed according to the actual situation. Therefore, the configuration center can set the corresponding configuration data for the host, that is, set the URL to be accessed when the host realizes the function or set the method name and parameters of the method to be called when the function is realized.
For any H5 page, the function that the H5 page needs to call the host end to realize is also fixed, so that the function that the H5 page needs to call the host end to realize can be corresponding to the URL required to be accessed when the host end realizes the function or the method name and the parameter of the method required to be called when the function is realized, and each function of the subsequent H5 page can be realized according to the URL required to be accessed when the function is realized or the method name and the parameter of the method required to be called when the function is realized when the subsequent H5 page calls the host end. For example, when an H5 page needs to call a function of a host end for sharing a current H5 page to share the current H5 page, the function of sharing the current H5 page is corresponding to a URL required to be accessed when the function of sharing the current H5 page is implemented or a method name and a parameter of a method required to be called when the function is implemented, so that when the H5 page performs an operation of sharing the current H5 page, a user can utilize the URL required to be accessed when the function is implemented or the method name and the parameter of the method required to be called when the function is implemented to share the current H5 page.
Optionally, a plurality of functional slots exist in the H5 page; each function slot is uniquely corresponding to one function of the functions to be called; the functional slot is a storage space which is divided in advance for the H5 page;
When the determined communication mode is an interception mode, each function slot is used for storing a URL corresponding to a function corresponding to the function slot in the target configuration data; when the determined communication mode is an API injection mode, each function slot is used for storing a method name and parameters corresponding to a function corresponding to the function slot in the target configuration data;
the acquisition mode of the URL corresponding to the function in the target configuration data comprises the following steps:
acquiring a URL corresponding to the function from a function slot corresponding to the function;
the method for obtaining the method name and the parameter corresponding to the function in the target configuration data comprises the following steps:
and obtaining the method name and the parameter corresponding to the function from the function slot corresponding to the function.
It can be understood that, for any H5 page, configuration data corresponding to different description information may be stored in the configuration center in advance, so that, for the same H5 page, corresponding configuration data applicable to the host may be obtained based on the description information of the host. In addition, the implementation manner of each function of the same host terminal is fixed, so that configuration data about the same host terminal in the configuration center can be multiplexed for different H5 pages. For example, the host a configures 100 functions of data in the configuration center, 10 functions to be used by the H5 page a are 10 functions, 20 functions to be used by the H5 page b are only required to acquire configuration data of the corresponding 10 functions when the H5 page a acquires the configuration data, only required to acquire configuration data of the corresponding 20 functions when the H5 page b acquires the configuration data, and the 10 functions corresponding to the H5 page a and the 20 functions corresponding to the H5 page b may have the same functions. When the H5 page obtains the function list, configuration data may be obtained according to the corresponding relationship between functions, for example, the H5 page c may call functions 1 and 2 of the host, the host may have 100 functions, and when the H5 page obtains the configuration data, the function list may include functions 1 and 2. For different home terminals, the H5 page may call the function 1 of the home terminal, when the home terminal 1 is accessed, the function 1 corresponding to the home terminal 1 may be included in the function list in the obtained configuration data, and when the home terminal 2 is accessed, the function 1 corresponding to the home terminal 2 may be included in the function list in the obtained configuration data. Therefore, the method and the device do not need to carry out targeted setting on different H5 pages, so that development cost can be reduced.
S103, determining a communication mode between the H5 page and the target host terminal based on the communication mode in the target configuration data;
s104, responding to the fact that a user sends out page operation about realizing any function on the H5 page, if the determined communication mode is an interception mode and the version of the target host terminal accords with the version requirement in the target configuration data, sending a call request carrying the URL corresponding to the function to the target host terminal based on the URL corresponding to the function in the target configuration data, so that the target host terminal intercepts and analyzes the call request and then calls the function according to the URL in the call request.
The URL corresponding to any function consists of a protocol name and a path which are utilized when the function is called; wherein the path contains parameters of the function.
After the target host side calls the function according to the URL in the call request, the target host side may return data related to the function to the H5 page according to a callback function corresponding to the function, and specifically, the callback function may acquire target data from the related data of the function returned by the target host side by using a key return path corresponding to the callback function, so that the H5 page executes corresponding operation according to the target data. The configuration data may include a callback function corresponding to each function and a key return path corresponding to the callback function.
The key return path is a parameter used by a callback function to acquire target data from the data returned by the target host. For example, after the function of storing the picture is executed, the data returned by the target host side includes various data, such as a storage path, a storage time, a picture size, and the like, and the H5 page only needs the target data, which is the storage path, and by using a key return path, the callback function can acquire the storage path from the data returned by the target host side and return the storage path to the H5 page. In general, the data returned by the target host end is in the form of JSON character strings, JSON (JavaScript Object Notation, JS object numbered musical notation) is a lightweight data exchange format, and the data is stored and represented by adopting a text format completely independent of a programming language, so that the data exchange format has a concise and clear hierarchical structure, is easy to read and write, is easy to analyze and generate by a machine, has high network transmission efficiency, and is an ideal data exchange format in a heterogeneous environment. The data returned by the target host is different for different functions, and the application is not limited to this.
After the H5 page sends a page operation about sharing the current H5 page, the H5 page may send a call request carrying a URL corresponding to the current H5 page to the target host after detecting that the version of the target host meets the version requirement in the target configuration data, the target host intercepts and parses the call request to obtain the URL corresponding to the current H5 page, and the target host may obtain parameters from the URL, and execute a method corresponding to the URL by using the obtained parameters, thereby implementing sharing the current H5 page. After sharing the current H5 page is achieved, the target host side can call a callback function to return information representing success of sharing the current H5 page to the H5 page, and after receiving the information representing success of sharing the current H5 page, the H5 page can pop-up window to display the information representing success of sharing the current H5 page.
The corresponding operation executed by the H5 page according to the data related to the function is specifically executed according to the specific type of the function, and the operations executed by different functions may be different, so the present application does not limit the operations executed by the H5 page. For example, if the executed function is to store a picture, the target host may return a storage path of the picture to the H5 page, and the H5 page may display the storage path after acquiring the storage path, so that the user may find the picture according to the storage path of the picture; if the executed function is to share the storage path, the target host may return information indicating success of sharing to the H5 page, and the H5 page may display the success information of sharing the page. The callback functions are preset functions, and each callback function is uniquely corresponding to one of the functions of the target host side. Of course, some functions may not have corresponding callback functions, and the target host does not need to return data.
In a specific implementation manner, the H5 page may mount, in advance, a callback function corresponding to a function of a target host to be called by the page on a window object (a global object), so that the callback function corresponding to the function may be executed after the target host executes the function. The target configuration data may include callback function data, and the H5 page may obtain callback function data from the target configuration data. The window object can be used as a global object of the H5 page, and the target host side can execute functions mounted on the window object because the H5 page runs in a webview component of the host side and the host side can access the webview component. The mounting mode of the callback function in this embodiment may be applicable when the communication mode is an interception mode or an API injection mode.
In a specific implementation manner, the sending of the call request carrying the URL corresponding to the function to the target host end may be window open (URL), where window open () is a method for opening a new page, and of course, the method is not required to open a new window, but is just used as a way for transferring URL. The form of the call request of the present application can be various, the present application is not limited thereto, and any request capable of transmitting URl can be applied to the present application.
S105, if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
S105 may be performed in response to detecting that the user issues a page operation on the H5 page to implement any function.
When the communication mode is an API injection mode, all methods corresponding to the functions of the target host end can be pre-mounted on the window object, so that the method corresponding to the functions can be directly executed after the subsequent target host end is triggered, and the mounting mode of the method corresponding to the functions is the same as that of the callback functions. Of course, the method of the partial functions needed by the H5 page may be mounted on the window object, which is not limited in the present application. However, it should be emphasized that, when the method name and the parameter corresponding to the function in the target configuration data are executed and the target host side is triggered to call the function, the method corresponding to the function needs to be mounted on the window object. The method corresponding to any function of the target host terminal is pre-mounted on the window object, which is equivalent to the API interface which leaves the function of the target host terminal for the H5 page. The H5 page may trigger the API interface to implement the corresponding function.
After the H5 page sends out the page operation about sharing the current H5 page, the user may send in parameters to an API interface implementing the function of sharing the current H5 page after detecting that the version of the target host meets the version requirement in the target configuration data, and trigger the API interface to implement sharing the current H5 page. After sharing the current H5 page is achieved, the target host side can call a callback function to return information representing success of sharing the current H5 page to the H5 page, and after receiving the information representing success of sharing the current H5 page, the H5 page can pop-up window to display the information representing success of sharing the current H5 page.
Optionally, the triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data includes:
sending a target instruction to the target host end to trigger the target host end to call the function; the instruction type of the target instruction is the instruction type corresponding to the API injection mode, and the target instruction carries the method name and the parameter corresponding to the function.
In a specific implementation, the target host may be triggered to call the function by a window [ object global object ] [ method name ] (parameter);
The method comprises the steps of triggering a function of a method mounted on a window object, wherein the method name is a method name corresponding to the function, the parameter is a parameter corresponding to the function, and the object global object is a path of the function mounted on the window object.
The mounting paths of the different methods on the window object are different, for example, the method of the a function is directly mounted on the window object, at this time, the object global object of the a function may be empty, the representation is directly mounted on the window object, the call target instruction corresponding to the a function may not have [ object global object ], that is, the method of the B function is represented by the window [ method name ] (parameter), the method of the B function is not directly mounted on the window object, but is mounted under the multi-level path of the window object, at this time, the mounting path of the B function may be in object obj1> in object obj2, in object obj1 may represent the object directly mounted on the window object, in object obj2 may be used as a child node of in object obj1, the method of the B function is actually mounted on the object in object, and the method of the B function may be used as a child node of the B function representation. At this time, the object global object in the call target instruction corresponding to the B function may be the object obj1> object obj2, which is expressed as a window [ object obj1] [ object obj2] [ method name ] (parameter). The [ object global object ] can be used as a path for each function to be mounted on the window object, and a method for the corresponding function can be found according to the path, so that the function can be triggered. Also, in general, a method of a function mounted on a window object may be a function that needs to be executed in order to implement the function. The mounting paths are merely illustrative, and specific paths are determined by specific implementation manners of different methods, which are not limited in the present application.
Whether the communication mode is an API injection mode or an interception mode, the version of the target host needs to be detected, because functions of different versions of the host, and URL or method names and parameters corresponding to the functions may be different, and thus if configuration data which does not conform to the version of the host is used, a call error to the functions of the host may be caused. In general, the version of the host may be downward compatible, so that the host of the latest version may be compatible with the configuration data corresponding to the old version of the host, and thus, the version of the host needs to be newer than the version of the host corresponding to the configuration data. When the version of the target host end is detected to be not in accordance with the version requirement in the target configuration data, information for representing updating of the version of the target host end can be sent to a user. For example, a popup window characterizing updating the target host-side version is displayed on the H5 page.
According to the method for calling the host function by the H5 page, the description information of the target host where the H5 page is located is determined to be used as target description information, the communication mode of the H5 page and the target host is determined based on the communication mode in the target configuration data, the page operation on any function is sent out by a user on the H5 page in response to detection, if the determined communication mode is an interception mode and the version of the target host meets the version requirement in the target configuration data, a call request carrying the URL corresponding to the function is sent to the target host based on the URL corresponding to the function in the target configuration data, so that the target host intercepts and analyzes the call request, and then calls the function according to the URL in the call request; and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
In the scheme of the application, for the same H5 page, the configuration data of each host end can be pre-stored in the configuration center based on the description information of each host end, when the H5 page is accessed to the target host end, the configuration data corresponding to the target host end is acquired from the configuration center, and then the function of the target host end can be invoked by using the acquired configuration data. Therefore, when the same H5 page is accessed to different host terminals, different calling modes are not required to be set for the different host terminals, and the function calling of the same H5 interface to the different host terminals can be realized under the condition that lengthy codes are not required.
In addition, the application relates to the H5 page, the host end and the configuration center when the method for calling the host end function by the H5 page is realized, and the H5 page, the host end and the configuration center are arranged in a micro-service architecture mode. Those skilled in the art will appreciate that micro services are an emerging style of software architecture, each of which is a small functional block focusing on a single responsibility and function, and several micro services can be combined into a complex large application. The method for realizing the function of the H5 page calling host end needs to be combined. The configuration center can be used as an application program independent of the H5 page and the host end to communicate with the H5 page. The configuration center may be deployed on any electronic device, such as a client and a server, which is not limited in the present application. The configuration center may store configuration data corresponding to each host end, and send the configuration data corresponding to the target description information to the corresponding H5 page according to the target description information.
And after the H5 page of the application obtains the target configuration data from the configuration center, the call of the host function is realized according to the corresponding processing logic, namely the S103-S105. It can be understood that when the H5 page of the present application is accessed to any host, the processing logic for completing the call to the function of the host according to the corresponding target configuration data of the host is the same. Therefore, no matter which host end the H5 page needs to be accessed to, the H5 page does not need to be changed. Therefore, by applying the scheme of the application, the H5 end is not required to adapt to different host ends, so that the development efficiency is improved, and the working cost is reduced.
Optionally, parameters of each function in the function list of the host end are in the form of character strings;
the configuration data of the configuration center may generally exist in the form of a character string, so the configuration data received by the H5 page is also in the form of a character string, but the types of parameters corresponding to different functions are different, the parameters of some functions may be in the form of a character string, and the parameters of some functions may be in the form of an object. When the parameter is in the form of a character string, the character string corresponding to the parameter in the configuration data is directly used, and when the parameter is in the form of an object, the following steps can be executed:
Before triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data, the method further comprises: in the steps A1-A3,
a1, judging whether a parameter character string corresponding to the function needs to be analyzed or not; namely judging whether the parameter form corresponding to the function is the form of an object shape or not;
step A2, if the parameter character string needs to be analyzed, analyzing the parameter character string by utilizing a predetermined analysis mode to obtain a parameter corresponding to the function;
the object may be a JSON object. The parameter string may be a JSON string.
Each object may include a plurality of parameters, if any method only needs to use some of the parameters, the parameter character string may be restored by using a predetermined restoration mode to obtain an object corresponding to the function, the required parameters are obtained from the object, and the obtained parameters are used as parameters for triggering the target host to call the function. The parsing scheme includes a reduction scheme.
And step A3, if the parameter character string does not need to be analyzed, taking the parameter character string as a parameter corresponding to the function.
At this time, the parameter string is directly used as a parameter corresponding to the function, but when the target host side is triggered to call the function based on the method name and the parameter corresponding to the function in the target configuration data, the parameter string can be restored to be an object according to a predetermined restoration mode.
Optionally, based on the URL corresponding to the function in the target configuration data, sending, to the target host, a call request carrying the URL corresponding to the function includes:
acquiring a URL corresponding to the function from the target configuration data;
detecting whether the parameters contained in the URL corresponding to the function contain dynamic parameters or not;
if the dynamic parameter is included in the set of parameters,
replacing dynamic parameters contained in the URL corresponding to the function with real parameters to obtain the URL to be utilized, constructing and sending a call request carrying the URL to be utilized to the target host; wherein the real parameter is a parameter corresponding to the page operation obtained by determining based on the page operation for realizing any function;
if the dynamic parameters are not contained, constructing and sending a call request carrying the URL corresponding to the function to the target host terminal.
Whether the dynamic parameters are contained in the parameters contained in the URL corresponding to the function can be determined from the target configuration data. For the URL containing the dynamic parameter, the location of the dynamic parameter in the URL may be a placeholder symbol, for example $ and when the step of replacing the dynamic parameter contained in the URL corresponding to the function with the real parameter is performed, the placeholder symbol may be replaced with the real parameter. For example, in order to save the picture a, the H5 page needs to call the function of saving the picture at the target host, and in fact, the function called by saving any picture is the same, and the picture to be saved can be used as a dynamic parameter, so when the picture a is saved, the picture a can be used as a parameter to replace a corresponding occupation symbol in a URL corresponding to the function of saving the picture to obtain the URL to be utilized.
It can be understood that the real parameters are determined by the H5 page according to the operation of the user, and the real parameters corresponding to different operations of the user can be different.
Optionally, the triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data includes:
Acquiring a method name and a parameter corresponding to the function from the target configuration data;
detecting whether the parameters corresponding to the function contain dynamic parameters or not;
if the dynamic parameters are included, replacing the dynamic parameters included in the parameters corresponding to the function with real parameters to obtain corrected parameters, and triggering the target host terminal to call the function based on the method name corresponding to the function and the corrected parameters; wherein the real parameter is a parameter corresponding to the page operation obtained by determining based on the page operation for realizing any function;
and if the dynamic parameters are not included, triggering the target host terminal to call the function based on the acquired method name and parameters corresponding to the function.
The replacement logic of the dynamic parameters in the API injection mode is the same as the replacement logic of the dynamic parameters in the interception mode, and may be the replacement of the occupation symbol, which is not described in detail herein.
Whether the parameter is a dynamic parameter is determined by the parameter itself, irrespective of whether the parameter string is required to be parsed.
The above can be seen that the scheme of the application can be executed when the parameters corresponding to the functions comprise dynamic parameters, and also can analyze the parameter character strings to obtain the required parameters, so that the scheme of the application can correspond to the operation of the user, and accurately call the functions of the host terminal by utilizing the parameters corresponding to the operation.
Optionally, the configuration data corresponding to the object description information further includes: style configuration data, before determining the communication mode between the H5 page and the target host based on the communication mode in the target configuration data, the method further includes:
and rendering the H5 page based on the style configuration data.
The style configuration data may include configuration data of a position and a size of a component in the H5 page, a popup style, click feedback, a navigation bar style, a color, display and hiding of the component, and the like. It will be appreciated that the style configuration data is data about the H5 page itself, rendering the H5 page according to the style configuration data being performed by the H5 page itself. When the function of the host end of the H5 page is called to change the style of the H5 page, the method for calling the function of the host end by the H5 page can be utilized, namely, the function of changing the style of the H5 page is realized by calling the host end.
As can be seen from the above, the embodiment may change the style of the H5 page.
As shown in fig. 2, an interaction relationship among the user, the terminal, the front end H5 and the native configuration registry is schematically shown.
As shown in fig. 2, the terminal may include a plurality of APPs, where the APPs are the hosts, and the native configuration registry is the configuration center, and includes various configuration data, for example, the general configuration may include: environment identification, system type, call mode, etc., the native function, underlying function configuration may include version restriction, method, parameters, parameter type, callback registration, key return parameters, etc., and style personalization includes: version restrictions, style setting methods, style parameter selections, style module configurations, etc.
The front end H5 is the H5 page, and may include a native control center and a functional slot, where the native control center is configured to implement a style service, an assembly service, a version control service, and a callback registration service. The functional slot corresponds to the functional slot, and will not be described in detail herein.
The following describes, based on fig. 2, the interaction relationship among the user, the terminal, the front end H5, and the native configuration registry:
step 1, each APP independently registers the corresponding configuration.
The corresponding configuration is registered, namely, the configuration data corresponding to each APP is stored in a native configuration registry. As can be seen from fig. 2, the configurations of different APPs are different corresponding to the same function, and the APP configurations in the three function lists of function 1, function 2 and function 3 in fig. 2 may be specifically the URL corresponding to the function or the method name and parameter corresponding to the function. The application does not limit the function list and APP. The data in the original configuration registration center can be changed, for example, the version of the APP is changed, the corresponding configuration data can be changed, the APP to be added can be registered in the original configuration registration center, and therefore the scheme of the application can flexibly configure the H5 page and the host side.
Step 2, accessing H5 through APP.
The APP hosts the H5 page, so that when a user accesses the H5 page, the user can access the APP.
Step 3, APP turns on H5.
After the user accesses H5 through APP, APP opens H5.
And 4, acquiring configuration data.
The configuration center acquisition corresponds to the above S101-S102, and will not be described in detail herein.
In the actual execution, the step of acquiring the configuration data may be executed only once before the data of the configuration data is changed. The URL or method name and parameters corresponding to each function in the configuration data may be stored in the corresponding function slot.
This step may be performed after the data of the configuration data is changed, and accordingly, the data in the functional slot may be changed according to the new configuration data. Illustratively, the APP version update may cause the data of the configuration data to be changed, and the present application is not limited as to the cause of the data of the configuration data to be changed. The execution mode can improve the execution efficiency of the scheme and reduce the waste of computing resources.
And 5, style configuration processing.
The step corresponds to rendering the H5 page based on the style configuration data, and will not be described in detail herein.
When the operation needing to call the APP function exists in the style configuration, the method for calling the host function according to the H5 page can be realized.
And step 6, triggering function call.
This step corresponds to the above-described responding to the detection of the user issuing a page operation on the H5 page with respect to implementing any function. The user performs operation and triggers the calling of the function.
And 7, triggering a native method and calling a bottom layer function.
The method comprises the step of triggering the calling of a native method and a bottom layer function of the APP. It is emphasized that this step is merely triggering a native method, an underlying function call, and not executing a native method, an underlying function call. The calling of the original method and the bottom layer function of the APP is to call the method of the host end to realize the function corresponding to the method.
And 8, checking version control.
This step corresponds to the version of the target host meeting the version requirements in the target configuration data, and is used for detecting whether the version of the current APP meets the version requirements in the target configuration data.
And 9, registering a function callback.
Some functions require that the APP returns data by using a callback function, if the callback function corresponding to the function is not registered, the registration of the H5 page is required, and the specific registration mode is the same as the above, and will not be repeated here.
It can be seen that, in the scheme of this embodiment, the configuration data of each host end is pre-stored in the configuration center, when the H5 page is accessed to the host end, the configuration data corresponding to the host end is acquired from the configuration center, and then the function of the host end can be invoked by using the acquired configuration data. Therefore, when the same H5 page is accessed to different host terminals, different calling modes are not required to be set for the different host terminals, and the function calling of the same H5 interface to the different host terminals can be realized under the condition that lengthy codes are not required.
In addition, in this embodiment, URL or method name and parameter corresponding to the function to be called of the H5 page are stored in the corresponding function slot, so that when the H5 page calls the function, URL or method name and parameter corresponding to the function are obtained from the function slot corresponding to the function.
As shown in fig. 3, the H5 page obtains configuration data from the configuration center, and the right side of fig. 3 exemplarily describes the data content of the configuration data when different APPs are used as hosts.
When the hosts are different APP, the same H5 page can acquire configuration data corresponding to the current host from the configuration center.
The H5 page may send the target description information to the configuration center to obtain configuration data. This step corresponds to S102 described above. The parameters are as follows: { UA: userAgent, type: IOS/Android } is the target description information, userAgent is already described in the above embodiment, and is not described in detail herein, UA is an abbreviation of userAgent, and type refers to an operating system type. IOS: the iPhone OS is a proprietary mobile operating system developed by apple corporation for its mobile devices, android: is a free and open source operating system based on Linux kernel, which is led and developed by Google corporation and open cell phone alliance.
In fig. 3, APP1: IOS configuration/Android configuration, APP2: IOS configuration/Android configuration, and APP3: IOS configuration/Android configuration are configuration data corresponding to a host returned by an H5 page at different hosts. For APP, the communication modes of the two systems may be an API injection mode or an interception mode, which are generally divided into an IOS end and an Android end, and are specifically set by APP, which is not limited in the present application. Of course, the device type of the host may be raspberry group, intelligent device, etc., so the native method and the underlying function of dividing the APP by the system type are not limited to IOS and Android. It should be emphasized that even though the native method and the underlying functions of the APP are divided by the system type, they are essentially divided by the communication method, i.e., the API injection method or the interception method.
Fig. 3 exemplarily illustrates configuration data of APP1 at IOS end and native method and bottom layer functions of APP at Android end.
The native method and the bottom layer function of the APP at the IOS end comprise a host environment identifier, an IOS calling scheme, a protocol name, an IOS function calling list and an IOS style configuration list, wherein the IOS function calling list comprises the following components: acquiring an APP version number and opening a new H5 page, wherein the IOS style configuration list comprises the following steps: navigation bar style and page module control.
The data of each function in the IOS function call list comprises a path of a method for realizing the function, and a callback method name and a key return value path corresponding to the function. The callback method name corresponds to the callback function of the embodiment, and the key return value path corresponds to the key return path. After the APP executes the function, the callback method name and the key return value path can be utilized to acquire target data from the related data of the function returned by the target host end and return the target data to the H5 page.
The data of the navigation bar style comprises path parameters and the lowest version number; the path parameters are used for enabling the H5 page to set the navigation bar style according to the corresponding function of the calling APP, and the lowest version number is used for judging whether the APP where the H5 is located meets the lowest version number of the APP specified by the original method and the bottom function of the APP. The setting of the navigation bar style requires invoking the function of the APP. The specific implementation is realized by the method for calling the host function according to the H5 page.
The page module control includes setting data of whether each module in the H5 page is displayed or not, whether each module is hidden or not, and whether the color of each module is the same. Page module control is performed by H5 itself.
The native method and the bottom layer function of the APP at the Android end comprise host environment identifications, an Android call scheme, an Android function call list and an Android style configuration list, and the Android function call list comprises the following components: obtaining an APP version number and opening a new H5 page, wherein the Android style configuration list comprises the following steps: navigation bar style and page module control.
The data of each function in the Android function call list comprises a method name and a parameter of a method for realizing the function, an object global object, data of whether the parameter is deconstructed or not and a key return value path. The callback method name corresponds to the callback function of the embodiment, and the key return value path corresponds to the key return path. After the APP executes the function, the callback method name and the key return value path can be utilized to acquire target data from the related data of the function returned by the target host end and return the target data to the H5 page. The object global object is the method of the above-mentioned [ object global object ] in the call target instruction with different functions, the corresponding object global object may be different, and the object global object is determined according to the actual application situation of each method, which is not limited in the present application.
The data of the navigation bar style comprises a method name, parameters and a lowest version number; the method name and the parameters are used for enabling the corresponding function of the H5 page call APP to set the navigation bar style, and the lowest version number is used for judging whether the APP where the H5 is located meets the lowest version number of the APP specified by the original method and the bottom layer function of the APP. The setting of the navigation bar style requires a method of calling the APP. The specific implementation is realized by the method for calling the host function according to the H5 page.
The page module control includes setting data of whether each module in the H5 page is displayed or not, whether each module is hidden or not, and whether the color of each module is the same. Page module control is performed by H5 itself.
FIG. 4 is a flow chart of a method for H5 page calling host side functions. Next, a method for calling the host function by the H5 page is specifically described with reference to fig. 4.
S401, initializing an H5 page system;
s402, whether a terminal is moved;
in this embodiment, the host end of H5 is APP, and the terminal at which APP is located is the mobile end, so the following steps are executed when the mobile end is detected.
S403, calling a configuration center interface to acquire the current host environment configuration;
when the interface of the configuration center is called, parameters transferred to the interface can be userAgents and system types, wherein the userAgents and the system types are the target description information, and the system types can be obtained from the userAgents, so that the transferred parameters can be userAgents.
S404, whether the configured host environment is matched;
this step is to find the configuration data corresponding to the current hosting environment in the configuration center, and it is understood that the scheme of the present application can be continuously executed only when the configuration data corresponding to the current hosting environment exists in the configuration center, that is, matches to the configured hosting environment.
S405, the interface returns the matched host environment and the configuration of the corresponding system type;
the steps S403 to S404 correspond to the step S102, and are used to obtain the target configuration data corresponding to the current host.
S406, the H5 page acquires configuration data and stores the configuration data into a state management library, and sets a global identification of a calling scheme;
and H5, after the configuration data is obtained, storing the configuration data into a state management library, and setting corresponding functional slots according to the configuration data. And setting a calling scheme global identifier, wherein the calling scheme global identifier refers to a communication mode.
S407, whether a style configuration is included;
some configuration data may include style configuration data, and the H5 page may adjust the style of the H5 page according to the style configuration data. When the style configuration is included, S408 may be performed, and when not included, S411 may be performed.
S408, the style service analyzes the style configuration;
S409, rendering H5 related style configuration results;
S408-S409 correspond to the rendering step of the H5 page based on the style configuration data.
S410, whether the original style configuration data is acquired or not;
the native style configuration data refers to configuration data for calling a host function to adjust the style of the H5 interface. The native style configuration data is of the configuration data. Whether the native style configuration data is acquired is actually a determination as to whether the native style configuration data can be acquired from the configuration center. The native style configuration data is acquired, S411 may be executed, and if not acquired, S413 may be executed.
S411, the user operation triggers the execution of the native call function module;
the user operation triggers the native call function module to execute, namely the user sends out page operation on the H5 page for realizing the style adjusting function of the H5 interface.
S412, obtaining the function module configuration data;
the method comprises the steps of obtaining a URL corresponding to a style function for realizing the adjustment of the H5 interface or a method name and a parameter corresponding to the function, and realizing the style for realizing the adjustment of the H5 interface by using the obtained URL or the method name and the parameter.
S410-S412 need to call the function of the host end to adjust the style of the H5 interface, so S410-S412 are actually the method for executing the subsequent H5 page to call the function of the host end, and only the function is the method for adjusting the style of the H5 interface. That is, when S410-S412 are implemented, the steps performed correspond to the steps S414-S424 or the steps S425-S434. S408-S412 do not affect the method of the H5 page call host function of the present application.
S413, whether a URL scheme is used;
if yes, the communication mode of URL scheme (URL protocol) used by the H5 call host to call the host function, that is, the interception mode, is described, the steps S414-S424 are executed, if not, the mode of API injection is used, and the steps S425-S434 are executed. The URL schema is the URL described above.
S414, whether the lowest version is restricted from being called;
s414 corresponds to the version of the target host conforming to the version requirement in the target configuration data; if yes, S415 is performed, otherwise S420 is performed.
S415, whether the registered version obtains a callback function;
the version-related data needs to be returned to the H5 page through the version acquisition callback function, and whether the version acquisition callback function is registered or not is judged whether the version acquisition callback function is mounted on the window object or not. It is detected that registration is already performed, S417 is performed, and it is detected that registration is not already performed, S416 is performed.
S416, registering a callback function of the acquired version;
if the callback function is not registered, registering the callback function with the acquired version, namely, the callback function with the acquired version is mounted on the window object by the H5 page. The function of the callback function for obtaining the version is to intercept the URL schema obtained by calling the version number at the APP, and obtain the version number, and then take the version number from the return result of the APP by using the version number path. The version number path corresponds to the critical return path described above.
S417, calling the URL scheme acquired by the version number;
the step corresponds to the step of sending the call request carrying the URL corresponding to the function to the target host, and only the URL in the step is the URL for acquiring the version number, namely the URL corresponding to the function for acquiring the version number is realized;
of course, any manner of obtaining the host-side version number may be applied to the present application, which is not limited in this aspect of the present application.
S418, whether the current version can call the native method;
if not, S419 is performed.
S419, popup prompts a user to upgrade the APP version;
s418 and S419 correspond to the above embodiment of detecting the version of the host, and are not described herein.
S420, replacing parameters of the ${ } package in the configuration parameters with real parameters;
The placeholder symbols described above are $ { }.
S421, whether a callback function needs to be registered;
the callback function needs to be registered, S422 is executed, otherwise S423 is executed.
S422, obtaining callback function configuration and registering a callback function; obtaining key return parameter configuration, and carrying out corresponding data processing on key return parameter results in a callback function;
s423, splicing URL schema, and calling by using a window () method;
s424, the APP intercepts and analyzes the URL schema, and a method calling result is returned through callback;
the steps S414 to S424 are the process of implementing the method for calling the host function by the H5 page according to the interception mode, and correspond to the step S104, and are not described in detail herein;
s425, whether the minimum version is restricted from being called;
s425 corresponds to the version of the target host conforming to the version requirement in the target configuration data. Yes, S426 is executed, otherwise S429 is executed.
S426, window [ object global object ] [ get version number method name ] (parameter) get version number from executing result;
the step is to trigger the target host to call the function based on the corresponding method name and parameter of the function in the target configuration data, and the method name and parameter are the method name and parameter for obtaining the version number.
S427, whether the current version can call the native method;
yes, S429 is performed, otherwise S428 is performed.
S428, the popup prompts the user to upgrade the APP version;
s427 and S428 correspond to the above embodiment for detecting the version of the host, and are not described herein.
S429, replacing parameters wrapped in ${ } in the configuration parameters with real parameters;
the placeholder symbols described above are $ { }.
S430, analyzing the parameter from the JSON character string into a JSON object;
s431, whether parameter deconstructing is needed;
S430-S431 correspond to steps A1-A3 described above;
if deconstructing is required, S432 is executed after deconstructing, and if deconstructing is not required, S433 is executed.
S432, performing method call on window [ object global object ] [ method name ] (. Parameter);
". the parameter" identifies a number of parameters parsed from JSON objects.
S433, window [ object global object ] [ method name ] (parameter) makes method call;
s434, the parameter data is returned from the key of the calling result to carry out corresponding processing.
The steps S425 to S434 are the process of implementing the method for calling the host function by the H5 page according to the API injection, and correspond to the step S105, which is not described herein.
In the solution of this embodiment, when the H5 page needs to call the function of the host, the configuration data corresponding to the host may be obtained from the configuration center, and then the obtained configuration data may be used to implement the call of the function of the host. Therefore, when the same H5 page is accessed to different host terminals, different calling modes are not required to be set for the different host terminals, and the function calling of the same H5 interface to the different host terminals can be realized under the condition that lengthy codes are not required.
In addition, the scheme of the application can realize quick access when the H5 page is accessed to the new host terminal, so that the application can solve the problems of long butt joint test period, low development efficiency, long code, inconsistent content, difficult maintenance and the like when the H5 page is accessed to the new host terminal.
The configuration center of the embodiment exists in a micro-service architecture mode, and the H5 page is realized in a mode of registering with the micro-service architecture service configuration when the configuration center acquires configuration data, so that the scheme of the application can realize personalized and configured quick access multi-terminal original service capability of the H5 page, namely quick call to a host terminal function.
Based on the embodiment content of the method for calling the host function by the H5 page, the embodiment of the application also provides a device for calling the host function by the H5 page. Fig. 5 is a schematic structural diagram of an apparatus for H5 page calling host function according to an embodiment of the present application, where as shown in fig. 5, the apparatus for H5 page calling host function may include:
a first determining module 501, configured to determine description information of a target host side where the H5 page is located, as target description information;
An obtaining module 502, configured to obtain, from a configuration center, configuration data corresponding to the target description information, as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs corresponding to various functions to be called, and the function list corresponding to the API injection mode comprises method names and parameters corresponding to various functions to be called;
a second determining module 503, configured to determine a communication manner between the H5 page and the target host based on a communication manner in the target configuration data;
a calling module 504, configured to respond to detecting that a user sends out a page operation related to implementing any function on the H5 page, and if the determined communication mode is an interception mode and the version of the target host meets the version requirement in the target configuration data, send, based on a URL corresponding to the function in the target configuration data, a call request carrying the URL corresponding to the function to the target host, so that after the target host intercepts and parses the call request, call the function according to the URL in the call request;
And if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
According to the device for calling the host function by the H5 page, the description information of the target host where the H5 page is located is determined to be used as target description information, the communication mode of the H5 page and the target host is determined based on the communication mode in the target configuration data, the page operation on any function is sent out by a user on the H5 page in response to detection, if the determined communication mode is an interception mode and the version of the target host meets the version requirement in the target configuration data, a call request carrying the URL corresponding to the function is sent to the target host based on the URL corresponding to the function in the target configuration data, so that the target host intercepts and analyzes the call request, and then calls the function according to the URL in the call request; and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
In the scheme of the application, for the same H5 page, the configuration data of each host end can be pre-stored in the configuration center based on the description information of each host end, when the H5 page is accessed to the target host end, the configuration data corresponding to the target host end is acquired from the configuration center, and then the function of the target host end can be invoked by using the acquired configuration data. Therefore, when the same H5 page is accessed to different host terminals, different calling modes are not required to be set for the different host terminals, and the function calling of the same H5 interface to the different host terminals can be realized under the condition that lengthy codes are not required.
Optionally, the triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data includes:
sending a target instruction to the target host end to trigger the target host end to call the function; the instruction type of the target instruction is the instruction type corresponding to the API injection mode, and the target instruction carries the method name and the parameter corresponding to the function.
Optionally, the URL corresponding to any function is composed of a protocol name and a path utilized when the function is called; wherein the path contains parameters of the function;
based on the URL corresponding to the function in the target configuration data, sending, to the target host, a call request carrying the URL corresponding to the function includes:
acquiring a URL corresponding to the function from the target configuration data;
detecting whether the parameters contained in the URL corresponding to the function contain dynamic parameters or not;
if the dynamic parameter is included in the set of parameters,
replacing dynamic parameters contained in the URL corresponding to the function with real parameters to obtain the URL to be utilized, constructing and sending a call request carrying the URL to be utilized to the target host; wherein the real parameter is a parameter corresponding to the page operation obtained by determining based on the page operation for realizing any function;
if the dynamic parameters are not contained, constructing and sending a call request carrying the URL corresponding to the function to the target host terminal.
Optionally, the triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data includes:
Acquiring a method name and a parameter corresponding to the function from the target configuration data;
detecting whether the parameters corresponding to the function contain dynamic parameters or not;
if the dynamic parameters are included, replacing the dynamic parameters included in the parameters corresponding to the function with real parameters to obtain corrected parameters, and triggering the target host terminal to call the function based on the method name corresponding to the function and the corrected parameters; wherein the real parameter is a parameter corresponding to the page operation obtained by determining based on the page operation for realizing any function;
and if the dynamic parameters are not included, triggering the target host terminal to call the function based on the acquired method name and parameters corresponding to the function.
Optionally, the configuration data corresponding to the object description information further includes: style configuration data, the apparatus further comprising: and the rendering device is used for executing rendering of the H5 page based on the style configuration data before the communication mode between the H5 page and the target host terminal is determined based on the communication mode in the target configuration data.
Optionally, a plurality of functional slots exist in the H5 page; each function slot is uniquely corresponding to one function of the functions to be called;
When the determined communication mode is an interception mode, each function slot is used for storing a URL corresponding to a function corresponding to the function slot in the target configuration data; when the determined communication mode is an API injection mode, each function slot is used for storing a method name and parameters corresponding to a function corresponding to the function slot in the target configuration data;
the acquisition mode of the URL corresponding to the function in the target configuration data comprises the following steps:
acquiring a URL corresponding to the function from a function slot corresponding to the function;
the method for obtaining the method name and the parameter corresponding to the function in the target configuration data comprises the following steps:
and obtaining the method name and the parameter corresponding to the function from the function slot corresponding to the function.
The embodiment of the application also provides an electronic device, as shown in fig. 6, which comprises a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602 and the memory 603 complete communication with each other through the communication bus 604,
a memory 603 for storing a computer program;
the processor 601 is configured to implement the steps of the method for calling the host function by any H5 page when executing the program stored in the memory 603.
The communication bus mentioned above for the electronic devices may be a peripheral component interconnect standard (Peripheral Component Interconnect, PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, EISA) bus, etc. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the electronic device and other devices.
The Memory may include random access Memory (Random Access Memory, RAM) or may include Non-Volatile Memory (NVM), such as at least one disk Memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU), a network processor (Network Processor, NP), etc.; but also digital signal processors (Digital Signal Processor, DSP), application specific integrated circuits (APPlication Specific Integrated Circuit, ASIC), field programmable gate arrays (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present application, there is further provided a computer readable storage medium having a computer program stored therein, the computer program when executed by a processor implementing the steps of the method for any of the H5 pages to invoke the host-side function described above.
In yet another embodiment of the present application, a computer program product containing instructions that, when executed on a computer, cause the computer to perform the method of any of the H5 pages calling host-side functions of the above embodiments is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present application, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments.
The foregoing description is only of the preferred embodiments of the present application and is not intended to limit the scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application are included in the protection scope of the present application.

Claims (10)

1. A method for H5 page call host side functions, the method comprising:
determining description information of a target host end where the H5 page is located, and taking the description information as target description information;
acquiring configuration data corresponding to the target description information from a configuration center as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs corresponding to various functions to be called, and the function list corresponding to the API injection mode comprises method names and parameters corresponding to various functions to be called;
determining a communication mode between the H5 page and the target host terminal based on the communication mode in the target configuration data;
Responding to the detection that a user sends out page operation about realizing any function on the H5 page, if the determined communication mode is an interception mode and the version of the target host terminal accords with the version requirement in the target configuration data, sending a call request carrying the URL corresponding to the function to the target host terminal based on the URL corresponding to the function in the target configuration data, so that the target host terminal intercepts and analyzes the call request and then calls the function according to the URL in the call request;
and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
2. The method of claim 1, wherein triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data comprises:
sending a target instruction to the target host end to trigger the target host end to call the function; the instruction type of the target instruction is the instruction type corresponding to the API injection mode, and the target instruction carries the method name and the parameter corresponding to the function.
3. The method of claim 1, wherein the URL corresponding to any function is composed of a protocol name and a path utilized when the function is called; wherein the path contains parameters of the function;
based on the URL corresponding to the function in the target configuration data, sending, to the target host, a call request carrying the URL corresponding to the function includes:
acquiring a URL corresponding to the function from the target configuration data;
detecting whether the parameters contained in the URL corresponding to the function contain dynamic parameters or not;
if the dynamic parameter is included in the set of parameters,
replacing dynamic parameters contained in the URL corresponding to the function with real parameters to obtain the URL to be utilized, constructing and sending a call request carrying the URL to be utilized to the target host; wherein the real parameter is a parameter corresponding to the page operation obtained by determining based on the page operation for realizing any function;
if the dynamic parameters are not contained, constructing and sending a call request carrying the URL corresponding to the function to the target host terminal.
4. The method according to claim 1, wherein the triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data includes:
Acquiring a method name and a parameter corresponding to the function from the target configuration data;
detecting whether the parameters corresponding to the function contain dynamic parameters or not;
if the dynamic parameters are included, replacing the dynamic parameters included in the parameters corresponding to the function with real parameters to obtain corrected parameters, and triggering the target host terminal to call the function based on the method name corresponding to the function and the corrected parameters; wherein the real parameter is a parameter corresponding to the page operation obtained by determining based on the page operation for realizing any function; and if the dynamic parameters are not included, triggering the target host terminal to call the function based on the acquired method name and parameters corresponding to the function.
5. The method of claim 1, wherein the configuration data corresponding to the object description information further comprises: style configuration data, before determining the communication mode between the H5 page and the target host based on the communication mode in the target configuration data, the method further includes:
and rendering the H5 page based on the style configuration data.
6. The method of claim 1, wherein there are a plurality of functional slots in the H5 page; each function slot is uniquely corresponding to one function of the functions to be called;
When the determined communication mode is an interception mode, each function slot is used for storing a URL corresponding to a function corresponding to the function slot in the target configuration data; when the determined communication mode is an API injection mode, each function slot is used for storing a method name and parameters corresponding to a function corresponding to the function slot in the target configuration data;
the acquisition mode of the URL corresponding to the function in the target configuration data comprises the following steps:
acquiring a URL corresponding to the function from a function slot corresponding to the function;
the method for obtaining the method name and the parameter corresponding to the function in the target configuration data comprises the following steps:
and obtaining the method name and the parameter corresponding to the function from the function slot corresponding to the function.
7. An apparatus for H5 page call host side functions, the apparatus comprising:
the first determining module is used for determining description information of a target host end where the H5 page is located and taking the description information as target description information;
the acquisition module is used for acquiring configuration data corresponding to the target description information from a configuration center and taking the configuration data as target configuration data; the configuration data corresponding to the target description information is preset configuration data required when the H5 page is accessed to any host terminal with the target description information, and the configuration data corresponding to the target description information comprises: the communication mode of the H5 page and the accessed host end, the function list of the accessed host end corresponding to the communication mode and the version requirement of the accessed host end; the communication mode is an interception mode or an API injection mode, the function list corresponding to the interception mode comprises URLs corresponding to various functions to be called, and the function list corresponding to the API injection mode comprises method names and parameters corresponding to various functions to be called;
The second determining module is used for determining the communication mode between the H5 page and the target host end based on the communication mode in the target configuration data;
the calling module is used for responding to the fact that a user sends out page operation about realizing any function on the H5 page, if the determined communication mode is an interception mode and the version of the target host terminal accords with the version requirement in the target configuration data, a calling request carrying the URL corresponding to the function is sent to the target host terminal based on the URL corresponding to the function in the target configuration data, so that the target host terminal intercepts and analyzes the calling request and then calls the function according to the URL in the calling request;
and if the determined communication mode is an API injection mode and the version of the target host terminal accords with the version requirement in the target configuration data, triggering the target host terminal to call the function based on the method name and the parameter corresponding to the function in the target configuration data.
8. The apparatus of claim 7, wherein the triggering the target host to call the function based on the method name and the parameter corresponding to the function in the target configuration data comprises:
Sending a target instruction to the target host end to trigger the target host end to call the function; the instruction type of the target instruction is the instruction type corresponding to the API injection mode, and the target instruction carries the method name and the parameter corresponding to the function.
9. The electronic equipment is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory are communicated with each other through the communication bus;
a memory for storing a computer program;
a processor for implementing the method of any of claims 1-6 when executing a program stored on a memory.
10. A computer readable storage medium, characterized in that the computer readable storage medium has stored therein a computer program which, when executed by a processor, implements the method of any of claims 1-6.
CN202311420175.3A 2023-10-30 2023-10-30 Method, device, equipment and storage medium for calling host function by H5 page Active CN117149469B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311420175.3A CN117149469B (en) 2023-10-30 2023-10-30 Method, device, equipment and storage medium for calling host function by H5 page

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311420175.3A CN117149469B (en) 2023-10-30 2023-10-30 Method, device, equipment and storage medium for calling host function by H5 page

Publications (2)

Publication Number Publication Date
CN117149469A true CN117149469A (en) 2023-12-01
CN117149469B CN117149469B (en) 2024-01-19

Family

ID=88910489

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311420175.3A Active CN117149469B (en) 2023-10-30 2023-10-30 Method, device, equipment and storage medium for calling host function by H5 page

Country Status (1)

Country Link
CN (1) CN117149469B (en)

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003141272A (en) * 2001-11-02 2003-05-16 T2 Mediapal Kk System for supporting preparation of homepage of accommodations
CN116578297A (en) * 2023-05-18 2023-08-11 中国建设银行股份有限公司 H5 page running method and device, electronic equipment and storage medium
CN116661936A (en) * 2023-06-30 2023-08-29 中国平安财产保险股份有限公司 Page data processing method and device, computer equipment and storage medium

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2003141272A (en) * 2001-11-02 2003-05-16 T2 Mediapal Kk System for supporting preparation of homepage of accommodations
CN116578297A (en) * 2023-05-18 2023-08-11 中国建设银行股份有限公司 H5 page running method and device, electronic equipment and storage medium
CN116661936A (en) * 2023-06-30 2023-08-29 中国平安财产保险股份有限公司 Page data processing method and device, computer equipment and storage medium

Also Published As

Publication number Publication date
CN117149469B (en) 2024-01-19

Similar Documents

Publication Publication Date Title
CN107979508B (en) Micro-service test method and device
CN109391676B (en) Terminal device control method, terminal device, and computer-readable storage medium
CN105657191B (en) Application increment upgrading method and system based on Android system
CN110688232B (en) Application program calling method, terminal equipment and computer readable storage medium
CN110324169B (en) Interface management method and device
CN110365724B (en) Task processing method and device and electronic equipment
CN106502717B (en) Application program running method and device
CN113141405B (en) Service access method, middleware system, electronic device, and storage medium
CN102622237B (en) A kind of collocation method of business function procedure and system
CN106569880B (en) Method and system for dynamically sharing resources between Android applications
CN107273126B (en) Application development method and device
US11537367B1 (en) Source code conversion from application program interface to policy document
CN108733553A (en) Configuration method, the device and system of test device based on docker
CN108804100B (en) Method and device for creating interface element, storage medium and mobile terminal
CN110727469B (en) Terminal device control method and device, application program configuration file packaging method, terminal device and computer readable storage medium
CN110209983B (en) Method and device for deploying web project of webpage
US10078532B2 (en) Resource management method and device for terminal system among multiple operating systems
CN114968406A (en) Plug-in management method and device, electronic equipment and storage medium
CN117149469B (en) Method, device, equipment and storage medium for calling host function by H5 page
CN111880786A (en) Multi-application sharing method, system, device, electronic equipment and storage medium
CN111158777A (en) Component calling method and device and computer readable storage medium
CN110704041A (en) Software development method and device
CN115794214A (en) Application module metadata management method, device, storage medium and device
CN110730197A (en) Service discovery method and system
CN114726905A (en) Method, device, equipment and storage medium for accessing Tbox network to Android system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant