Interaction methods, devices, and storage media between H5 pages and native apps

The integration method for H5 pages and native apps through a message queue and task parser enhances stability and code quality by streamlining communication and reducing developer workload.

CN111767052BActive Publication Date: 2024-12-13PINGAN INT SMART CITY TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202010618670.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-06-30
Publication Date
2024-12-13
Estimated Expiration
2040-06-30

AI Technical Summary

Technical Problem

Traditional APP development faces challenges with long development cycles and poor code quality due to frequent updates, while H5 pages offer flexibility but inferior user experience, necessitating a better integration method.

Method used

An interaction method and device that loads a preset file with a message queue and interaction protocol into an H5 page, using a task parser and manager to process interactive messages, ensuring seamless communication between H5 pages and native apps, reducing security vulnerabilities and developer workload.

Benefits of technology

This approach unifies H5 and native app codes, enhances stability, improves code quality, and reduces development burden by focusing developers on business logic rather than underlying tasks, thus optimizing the interaction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111767052B_ABST
    Figure CN111767052B_ABST
Patent Text Reader

Abstract

The present invention discloses an interaction method, device and storage medium for an H5 page and a native APP. The method comprises: when a target APP loads an H5 page, loading a preset file into the H5 page; wherein the preset file comprises: a message queue and an interaction protocol; adding an interaction message sent by the H5 page to the target APP to the message queue, and notifying the target APP according to the interaction protocol, so that the target APP can obtain the interaction message from the message queue; determining a target task processor corresponding to interaction type information in the interaction message by calling a task parser, and adding interaction parameter information in the interaction information to the target task processor; running the target task processor by calling a task manager, thereby realizing interaction operations corresponding to the interaction message; the present invention can ensure the convenience and reliability of interaction between the H5 page and the native APP.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of research and development management, and in particular to an interaction method, device and storage medium between an H5 page and a native APP. Background Art

[0002] Traditional APP development has defects such as difficulty in updating and long review cycle before listing. For example, a short-term activity page that needs to be modified many times takes a lot of time to develop the page, and the code needs to be modified and resubmitted for review when the activity is updated. Therefore, the lengthy development cycle causes a waste of development manpower and easily buries code defects, resulting in poor APP code quality.

[0003] Compared with native apps, H5 pages have a short development cycle and are more flexible to update, but their user experience is worse than that of native apps. Therefore, how to better combine H5 pages with native apps to complement each other's advantages has become a technical problem that technical personnel urgently need to solve. Summary of the invention

[0004] The purpose of the present invention is to provide an H5 page and native APP interaction method, device and storage medium, which can ensure the convenience and reliability of the interaction between the H5 page and the native APP.

[0005] According to one aspect of the present invention, a method for interaction between an H5 page and a native APP is provided, the method comprising:

[0006] When the target APP loads the H5 page, the preset file is loaded into the H5 page; wherein the preset file includes: a message queue and an interaction protocol;

[0007] Adding the interactive message sent by the H5 page to the target APP to the message queue, and notifying the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue;

[0008] Determine a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and add the interaction parameter information in the interaction message to the target task processor;

[0009] The target task processor is run by calling the task manager, thereby implementing the interactive operation corresponding to the interactive message.

[0010] Optionally, the step of loading the preset file into the H5 page specifically includes:

[0011] Obtain the preset file, and read the preset file into the target APP memory;

[0012] Convert the preset file into a string;

[0013] The string in the memory is loaded into the H5 page by calling the web page view.

[0014] Optionally, the method further includes:

[0015] When the target APP loads the H5 page, a task parser for parsing interactive messages, multiple task processors for processing different types of interactive services, and a task manager for managing all task processors are registered in the target APP.

[0016] Optionally, notifying the target APP according to the interaction protocol so that the target APP obtains the interaction message from the message queue specifically includes:

[0017] The interactive message in the message queue is sent to the target APP through the console log according to the interactive protocol, so that the target APP obtains the interactive message from the console log.

[0018] Optionally, the determining, by calling a task parser, a target task processor corresponding to the interaction type information in the interaction message specifically includes:

[0019] By calling the task parser, the task type annotation contained in each task processor is obtained by using the reflection mechanism;

[0020] Determine the target task type annotation corresponding to the interaction type information by calling the task parser;

[0021] By calling the task parser, the task processor containing the target task type annotation is set as the target task processor.

[0022] Optionally, the adding the interaction parameter information in the interaction information to the target task processor specifically includes:

