Communication method, device, electronic device and readable medium between page end and native end
By generating function call information on the page side and calling the corresponding modules in the native side, the problem of limited communication between script code and native code in mobile applications is solved, cross-version and platform communication is achieved, and security is enhanced.
Patent Information
- Application Number
- CN201910212797.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-03-20
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2039-03-20
AI Technical Summary
In the existing technology, the communication between the script code and the native code in the mobile application is limited by the version or platform of the native code. As a result, the attacker can use the reflection mechanism to call unregistered class methods, resulting in the infinite enhancement of the script code capabilities, and thus Affect user safety.
By generating the function call information of the business trigger event on the page side, and by calling the object used to interact with the page code, a function call message carrying the function call information is sent to the native side to call the specified function module in the native side. Implement communication between the page side and the native side.
This method makes the communication between the page side and the native side not restricted by the native side version or platform, enhances the flexibility and security of communication, and prevents attackers from abusing unregistered class methods.
Smart Images

Figure CN111722935B
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of Internet technology, and in particular, to a communication method, device, electronic device and computer-readable medium between a page end and a native end. Background Art
[0002] With the development of mobile Internet technology and the popularization of smart mobile terminals, the importance of mobile Internet in life is becoming more and more obvious, and the development of mobile applications is becoming more and more important. At present, mobile applications mainly adopt a hybrid development model, that is, they are written in both web language and program language, and the application store distinguishes the operating system and distributes the applications that users need to install. Because hybrid development applications have both good user experience and low development costs, they are increasingly popular with developers.
[0003] Currently, on Android devices, the communication between the script code in the application and the native code needs to be implemented through the network view. Specifically, the application interface is first called to enable the network view to support the functions in the script code, and then the application interface is called to register a method class that can be called by the script code with the network view to enhance the functions of the script code. However, the system versions before Android 4.2 have no restrictions on the call of class methods, which allows attackers to use the reflection mechanism to call any other unregistered class methods, ultimately leading to unlimited enhancement of the capabilities of the script code. Attackers can exploit this vulnerability to do whatever they want based on the client's capabilities. Therefore, the communication between the script code in the application and the native code needs to be compatible with the system version of the native code. In this way, the communication between the script code in the application and the native code is restricted by the version or platform of the native code. Summary of the invention
[0004] The purpose of this application is to propose a communication method, device, electronic device and computer-readable medium between a page end and a native end, so as to solve the problem existing in the prior art of how to facilitate communication between a page end and a native end.
[0005] According to a first aspect of an embodiment of the present application, a communication method between a page end and a native end is provided. The method includes: determining first function call information of a first service trigger event generated at the page end; sending a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call a first function module indicated by the first function call information in the native end.
[0006] According to the second aspect of the embodiment of the present application, a communication method between a page end and a native end is provided. The method includes: receiving a function call message sent by the page end by calling an object used to interact with the page code; parsing the function call message to obtain first function call information carried by the function call message; calling a first function module indicated by the first function call information; and calling back the function execution result of the first function module to the page end.
[0007] According to a third aspect of an embodiment of the present application, a communication device between a page end and a native end is provided. The device includes: a determination module, used to determine first function call information of a first service trigger event generated on the page end; a sending module, used to send a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end.
[0008] According to a fourth aspect of the embodiment of the present application, a communication device between a page end and a native end is provided. The device includes: a first receiving module, used to receive a function call message sent by the page end by calling an object used to interact with the page code; a first parsing module, used to parse the function call message to obtain the first function call information carried by the function call message; a calling module, used to call the first function module indicated by the first function call information; a first callback module, used to call back the function execution result of the first function module to the page end.
[0009] According to the fifth aspect of the embodiments of the present application, an electronic device is provided, comprising: one or more processors; a computer-readable medium configured to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the communication method between the page end and the native end as described in the first aspect or the second aspect of the above-mentioned embodiments.
[0010] According to the sixth aspect of the embodiments of the present application, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the communication method between the page end and the native end as described in the first aspect or the second aspect of the above-mentioned embodiment is implemented.
[0011] Through the technical solution provided in the embodiment of the present application, the first function call information of the first business trigger event generated on the page end is determined, and by calling the object used to interact with the page code, a function call message carrying the first function call information is sent to the native end to call the first function module indicated by the first function call information in the native end. Compared with other existing methods, by calling the object used to interact with the page code to call the function module indicated by the function call information in the native end, the communication between the page end and the native end is not limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0013] Figure 1 This is a flowchart of the communication method between the page end and the native end in the first embodiment of the present application;
[0014] Figure 2 This is a flowchart of the steps of the communication method between the page end and the native end in the second embodiment of the present application;
[0015] Figure 3 This is a flowchart of the communication method between the page end and the native end in the third embodiment of the present application;
[0016] Figure 4 This is a flowchart of the communication method between the page end and the native end in the fourth embodiment of the present application;
[0017] Figure 5 This is a schematic diagram of the structure of the communication device between the page end and the native end in the fifth embodiment of the present application;
[0018] Figure 6 This is a schematic diagram of the structure of the communication device between the page end and the native end in the sixth embodiment of the present application;
[0019] Figure 7 This is a schematic diagram of the structure of the communication device between the page end and the native end in the seventh embodiment of the present application;
[0020] Figure 8 This is a schematic diagram of the structure of the communication device between the page end and the native end in the eighth embodiment of the present application;
[0021] Fig. 9 This is a schematic diagram of the structure of an electronic device in Embodiment 9 of the present application;
[0022] Fig.10 This is the hardware structure of the electronic device in the tenth embodiment of the present application. DETAILED DESCRIPTION
[0023] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only configured to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.
[0024] 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.
[0025] Reference Figure 1 , showing a step flow chart of the communication method between the page end and the native end of Example 1 of the present application.
[0026] This embodiment describes the communication method between the page end and the native end provided in the embodiment of the present application from the perspective of the page end. Specifically, the communication method between the page end and the native end of this embodiment includes the following steps:
[0027] In step S101, first function call information of a first service triggering event generated on the page end is determined.
[0028] In the embodiment of the present application, the page end can be understood as a general term for the script code of the page of the application developed using the JavaScript scripting language, and the native end can be understood as a general term for the native code of the IOS system application developed using the Objective-C language, or a general term for the native code of the Android system application developed using the Java language. In the same application, some functions may be developed by the JavaScript scripting language, and some functions may be developed by the Java language or the Objective-C language. Therefore, the native end and the page end can exist in the same application. The Android system where the application is located provides an interface for the native end to interact with the page end, and the IOS system where the application is located also provides an interface for the native end to interact with the page end. The communication device between the page end and the native end can be a page end, or a browser application, or an audio and video player application, an instant messaging application, a shopping application, etc. It can be understood that the above description is only exemplary, and the embodiment of the present application does not impose any limitation on this.
[0029] In an embodiment of the present application, the first service triggering event may be a user clicking a specific button, opening a local folder, enabling a gyroscope, enabling air pressure sensing, enabling a camera, enabling hardware such as a microphone, enabling the native end to open a page, or calling the native end's recorder function for recording, etc. The first function call information includes at least one of the following: the name of the first function module, the parameters of the first function module, and a function callback function for calling back the function execution result of the first function module. Among them, the first function module may be a function module for executing a file opening method, a function module for executing a file moving method, a function module for executing a file copying method, a function module for executing a file pasting method, a function module for executing a file deletion method, etc. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0030] In some optional embodiments, when determining the first function call information of the first business trigger event generated at the page end, the first function call information of the first business trigger event is transmitted to the page end through the business function corresponding to the first business trigger event, so as to determine the first function call information of the first business trigger event generated at the page end. Specifically, under the triggering of the first business trigger event, the first function call information of the first business trigger event is transmitted to the preset function of the page end by calling the business function corresponding to the first business trigger event, so as to determine the first function call information of the first business trigger event generated at the page end. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0031] In step S102, a function call message carrying the first function call information is sent to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end.
[0032] In an embodiment of the present application, the object used to interact with the page code includes a console function, for example, console.log(), console.info(), console.error(), console.warn(), etc. Among them, console.log() is used to output information, console.info() is an alias of console.log(), and when console.error() is used to output information, a red cross is added to the front to indicate an error, and the stack where the error occurred is displayed. Console.warn() is used to output warning information. The reason why a function call message carrying the first function call information is sent to the native end by calling the console function is that the native console channel can be reused in this way, and the communication between the page end and the native end is not limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end. It can be understood that the above description is only exemplary, and the embodiment of the present application does not make any limitation to this.
[0033] In some optional embodiments, when a function call message carrying the first function call information is sent to the native end by calling an object for interacting with the page code, the first function call information is structured to obtain structured data that facilitates the native end to parse the first function call information; a function call message carrying the structured data is generated; and the function call message carrying the structured data is sent to the native end by calling the object for interacting with the page code. Thus, the structured data carried by the function call message can facilitate the native end to parse the first function call information. Of course, the embodiments of the present application are not limited to this, and a function call message carrying the first function call information can be directly generated, and then the function call message carrying the first function call information is sent to the native end by calling the object for interacting with the page code. The embodiments of the present application do not impose any limitations on this.
[0034] In a specific example, when the structured data includes a page link address, the structured processing of the first function call information includes: generating a page link address based on the name and parameters of the first function module in the first function call information. Specifically, the string in the protocol field, the string of the name of the first function module, and the string of the parameters of the first function module are pieced together to generate a page link address in the form of a link address similar to the src field of an iframe tag, or a page link address in the form of a link address similar to window.location.href, or a page link address in the form of a link address similar to window.open, or a page link address in the form of a link address similar to self.location.href. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0035] In a specific example, the function callback function for calling back the function execution result of the first function module can be stored in the container, and the identification information of the function callback function generated by the container is obtained, and then based on the name and parameters of the first function module and the identification information of the function callback function, a page link address is generated. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0036] In a specific example, when the structured data includes JSON data carrying the first function call information, the structured processing of the first function call information includes: generating the JSON data based on the name and parameters of the first function module in the first function call information. Specifically, the name of the first function module in the first function call information is stored in the method field in the JSON data, and the parameters of the first function module in the first function call information are stored in the parameter field in the JSON data, thereby generating the JSON data carrying the first function call information. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0037] In a specific example, the native end parses the received function call message to obtain the first function call information carried by the function call message, and then calls the first function module indicated by the first function call information. Thereby, the page end transmits the first function call information of the first business triggering event to the native end through the function call message, without being limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0038] In some optional embodiments, the method further includes: receiving the function execution result of the first function module returned by the native end; calling back the received function execution result to the business function corresponding to the first business triggering event through the function callback function of the first business triggering event. Thereby, by calling back the received function execution result through the function callback function of the first business triggering event, the business function of the first business triggering event generated by the page end can obtain the corresponding function execution result. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0039] In a specific example, the page end receives the function execution result of the first function module returned by the native end through script code injection. The page end calls back the received function execution result by executing the callback function of the function callback function of the first business triggering event. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0040] In some optional embodiments, the method further includes: receiving second function call information of a second service trigger event transmitted from the native end; calling a second function module indicated by the second function call information; and calling back the function execution result of the second function module to the native end. Thus, through the function call information of the service trigger event transmitted from the native end, the function module indicated by the function call information can be called on the page end, and the corresponding function execution result can be obtained. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0041] In a specific example, when receiving the second function call information of the second service trigger event transmitted by the native end, the page end receives the second function call information of the second service trigger event transmitted by the native end through script code injection. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0042] In a specific example, when calling the second function module indicated by the second function call information, the second function module indicated by the second function call information is called through the function in the script code for calculating the string and executing the script code corresponding to the string. Among them, the function for calculating the string and executing the script code corresponding to the string can be the eval() function in the JavaScript scripting language. Calling the second function module indicated by the second function call information through the eval() function is more flexible. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0043] In a specific example, when the function execution result of the second function module is called back to the native end, by calling the object for interacting with the page code, a result callback message carrying the function execution result of the second function module is sent to the native end to call back the function execution result of the second function module to the native end. Thus, by calling the object for interacting with the page code, the function execution result of the function module can be called back to the native end. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0044] In a specific example, when a result callback message carrying the function execution result of the second function module is sent to the native end by calling an object for interacting with the page code, the function execution result of the second function module is structured to obtain structured data that facilitates the native end to parse the function execution result of the second function module; a result callback message carrying the structured data is generated; and the result callback message carrying the structured data is sent to the native end by calling the object for interacting with the page code. Thus, the structured data carried by the result callback message can facilitate the native end to parse the function execution result of the second function module. Of course, the embodiment of the present application is not limited to this, and a result callback message carrying the function execution result of the second function module can also be directly generated, and then the result callback message carrying the function execution result of the second function module is sent to the native end by calling the object for interacting with the page code. The embodiment of the present application does not impose any limitation on this.
[0045] In a specific example, when the structured data includes a page link address, the structured processing of the function execution result of the second function module includes: generating a page link address based on the function execution result of the second function module. Specifically, the character string in the protocol field and the character string of the function execution result of the second function module are pieced together to generate a page link address in the form of a link address similar to the src field of the iframe tag, or a page link address in the form of a link address similar to window.location.href, or a page link address in the form of a link address similar to window.open, or a page link address in the form of a link address similar to self.location.href. It can be understood that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0046] In a specific example, when the structured data includes JSON data carrying the function execution result of the second function module, the structured processing of the function execution result of the second function module includes: generating the JSON data based on the function execution result of the second function module. Specifically, the function execution result of the second function module is stored in the function execution result field in the JSON data, thereby generating the JSON data carrying the function execution result of the second function module. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0047] Through the communication method between the page end and the native end provided in the embodiment of the present application, the first function call information of the first business trigger event generated on the page end is determined, and by calling the object used to interact with the page code, a function call message carrying the first function call information is sent to the native end to call the first function module indicated by the first function call information in the native end. Compared with other existing methods, by calling the object used to interact with the page code to call the function module indicated by the function call information in the native end, the communication between the page end and the native end is not limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end.
[0048] The communication method between the page end and the native end of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted equipment, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, GearVR), etc.
[0049] Reference Figure 2 , showing a step flow chart of the communication method between the page end and the native end of the second embodiment of the present application.
[0050] This embodiment describes the communication method between the page end and the native end provided in the embodiment of the present application from the perspective of the native end. Specifically, the communication method between the page end and the native end of this embodiment includes the following steps:
[0051] In step S201, a function call message is received which is sent by the page end by calling an object for interacting with the page code.
[0052] In an embodiment of the present application, the object for interacting with the page code includes a console function. When the page end sends a function call message carrying the first function call information to the native end by calling the console function, the native end uses a native method to receive the function call message sent by the page end. For example, when the page end sends a function call message carrying the first function call information to the native end by calling the console.log() function, the console.info() function, the console.error() function, or the console.warn() function, the native end uses a related native method (such as the onConsoleMessage method) to receive the function call message sent by the page end. It can be seen that the call of the console function of the page end is executed by the system where the application is located (for example, the Android system, or the IOS system) to the native method corresponding to the native end. It can be understood that the above description is only exemplary, and the embodiment of the present application does not make any limitation to this.
[0053] In step S202, the function calling message is parsed to obtain first function calling information carried by the function calling message.
[0054] In an embodiment of the present application, when the function call message directly carries the first function call information, the native end directly parses the function call message to obtain the first function call information carried by the function call message. When the function call message carries a page link address, the native end parses the page link address according to a preset rule to obtain the first function call information carried by the function call message. Among them, the preset rule may include a scheme protocol rule. Specifically, the scheme protocol defines that the beginning of the content of the page link address is jsbridge: / / , then the page link address whose content begins with jsbridge: / / will be parsed, and if it is defined as abs: / / , it is also possible, as long as the page end and the native end negotiate the beginning of the content of the link address. In other words, if it is detected that the beginning of the content of the page link address carried by the function call message meets the beginning of the content of the link address specified by the scheme protocol, the page link address will be parsed. After detecting that the page link address carried by the function call message meets the preset rule, the native end parses the content of the page link address carried by the function call message to obtain the first function call information carried by the function call message. When the function call message carries json data, the native end parses the json data according to the fields in the json data to obtain the first function call information carried by the function call message. It is understandable that the above description is only exemplary and the embodiments of the present application do not impose any limitation on this.
[0055] In step S203, the first function module indicated by the first function calling information is called.
[0056] In some optional embodiments, when calling the first function module indicated by the first function call information, the first function module indicated by the first function call information is reflected and called. Thus, the function module indicated by the function call information is more flexible to use by reflection. It can be understood that the above description is only exemplary, and the embodiments of the present application do not make any limitation to this.
[0057] In step S204, the function execution result of the first function module is called back to the page end.
[0058] In some optional embodiments, when the function execution result of the first function module is called back to the page end, the function execution result of the first function module is transmitted to the page end by means of script code injection. Among them, the script code injection method can be understood as the native end calling the function module in the page end by loading a script code, for example, loadurl("javascript:abs()") calls the function module whose function module name is abs. Thereby, the function execution result of the function module can be transmitted to the page end by means of script code injection. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0059] In some optional embodiments, the method further includes: receiving a result callback message sent by the page end by calling the object for interacting with the page code; parsing the result callback message to obtain the function execution result of the second function module carried by the result callback message; and calling back the received function execution result to the business method corresponding to the business trigger event through the function callback interface of the business trigger event corresponding to the second function module. Among them, the specific implementation of receiving the result callback message sent by the page end by calling the object for interacting with the page code is similar to the specific implementation of receiving the function call message sent by the page end by calling the object for interacting with the page code, which is not repeated here. The specific implementation of parsing the result callback message is similar to the specific implementation of parsing the function call message, which is not repeated here. Thus, by calling back the received function execution result through the function callback interface of the business trigger event corresponding to the second function module, the business method corresponding to the business trigger event generated by the native end can obtain the corresponding function execution result. It can be understood that the above description is only exemplary, and the embodiment of the present application does not make any limitation to this.
[0060] In a specific example, the native end calls back the received function execution result of the second function module by executing the function callback interface of the service triggering event corresponding to the second function module. It can be understood that the above description is only exemplary and the embodiment of the present application does not make any limitation to this.
[0061] Through the communication method between the page end and the native end provided in the embodiment of the present application, the function call message sent by the page end through calling the object used to interact with the page code is received, and the function call message is parsed to obtain the first function call information carried by the function call message, and then the first function module indicated by the first function call information is called, and then the function execution result of the first function module is called back to the page end. Compared with other existing methods, by calling the object used to interact with the page code to call the function module indicated by the function call information in the native end, the communication between the page end and the native end is not limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end.
[0062] The communication method between the page end and the native end of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted equipment, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, GearVR), etc.
[0063] Reference Figure 3 , showing a step flow chart of the communication method between the page end and the native end of Example 3 of the present application.
[0064] This embodiment describes the communication method between the page end and the native end provided in the embodiment of the present application from the perspective of interaction between the page end and the native end. Specifically, the communication method between the page end and the native end of this embodiment includes the following steps:
[0065] In step S301, first function call information of a first service triggering event generated on the page end is determined.
[0066] Since the specific implementation of step S301 is similar to the specific implementation of step S101 above, it will not be described again here.
[0067] In step S302, a function call message carrying the first function call information is sent to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end.
[0068] Since the specific implementation of step S302 is similar to the specific implementation of step S102 described above, it will not be repeated here.
[0069] In step S303, a function call message is received which is sent by the page end by calling an object for interacting with the page code.
[0070] Since the specific implementation of step S303 is similar to the specific implementation of step S201 above, it will not be repeated here.
[0071] In step S304, the function calling message is parsed to obtain first function calling information carried by the function calling message.
[0072] Since the specific implementation of step S304 is similar to the specific implementation of step S202, it will not be described again here.
[0073] In step S305, the first function module indicated by the first function calling information is called.
[0074] Since the specific implementation of step S305 is similar to the specific implementation of step S203, it will not be described again here.
[0075] In step S306, the function execution result of the first function module is called back to the page end.
[0076] Since the specific implementation of step S306 is similar to the specific implementation of step S204, it will not be described again here.
[0077] Through the communication method between the page end and the native end provided in the embodiment of the present application, the page end determines the first function call information of the first business trigger event generated on the page end, and sends a function call message carrying the first function call information to the native end by calling the object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end; the native end receives the function call message sent by the page end by calling the object used to interact with the page code, and parses the function call message to obtain the first function call information carried by the function call message, and then calls the first function module indicated by the first function call information, and then calls back the function execution result of the first function module to the page end. Compared with other existing methods, by calling the object used to interact with the page code to call the function module indicated by the function call information in the native end, the communication between the page end and the native end is not limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end.
[0078] The communication method between the page end and the native end of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted equipment, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, GearVR), etc.
[0079] Reference Figure 4 , showing a step flow chart of the communication method between the page end and the native end of Example 4 of the present application.
[0080] This embodiment describes the communication method between the page end and the native end provided in the embodiment of the present application from the perspective of interaction between the page end and the native end. Specifically, the communication method between the page end and the native end of this embodiment includes the following steps:
[0081] In step S401, second function call information of a second service triggering event generated at the native end is determined.
[0082] In the embodiment of the present application, the second service triggering event may be a user's click operation in the native page, a call to an existing function in the page end, the native page needs to notify the H5 page that a certain control needs to update the style, or the native page asks the H5 page to refresh part of the content, etc. The second function call information includes at least one of the following: the name of the second function module, the parameters of the second function module, and the function callback interface for calling back the function execution result of the second function module. Among them, the second function module may be a function module for obtaining H5 page information, etc. It can be understood that the above description is only exemplary, and the embodiment of the present application does not impose any limitation on this.
[0083] In some optional embodiments, when determining the second function call information of the second business trigger event generated at the native end, the second function call information of the second business trigger event is transmitted to the native end through the business method corresponding to the second business trigger event, so as to determine the second function call information of the second business trigger event generated at the native end. Specifically, under the triggering of the second business trigger event, the second function call information of the second business trigger event is transmitted to the preset function of the page end by calling the business method corresponding to the second business trigger event, so as to determine the second function call information of the second business trigger event generated at the native end. It can be understood that the above description is only exemplary, and the embodiments of the present application do not impose any limitation on this.
[0084] In step S402, the second function calling information is transmitted to the page end, so as to call the second function module indicated by the second function calling information in the page end.
[0085] In some optional embodiments, when the second function call information is passed to the page end, the second function call information is passed to the page end by means of script code injection. Thereby, the native end passes the second function call information of the second business triggering event to the page end by means of script code injection, without being limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end. Among them, the method of script code injection is similar to the above description and will not be repeated here. It can be understood that the above description is only exemplary and the embodiments of the present application do not make any limitation to this.
[0086] In step S403, second function call information of a second service triggering event transmitted from the native end is received.
[0087] Since the specific implementation of step S403 is similar to the specific implementation described above, it will not be repeated here.
[0088] In step S404, the second function module indicated by the second function calling information is called.
[0089] Since the specific implementation of step S404 is similar to the specific implementation described above, it will not be repeated here.
[0090] In step S405, the function execution result of the second function module is called back to the native end.
[0091] Since the specific implementation of step S405 is similar to the specific implementation described above, it will not be repeated here.
[0092] Through the communication method between the page end and the native end provided in the embodiment of the present application, the native end determines the second function call information of the second business trigger event generated on the native end, and transmits the second function call information to the page end, so as to call the second function module indicated by the second function call information in the page end. The page end receives the second function call information of the second business trigger event transmitted by the native end, and calls the second function module indicated by the second function call information, and then calls back the function execution result of the second function module to the native end. Compared with other existing methods, the function module indicated by the function call information is called in the page end, and the communication between the page end and the native end is not limited by the version or platform of the native end, thereby facilitating the communication between the page end and the native end.
[0093] The communication method between the page end and the native end of this embodiment can be executed by any appropriate device with data processing capabilities, including but not limited to: cameras, terminals, mobile terminals, PCs, servers, vehicle-mounted equipment, entertainment equipment, advertising equipment, personal digital assistants (PDAs), tablet computers, laptop computers, handheld game consoles, smart glasses, smart watches, wearable devices, virtual display devices or display enhancement devices (such as Google Glass, Oculus Rift, Hololens, GearVR), etc.
[0094] Reference Figure 5 , showing a schematic diagram of the structure of the communication device between the page end and the native end in Example 5 of the present application.
[0095] The communication device between the page end and the native end of this embodiment includes: a determination module 501, used to determine the first function call information of the first business trigger event generated on the page end; a sending module 502, used to send a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end.
[0096] The communication device between the page end and the native end of this embodiment is used to implement the corresponding communication methods between the page end and the native end in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0097] Reference Figure 6 , showing a structural diagram of the communication device between the page end and the native end in Example 6 of the present application.
[0098] The communication device between the page end and the native end of this embodiment includes: a determination module 604, used to determine the first function call information of the first business trigger event generated on the page end; a sending module 605, used to send a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end.
[0099] Optionally, the determination module 604 includes: an input module 6041, which is used to input the first function call information of the first business trigger event to the page end through the business function corresponding to the first business trigger event, so as to determine the first function call information of the first business trigger event generated at the page end.
[0100] Optionally, the device also includes: a first receiving module 606, used to receive the function execution result of the first function module transmitted back by the native end; a first callback module 607, used to callback the received function execution result to the business function corresponding to the first business trigger event through the function callback function of the first business trigger event.
[0101] Optionally, the device also includes: a second receiving module 601, used to receive second function call information of a second business trigger event transmitted from the native end; a calling module 602, used to call a second function module indicated by the second function call information; and a second callback module 603, used to call back the function execution result of the second function module to the native end.
[0102] Optionally, the calling module 602 is specifically used to call the second function module indicated by the second function calling information through a function in the script code that is used to calculate a string and execute the script code corresponding to the string.
[0103] Optionally, the second callback module 603 is specifically used to: send a result callback message carrying the function execution result of the second function module to the native end by calling the object used to interact with the page code, so as to call back the function execution result of the second function module to the native end.
[0104] Optionally, the object for interacting with the page code includes a console function.
[0105] Optionally, the first function call information includes at least one of the following: a name of the first function module, parameters of the first function module, and a function callback function for calling back a function execution result of the first function module.
[0106] The communication device between the page end and the native end of this embodiment is used to implement the corresponding communication methods between the page end and the native end in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0107] Reference Figure 7 , showing a structural schematic diagram of the communication device between the page end and the native end in Example 7 of the present application.
[0108] The communication device between the page end and the native end of this embodiment includes: a first receiving module 701, which is used to receive a function call message sent by the page end by calling an object used to interact with the page code; a first parsing module 702, which is used to parse the function call message to obtain the first function call information carried by the function call message; a calling module 703, which is used to call the first function module indicated by the first function call information; and a first callback module 704, which is used to call back the function execution result of the first function module to the page end.
[0109] The communication device between the page end and the native end of this embodiment is used to implement the corresponding communication methods between the page end and the native end in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0110] Reference Figure 8 , showing a schematic diagram of the structure of the communication device between the page end and the native end in Example 8 of the present application.
[0111] The communication device between the page end and the native end of this embodiment includes: a first receiving module 801, used to receive a function call message sent by the page end by calling an object used to interact with the page code; a first parsing module 802, used to parse the function call message to obtain the first function call information carried by the function call message; a calling module 803, used to call the first function module indicated by the first function call information; a first callback module 804, used to call back the function execution result of the first function module to the page end.
[0112] Optionally, the calling module 803 is specifically used to: reflectively call the first function module indicated by the first function calling information.
[0113] Optionally, the first callback module 804 is specifically used to: transmit the function execution result of the first function module to the page end by means of script code injection.
[0114] Optionally, the device also includes: a second receiving module 805, used to receive a result callback message sent by the page end by calling the object used to interact with the page code; a second parsing module 806, used to parse the result callback message to obtain the function execution result of the second function module carried by the result callback message; a second callback module 807, used to callback the received function execution result to the business method corresponding to the business trigger event through the function callback interface of the business trigger event corresponding to the second function module.
[0115] The communication device between the page end and the native end of this embodiment is used to implement the corresponding communication methods between the page end and the native end in the aforementioned multiple method embodiments, and has the beneficial effects of the corresponding method embodiments, which will not be repeated here.
[0116] Fig. 9 This is a schematic diagram of the structure of an electronic device in Embodiment 9 of the present application; the electronic device may include:
[0117] One or more processors 901;
[0118] The computer readable medium 902 may be configured to store one or more programs,
[0119] When the one or more programs are executed by the one or more processors, the one or more processors implement the communication method between the page end and the native end as described in the above-mentioned embodiment one, embodiment two, embodiment three or embodiment four.
[0120] Fig.10 The hardware structure of the electronic device in the tenth embodiment of the present application; Fig.10 As shown, the hardware structure of the electronic device may include: a processor 1001, a communication interface 1002, a computer readable medium 1003 and a communication bus 1004;
[0121] The processor 1001, the communication interface 1002, and the computer-readable medium 1003 communicate with each other via a communication bus 1004;
[0122] Optionally, the communication interface 1002 may be an interface of a communication module, such as an interface of a GSM module;
[0123] The processor 1001 can be specifically configured to: determine the first function call information of the first business trigger event generated on the page end; send a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end. In addition, it can also be configured to: receive a function call message sent by the page end by calling an object used to interact with the page code; parse the function call message to obtain the first function call information carried by the function call message; call the first function module indicated by the first function call information; and call back the function execution result of the first function module to the page end.
[0124] The processor 1001 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0125] The computer readable medium 1003 can be, but is not limited to, a random access memory medium (RAM), a read-only memory medium (ROM), a programmable read-only memory medium (PROM), an erasable read-only memory medium (EPROM), an electrically erasable read-only memory medium (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
[0126] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code configured to execute the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through a communication part, and / or installed from a removable medium. When the computer program is executed by a central processing unit (CPU), the above functions defined in the method of the present application are executed. It should be noted that the computer-readable medium described in the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable medium can be, for example, but not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access storage medium (RAM), a read-only storage medium (ROM), an erasable programmable read-only storage medium (EPROM or flash memory), an optical fiber, a portable compact disk read-only storage medium (CD-ROM), an optical storage medium, a magnetic storage medium, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, an apparatus or a device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program configured to be used by or in combination with an instruction execution system, an apparatus or a device. The program code embodied on the computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
[0127] Computer program code configured to perform the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0128] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment, or a part of a code, and the module, program segment, or a part of the code contains one or more executable instructions configured to implement the specified logical function. There are specific sequential relationships in the above-mentioned specific embodiments, but these sequential relationships are only exemplary. When the specific implementation is implemented, these steps may be less, more, or the execution order may be adjusted. That is, in some implementations as replacements, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0129] The modules involved in the embodiments of the present application may be implemented by software or hardware. The modules described may also be provided in a processor, for example, may be described as: a processor includes a determination module and a sending module. The names of these modules do not, in some cases, constitute limitations on the modules themselves, for example, the determination module may also be described as "a module for determining the first function call information of the first service trigger event generated at the page end".
[0130] As another aspect, the present application also provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the communication method between the page end and the native end as described in the above-mentioned embodiment one, embodiment two, embodiment three or embodiment four.
[0131] As another aspect, the present application also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by the device, the device: determines the first function call information of the first business trigger event generated at the page end; sends a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call the first function module indicated by the first function call information in the native end. In addition, the device is also configured to: receive a function call message sent by the page end by calling an object used to interact with the page code; parse the function call message to obtain the first function call information carried by the function call message; call the first function module indicated by the first function call information; and call back the function execution result of the first function module to the page end.
[0132] The expressions "first", "second", "the first" or "the second" used in various embodiments of the present disclosure may modify various components regardless of order and / or importance, but these expressions do not limit the corresponding components. The above expressions are only configured for the purpose of distinguishing an element from other elements. For example, a first user device and a second user device represent different user devices, although both are user devices. For example, a first element may be referred to as a second element, and similarly, a second element may be referred to as a first element without departing from the scope of the present disclosure.
[0133] When one element (e.g., a first element) is referred to as being "(operably or communicatively) coupled" or "(operably or communicatively) coupled to" or "connected to" another element (e.g., a second element), it is understood that the one element is directly connected to the other element or the one element is indirectly connected to the other element via yet another element (e.g., a third element). Conversely, it is understood that when an element (e.g., a first element) is referred to as being "directly connected" or "directly coupled" to another element (the second element), no element (e.g., a third element) is interposed between the two.
[0134] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.
Claims
1. A communication method between a page end and a native end, characterized in that: The method comprises: Determine first function call information of a first service triggering event generated on the page end; Sending a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, so as to call a first function module indicated by the first function call information in the native end, wherein the object used to interact with the page code includes a console function; Receiving the function execution result of the first function module returned by the native end through script code injection; The sending of the function call message carrying the first function call information to the native end by calling the object used to interact with the page code includes: performing structured processing on the first function call information to obtain structured data that facilitates the native end to parse the first function call information; generating a function call message carrying the structured data; sending the function call message carrying the structured data to the native end by calling the object used to interact with the page code; When the structured data includes a page link address, the structured processing of the first function call information includes: generating a Said Page link address.
2. The method according to claim 1, characterized in that The determining of the first function call information of the first service triggering event generated at the page end includes: The first function call information of the first service trigger event is transmitted to the page end through the service function corresponding to the first service trigger event, so as to determine the first function call information of the first service trigger event generated at the page end.
3. The method according to claim 1, characterized in that: The method further comprises: Receiving a function execution result of the first function module returned by the native end; Through the function callback function of the first business triggering event, the received function execution result is called back to the business function corresponding to the first business triggering event.
4. The method according to claim 1, characterized in that: The method further comprises: Receiving second function call information of a second service triggering event transmitted by the native end; Calling the second function module indicated by the second function calling information; The function execution result of the second function module is called back to the native end.
5. The method according to claim 4, characterized in that The calling of the second function module indicated by the second function calling information includes: The second function module indicated by the second function calling information is called through a function in the script code that is used to calculate a character string and execute the script code corresponding to the character string.
6. The method according to claim 4, characterized in that The calling back the function execution result of the second function module to the native end includes: By calling the object for interacting with the page code, a result callback message carrying the function execution result of the second function module is sent to the native end, so as to call back the function execution result of the second function module to the native end.
7. The method according to any one of claims 1 to 6, characterized in that: The first function call information includes at least one of the following: The name of the first functional module, the parameters of the first functional module, and a function callback function for calling back the function execution result of the first functional module.
8. A communication method between a page end and a native end, characterized in that: The method comprises: Receiving a function call message sent by the page end by calling an object for interacting with the page code, wherein the object for interacting with the page code includes a console function; Parsing the function call message, and when the function call message carries a page link address, parsing the page link address according to a preset rule to obtain first function call information carried by the function call message; calling a first function module indicated by the first function call information; By means of script code injection, the function execution result of the first function module is called back to the page end; Among them, the function call message is generated by structuring the first function call information through the page end, and the function call message carries structured data. When the structured data includes the page link address, the structured processing of the first function call information includes: generating the page link address based on the name and parameters of the first function module in the first function call information.
9. The method according to claim 8, characterized in that The calling of the first function module indicated by the first function calling information includes: The first function module indicated by the first function call information is reflected and called.
10. The method according to claim 8, characterized in that The method further comprises: Receiving a result callback message sent by the page end by calling the object used to interact with the page code; Parsing the result callback message to obtain the function execution result of the second function module carried in the result callback message; Through the function callback interface of the business triggering event corresponding to the second function module, the received function execution result is called back to the business method corresponding to the business triggering event.
11. A communication device between a page end and a native end, characterized in that: The device comprises: A determination module, used to determine first function call information of a first service triggering event generated on the page end; a sending module, configured to send a function call message carrying the first function call information to the native end by calling an object for interacting with the page code, so as to call a first function module indicated by the first function call information in the native end, wherein the object for interacting with the page code includes a console function; A first callback module, used for transferring the function execution result of the first function module to the page end by means of script code injection; The sending module sends a function call message carrying the first function call information to the native end by calling an object used to interact with the page code, including: structuring the first function call information to obtain structured data that is convenient for the native end to parse the first function call information; generating a function call message carrying the structured data; sending the function call message carrying the structured data to the native end by calling the object used to interact with the page code; when the structured data includes a page link address, structuring the first function call information, including: generating the page link address based on the name and parameters of the first function module in the first function call information.
12. The device according to claim 11, characterized in that The determining module comprises: The input module is used to input the first function call information of the first business trigger event to the page end through the business function corresponding to the first business trigger event, so as to determine the first function call information of the first business trigger event generated at the page end.
13. The device according to claim 11, characterized in that The device also includes: A first receiving module, used for receiving the function execution result of the first function module returned by the native end; The first callback module is used to call back the received function execution result to the business function corresponding to the first business triggering event through the function callback function of the first business triggering event.
14. The device according to claim 11, characterized in that The device also includes: A second receiving module, used for receiving second function call information of a second service triggering event transmitted by the native end; A calling module, used for calling the second function module indicated by the second function calling information; The second callback module is used to call back the function execution result of the second function module to the native end.
15. The device according to claim 14, characterized in that The calling module is specifically used for: The second function module indicated by the second function calling information is called through a function in the script code that is used to calculate a character string and execute the script code corresponding to the character string.
16. The device according to claim 14, characterized in that The second callback module is specifically used for: By calling the object for interacting with the page code, a result callback message carrying the function execution result of the second function module is sent to the native end, so as to call back the function execution result of the second function module to the native end.
17. The device according to any one of claims 11 to 16, characterized in that The first function call information includes at least one of the following: The name of the first functional module, the parameters of the first functional module, and a function callback function for calling back the function execution result of the first functional module.
18. A communication device between a page end and a native end, characterized in that: The device comprises: A first receiving module is used to receive a function call message sent by the page end by calling an object used to interact with the page code, wherein the object used to interact with the page code includes a console function; A first parsing module is used to parse the function call message, and when the function call message carries a page link address, parse the page link address according to a preset rule to obtain first function call information carried by the function call message; A calling module, used for calling the first function module indicated by the first function calling information; A first callback module, used for calling back the function execution result of the first function module to the page end by means of script code injection; Among them, the function call message is generated by structuring the first function call information through the page end, and the function call message carries structured data. When the structured data includes the page link address, the structured processing of the first function call information includes: generating the page link address based on the name and parameters of the first function module in the first function call information.
19. The device according to claim 18, characterized in that The calling module is specifically used for: The first function module indicated by the first function call information is reflected and called.
20. The device according to claim 18, characterized in that The device also includes: A second receiving module is used to receive a result callback message sent by the page end by calling the object used to interact with the page code; A second parsing module is used to parse the result callback message to obtain the function execution result of the second function module carried in the result callback message; The second callback module is used to call back the received function execution result to the business method corresponding to the business triggering event through the function callback interface of the business triggering event corresponding to the second function module.
21. An electronic device, comprising: one or more processors; A computer readable medium configured to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the communication method between the page end and the native end as described in any one of claims 1 to 7, or implement the communication method between the page end and the native end as described in any one of claims 8 to 10.
22. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, it implements the communication method between the page end and the native end as described in any one of claims 1 to 7, or implements the communication method between the page end and the native end as described in any one of claims 8 to 10.
