Data communication method, computer readable storage medium and communication system
By introducing a container transceiver between applets and HTML5 pages, using local storage space and callback functions, the data loss caused by communication data length limitations and page updates is solved, and the stability and efficiency between applets and HTML5 pages is achieved. Data delivery.
Patent Information
- Application Number
- CN202411186135.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-12-06
AI Technical Summary
In the prior art, communication between the applet and HTML5 pages has length limitations and data loss problems, and the page update of the HTML5 page leads to inconsistency in the original page data.
By introducing a container transceiver as a third-party agent, it receives control instructions from the applet and stores the execution results, and uses the listener in the local storage space to trigger the callback function to avoid URL parameters updates and ensure data consistency.
It solves the problem of data loss when the applet carries parameters through URLs, ensures the page consistency and stability of HTML5 pages, and reduces server pressure.
Smart Images

Figure CN119094308A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data communication technology, and in particular to a data communication method, a computer-readable storage medium, and a communication system. Background Art
[0002] Mini Programs are a brand-new way to connect users and services. They can be easily acquired and distributed in a container, and provide an excellent user experience. However, there are certain limitations in the Mini Program ecosystem and native scenarios, such as the lack of a Mini Program SDK (Software Development Kit), package size restrictions, and incomplete design specifications. HTML5 (H5 for short) pages have a wider range of uses and can be adapted to multiple terminals. Therefore, a hybrid development model is used in actual business, that is, a Mini Program partially uses Mini Program native pages, and partially uses WebView embedded H5 pages. The two work together to implement a complete business logic solution.
[0003] In the hybrid development mode, there are many scenarios where native mini-program pages communicate with H5, but the current solutions have certain limitations and drawbacks. Currently, native mini-programs only support one way to communicate with H5, that is, passing parameters through the address bar URL, but the URL parameter length on the H5 link embedded in WebView is limited, and the modification of the H5 link parameters will cause the original H5 page to be reloaded, and the data consistency of the original page cannot be guaranteed. Summary of the invention
[0004] The main purpose of the present application is to provide a data communication method, a computer-readable storage medium and a communication system, so as to at least solve the problems in the prior art that the communication data between the web page and the native applet has a length limitation, information is easily lost, and the web page will be reloaded when the two communicate.
[0005] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a data communication method is provided, including: receiving a control instruction sent by a Web page, the control instruction being used to instruct a native applet to execute a corresponding instruction; sending the control instruction to the native applet, and receiving an execution result obtained by the native applet executing the control instruction; storing the execution result in a local storage space of a container router to trigger the execution of a callback function, the callback function being used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is a change in the storage data of the local storage space.
[0006] Optionally, the control instruction and the execution result carry identification information, and the execution result is stored in the local storage space of the container transferor, including: storing the execution result and the identification information in the local storage space, and the callback function is used to send the execution result and the identification information to the Web page, so that the Web page determines the control instruction corresponding to the execution result according to the identification information and the identification management object, and the identification management object stores the correspondence between the control instruction and the identification information.
[0007] Optionally, storing the execution result and the identification information in the local storage space includes: storing the execution result and the identification information in a local permanent storage space and / or a local session storage space of the container hub.
[0008] Optionally, sending the control instruction to the native applet includes: obtaining a matching relationship between the instruction type and the application program interface; determining, based on the instruction type of the control instruction and the matching relationship, that the application program interface corresponding to the instruction type in the matching relationship is a target application program interface; and sending the control instruction to the native applet through the target application program interface.
[0009] Optionally, after storing the execution result in the local storage space of the container hub, the method further includes: executing a self-closing program.
[0010] According to another aspect of the present application, a data communication method is provided, including: adding a listener in the local storage space of a container router, the listening event of the listener being a change in the storage data of the local storage space; sending a control instruction to the container router, so that the container router sends the control instruction to a native applet, the control instruction being used to instruct the native applet to execute a corresponding instruction; at least receiving an execution result sent by a callback function, the execution result being obtained by the native applet executing the control instruction and sent to the container router, and the callback function being triggered for execution when the container router stores the execution result in the local storage space of the container router.
[0011] Optionally, before sending the control instruction to the container router, the method also includes: generating the control instruction and identification information of the control instruction, and storing the correspondence between the control instruction and the identification information in an identification management object; sending the control instruction to the container router, including: sending the control instruction and the identification information to the container router; at least receiving the execution result sent by the callback function, including: receiving the execution result and the identification information sent by the callback function; determining the control instruction corresponding to the execution result according to the identification information and the identification management object.
[0012] Optionally, after determining the control instruction corresponding to the execution result, the method further includes: deleting the listener; and deleting the corresponding relationship from an identification management object.
[0013] Optionally, adding the listener in the local storage space of the container translator includes: adding the listener in the local permanent storage space and / or the local session storage space of the container translator.
[0014] Optionally, the control instruction is sent by the container router to the native applet through a target application interface, and the target application interface is the application interface corresponding to the instruction type determined by the container router from the matching relationship based on the instruction type of the control instruction and the matching relationship between the instruction type and the application interface.
[0015] According to another aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute any one of the methods described, or execute any one of the methods described.
[0016] According to another aspect of the present application, a communication system is provided, including: a native applet; a container hub, communicatively connected to the native applet, the container hub including one or more first processors, a first memory, and one or more first programs, wherein the one or more first programs are stored in the first memory and configured to be executed by the one or more first processors, and the one or more first programs include methods for executing any one of the described methods; a Web page, communicatively connected to the container hub, the Web page including one or more second processors, a second memory, and one or more second programs, wherein the one or more second programs are stored in the second memory and configured to be executed by the one or more second processors, and the one or more second programs include methods for executing any one of the described methods.
[0017] By applying the technical solution of the present application, the container router is used as a third-party proxy container between the Web page and the native applet, and communication between the two is achieved through the container router. Since the execution result of the native applet will be stored in the local storage space of the container router, and the data storage capacity of the local storage space of the container router is much larger than the data volume of the execution result, the problem of partial transmission data loss of the execution result caused by the URL length limitation when the native applet sends the execution result to the Web page by carrying parameters in the URL is solved; and the Web page monitors the local storage space through the listener, and when the storage of the execution result is monitored, the callback function will be triggered to send the execution result to the Web page, and the URL parameter of the Web page will not be updated, thereby avoiding the problem of the Web page being reloaded and the original page data being lost, thereby ensuring the page consistency and stability of the Web page. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The drawings constituting part of the present application are used to provide a further understanding of the present application. The exemplary embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0019] Figure 1 A hardware structure block diagram of a mobile terminal for executing a data communication method provided in an embodiment of the present application is shown;
[0020] Figure 2 A schematic diagram of a data communication method according to an embodiment of the present application is shown;
[0021] Figure 3 A schematic diagram of a flow chart of another data communication method provided according to an embodiment of the present application is shown;
[0022] Figure 4 A structural block diagram of a data communication device provided according to an embodiment of the present application is shown;
[0023] Figure 5 A structural block diagram of another data communication device provided according to an embodiment of the present application is shown;
[0024] Figure 6 A schematic diagram of the structure of a communication system provided according to an embodiment of the present application is shown;
[0025] Figure 7 A schematic diagram of a data communication process provided according to an embodiment of the present application is shown;
[0026] Figure 8 A schematic diagram of interaction of a communication system provided according to an embodiment of the present application is shown.
[0027] The above drawings include the following reference numerals:
[0028] 102, processor; 104, memory; 106, transmission device; 108, input and output devices. DETAILED DESCRIPTION
[0029] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0030] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the accompanying drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0032] As introduced in the background technology, in the prior art, there is a length limit for the communication data between the web page and the native applet, information is easily lost, and the web page will be reloaded when the two communicate. To solve the above technical problems, the embodiments of the present application provide a data communication method, a computer-readable storage medium and a communication system.
[0033] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0034] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure block diagram of a mobile terminal of a data communication method according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is for illustration only and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0035] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the data communication method in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, the method described is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof. The transmission device 106 is used to receive or send data via a network. The specific example of the network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0036] In this embodiment, a data communication method running on a mobile terminal, a computer terminal or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0037] Figure 2 1 is a flow chart of a data communication method according to an embodiment of the present application. The method is applied to a container transfer device, which can be a web page container or a mini program page container, such as Figure 2As shown, the method comprises the following steps:
[0038] Step S201, receiving a control instruction sent by a web page, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0039] Specifically, the web page includes HTML (Hypertext Markup Language), CSS (Cascading Style Sheets), JavaScript and the like.
[0040] Step S202, sending the control instruction to the native applet, and receiving an execution result obtained by the native applet executing the control instruction;
[0041] Step S203, storing the execution result in the local storage space of the container router to trigger the execution of the callback function, and the callback function is used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is the change of the storage data of the local storage space.
[0042] Specifically, when the execution result is stored in the local storage space, the storage data of the local storage space changes, that is, the monitoring event occurs. The callback function is a function executed when the monitoring event occurs, and is used to send the changed part of the storage data (that is, the execution result) to the Web page.
[0043] Through the embodiment, first, a control instruction sent by a Web page to instruct the execution of a native applet is received; then, the control instruction is sent to the native applet, so that the native applet executes the control instruction to generate an execution result, and receives the execution result sent by the native applet; finally, the execution result is stored in the local storage space of the container router, triggering the occurrence of a listening event set by the Web page in the local storage space, thereby triggering the execution callback function, and sending the execution result to the Web page, thereby realizing data communication between the Web page and the native applet. In this application, the container router is used as a third-party proxy container between the Web page and the native applet, and communication between the two is achieved through the container router. Since the execution result of the native applet will be stored in the local storage space of the container router, and the data storage capacity of the local storage space of the container router is much larger than the data volume of the execution result, the problem of partial transmission data loss of the execution result caused by the URL length limitation when the native applet sends the execution result to the Web page by carrying parameters in the URL is solved; and the Web page monitors the local storage space through the listener, and when the storage of the execution result is monitored, the callback function will be triggered to send the execution result to the Web page, and the URL parameter of the Web page will not be updated, thereby avoiding the problem of the Web page being reloaded and the original page data being lost, thereby ensuring the page consistency and stability of the Web page.
[0044] In addition, the solution of the present application does not need to rely on a WebSocket server for communication between a Web page and a native applet, thereby ensuring that the cost of communication between the Web page and the native applet is low and reducing server pressure.
[0045] The web page of the present application can be specifically an H5 web page embedded in WebView. By embedding the H5 page in the application, the developer can use web page technology to achieve richer and more interactive interfaces and functions, and can also update and maintain the page content more conveniently. This method can achieve seamless integration between applications and web pages, providing better user experience and functional scalability. Among them, H5 is the specification of HTML, the core language in the Web. The content that users see when browsing the web by any means is originally in HTML format, and it is converted into recognizable information in the browser through some technical processing. WebView is the core view class in the WebKit framework, which is used to manage the interaction between the WebFrame and WebFrameView classes. To embed web content in an application, you only need to create a WebView object, attach it to the window, and send a load message to its main frame. WebKit is an open source browser engine, and the corresponding engines are Gecko (used by Mozilla Firefox, etc.), Trident (also known as MSHTML, used by IE) and EdgeHTML (also known as Chakra, used by Edge and other UWP browsers).
[0046] Specifically, a specific implementation method of receiving the control instruction sent by the Web page may be: intercepting the information sent by the Web page to the native applet to obtain the control instruction.
[0047] After executing the control instruction and generating the execution result, the native applet sends the execution result to the container converter by jumping to the container converter.
[0048] This application builds a message communication channel between H5 and the mini program through a container router, which is implemented by using logical distribution and storage of return parameters.
[0049] In an optional solution, the control instruction and the execution result carry identification information, and step S203: storing the execution result in the local storage space of the container router includes: storing the execution result and the identification information in the local storage space, and the callback function is used to send the execution result and the identification information to the Web page, so that the Web page determines the control instruction corresponding to the execution result according to the identification information and the identification management object, and the identification management object stores the correspondence between the control instruction and the identification information. In this embodiment, in the process of executing data communication between the Web page and the native applet through the container router, the interactive communication data all carry the identification information, which ensures that the Web page can accurately identify the control instruction corresponding to the execution result according to the identification information and the corresponding relationship stored in the identification management object when receiving the execution result, thereby ensuring the mutual correspondence between the control instruction and the execution result during the communication process.
[0050] Among them, when the native applet receives the control instruction carrying the identification information, after executing the control instruction to obtain the execution result, it will package the execution result and the corresponding identification information and send them to the container transferor.
[0051] Specifically, the identification information may be information of a unique identification representing a control instruction generated by a Web page. The container retransmitter may also store the corresponding relationship, and the identification information may also be information of a unique identification representing a control instruction generated by the container retransmitter.
[0052] Those skilled in the art can flexibly set the specific content of the identification information, such as setting the identification information to a unique identification number, an account number, a unique code, etc. In a specific embodiment, the identification information is key information, the execution result corresponding to the identification information is value information, and the identification information and the execution result are stored as a key-value pair in the local storage space.
[0053] Furthermore, storing the execution result and the identification information in the local storage space includes: storing the execution result and the identification information in the local permanent storage space and / or the local session storage space of the container transfer device. The execution result of the present application and its corresponding identification information can be stored in the local permanent storage (LocalStorage) space. The local permanent storage space is a persistent local storage. Even if the webpage is closed, the data will not disappear, and the data reliability is high; the execution result of the present application and its corresponding identification information can also be stored in the local session storage space (SessionStorage). The local session storage space is a session storage object used to temporarily save the data of the same window (or tab). It has a life cycle. When the window or webpage is closed, the data will be deleted, which avoids the data occupying too much storage space.
[0054] In an embodiment of the present application, the execution result and the identification information are stored in the local permanent storage space. The local permanent storage space is a Web storage method that can be used to store data in a browser when JavaScript is used to write websites and apps. It allows web pages to store data locally and retrieve the data when needed. The local permanent storage space uses key-value pairs to store data, and the data is retained after the browser is closed until the user clears it or the web page uses code to delete the data.
[0055] According to other exemplary embodiments of the present application, step S202: sending the control instruction to the native applet includes: obtaining a matching relationship between the instruction type and the application program interface; determining, based on the instruction type of the control instruction and the matching relationship, that the application program interface corresponding to the instruction type in the matching relationship is a target application program interface; and sending the control instruction to the native applet through the target application program interface. In this embodiment, by presetting the matching relationship between the instruction type and the application interface, the acquired control instruction is sent to the native applet according to the matching relationship, thereby further realizing the distribution of communication data.
[0056] Optionally, after storing the execution result in the local storage space of the container translator, the method further includes: executing a self-closing program, that is, the container translator is automatically closed to prevent the container translator from affecting the display of subsequent web pages.
[0057] The corresponding relationship and matching relationship may be present in a table form, or in other suitable forms, such as text.
[0058] Figure 3: is a flow chart of a data communication method according to another embodiment of the present application. The method is applied to a web page, and the web page includes HTML, CSS, and JavaScript. Specifically, the web page can be an H5 page embedded in WebView. Figure 3 As shown, the method comprises the following steps:
[0059] Step S301: adding a listener in the local storage space of the container transfer device, wherein the listening event of the listener is a change in the storage data of the local storage space;
[0060] Specifically, the listener can be added to the specified element through a Javascript method (such as the addEventListener method), and the corresponding callback function is triggered when the specified event (ie the listening event) occurs.
[0061] Step S302: Sending a control instruction to the container transfer device, so that the container transfer device sends the control instruction to the native applet, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0062] Specifically, the method for navigating to a specified page or location (such as the navigateTo method) may be called to jump to the container mediator.
[0063] Step S303: at least receive the execution result sent by the callback function, wherein the execution result is obtained by the native applet executing the control instruction and sent to the container router, and the callback function is triggered to execute when the container router stores the execution result in the local storage space of the container router.
[0064] Specifically, when the execution result is stored in the local storage space, the storage data of the local storage space changes, that is, the monitoring event occurs. The callback function is a function executed when the monitoring event occurs, and is used to send the changed part of the storage data (that is, the execution result) to the Web page.
[0065] Through the described embodiment, a listener is first added to the local storage space of the container router to listen to events in which the storage data of the local storage space changes; then a control instruction is sent to the container router, so that the container router sends the control instruction used to instruct the execution of the native applet to the native applet; finally, at least the execution result sent by the callback function is received, and the callback function is triggered to execute when the container router stores the execution result in the local storage space, and the execution result is obtained by the native applet execution control instruction and sent to the container router. In this application, the container router is used as a third-party proxy container between the Web page and the native applet, and communication between the two is achieved through the container router. Since the execution result of the native applet will be stored in the local storage space of the container router, and the data storage capacity of the local storage space of the container router is much larger than the data volume of the execution result, the problem of partial transmission data loss of the execution result caused by the URL length limitation when the native applet sends the execution result to the Web page by carrying parameters in the URL is solved; and the Web page monitors the local storage space through the listener, and when the storage of the execution result is monitored, the callback function will be triggered to send the execution result to the Web page, and the URL parameter of the Web page will not be updated, thereby avoiding the problem of the Web page being reloaded and the original page data being lost, thereby ensuring the page consistency and stability of the Web page.
[0066] In addition, the solution of the present application does not need to rely on a WebSocket server for communication between a Web page and a native applet, thereby ensuring that the cost of communication between the Web page and the native applet is low and reducing server pressure.
[0067] In an optional solution, before sending the control instruction to the container router, the method further includes: generating the control instruction and the identification information of the control instruction, and storing the correspondence between the control instruction and the identification information in the identification management object; sending the control instruction to the container router includes: sending the control instruction and the identification information to the container router; at least receiving the execution result sent by the callback function, including: receiving the execution result and the identification information sent by the callback function; determining the control instruction corresponding to the execution result according to the identification information and the identification management object. In this embodiment, in the process of executing data communication between the Web page and the native applet through the container router, the interactive communication data all carry the identification information, which ensures that the Web page can accurately identify the control instruction corresponding to the execution result according to the identification information and the corresponding relationship stored in the identification management object when receiving the execution result, thereby ensuring the mutual correspondence between the control instruction and the execution result during the communication process.
[0068] Among them, when the native applet receives the control instruction carrying the identification information, after executing the control instruction to obtain the execution result, it will package the execution result and the corresponding identification information and send them to the container transferor.
[0069] The identification information may be information of a unique identification representing a control instruction generated by a Web page. A person skilled in the art may flexibly set the specific content of the identification information, such as setting the identification information to a unique identification number, an account number, a unique code, etc. In a specific embodiment, the identification information is key information, and the execution result corresponding to the identification information is used as value information, and the identification information and the execution result are stored as a key-value pair in the local storage space.
[0070] In other solutions, after determining the control instruction corresponding to the execution result, the method further includes: deleting the listener; and deleting the corresponding relationship from the identification management object. By canceling the monitoring of the current interactive data and the corresponding relationship of the relevant identification, it is convenient to pre-process the next communication interaction.
[0071] Of course, in the entire process of executing data communication between the Web page and the native applet through the container relay, the same listener and the same corresponding relationship can be used. This application does not limit this.
[0072] In some other optional embodiments, adding a listener in the local storage space of the container router includes: adding the listener in the local permanent storage space and / or the local session storage space of the container router. The execution results of the present application and the corresponding identification information can be stored in the local permanent storage (LocalStorage) space. The local permanent storage space is a persistent local storage. Even if the webpage is closed, the data will not disappear, and the data reliability is high; the execution results of the present application and the corresponding identification information can also be stored in the local session storage space (SessionStorage). The local session storage space is a session storage object used to temporarily save the data of the same window (or tab). It has a life cycle. When the window or webpage is closed, the data will be deleted, avoiding the data from occupying too much storage space.
[0073] Furthermore, the control instruction is sent by the container router to the native applet through a target application interface, and the target application interface is the application interface corresponding to the instruction type determined by the container router from the matching relationship based on the instruction type of the control instruction and the matching relationship between the instruction type and the application interface. In this embodiment, by presetting the matching relationship between the instruction type and the application interface, the acquired control instruction is sent to the native applet according to the matching relationship, thereby further realizing the distribution of communication data.
[0074] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0075] The present application embodiment also provides a kind of data communication device, it should be noted that the data communication device of the present application embodiment can be used to execute the data communication method provided by the present application embodiment. The device is used to implement the embodiments and preferred implementations, and the descriptions have been made without further details. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.
[0076] The following is an introduction to the data communication device provided in the embodiments of the present application.
[0077] Figure 4 is a schematic diagram of a data communication device according to an embodiment of the present application. The device is applied to a container transfer device, and the container transfer device can be a web page container or a small program page container, such as Figure 4 As shown, the device comprises:
[0078] A first receiving unit 10 is used to receive a control instruction sent by a Web page, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0079] Specifically, the web page includes HTML (Hypertext Markup Language), CSS (Cascading Style Sheets), JavaScript and the like.
[0080] A first sending unit 20 is used to send the control instruction to the native applet, and receive an execution result obtained by the native applet executing the control instruction;
[0081] The storage unit 30 is used to store the execution result in the local storage space of the container router to trigger the execution of the callback function, and the callback function is used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is the change of the storage data of the local storage space.
[0082] Specifically, when the execution result is stored in the local storage space, the storage data of the local storage space changes, that is, the monitoring event occurs. The callback function is a function executed when the monitoring event occurs, and is used to send the changed part of the storage data (that is, the execution result) to the Web page.
[0083] Through the embodiment, a control instruction sent by a Web page for instructing the execution of a native applet is received by a first receiving unit; the control instruction is sent to the native applet by the first sending unit, so that the native applet executes the control instruction to generate an execution result, and receives the execution result sent by the native applet; the execution result is stored in the local storage space of the container router by a storage unit, triggering the occurrence of a listening event set by the Web page in the local storage space, thereby triggering the execution callback function, and sending the execution result to the Web page, thereby realizing data communication between the Web page and the native applet. In this application, the container router is used as a third-party proxy container between the Web page and the native applet, and communication between the two is achieved through the container router. Since the execution result of the native applet will be stored in the local storage space of the container router, and the data storage capacity of the local storage space of the container router is much larger than the data volume of the execution result, the problem of partial transmission data loss of the execution result caused by the URL length limitation when the native applet sends the execution result to the Web page by carrying parameters in the URL is solved; and the Web page monitors the local storage space through the listener, and when the storage of the execution result is monitored, the callback function will be triggered to send the execution result to the Web page, and the URL parameter of the Web page will not be updated, thereby avoiding the problem of the Web page being reloaded and the original page data being lost, thereby ensuring the page consistency and stability of the Web page.
[0084] In addition, the solution of the present application does not need to rely on a WebSocket server for communication between a Web page and a native applet, thereby ensuring that the cost of communication between the Web page and the native applet is low and reducing server pressure.
[0085] Figure 5is a schematic diagram of a data communication device according to another embodiment of the present application. The device is applied to a web page, and the web page includes HTML, CSS, and JavaScript. Specifically, the web page can be an H5 page embedded in WebView. Figure 5 As shown, the device comprises:
[0086] An adding unit 40 is used to add a listener in the local storage space of the container transfer device, wherein the listening event of the listener is a change in the storage data of the local storage space;
[0087] Specifically, the listener can be added to the specified element through a Javascript method (such as the addEventListener method), and the corresponding callback function is triggered when the specified event (ie the listening event) occurs.
[0088] A second sending unit 50 is used to send a control instruction to the container converter, so that the container converter sends the control instruction to the native applet, and the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0089] Specifically, the method for navigating to a specified page or location (such as the navigateTo method) may be called to jump to the container mediator.
[0090] The second receiving unit 60 is used to at least receive the execution result sent by the callback function, wherein the execution result is obtained by the native applet executing the control instruction and sent to the container router, and the callback function is triggered to execute when the container router stores the execution result in the local storage space of the container router.
[0091] Specifically, when the execution result is stored in the local storage space, the storage data of the local storage space changes, that is, the monitoring event occurs. The callback function is a function executed when the monitoring event occurs, and is used to send the changed part of the storage data (that is, the execution result) to the Web page.
[0092] Through the described embodiment, a listener is added to the local storage space of the container router through the adding unit to listen to the event of changes in the storage data of the local storage space; a control instruction is sent to the container router through the second sending unit, so that the container router sends the control instruction used to instruct the execution of the native applet to the native applet; and the second receiving unit at least receives the execution result sent by the callback function, and the callback function is triggered to execute when the container router stores the execution result in the local storage space, and the execution result is obtained by the native applet execution control instruction and sent to the container router. In this application, the container router is used as a third-party proxy container between the Web page and the native applet, and communication between the two is achieved through the container router. Since the execution result of the native applet will be stored in the local storage space of the container router, and the data storage capacity of the local storage space of the container router is much larger than the data volume of the execution result, the problem of partial transmission data loss of the execution result caused by the URL length limitation when the native applet sends the execution result to the Web page by carrying parameters in the URL is solved; and the Web page monitors the local storage space through the listener, and when the storage of the execution result is monitored, the callback function will be triggered to send the execution result to the Web page, and the URL parameter of the Web page will not be updated, thereby avoiding the problem of the Web page being reloaded and the original page data being lost, thereby ensuring the page consistency and stability of the Web page.
[0093] In addition, the solution of the present application does not need to rely on a WebSocket server for communication between a Web page and a native applet, thereby ensuring that the cost of communication between the Web page and the native applet is low and reducing server pressure.
[0094] The data communication device includes a processor and a memory, wherein the first receiving unit, the first sending unit, the storage unit, the adding unit, the second sending unit, and the second receiving unit are all stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions. The modules are all located in the same processor; or, the modules are located in different processors in any combination.
[0095] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and by adjusting the kernel parameters, at least the problem of length limitation of communication data between the web page and the native applet in the prior art, easy loss of information, and the page of the web page being reloaded when the two communicate, can be solved.
[0096] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0097] An embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the data communication method.
[0098] Specifically, the data communication method includes:
[0099] Step S201, receiving a control instruction sent by a web page, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0100] Specifically, the web page includes HTML (Hypertext Markup Language), CSS (Cascading Style Sheets), JavaScript and the like.
[0101] Step S202, sending the control instruction to the native applet, and receiving an execution result obtained by the native applet executing the control instruction;
[0102] Step S203, storing the execution result in the local storage space of the container router to trigger the execution of the callback function, and the callback function is used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is the change of the storage data of the local storage space.
[0103] Specifically, when the execution result is stored in the local storage space, the storage data of the local storage space changes, that is, the monitoring event occurs. The callback function is a function executed when the monitoring event occurs, and is used to send the changed part of the storage data (that is, the execution result) to the Web page.
[0104] Optionally, the control instruction and the execution result carry identification information, and the execution result is stored in the local storage space of the container transferor, including: storing the execution result and the identification information in the local storage space, and the callback function is used to send the execution result and the identification information to the Web page, so that the Web page determines the control instruction corresponding to the execution result according to the identification information and the identification management object, and the identification management object stores the correspondence between the control instruction and the identification information.
[0105] Optionally, storing the execution result and the identification information in the local storage space includes: storing the execution result and the identification information in a local permanent storage space and / or a local session storage space of the container hub.
[0106] Optionally, sending the control instruction to the native applet includes: obtaining a matching relationship between the instruction type and the application program interface; determining, based on the instruction type of the control instruction and the matching relationship, that the application program interface corresponding to the instruction type in the matching relationship is a target application program interface; and sending the control instruction to the native applet through the target application program interface.
[0107] Optionally, after storing the execution result in the local storage space of the container hub, the method further includes: executing a self-closing program.
[0108] Alternatively, the data communication method includes:
[0109] Step S301: adding a listener in the local storage space of the container transfer device, wherein the listening event of the listener is a change in the storage data of the local storage space;
[0110] Specifically, the listener can be added to the specified element through a Javascript method (such as the addEventListener method), and the corresponding callback function is triggered when the specified event (ie the listening event) occurs.
[0111] Step S302: Sending a control instruction to the container transfer device, so that the container transfer device sends the control instruction to the native applet, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0112] Specifically, the method for navigating to a specified page or location (such as the navigateTo method) may be called to jump to the container mediator.
[0113] Step S303: at least receive the execution result sent by the callback function, wherein the execution result is obtained by the native applet executing the control instruction and sent to the container router, and the callback function is triggered to execute when the container router stores the execution result in the local storage space of the container router.
[0114] Specifically, when the execution result is stored in the local storage space, the storage data of the local storage space changes, that is, the monitoring event occurs. The callback function is a function executed when the monitoring event occurs, and is used to send the changed part of the storage data (that is, the execution result) to the Web page.
[0115] Optionally, before sending the control instruction to the container router, the method also includes: generating the control instruction and identification information of the control instruction, and storing the correspondence between the control instruction and the identification information in an identification management object; sending the control instruction to the container router, including: sending the control instruction and the identification information to the container router; at least receiving the execution result sent by the callback function, including: receiving the execution result and the identification information sent by the callback function; determining the control instruction corresponding to the execution result according to the identification information and the identification management object.
[0116] Optionally, after determining the control instruction corresponding to the execution result, the method further includes: deleting the listener; and deleting the corresponding relationship from an identification management object.
[0117] Optionally, adding the listener in the local storage space of the container translator includes: adding the listener in the local permanent storage space and / or the local session storage space of the container translator.
[0118] Optionally, the control instruction is sent by the container router to the native applet through a target application interface, and the target application interface is the application interface corresponding to the instruction type determined by the container router from the matching relationship based on the instruction type of the control instruction and the matching relationship between the instruction type and the application interface.
[0119] An embodiment of the present application also provides a communication system.
[0120] Figure 6 The structure diagram of the communication system of the present application is shown as an example. Figure 6 As shown, the communication system includes:
[0121] Native applet;
[0122] A container converter, which is communicatively connected to the native applet, and includes one or more first processors, a first memory, and one or more first programs, wherein the one or more first programs are stored in the first memory and are configured to be executed by the one or more first processors, and the one or more first programs include a method for executing any one of the methods;
[0123] A web page is communicatively connected to the container hub, the web page comprising one or more second processors, a second memory and one or more second programs, wherein the one or more second programs are stored in the second memory and are configured to be executed by the one or more second processors, and the one or more second programs include a program for executing any one of the methods described.
[0124] The communication system of the present application proposes a method of combining a container transferor with persistent storage. When a Web page communicates with a small program, data monitoring will be enabled first, and then the container transferor will be used for logical distribution. The container transferor will jump to the small program page for processing according to the logical command. After logical processing, the small program will add the callback data to the URL parameter and return it to the container transferor. At this time, the data will be stored and returned in the container transferor. Finally, the Web page receives the corresponding data, thus realizing a communication interaction between the Web page and the native small program. It not only ensures accurate data transmission, but also ensures that the original page state of the Web page is not updated, thereby ensuring the state consistency of the Web page, and also realizes the data communication capability of the small program and the Web page.
[0125] In order to enable those skilled in the art to more clearly understand the technical solution of the present application, the implementation process of the data communication method of the present application will be described in detail below in conjunction with specific embodiments.
[0126] This embodiment relates to a specific communication system and a data communication method of the communication system. The communication system is as follows: Figure 6 As shown, the communication system includes a native applet, a container transfer device and a Web page. In this embodiment, the Web page is specifically an H5 page embedded in WebView, and the container transfer device specifically includes a page container, a applet container and LocalStorage.
[0127] The data communication process of the data communication system is as follows: Figure 7 and Figure 8 As shown, the data communication method comprises the following steps:
[0128] Step S1: The H5 page embedded in WebView calls the navigateTo method to jump to the container router. Before the jump, LocalStorage persistent storage monitoring is enabled through addEventListener, and a unique identifier for data transmission generated for this monitoring is stored in the global identifier management object;
[0129] Step S2: The container mediator performs logic distribution, specifically by intercepting and processing the API execution path matching rules, thereby achieving logic distribution;
[0130] Step S3: The native applet performs business logic processing, and after processing, jumps back to the container transfer page with the callback data;
[0131] Step S4: The container transfer device stores the returned parameters, distinguishes the data transmission identity by maintaining the global unique identification object, and stores the data in the local LocalStorage according to the unique identification. At the same time, the container transfer device closes itself;
[0132] Step S5: The H5 page performs persistent storage monitoring through storage.addEventListener(). After the container transfer device stores the data, the callback logic of the monitoring is triggered. At this point, the H5 page obtains the returned data, and the original H5 page receives the required data, unbinds the previous monitoring, and preprocesses the next data acquisition.
[0133] An embodiment of the present invention provides a device, the device including a processor, a memory, and a program stored in the memory and executable on the processor, and when the processor executes the program, at least the following steps are implemented:
[0134] Step S201, receiving a control instruction sent by a web page, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0135] Step S202, sending the control instruction to the native applet, and receiving an execution result obtained by the native applet executing the control instruction;
[0136] Step S203, storing the execution result in the local storage space of the container router to trigger the execution of the callback function, and the callback function is used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is the change of the storage data of the local storage space.
[0137] Alternatively, the processor implements at least the following steps when executing the program:
[0138] Step S301: adding a listener in the local storage space of the container transfer device, wherein the listening event of the listener is a change in the storage data of the local storage space;
[0139] Step S302: Sending a control instruction to the container transfer device, so that the container transfer device sends the control instruction to the native applet, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0140] Step S303: at least receive the execution result sent by the callback function, wherein the execution result is obtained by the native applet executing the control instruction and sent to the container router, and the callback function is triggered to execute when the container router stores the execution result in the local storage space of the container router.
[0141] The devices in this article can be servers, PCs, PADs, mobile phones, etc.
[0142] The present application also provides a computer program product, including computer instructions, which, when executed by a processor, implement at least the following method steps:
[0143] Step S201, receiving a control instruction sent by a web page, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0144] Step S202, sending the control instruction to the native applet, and receiving an execution result obtained by the native applet executing the control instruction;
[0145] Step S203, storing the execution result in the local storage space of the container router to trigger the execution of the callback function, and the callback function is used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is the change of the storage data of the local storage space.
[0146] Alternatively, the computer instructions are a program that, when executed by a processor, at least implements the following method steps:
[0147] Step S301: adding a listener in the local storage space of the container transfer device, wherein the listening event of the listener is a change in the storage data of the local storage space;
[0148] Step S302: Sending a control instruction to the container transfer device, so that the container transfer device sends the control instruction to the native applet, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction;
[0149] Step S303: at least receive the execution result sent by the callback function, wherein the execution result is obtained by the native applet executing the control instruction and sent to the container router, and the callback function is triggered to execute when the container router stores the execution result in the local storage space of the container router.
[0150] Obviously, those skilled in the art should understand that the modules or steps of the present invention described above can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than herein, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0151] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0152] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0153] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0154] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0155] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0156] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0157] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0158] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity 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, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0159] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data communication method, characterized in that: include: Receive a control instruction sent by a web page, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction; Sending the control instruction to the native applet, and receiving an execution result obtained by the native applet executing the control instruction; The execution result is stored in the local storage space of the container router to trigger the execution of a callback function, and the callback function is used to send the execution result to the Web page, wherein the local storage space has a listener added by the Web page, and the listening event of the listener is the change of the storage data of the local storage space.
2. The method according to claim 1, characterized in that The control instruction and the execution result carry identification information, and the execution result is stored in the local storage space of the container transfer device, including: The execution result and the identification information are stored in the local storage space, and the callback function is used to send the execution result and the identification information to the Web page, so that the Web page determines the control instruction corresponding to the execution result according to the identification information and the identification management object, and the identification management object stores the correspondence between the control instruction and the identification information.
3. The method according to claim 2, characterized in that Storing the execution result and the identification information in the local storage space includes: The execution result and the identification information are stored in the local permanent storage space and / or the local session storage space of the container hub.
4. The method according to claim 1, characterized in that: Sending the control instruction to the native applet includes: Get the matching relationship between the instruction type and the application program interface; According to the instruction type of the control instruction and the matching relationship, determining the application program interface corresponding to the instruction type in the matching relationship as the target application program interface; The control instruction is sent to the native applet through the target application program interface.
5. The method according to any one of claims 1 to 4, characterized in that After storing the execution result in the local storage space of the container hub, the method further includes: Execute a self-closing procedure.
6. A data communication method, characterized in that: include: Add a listener in the local storage space of the container transfer device, wherein the listening event of the listener is a change in the storage data of the local storage space; Sending a control instruction to the container converter, so that the container converter sends the control instruction to the native applet, wherein the control instruction is used to instruct the native applet to execute a corresponding instruction; At least receive the execution result sent by the callback function, wherein the execution result is obtained by the native applet executing the control instruction and sent to the container router, and the callback function is triggered to execute when the container router stores the execution result in the local storage space of the container router.
7. The method according to claim 6, characterized in that Before sending the control instruction to the container transfer device, the method further includes: generating the control instruction and identification information of the control instruction, and storing the corresponding relationship between the control instruction and the identification information in an identification management object, Sending a control instruction to the container transfer device includes: sending the control instruction and the identification information to the container transfer device, At least receiving the execution result sent by the callback function includes: receiving the execution result and the identification information sent by the callback function; and determining the control instruction corresponding to the execution result according to the identification information and the identification management object.
8. The method according to claim 7, characterized in that After determining the control instruction corresponding to the execution result, the method further includes: Deleting the listener; The corresponding relationship is deleted from the identification management object.
9. The method according to claim 6, characterized in that Add a listener to the local storage space of the container transfer, including: The listener is added to the local permanent storage space and / or the local session storage space of the container hub.
10. The method according to any one of claims 6 to 9, characterized in that The control instruction is sent by the container router to the native applet through the target application interface, and the target application interface is the application interface corresponding to the instruction type determined by the container router from the matching relationship based on the instruction type of the control instruction and the matching relationship between the instruction type and the application interface.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method described in any one of claims 1 to 5, or to execute the method described in any one of claims 6 to 10.
12. A communication system, characterized in that: include: Native applet; A container transfer device, which is communicatively connected to the native applet, and the container transfer device includes one or more first processors, a first memory, and one or more first programs, wherein the one or more first programs are stored in the first memory and are configured to be executed by the one or more first processors, and the one or more first programs include a method for executing any one of claims 1 to 5; A web page is communicatively connected to the container hub, the web page comprising one or more second processors, a second memory and one or more second programs, wherein the one or more second programs are stored in the second memory and are configured to be executed by the one or more second processors, and the one or more second programs include a method for executing any one of claims 6 to 10.