[0023] The parameter requirement annotation contained in the target task processor is parsed by calling the task parser, and the corresponding interaction parameter information is determined from the interaction message according to the parameter requirement annotation, and the determined interaction parameter information is added to the target task processor.

[0024] Optionally, the calling of a task manager to run the target task processor, thereby implementing an interactive operation corresponding to the interactive message, specifically includes:

[0025] Acquire the execution annotation in the target task processor by calling the task manager; wherein the execution annotation is used to characterize synchronous execution or asynchronous execution;

[0026] If it is executed asynchronously, the target task processor is run using a thread pool;

[0027] If it is executed synchronously, the target task processor is run in the main thread using the asynchronous callback processing mechanism of the UI interface thread.

[0028] In order to achieve the above object, the present invention also provides an interactive device between an H5 page and a native APP, the device comprising:

[0029] A loading module, used to load a preset file into the H5 page when the target APP loads the H5 page; wherein the preset file includes: a message queue and an interaction protocol;

[0030] A processing module, configured to add the interactive message sent by the H5 page to the target APP to the message queue, and notify the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue;

[0031] A parsing module, configured to determine a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and add the interaction parameter information in the interaction message to the target task processor;

[0032] The interaction module is used to run the target task processor by calling the task manager, so as to realize the interaction operation corresponding to the interaction message.

[0033] In order to achieve the above-mentioned purpose, the present invention also provides a computer device, which specifically includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the steps of the method for interacting between the H5 page and the native APP introduced above are implemented.

[0034] In order to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned method for interacting between the H5 page and the native APP are implemented.

[0035] The method, device and storage medium for interaction between H5 page and native APP provided by the present invention can unify the code of H5 page in Android system, reduce the security vulnerabilities of H5 page and native APP in the interaction process, and increase the middle layer for interaction between H5 page and native APP by injecting local preset files of APP into H5 page, reduce the amount of H5 business development, and let H5 developers focus on specific business logic. By adopting the structure of task parser-task processor-task manager to unify the underlying interaction logic between H5 page and native APP, APP business developers do not need to pay attention to logic such as task execution, thread scheduling, data parsing, etc., but only need to pay attention to business implementation. Through this embodiment, the changes made by developers to the bottom layer are reduced, the stability of APP is increased, the code quality is improved, and the corresponding business burden of developers is also reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:

[0037] Figure 1 An optional flow chart of the method for interaction between an H5 page and a native APP provided in Example 1;

[0038] Figure 2 A schematic diagram of an optional composition structure of an interactive device between an H5 page and a native APP provided in Example 2;

[0039] Figure 3 A schematic diagram of an optional hardware architecture of a computer device provided in Example 3. DETAILED DESCRIPTION

[0040] In order to make the purpose, technical scheme and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0041] Embodiment 1

[0042] The embodiment of the present invention provides an interaction method between an H5 page and a native APP, which is applied to a mobile terminal of an Android system, such as Figure 1 As shown, the method specifically comprises the following steps:

[0043] Step S101: When the target APP loads the H5 page, a preset file is loaded into the H5 page; wherein the preset file includes: a message queue and an interaction protocol.

[0044] Among them, H5 page is the abbreviation of HTML5 page, and HTML5 is a language description method for building Web content.

[0045] Specifically, the preset file includes: a message queue for storing interactive messages sent by the H5 page to the target APP, and an interactive protocol agreed in advance between the H5 page and the target APP.

[0046] Furthermore, the step of loading the preset file into the H5 page specifically includes:

[0047] Step A1: Obtain the preset file, and read the preset file into the target APP memory;

[0048] Step A2: converting the preset file into a character string;

[0049] Step A3: Load the string in the memory into the H5 page by calling the web view WebView.

[0050] Preferably, the string in the memory is loaded into the H5 page by calling loadUrl of WebView.

[0051] In this embodiment, the preset file is the middle layer for the interaction between the H5 page and the native APP. The preset file includes a message queue for temporarily storing the interactive messages sent by the H5 page to the native APP. In addition, the preset file implements the method of H5 calling Java, and the preset file contains the interactive protocol agreed in advance with the native APP.

[0052] Furthermore, the method further comprises:

[0053] When the target APP loads the H5 page, a task parser for parsing interactive messages, multiple task processors for processing different types of interactive services, and a task manager for managing all task processors are registered in the target APP.

[0054] Among them, the task processor includes: a user-related processor and a page sharing processor; the user-related processor is used to send the user information of the logged-in APP to the H5 page; the page sharing processor is used to share the H5 page to the specified APP.

[0055] In this embodiment, the developer encapsulates various types of interactive services that the H5 page needs to entrust the native APP to process into corresponding task processors in advance. The type of task processor is determined by the specific business scenario of the APP. For example, when the H5 page needs to obtain the user information of the logged-in native APP, a user-related processor is created to return the user information to the H5 page; for another example, when the H5 page needs to share the page to other social APPs, a page sharing processor is created accordingly.

[0056] In addition, in this embodiment, the task parser is equivalent to an adapter, which finds the corresponding task processor according to the interactive message initiated by H5, and converts the interactive message into the parameter information required by the corresponding task processor; all types of task processors are uniformly managed by the task manager and initiated by the task manager. By using the task parser, task processor and task manager, redundant code is reduced, and business developers do not need to understand the implementation of specific parsing, task execution and other codes.

[0057] Step S102: adding the interactive message sent by the H5 page to the target APP to the message queue, and notifying the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue.

[0058] The interaction message includes: interaction type information and interaction parameter information.

[0059] In this embodiment, when the H5 page is initialized, the business js can call the js function in the preset file to put the interactive message into the message queue; in addition, the interactive parameter information that the business js needs to pass to the target APP can be encapsulated in json to achieve object-oriented development.

[0060] It should be noted that the interaction message is a JSON string, which contains the interaction type information and the interaction parameter information required to perform the interaction task; for example, when the interaction type information is a user-related interaction type, the user-related processor needs to be called to obtain the user information of the target APP. Since user information involves privacy issues, the user-related processor is required to verify the H5 page to determine whether the H5 page has the authority to obtain user information. Then, the interaction parameter information of the interaction message needs to include AppSecret information and AppKey information, so that the user-related processor can verify the authority of the H5 page based on the AppSecret information and AppKey information. Only after the verification is passed will the user information be fed back to the H5 page.

[0061] Specifically, notifying the target APP according to the interaction protocol in the preset file so that the target APP obtains the interaction message from the message queue includes:

[0062] According to the interactive protocol, the interactive message in the message queue is sent to the target APP through the console log console.log, so that the target APP can obtain the interactive message from the console log console.log through onConsoleMessage.

[0063] In this embodiment, the interactive message is obtained from the message queue by calling console.log, and the interactive message is sent to the target APP. The WebView that loads the H5 page monitors the console.log printed by the preset file, and the interactive message is passed to the target APP through the parameters of console.log. In this embodiment, the log monitoring protocol is used to avoid occupying the WebViewClient.

[0064] In addition, in this embodiment, when the target APP loads the H5 page through WebView, the target APP registers WebChromeClient to implement the onConsoleMessage method, thereby monitoring the interactive message through the onConsoleMessage method. When console.log is called, WebView will call back onConsoleMessage to obtain the interactive message.

[0065] Step S103: determining a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and adding the interaction parameter information in the interaction message to the target task processor.

[0066] Specifically, the determining the target task processor corresponding to the interaction type information in the interaction message by calling the task parser specifically includes:

[0067] Step B1: by calling the task parser, using the reflection mechanism to obtain the task type annotation contained in each task processor;

[0068] Step B2: determining a target task type annotation corresponding to the interaction type information by calling the task parser;

[0069] Step B3: By calling the task parser, the task processor containing the target task type annotation is set as the target task processor.

[0070] It should be noted that when creating a task processor, it is necessary to set the corresponding method annotation task type (target type: ElementType.METHOD) for each method contained in the task processor. The task parser uses the reflection mechanism to obtain the task type annotation of each method in the task processor and determine the target task type annotation corresponding to the interaction type information.

[0071] Furthermore, the adding the interaction parameter information in the interaction information to the target task processor specifically includes:

[0072] The parameter requirement annotation contained in the target task processor is parsed by calling the task parser, and the corresponding interaction parameter information is determined from the interaction message according to the parameter requirement annotation, and the determined interaction parameter information is added to the target task processor.

[0073] It should be noted that when creating a task processor, it is necessary to add a class member variable annotation requirement identifier (target type: ElementType.FIELD) in the task processor. If the member variable in the task processor uses the requirement identifier annotation, it indicates that the member variable needs to be assigned a corresponding parameter value when the task is executed. When the task parser parses the member variable with the requirement identifier annotation, it determines the variable value corresponding to the member variable from the interactive parameter information of the interactive message, and assigns the variable value to the member variable. In this embodiment, the task parser encapsulates the parameter information of the H5 page in advance and passes it to the task processor through reflection and annotation.

[0074] Step S104: By calling the task parser, the task processor containing the target task type annotation is set as the target task processor.

[0075] Specifically, step S104 includes:

[0076] Acquire the execution annotation in the target task processor by calling the task manager; wherein the execution annotation is used to characterize synchronous execution or asynchronous execution;

[0077] If it is executed asynchronously, the target task processor is run using a thread pool;

[0078] If it is executed synchronously, the asynchronous callback processing Handler mechanism of the UI interface thread is used to run the target task processor in the main thread.

[0079] It should be noted that when defining each task processor, it is necessary to use execution annotations to identify whether the corresponding task processor executes the task synchronously or asynchronously. If it is an asynchronous task, the thread pool is used for execution. If it is a synchronous task, the UI thread's Handler is used to send it to the main thread for execution.

[0080] This embodiment can unify the code of H5 pages in the Android system, reduce the security vulnerabilities in the interaction process between H5 pages and native APPs, and increase the middle layer for the interaction between H5 pages and native APPs by injecting local preset files of APPs into H5 pages, reducing the amount of H5 business development, allowing H5 developers to focus on specific business logic. By adopting the structure of task parser-task processor-task manager to unify the underlying interaction logic between H5 pages and native APPs, APP business developers do not need to pay attention to logic such as task execution, thread scheduling, and data parsing, but only need to pay attention to business implementation. This embodiment reduces the changes made by developers to the underlying layer, increases the stability of APPs, improves the code quality, and also reduces the corresponding business burden on developers.

[0081] Embodiment 2

[0082] The embodiment of the present invention provides an interactive device between an H5 page and a native APP, such as Figure 2 As shown, the device specifically includes the following components:

[0083] 1) A loading module 201 is used to load a preset file into an H5 page when the target APP loads the H5 page; wherein the preset file includes: a message queue and an interaction protocol.

[0084] Specifically, the loading module 201 is used to:

[0085] Obtain the preset file, and read the preset file into the target APP memory;

[0086] Convert the preset file into a string;

[0087] The string in the memory is loaded into the H5 page by calling the web page view.

[0088] Furthermore, the device also includes:

[0089] A registration module is used to register a task parser for parsing interactive messages, register multiple task processors for processing different types of interactive services, and register a task manager for managing all task processors in the target APP when the target APP loads the H5 page.

[0090] Among them, the task processor includes: a user-related processor and a page sharing processor; the user-related processor is used to send the user information of the logged-in APP to the H5 page; the page sharing processor is used to share the H5 page to the specified APP.

[0091] 2) A processing module 202 is used to add the interactive message sent by the H5 page to the target APP to the message queue, and to notify the target APP according to the interactive protocol, so that the target APP can obtain the interactive message from the message queue.

[0092] The interaction message includes: interaction type information and interaction parameter information.

[0093] Specifically, the processing module 202 is used to:

[0094] According to the interactive protocol, the interactive message in the message queue is sent to the target APP through the console log console.log, so that the target APP can obtain the interactive message from the console log console.log through onConsoleMessage.

[0095] In this embodiment, the interactive message is obtained from the message queue by calling console.log, and the interactive message is sent to the target APP. The WebView that loads the H5 page monitors the console.log printed by the preset file, and the interactive message is passed to the target APP through the parameters of console.log. In this embodiment, the log monitoring protocol is used to avoid occupying the WebViewClient.

[0096] In addition, in this embodiment, when the target APP loads the H5 page through WebView, the target APP registers WebChromeClient to implement the onConsoleMessage method, thereby monitoring the interactive message through the onConsoleMessage method. When console.log is called, WebView will call back onConsoleMessage to obtain the interactive message.

[0097] 3) The parsing module 203 is used to determine the target task processor corresponding to the interaction type information in the interaction message by calling the task parser, and add the interaction parameter information in the interaction message to the target task processor.

[0098] Specifically, the parsing module 203 includes:

[0099] A determination unit is used to obtain the task type annotation contained in each task processor by calling the task parser using a reflection mechanism; determine the target task type annotation corresponding to the interaction type information by calling the task parser; and set the task processor containing the target task type annotation as the target task processor by calling the task parser.

[0100] An adding unit is used to parse the parameter requirement annotation contained in the target task processor by calling the task parser, determine the corresponding interaction parameter information from the interaction message according to the parameter requirement annotation, and add the determined interaction parameter information to the target task processor.

[0101] 4) An interaction module 204 is used to run the target task processor by calling a task manager, thereby implementing an interaction operation corresponding to the interaction message.

[0102] Specifically, the interaction module 204 is used to:

[0103] Acquire the execution annotation in the target task processor by calling the task manager; wherein the execution annotation is used to characterize synchronous execution or asynchronous execution;

[0104] If it is executed asynchronously, the target task processor is run using a thread pool;

[0105] If it is executed synchronously, the asynchronous callback processing Handler mechanism of the UI interface thread is used to run the target task processor in the main thread.

[0106] It should be noted that when defining each task processor, it is necessary to use execution annotations to identify whether the corresponding task processor executes the task synchronously or asynchronously. If it is an asynchronous task, the thread pool is used for execution. If it is a synchronous task, the UI thread's Handler is used to send it to the main thread for execution.

[0107] This embodiment can unify the code of H5 pages in the Android system, reduce the security vulnerabilities in the interaction process between H5 pages and native APPs, and increase the middle layer for the interaction between H5 pages and native APPs by injecting local preset files of APPs into H5 pages, reducing the amount of H5 business development, allowing H5 developers to focus on specific business logic. By adopting the structure of task parser-task processor-task manager to unify the underlying interaction logic between H5 pages and native APPs, APP business developers do not need to pay attention to logic such as task execution, thread scheduling, and data parsing, but only need to pay attention to business implementation. This embodiment reduces the changes made by developers to the underlying layer, increases the stability of APPs, improves the code quality, and also reduces the corresponding business burden on developers.

[0108] Embodiment 3

[0109] This embodiment also provides a computer device, such as a smart phone, tablet computer, laptop computer, desktop computer, rack server, blade server, tower server or cabinet server (including an independent server or a server cluster composed of multiple servers) that can execute programs. Figure 3 As shown, the computer device 30 of this embodiment includes at least but not limited to: a memory 301 and a processor 302 that can communicate with each other via a system bus. It should be noted that Figure 3 Only computer device 30 is shown with components 301 - 302 , but it should be understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.

[0110] In this embodiment, the memory 301 (i.e., a readable storage medium) includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 301 may be an internal storage unit of the computer device 30, such as a hard disk or a memory of the computer device 30. In other embodiments, the memory 301 may also be an external storage device of the computer device 30, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. equipped on the computer device 30. Of course, the memory 301 may also include both the internal storage unit and the external storage device of the computer device 30. In this embodiment, the memory 301 is generally used to store the operating system and various application software installed on the computer device 30. In addition, the memory 301 may also be used to temporarily store various types of data that have been output or are to be output.

[0111] In some embodiments, the processor 302 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips. The processor 302 is generally used to control the overall operation of the computer device 30 .

[0112] Specifically, in this embodiment, the processor 302 is used to execute a program of the method for interacting between the H5 page and the native APP stored in the processor 302, and the program of the method for interacting between the H5 page and the native APP implements the following steps when being executed:

[0113] When the target APP loads the H5 page, the preset file is loaded into the H5 page; wherein the preset file includes: a message queue and an interaction protocol;

[0114] Adding the interactive message sent by the H5 page to the target APP to the message queue, and notifying the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue;

[0115] Determine a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and add the interaction parameter information in the interaction message to the target task processor;

[0116] The target task processor is run by calling the task manager, thereby implementing the interactive operation corresponding to the interactive message.

[0117] The specific implementation process of the above method steps can be found in the first embodiment, and this embodiment will not be repeated here.

[0118] Embodiment 4

[0119] This embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored. When the computer program is executed by a processor, the following method steps are implemented:

[0120] When the target APP loads the H5 page, the preset file is loaded into the H5 page; wherein the preset file includes: a message queue and an interaction protocol;

[0121] Adding the interactive message sent by the H5 page to the target APP to the message queue, and notifying the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue;

[0122] Determine a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and add the interaction parameter information in the interaction message to the target task processor;

[0123] The target task processor is run by calling the task manager, thereby implementing the interactive operation corresponding to the interactive message.

[0124] The specific implementation process of the above method steps can be found in the first embodiment, and this embodiment will not be repeated here.

[0125] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0126] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.

[0127] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method.

[0128] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for interaction between an H5 page and a native APP, characterized in that: The method comprises: When the target APP loads the H5 page, the preset file is loaded into the H5 page; wherein the preset file includes: a message queue and an interaction protocol; Adding the interactive message sent by the H5 page to the target APP to the message queue, and notifying the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue; Determine a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and add the interaction parameter information in the interaction message to the target task processor; Running the target task processor by calling the task manager, thereby implementing the interactive operation corresponding to the interactive message; The method further comprises: When the target APP loads the H5 page, a task parser for parsing interactive messages, multiple task processors for processing different types of interactive services, and a task manager for managing all task processors are registered in the target APP; The step of determining the target task processor corresponding to the interaction type information in the interaction message by calling the task parser and adding the interaction parameter information in the interaction message to the target task processor specifically includes: By calling the task parser, the task type annotation contained in each task processor is obtained by using the reflection mechanism, the target task type annotation corresponding to the interaction type information is determined, and the task processor containing the target task type annotation is set as the target task processor; wherein the task type annotation is set for each method contained in the task processor when the task processor is created; By calling the task parser, the parameter requirement annotation contained in the target task processor is parsed, and the corresponding interaction parameter information is determined from the interaction message according to the parameter requirement annotation, and the determined interaction parameter information is added to the target task processor; wherein, the parameter requirement annotation is added for the member variables in the task processor when the task processor is created, and the parameter requirement annotation is used to determine the variable value corresponding to the member variable from the interaction parameter information and assign it to the member variable.

2. The method for interaction between an H5 page and a native APP according to claim 1, characterized in that: The step of loading the preset file into the H5 page specifically includes: Obtain the preset file, and read the preset file into the target APP memory; Convert the preset file into a string; The string in the memory is loaded into the H5 page by calling the web page view.

3. The method for interaction between an H5 page and a native APP according to claim 1, characterized in that: The notifying the target APP according to the interaction protocol so that the target APP obtains the interaction message from the message queue specifically includes: The interactive message in the message queue is sent to the target APP through the console log according to the interactive protocol, so that the target APP obtains the interactive message from the console log.

4. The method for interaction between an H5 page and a native APP according to claim 1, characterized in that: The calling of the task manager to run the target task processor, thereby implementing the interactive operation corresponding to the interactive message, specifically includes: Acquire the execution annotation in the target task processor by calling the task manager; wherein the execution annotation is used to characterize synchronous execution or asynchronous execution; If it is executed asynchronously, the target task processor is run using a thread pool; If it is executed synchronously, the target task processor is run in the main thread using the asynchronous callback processing mechanism of the UI interface thread.

5. An interactive device between an H5 page and a native APP, characterized in that: The device comprises: A loading module, used to load a preset file into the H5 page when the target APP loads the H5 page through WebView; wherein the preset file includes: a message queue and an interaction protocol; A processing module, configured to add the interactive message sent by the H5 page to the target APP to the message queue, and notify the target APP according to the interactive protocol, so that the target APP obtains the interactive message from the message queue; A parsing module, configured to determine a target task processor corresponding to the interaction type information in the interaction message by calling a task parser, and add the interaction parameter information in the interaction message to the target task processor; An interaction module, used to run the target task processor by calling a task manager, thereby implementing an interaction operation corresponding to the interaction message; The device also includes: A registration module, used to register a task parser for parsing interactive messages, register multiple task processors for processing different types of interactive services, and register a task manager for managing all task processors in the target APP when the target APP loads the H5 page; The analysis module is specifically used for: By calling the task parser, the task type annotation contained in each task processor is obtained by using the reflection mechanism, the target task type annotation corresponding to the interaction type information is determined, and the task processor containing the target task type annotation is set as the target task processor; wherein the task type annotation is set for each method contained in the task processor when the task processor is created; By calling the task parser, the parameter requirement annotation contained in the target task processor is parsed, and the corresponding interaction parameter information is determined from the interaction message according to the parameter requirement annotation, and the determined interaction parameter information is added to the target task processor; wherein, the parameter requirement annotation is added for the member variables in the task processor when the task processor is created, and the parameter requirement annotation is used to determine the variable value corresponding to the member variable from the interaction parameter information and assign it to the member variable.

6. A computer device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 4 when executing the computer program.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.

Citation Information

Patent Citations

  • Application operation method and device

    CN105718313A

  • An e-commerce big data acquisition system based on service plug-in

    CN109285046A

  • A webpage loading abnormity monitoring method and device

    CN109783309A

  • H5 page and native APP interaction method and device based on custom protocol

    CN110704783A

  • Webpage link skip processing method, computer device and storage medium

    CN110750741A