WO2019153492A1 - Method for realizing web and native function interaction, and electronic apparatus and readable storage medium - Google Patents

Method for realizing web and native function interaction, and electronic apparatus and readable storage medium Download PDF

Info

Publication number
WO2019153492A1
WO2019153492A1 PCT/CN2018/083077 CN2018083077W WO2019153492A1 WO 2019153492 A1 WO2019153492 A1 WO 2019153492A1 CN 2018083077 W CN2018083077 W CN 2018083077W WO 2019153492 A1 WO2019153492 A1 WO 2019153492A1
Authority
WO
WIPO (PCT)
Prior art keywords
address
interface
call
webpage
web
Prior art date
Application number
PCT/CN2018/083077
Other languages
French (fr)
Chinese (zh)
Inventor
杨帅
Original Assignee
平安科技(深圳)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2019153492A1 publication Critical patent/WO2019153492A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/76Adapting program code to run in a different environment; Porting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/541Interprogram communication via adapters, e.g. between incompatible applications
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/448Execution paradigms, e.g. implementations of programming paradigms
    • G06F9/4482Procedural
    • G06F9/4484Executing subprograms

Definitions

  • the present application relates to the field of computer technology, and relates to a method, an electronic device, and a readable storage medium for implementing interaction between a web and a native function.
  • the mobile APP that is, the application software on the mobile terminal
  • the security restrictions and the communication method standards are different, and then the native function modules developed by sdk are in accordance with the conventions of the respective iOS/Android systems.
  • the method is called by the outside world or invoked by itself. Too many methods are not standardized and are not easy to maintain.
  • the technical problem to be solved by the present application is to overcome the shortcomings of the prior art that the App and the Web require two sets of calling modes to invoke the same native function, and propose a method, an electronic device and a readable storage medium for realizing interaction between the web and the native function.
  • the App and the Web use the same native function in a set call mode.
  • a method of implementing web interaction with native functions including page calls and interface calls, including the following steps:
  • S1 receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
  • step S2 determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
  • An electronic device includes a memory and a processor, wherein the memory stores a system executable by the processor to implement interaction between a web and a native function, and the system for implementing interaction between the web and the native function comprises:
  • the receiving parsing module is configured to receive a webpage address sent by the web browser, and parse the webpage address to generate an object or an API interface according to a preset parsing rule;
  • a determining module configured to determine whether a parameter value is included in the webpage address
  • a value passing module configured to pass the parameter value included in the webpage address to the generated object or API interface
  • a webpage generating module for generating a corresponding webpage.
  • a computer readable storage medium wherein the computer readable storage medium stores a system for implementing interaction between a web and a native function, and the system for implementing interaction between the web and the native function is executable by at least one processor, To achieve the following steps:
  • S1 receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
  • step S2 determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
  • the positive progress of the application is that the present application converts the webpage address into a corresponding object or API interface by using a preset parsing rule, so that the App and the web can use the same set of calling standards to call the same native function, simplifying the calling method. Easy to maintain, extending the range of native features of the web call.
  • FIG. 1 is a schematic diagram showing the hardware architecture of an embodiment of an electronic device of the present application.
  • FIG. 2 is a schematic diagram of a program module of a first embodiment of a system for implementing web and native function interaction in an electronic device of the present application;
  • FIG. 3 is a schematic diagram of a program module of a second embodiment of a system for implementing web and native function interaction in an electronic device of the present application;
  • Embodiment 4 is a flowchart of Embodiment 1 of a method for implementing interaction between a web and a native function according to the present application;
  • FIG. 5 is a flow chart showing the registration of a page calling function in the second embodiment of the method for implementing interaction between a web and a native function
  • FIG. 6 is a flowchart of address translation when a page is invoked in Embodiment 3 of the method for implementing interaction between a web and a native function according to the present application;
  • FIG. 7 is a flowchart of registering an interface call function of a method for implementing interaction between a web and a native function according to the present application.
  • FIG. 8 is a flow chart showing the address translation when the interface is invoked in the fifth embodiment of the method for implementing interaction between the web and the native function.
  • the present application proposes an electronic device.
  • the electronic device 2 is an apparatus capable of automatically performing numerical calculation and/or information processing in accordance with an instruction set or stored in advance.
  • the electronic device 2 can be a smartphone, a tablet, a laptop, a desktop computer, a rack server, a blade server, a tower server, or a rack server (including a stand-alone server, or a server cluster composed of multiple servers).
  • the electronic device 2 includes at least, but not limited to, a memory 21, a processor 22, a network interface 23, and a system 20 that enables web interaction with native functions via a system bus. among them:
  • the memory 21 includes at least one type of computer readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (eg, SD or DX memory, etc.), a random access memory (RAM), Static Random Access Memory (SRAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), Programmable Read Only Memory (PROM), magnetic memory, magnetic disk, optical disk, and the like.
  • the memory 21 may be an internal storage unit of the electronic device 2, such as a hard disk or a memory of the electronic device 2.
  • the memory 21 may also be an external storage device of the electronic device 2, such as a plug-in hard disk equipped on the electronic device 2, a smart memory card (SMC), and a secure digital device. (Secure Digital, SD) card, flash card, etc.
  • the memory 21 can also include both the internal storage unit of the electronic device 2 and its external storage device.
  • the memory 21 is generally used to store an operating system installed in the electronic device 2 and various types of application software, such as the program code of the system 20 that implements the interaction between the web and the native function. Further, the memory 21 can also be used to temporarily store various types of data that have been output or are to be output.
  • the processor 22 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments.
  • the processor 22 is typically used to control the overall operation of the electronic device 2, such as performing control and processing associated with data interaction or communication with the electronic device 2.
  • the processor 22 is configured to run program code or process data stored in the memory 21, such as running the system 20 for implementing web and native function interaction.
  • the network interface 23 may comprise a wireless network interface or a wired network interface, which is typically used to establish a communication connection between the electronic device 2 and other electronic devices.
  • the network interface 23 is configured to connect the electronic device 2 to an external terminal through a network, establish a data transmission channel, a communication connection, and the like between the electronic device 2 and an external terminal.
  • the network may be an intranet, an Internet, a Global System of Mobile communication (GSM), a Wideband Code Division Multiple Access (WCDMA), a 4G network, or a 5G network.
  • Wireless or wired networks such as network, Bluetooth, Wi-Fi, etc.
  • FIG. 1 only shows the electronic device 2 with the components 21-23, but it should be understood that not all illustrated components are required to be implemented, and more or fewer components may be implemented instead.
  • system 20 that interacts with the native function stored in the memory 21 can be divided into one or more program modules, and the one or more program modules are stored in the memory 21, and It can be performed by one or more processors (the processor 22 in this embodiment) to complete the application.
  • FIG. 2 shows a schematic diagram of a program module of the first embodiment of the system 20 for implementing interaction between a web and a native function.
  • the system 20 for implementing web interaction with a native function may be partitioned into a receiving parsing module. 201.
  • the program module referred to in the present application refers to a series of computer program instruction segments capable of performing a specific function. The following description will specifically describe the specific functions of the program modules 201-204.
  • the receiving parsing module 201 is configured to receive a webpage address sent by a web browser, and parse the webpage address into an object or an API interface according to a preset parsing rule;
  • the preset parsing rule refers to a correspondence table corresponding to an object or an API interface, and after receiving the webpage address, the corresponding object or API interface can be obtained from the corresponding table.
  • this is not limited to the form of the corresponding table.
  • the determining module 202 is configured to determine whether a parameter value is included in a webpage address
  • the value passing module 203 is configured to pass the parameter value included in the webpage address to the generated object or API interface;
  • the webpage generating module 204 is configured to generate a corresponding webpage.
  • the system is applicable to the direct invocation of the page, and is also applicable to the interface call, and then opens the corresponding page through the interface, where the page and the interface are pre-packaged.
  • This system is equivalent to adding an intermediate layer between the web browser and the called page or interface, which is mainly used for address conversion.
  • the operator inputs the webpage address in the address bar of the web browser, and the web browser sends the webpage address to the system, and the system parses the webpage address according to the preset parsing rule to generate an object or an API interface.
  • the webpage having the corresponding function is directly produced, for example, the chat page is directly opened, and the page is fixed; if the API interface is generated, the relative page is opened by the interface, for example, The interface opens its corresponding weather forecast page, which is changeable.
  • FIG. 3 shows a schematic diagram of a program module of the second embodiment of the system 20 for implementing interaction between the web and the native function.
  • the system 20 for implementing web interaction with the native function can also be divided into receiving.
  • the modules 201-204 are the same as the first embodiment, and are not described herein again.
  • the encapsulating module 205 is configured to encapsulate a page corresponding to the page call into an object, and encapsulate the interface corresponding to the interface call as an API interface;
  • the call address generation module 206 is configured to generate an object call address corresponding to the object according to a preset protocol, where the object call address includes an instruction type, a class, and a default parameter value, and generates and coordinates according to a preset protocol.
  • the corresponding interface call address of the API interface where the interface call address includes an instruction type, a method, and a default parameter value;
  • the protocol refers to a rule for converting a packaged object or an API interface into a corresponding object call address or an interface call address; taking an object as an example, the object call address includes an instruction type, a class, and a default parameter value, and the encapsulated object First convert to a string, the string includes the instruction type and class, set the instruction type and the starting position of the string of the class, and add the string of the specific position to the corresponding position in the object call address by Generate a specific object call address.
  • the address conversion module 207 is configured to convert the object call address and the interface call address into a corresponding webpage address according to a preset URL conversion rule
  • the preset URL conversion rule refers to a correspondence table corresponding to a preset call address and a webpage address. After receiving the call address, the corresponding webpage address is obtained from the correspondence table. Of course, this is not limited to the form of the corresponding table.
  • the mapping module 208 is configured to map a class included in the object call address to a webpage address converted by the object call address, form a class-web address mapping relationship, and save the mapping relationship to a class-page address. Mapping the table, and mapping the method included in the interface call address to the webpage address converted by the interface call address, and saving to the memory.
  • chat page is first packaged into the object ChatVideoViewController and loaded into the system.
  • step 4 is different.
  • the method is mapped to the web page address and saved directly to the system memory. There is no mapping table.
  • the present application proposes a method for implementing interaction between a web and a native function, where the native function may be a page calling function or an interface calling function.
  • the method for implementing interaction between the web and the native function includes the following steps:
  • S1 receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
  • step S2 determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
  • the parameter value in the webpage address is utf-8, and the parameter value is transmitted to the generated object to generate a corresponding function (that is, the parameter value replaces the default parameter value), that is, the corresponding page is opened, if If there is no parameter value, the default parameter value is directly obtained to generate the corresponding function, and there is no step of passing the parameter.
  • the interface call method (hereinafter referred to as the method) is generated in step 1.
  • the method directly calls an interface, and then the corresponding page needs to be opened through the interface.
  • the page can be dynamic. .
  • step S1 when the native function is called by the page, the following steps are also included before the step S1:
  • S011 encapsulating the page corresponding to the page call into an object, and generating a corresponding object calling address according to a preset protocol, where the object calling address includes an instruction type, a class, and a default parameter value;
  • S013 Mapping a class included in the object call address to a webpage address converted by the object call address, forming a class-web address mapping relationship, and saving the mapping relationship to the class-web address mapping table.
  • the webpage address includes a parameter name, and the parameter name corresponds to a class included in the object; the parameter name is followed by a parameter value or no parameter value; in the step S2, by identifying the webpage address
  • the parameter name is used to get the parameter value following the parameter name.
  • chat page The following is a specific example of registration on the chat page:
  • chat page Before the website is converted, the chat page is first encapsulated, and the chat page is encapsulated into the object ChatVideoViewController, and the corresponding object call address local://view/VideoChat is generated according to a preset protocol.
  • the interface is registered, it is encapsulated as an API interface.
  • step S1 specifically includes the following sub-steps:
  • the method further includes:
  • S021. Encapsulate an interface corresponding to the interface call as an API interface, and generate a corresponding interface call address according to a preset protocol, where the interface call address includes an instruction type, a method, and a default parameter value;
  • S023 Map a method included in the interface call address to a webpage address converted by the interface call address, and save the file to an internal memory.
  • the webpage address includes a parameter name, and the parameter name corresponds to a method included in the API interface; the parameter name is followed by a parameter value or no parameter value; in the step S2, by identifying the webpage address The parameter name is used to get the parameter value following the parameter name. Similar to page calls.
  • the difference between the interface call and the page call in this embodiment is that the instruction in the interface call address is a method, and the instruction in the object call address is a class; the interface calls the address and the method maps to the address conversion by the interface call.
  • the resulting web page address is saved directly to memory and there is no mapping table as described in the web page call.
  • step S1 includes the following sub-steps:
  • the difference between this embodiment and the third embodiment is that the API interface finally found needs to be further removed from the interface through the interface.
  • the advantage is that the page opened through the interface can be a dynamic page; and the direct solution found in the third embodiment is directly
  • the page can be opened as long as the page is open, but the page is usually fixed.
  • the present application is a computer readable storage medium having stored therein a system 20 that implements web-to-native function interaction, the system 20 that implements web interaction with native functions can be executed by one or more processors In the above, the method or the operation of the electronic device that implements the interaction between the web and the native function is implemented.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

Disclosed are a method for realizing web and native function interaction, and an electronic apparatus and a readable storage medium, belonging to the technical field of computers. The method for realizing web and native function interaction, with a native function comprising page calling and interface calling, comprises the following steps: S1, receiving a webpage address sent by a Web browser, and according to a pre-set parsing rule, parsing the webpage address to generate an object or API interface; S2, determining whether the webpage address includes a parameter value, and if so, executing step S3, otherwise, executing step S4; S3, transmitting the parameter value to the object or API interface, so as to generate a corresponding page; and S4, acquiring a default parameter value of the object or API interface, so as to generate the corresponding page. In the present application, a webpage address is converted into a corresponding object or API interface by means of a pre-set parsing rule, such that an App and Web can use the same set of calling standards to call the same native function, simplifying a calling mode and facilitating maintenance.

Description

实现web与原生功能交互的方法、电子装置及可读存储介质Method, electronic device and readable storage medium for realizing interaction between web and native functions
本申请申明享有2018年2月7日递交的申请号为201810127625.2、名称为“实现web与原生功能交互的方法、电子装置及可读存储介质”的中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。The present application claims priority to Chinese Patent Application No. 201101127625.2, entitled "Implementation of Web and Native Functional Interaction, Electronic Devices, and Readable Storage Media", filed on February 7, 2018, the priority of the Chinese Patent Application The entire content is incorporated herein by reference.
技术领域Technical field
本申请涉及计算机技术领域,涉及一种实现web与原生功能交互的方法、电子装置及可读存储介质。The present application relates to the field of computer technology, and relates to a method, an electronic device, and a readable storage medium for implementing interaction between a web and a native function.
背景技术Background technique
由于移动APP(即移动终端上的应用软件)是要区分android、ios等设备的,因此安全限制和通讯方法标准均不一样,进而通过sdk开发的各原生功能模块按各自iOS/Android系统的常规方法被外界调用或自身调用,方法太多不规范不便于维护。Since the mobile APP (that is, the application software on the mobile terminal) is to distinguish the devices such as android and ios, the security restrictions and the communication method standards are different, and then the native function modules developed by sdk are in accordance with the conventions of the respective iOS/Android systems. The method is called by the outside world or invoked by itself. Too many methods are not standardized and are not easy to maintain.
除此以外,外界App和web调用同一原生功能模块需要使用两种方式,造成冗余。In addition, the external App and the web call the same native function module need to use two ways, resulting in redundancy.
发明内容Summary of the invention
本申请要解决的技术问题是为了克服现有技术中App和Web需两套调用方式调用同一原生功能的缺点,提出了一种实现web与原生功能交互的方法、电子装置及可读存储介质,通过增加中间层,实现App和Web采用一套调用方式用同一原生功能。The technical problem to be solved by the present application is to overcome the shortcomings of the prior art that the App and the Web require two sets of calling modes to invoke the same native function, and propose a method, an electronic device and a readable storage medium for realizing interaction between the web and the native function. By adding the middle layer, the App and the Web use the same native function in a set call mode.
本申请是通过下述技术方案来解决上述技术问题:The present application solves the above technical problems by the following technical solutions:
一种实现web与原生功能交互的方法,所述原生功能包括页面调用和接 口调用,包括如下步骤:A method of implementing web interaction with native functions, the native functions including page calls and interface calls, including the following steps:
S1、接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;S1: receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
S2、判断网页地址中是否包含有参数值,若是执行步骤S3,若否执行步骤S4;S2, determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
S3、将所述参数值传给所述对象或API接口,生成对应的页面;S3. Pass the parameter value to the object or the API interface to generate a corresponding page.
S4、获取所述对象或API接口的默认参数值,生成对应的页面。S4. Obtain a default parameter value of the object or the API interface, and generate a corresponding page.
一种电子装置,包括存储器和处理器,所述存储器上存储有可被所述处理器执行的实现web与原生功能交互的系统,所述实现web与原生功能交互的系统包括:An electronic device includes a memory and a processor, wherein the memory stores a system executable by the processor to implement interaction between a web and a native function, and the system for implementing interaction between the web and the native function comprises:
接收解析模块,用于接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;The receiving parsing module is configured to receive a webpage address sent by the web browser, and parse the webpage address to generate an object or an API interface according to a preset parsing rule;
判断模块,用于判断网页地址中是否包含有参数值;a determining module, configured to determine whether a parameter value is included in the webpage address;
传值模块,用于将网页地址中包含的参数值传给生成的对象或API接口;a value passing module, configured to pass the parameter value included in the webpage address to the generated object or API interface;
网页生成模块,用于生成对应的网页。A webpage generating module for generating a corresponding webpage.
一种计算机可读存储介质,其特征在于,所述计算机可读存储介质内存储有实现web与原生功能交互的系统,所述实现web与原生功能交互的系统可被至少一个处理器所执行,以实现以下步骤:A computer readable storage medium, wherein the computer readable storage medium stores a system for implementing interaction between a web and a native function, and the system for implementing interaction between the web and the native function is executable by at least one processor, To achieve the following steps:
S1、接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;S1: receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
S2、判断网页地址中是否包含有参数值,若是执行步骤S3,若否执行步骤S4;S2, determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
S3、将所述参数值传给所述对象或API接口,生成对应的页面;S3. Pass the parameter value to the object or the API interface to generate a corresponding page.
S4、获取所述对象或API接口的默认参数值,生成对应的页面。S4. Obtain a default parameter value of the object or the API interface, and generate a corresponding page.
本申请的积极进步效果在于:本申请通过预设解析规则,将网页地址转 换成相应的对象或API接口,使得App和Web可以使用同一套调用标准对同一个原生功能进行调用,简化了调用方式易维护,扩展了Web调用原生功能的范围。The positive progress of the application is that the present application converts the webpage address into a corresponding object or API interface by using a preset parsing rule, so that the App and the web can use the same set of calling standards to call the same native function, simplifying the calling method. Easy to maintain, extending the range of native features of the web call.
附图说明DRAWINGS
图1示出了本申请电子装置一实施例的硬件架构示意图;1 is a schematic diagram showing the hardware architecture of an embodiment of an electronic device of the present application;
图2示出了本申请电子装置中实现web与原生功能交互的系统第一实施例的程序模块示意图;2 is a schematic diagram of a program module of a first embodiment of a system for implementing web and native function interaction in an electronic device of the present application;
图3示出了本申请电子装置中实现web与原生功能交互的系统第二实施例的程序模块示意图;3 is a schematic diagram of a program module of a second embodiment of a system for implementing web and native function interaction in an electronic device of the present application;
图4示出了本申请实现web与原生功能交互的方法实施例一的流程图;4 is a flowchart of Embodiment 1 of a method for implementing interaction between a web and a native function according to the present application;
图5示出了本申请实现web与原生功能交互的方法实施例二中页面调用功能的注册流程图;FIG. 5 is a flow chart showing the registration of a page calling function in the second embodiment of the method for implementing interaction between a web and a native function;
图6示出了本申请实现web与原生功能交互的方法实施例三中页面调用时的地址转换流程图;6 is a flowchart of address translation when a page is invoked in Embodiment 3 of the method for implementing interaction between a web and a native function according to the present application;
图7示出了本申请实现web与原生功能交互的方法实施例四接口调用功能的注册流程图;FIG. 7 is a flowchart of registering an interface call function of a method for implementing interaction between a web and a native function according to the present application; FIG.
图8示出了本申请实现web与原生功能交互的方法实施例五中接口调用时的地址转换流程图。FIG. 8 is a flow chart showing the address translation when the interface is invoked in the fifth embodiment of the method for implementing interaction between the web and the native function.
具体实施方式Detailed ways
下面通过实施例的方式进一步说明本申请,但并不因此将本申请限制在所述的实施例范围之中。The present application is further illustrated by the following examples, but is not intended to limit the scope of the embodiments.
首先,本申请提出了一种电子装置。First of all, the present application proposes an electronic device.
参阅图1所示,是本申请电子装置一实施例的硬件架构示意图。本实施 例中,所述电子装置2是一种能够按照事先设定或者存储的指令,自动进行数值计算和/或信息处理的设备。例如,可以是智能手机、平板电脑、笔记本电脑、台式计算机、机架式服务器、刀片式服务器、塔式服务器或机柜式服务器(包括独立的服务器,或者多个服务器所组成的服务器集群)等。如图所示,所述电子装置2至少包括,但不限于,可通过系统总线相互通信连接存储器21、处理器22、网络接口23、以及实现web与原生功能交互的系统20。其中:1 is a schematic diagram of a hardware architecture of an embodiment of an electronic device of the present application. In the present embodiment, the electronic device 2 is an apparatus capable of automatically performing numerical calculation and/or information processing in accordance with an instruction set or stored in advance. For example, it can be a smartphone, a tablet, a laptop, a desktop computer, a rack server, a blade server, a tower server, or a rack server (including a stand-alone server, or a server cluster composed of multiple servers). As shown, the electronic device 2 includes at least, but not limited to, a memory 21, a processor 22, a network interface 23, and a system 20 that enables web interaction with native functions via a system bus. among them:
所述存储器21至少包括一种类型的计算机可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、随机访问存储器(RAM)、静态随机访问存储器(SRAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、可编程只读存储器(PROM)、磁性存储器、磁盘、光盘等。在一些实施例中,所述存储器21可以是所述电子装置2的内部存储单元,例如该电子装置2的硬盘或内存。在另一些实施例中,所述存储器21也可以是所述电子装置2的外部存储设备,例如该电子装置2上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。当然,所述存储器21还可以既包括所述电子装置2的内部存储单元也包括其外部存储设备。本实施例中,所述存储器21通常用于存储安装于所述电子装置2的操作系统和各类应用软件,例如所述实现web与原生功能交互的系统20的程序代码等。此外,所述存储器21还可以用于暂时地存储已经输出或者将要输出的各类数据。The memory 21 includes at least one type of computer readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (eg, SD or DX memory, etc.), a random access memory (RAM), Static Random Access Memory (SRAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), Programmable Read Only Memory (PROM), magnetic memory, magnetic disk, optical disk, and the like. In some embodiments, the memory 21 may be an internal storage unit of the electronic device 2, such as a hard disk or a memory of the electronic device 2. In other embodiments, the memory 21 may also be an external storage device of the electronic device 2, such as a plug-in hard disk equipped on the electronic device 2, a smart memory card (SMC), and a secure digital device. (Secure Digital, SD) card, flash card, etc. Of course, the memory 21 can also include both the internal storage unit of the electronic device 2 and its external storage device. In this embodiment, the memory 21 is generally used to store an operating system installed in the electronic device 2 and various types of application software, such as the program code of the system 20 that implements the interaction between the web and the native function. Further, the memory 21 can also be used to temporarily store various types of data that have been output or are to be output.
所述处理器22在一些实施例中可以是中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器、或其他数据处理芯片。该处理器22通常用于控制所述电子装置2的总体操作,例如执行与所述电子装置2进行数据交互或者通信相关的控制和处理等。本实施例中,所述处理器22用于运行所述存储器21中存储的程序代码或者处理数据,例如运行所述的 实现web与原生功能交互的系统20等。The processor 22 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 22 is typically used to control the overall operation of the electronic device 2, such as performing control and processing associated with data interaction or communication with the electronic device 2. In this embodiment, the processor 22 is configured to run program code or process data stored in the memory 21, such as running the system 20 for implementing web and native function interaction.
所述网络接口23可包括无线网络接口或有线网络接口,该网络接口23通常用于在所述电子装置2与其他电子装置之间建立通信连接。例如,所述网络接口23用于通过网络将所述电子装置2与外部终端相连,在所述电子装置2与外部终端之间的建立数据传输通道和通信连接等。所述网络可以是企业内部网(Intranet)、互联网(Internet)、全球移动通讯系统(Global System of Mobile communication,GSM)、宽带码分多址(Wideband Code Division Multiple Access,WCDMA)、4G网络、5G网络、蓝牙(Bluetooth)、Wi-Fi等无线或有线网络。The network interface 23 may comprise a wireless network interface or a wired network interface, which is typically used to establish a communication connection between the electronic device 2 and other electronic devices. For example, the network interface 23 is configured to connect the electronic device 2 to an external terminal through a network, establish a data transmission channel, a communication connection, and the like between the electronic device 2 and an external terminal. The network may be an intranet, an Internet, a Global System of Mobile communication (GSM), a Wideband Code Division Multiple Access (WCDMA), a 4G network, or a 5G network. Wireless or wired networks such as network, Bluetooth, Wi-Fi, etc.
需要指出的是,图1仅示出了具有组件21-23的电子装置2,但是应理解的是,并不要求实施所有示出的组件,可以替代的实施更多或者更少的组件。It is pointed out that FIG. 1 only shows the electronic device 2 with the components 21-23, but it should be understood that not all illustrated components are required to be implemented, and more or fewer components may be implemented instead.
在本实施例中,存储于存储器21中的所述实现web与原生功能交互的系统20可以被分割为一个或者多个程序模块,所述一个或者多个程序模块被存储于存储器21中,并可由一个或多个处理器(本实施例为处理器22)所执行,以完成本申请。In this embodiment, the system 20 that interacts with the native function stored in the memory 21 can be divided into one or more program modules, and the one or more program modules are stored in the memory 21, and It can be performed by one or more processors (the processor 22 in this embodiment) to complete the application.
例如,图2示出了所述实现web与原生功能交互的系统20第一实施例的程序模块示意图,该实施例中,所述实现web与原生功能交互的系统20可以被分割为接收解析模块201、判断模块202、传值模块203和网页生成模块204。其中,本申请所称的程序模块是指能够完成特定功能的一系列计算机程序指令段。以下描述将具体介绍所述程序模块201-204的具体功能。For example, FIG. 2 shows a schematic diagram of a program module of the first embodiment of the system 20 for implementing interaction between a web and a native function. In this embodiment, the system 20 for implementing web interaction with a native function may be partitioned into a receiving parsing module. 201. The determining module 202, the value transmitting module 203, and the webpage generating module 204. Wherein, the program module referred to in the present application refers to a series of computer program instruction segments capable of performing a specific function. The following description will specifically describe the specific functions of the program modules 201-204.
所述接收解析模块201用于接收Web浏览器发送来的网页地址,并根据预设解析规则将所述网页地址解析生成对象或API接口;The receiving parsing module 201 is configured to receive a webpage address sent by a web browser, and parse the webpage address into an object or an API interface according to a preset parsing rule;
所述预设解析规则是指预设有网页地址与对象或者API接口相对应的对应表,接收到网页地址后,从所述对应表中可以获取相对应的对象或者 API接口。当然,此处不限于对应表的形式。The preset parsing rule refers to a correspondence table corresponding to an object or an API interface, and after receiving the webpage address, the corresponding object or API interface can be obtained from the corresponding table. Of course, this is not limited to the form of the corresponding table.
所述判断模块202用于判断网页地址中是否包含有参数值;The determining module 202 is configured to determine whether a parameter value is included in a webpage address;
所述传值模块203用于将网页地址中包含的参数值传给生成的对象或API接口;The value passing module 203 is configured to pass the parameter value included in the webpage address to the generated object or API interface;
所述网页生成模块204用于生成对应的网页。The webpage generating module 204 is configured to generate a corresponding webpage.
本系统适用于页面的直接调用,也适用于接口调用,然后通过接口打开对应的页面,这里所述页面和接口都是预先做好封装的。本系统相当于在Web浏览器和调用的页面或接口之间增加了一层中间层,该中间层主要用于地址的转换。The system is applicable to the direct invocation of the page, and is also applicable to the interface call, and then opens the corresponding page through the interface, where the page and the interface are pre-packaged. This system is equivalent to adding an intermediate layer between the web browser and the called page or interface, which is mainly used for address conversion.
下面以操作人员使用本系统为例做具体说明:The following is an example of the operator using the system as an example:
1、操作人员在Web浏览器的地址栏中输入网页地址,Web浏览器会将该网页地址发送到本系统,本系统根据预设解析规则将该网页地址进行解析生成对象或者API接口。1. The operator inputs the webpage address in the address bar of the web browser, and the web browser sends the webpage address to the system, and the system parses the webpage address according to the preset parsing rule to generate an object or an API interface.
2、判断网页地址是否包含有参数值;如果有,则需要向相应的对象或API接口进行传参;如果没有,则直接采用默认参数无需传参步骤。2. Determine whether the webpage address contains the parameter value; if there is, it needs to pass the parameter to the corresponding object or API interface; if not, the default parameter is directly used without the step of transmitting the parameter.
3、如果生成的是对象,则直接生产具有相应功能的网页,比如直接打开聊天页面等,该页面是固定的;如果生成的是API接口,则通过该接口调用其相对的页面打开,比如通过接口打开其对应的天气预报页面,该页面是可变化的。3. If the generated object is an object, the webpage having the corresponding function is directly produced, for example, the chat page is directly opened, and the page is fixed; if the API interface is generated, the relative page is opened by the interface, for example, The interface opens its corresponding weather forecast page, which is changeable.
又例如,图3示出了所述实现web与原生功能交互的系统20第二实施例的程序模块示意图,该实施例中,所述实现web与原生功能交互的系统20还可以被分割为接收解析模块201、判断模块202、传值模块203、网页生成模块204、封装模块205、调用地址生成模块206、地址转换模块207和映射模块208。For another example, FIG. 3 shows a schematic diagram of a program module of the second embodiment of the system 20 for implementing interaction between the web and the native function. In this embodiment, the system 20 for implementing web interaction with the native function can also be divided into receiving. The parsing module 201, the judging module 202, the value transmitting module 203, the webpage generating module 204, the encapsulating module 205, the calling address generating module 206, the address converting module 207, and the mapping module 208.
其中,模块201-204同第一实施例,此处不再赘述。The modules 201-204 are the same as the first embodiment, and are not described herein again.
所述封装模块205,用于将页面调用所对应的页面封装成对象,以及将接口调用所对应的接口封装为API接口;The encapsulating module 205 is configured to encapsulate a page corresponding to the page call into an object, and encapsulate the interface corresponding to the interface call as an API interface;
所述调用地址生成模块206,用于按预设的协议生成与所述对象相应的对象调用地址,所述对象调用地址包括指令类型、类和默认参数值,以及按预设的协议生成与所述API接口相应的接口调用地址,所述接口调用地址包括指令类型、方法和默认参数值;The call address generation module 206 is configured to generate an object call address corresponding to the object according to a preset protocol, where the object call address includes an instruction type, a class, and a default parameter value, and generates and coordinates according to a preset protocol. The corresponding interface call address of the API interface, where the interface call address includes an instruction type, a method, and a default parameter value;
所述协议是指将封装后的对象或者API接口转换成相应的对象调用地址或者接口调用地址的规则;以对象为例,对象调用地址包括指令类型、类和默认参数值,将封装后的对象先转换为字符串,所述字符串中包括指令类型和类,设定指令类型和类的字符串的起始位置,通过截取特定位置的字符串添加到对象调用地址中对应的位置上,以生成特定的对象调用地址。The protocol refers to a rule for converting a packaged object or an API interface into a corresponding object call address or an interface call address; taking an object as an example, the object call address includes an instruction type, a class, and a default parameter value, and the encapsulated object First convert to a string, the string includes the instruction type and class, set the instruction type and the starting position of the string of the class, and add the string of the specific position to the corresponding position in the object call address by Generate a specific object call address.
所述地址转换模块207,用于根据预设的网址转换规则,将所述对象调用地址和所述接口调用地址转换为相应的网页地址;The address conversion module 207 is configured to convert the object call address and the interface call address into a corresponding webpage address according to a preset URL conversion rule;
所述预设的网址转换规则是指预设的调用地址与网页地址相对应的对应表,接收到调用地址后,从所述对应表中获取相对应的网页地址。当然,此处不限于对应表的形式。The preset URL conversion rule refers to a correspondence table corresponding to a preset call address and a webpage address. After receiving the call address, the corresponding webpage address is obtained from the correspondence table. Of course, this is not limited to the form of the corresponding table.
所述映射模块208,用于将所述对象调用地址中包含的类映射到由该对象调用地址转换成的网页地址,形成类-网页地址映射关系,并将该映射关系保存至类-网页地址映射表中,以及将所述接口调用地址中包含的方法映射到由所述接口调用地址转换成的网页地址,并保存至内存中。The mapping module 208 is configured to map a class included in the object call address to a webpage address converted by the object call address, form a class-web address mapping relationship, and save the mapping relationship to a class-page address. Mapping the table, and mapping the method included in the interface call address to the webpage address converted by the interface call address, and saving to the memory.
相较于第一实施例,本实施例中增加了页面和接口在系统(中间层)进行注册时使用的几个模块。Compared with the first embodiment, several modules used in the registration of the system (intermediate layer) by the page and the interface are added in this embodiment.
下面以页面在本系统中进行注册为例作具体说明:The following is a detailed description of the registration of the page in this system:
1、先将聊天页面封装成对象ChatVideoViewController后加载到本系统中。1. The chat page is first packaged into the object ChatVideoViewController and loaded into the system.
2、按预设的协议生成与所述对象ChatVideoViewController相应的对象 调用地址(协议类型://指令类型/指令?参数1=值1&参数2=值2;),比如:local://view/VideoChat?callNum=参数&groupCode=参数,其中local://view/表示页面或传值类型,view具体为指令类型,VideoChat具体为类,这个对象调用地址包含2个参数callNum和groupCode,转换时可以分别赋予这两个参数相对应的默认参数值。2. Generate an object call address corresponding to the object ChatVideoViewController according to a preset protocol (protocol type:://instruction type/instruction?parameter 1=value 1&parameter 2=value 2;), for example: local://view/ VideoChat? callNum=parameter &groupCode=parameter, where local://view/ indicates the page or value type, view is specific to the instruction type, VideoChat is specific to the class, and the object call address contains two parameters callNum and groupCode, which can be assigned to this when converting. The default parameter value corresponding to the two parameters.
3、然后将上述步骤2中对象调用地址根据预设的网址转换规则转换成网页地址,以便Web进行调用,比如转换为https://www.baidu.com/s?ie=utf-8。3. Then, the object calling address in the above step 2 is converted into a webpage address according to a preset URL conversion rule, so that the web can be called, for example, converted to https://www.baidu.com/s? Ie=utf-8.
4、形成类-网页地址映射表,将类VideoChat与网页地址https://www.baidu.com/s?ie=utf-8进行映射,并将该映射关系保存到映射表中。4, form a class-web address mapping table, the class VideoChat and the web address https://www.baidu.com/s? Ie=utf-8 maps and saves the mapping to the mapping table.
假设是接口在本系统中进行注册,则步骤4不同,将方法映射到网页地址后直接保存到系统内存中,不存在映射表。Assuming that the interface is registered in the system, step 4 is different. The method is mapped to the web page address and saved directly to the system memory. There is no mapping table.
其次,本申请提出一种实现web与原生功能交互的方法,这里所述原生功能可以是页面调用功能,也可以是接口调用功能。Secondly, the present application proposes a method for implementing interaction between a web and a native function, where the native function may be a page calling function or an interface calling function.
在实施例一中,如图4所示,所述的实现web与原生功能交互的方法包括如下步骤:In the first embodiment, as shown in FIG. 4, the method for implementing interaction between the web and the native function includes the following steps:
S1、接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;S1: receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
S2、判断网页地址中是否包含有参数值,若是执行步骤S3,若否执行步骤S4;S2, determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
S3、将所述参数值传给所述对象或API接口(传参步骤),生成对应的页面;S3. Pass the parameter value to the object or the API interface (passing the step) to generate a corresponding page.
S4、获取所述对象或API接口的默认参数值(不传参步骤),生成对应的页面。S4. Obtain a default parameter value of the object or the API interface (steps are not passed), and generate a corresponding page.
下面以通过网页调用打开聊天页面为例做具体说明:The following is an example of opening a chat page through a web page:
1、接收到Web浏览器发送来的网页地址 https://www.baidu.com/s?ie=utf-8,根据预设解析规则解析生成对象ChatVideoViewController。1. Receive the web address sent by the web browser https://www.baidu.com/s? Ie=utf-8, parsing the generated object ChatVideoViewController according to the preset parsing rules.
2、判断有无参数值,该网页地址中的参数值为utf-8,将该参数值传给生成的对象生成对应功能(即将参数值替代默认参数值),即打开了相应的页面,如果没有参数值,则直接获取默认参数值以生成对应功能,没有传参的步骤。2. Determine whether there is a parameter value, the parameter value in the webpage address is utf-8, and the parameter value is transmitted to the generated object to generate a corresponding function (that is, the parameter value replaces the default parameter value), that is, the corresponding page is opened, if If there is no parameter value, the default parameter value is directly obtained to generate the corresponding function, and there is no step of passing the parameter.
假设是接口调用,则步骤1中生成的是接口调用方法(以下简称方法),通过该方法直接调用的是某个接口,然后需要通过该接口去打开相应的页面,这种页面可以是动态的。Assume that the interface is called, then the interface call method (hereinafter referred to as the method) is generated in step 1. The method directly calls an interface, and then the corresponding page needs to be opened through the interface. The page can be dynamic. .
在实施例二中,基于实施例一的基础上,如图5所示,当原生功能为页面调用时,步骤S1之前还包括以下步骤:In the second embodiment, based on the first embodiment, as shown in FIG. 5, when the native function is called by the page, the following steps are also included before the step S1:
S011、将页面调用所对应的页面封装成对象,并按预设的协议生成相应的对象调用地址,所述对象调用地址包括指令类型、类和默认参数值;S011, encapsulating the page corresponding to the page call into an object, and generating a corresponding object calling address according to a preset protocol, where the object calling address includes an instruction type, a class, and a default parameter value;
S012、根据预设的网址转换规则,将所述对象调用地址转换为网页地址;S012. Convert the object call address to a webpage address according to a preset URL conversion rule.
S013、将所述对象调用地址中包含的类映射到由该对象调用地址转换成的网页地址,形成类-网页地址映射关系,并将该映射关系保存至类-网页地址映射表中。S013: Mapping a class included in the object call address to a webpage address converted by the object call address, forming a class-web address mapping relationship, and saving the mapping relationship to the class-web address mapping table.
这里所述网页地址中包含有参数名,所述参数名与对象中包含的类相对应;所述参数名之后带参数值或者不带参数值;所述步骤S2中,通过识别网页地址中的参数名来获取跟在所述参数名之后的参数值。The webpage address includes a parameter name, and the parameter name corresponds to a class included in the object; the parameter name is followed by a parameter value or no parameter value; in the step S2, by identifying the webpage address The parameter name is used to get the parameter value following the parameter name.
下面以聊天页面进行注册为例作具体说明:The following is a specific example of registration on the chat page:
1、聊天页面在进行网址转换前,先要进行封装,将所述聊天页面封装成对象ChatVideoViewController,并按预设的协议生成相应的对象调用地址local://view/VideoChat?callNum=参数&groupCode=参数。1. Before the website is converted, the chat page is first encapsulated, and the chat page is encapsulated into the object ChatVideoViewController, and the corresponding object call address local://view/VideoChat is generated according to a preset protocol. callNum=parameter &groupCode=parameter.
2、将所述对象调用地址按预设的网址转换规则转换成网页地址https:// www.baidu.com/s?ie=utf-8,其中ie为参数名,将参数名ie与对象ChatVideoViewController中的类(名)ChatVideo进行对应,参数名ie之后的utf-8为具体的参数值。2. Convert the object call address into a web address https://www.baidu.com/s according to the preset URL conversion rule. Ie=utf-8, where ie is the parameter name, the parameter name ie corresponds to the class (name) ChatVideo in the object ChatVideoViewController, and the utf-8 after the parameter name ie is the specific parameter value.
3、将类(名)VideoChat映射到网页地址https://www.baidu.com/s?ie=utf-8,并将这种类-网页地址的映射关系保存到类-网页地址映射表中。3. Map the class (name) VideoChat to the web address https://www.baidu.com/s? Ie=utf-8, and save this class-web address mapping relationship to the class-page address mapping table.
如果是接口进行注册,则封装后为API接口,If the interface is registered, it is encapsulated as an API interface.
在实施例三中,基于实施例二的基础上,如图6所示,步骤S1具体包括以下分步骤:In the third embodiment, based on the second embodiment, as shown in FIG. 6, step S1 specifically includes the following sub-steps:
S111、接收Web浏览器发送来的网页地址;S111. Receive a webpage address sent by a web browser.
S112、从类-网页地址映射表找到与接收到的网页地址相对应的类;S112. Find a class corresponding to the received webpage address from the class-webpage address mapping table.
S113、生成包含所述类的对象调用地址;S113. Generate an object call address that includes the class.
S114、根据所述对象调用地址动态生成相应的对象。S114. Dynamically generate a corresponding object according to the object calling address.
接上例,对本步骤做具体说明:Connect the above example and give specific instructions on this step:
1、接收到Web浏览器发送来的网页地址https://www.baidu.com/s?ie=utf-8。1. Receive the web address sent by the web browser https://www.baidu.com/s? Ie=utf-8.
2、从类-网页地址映射表找到与该网页地址相对应的类为VideoChat。2. Find the class corresponding to the webpage address from the class-page address mapping table as VideoChat.
3、生成对象调用地址local://view/VideoChat?callNum=参数&groupCode=参数。3, generate object call address local://view/VideoChat? callNum=parameter &groupCode=parameter.
4、动态生成相应的对象ChatVideoViewController。4. Dynamically generate the corresponding object ChatVideoViewController.
在实施例四中,基于实施例一的基础上,如图7所示,当原生功能为接口调用时,步骤S1之前还包括:In the fourth embodiment, based on the first embodiment, as shown in FIG. 7, when the native function is called by the interface, before step S1, the method further includes:
S021、将接口调用所对应的接口封装为API接口,按预设的协议生成相应的接口调用地址,所述接口调用地址包括指令类型、方法和默认参数值;S021. Encapsulate an interface corresponding to the interface call as an API interface, and generate a corresponding interface call address according to a preset protocol, where the interface call address includes an instruction type, a method, and a default parameter value;
S022、根据预设的网址转换规则,将所述接口调用地址转换为网页地址;S022. Convert the interface call address to a webpage address according to a preset URL conversion rule.
S023、将所述接口调用地址中包含的方法映射到由所述接口调用地址转换成的网页地址,并保存至内存中。S023: Map a method included in the interface call address to a webpage address converted by the interface call address, and save the file to an internal memory.
所述网页地址中包含有参数名,所述参数名与API接口中包含的方法相对应;所述参数名之后带参数值或者不带参数值;所述步骤S2中,通过识别网页地址中的参数名来获取跟在所述参数名之后的参数值。类似于页面调用。The webpage address includes a parameter name, and the parameter name corresponds to a method included in the API interface; the parameter name is followed by a parameter value or no parameter value; in the step S2, by identifying the webpage address The parameter name is used to get the parameter value following the parameter name. Similar to page calls.
本实施例中所述接口调用与页面调用的区别在于:接口调用地址中的指令为方法,而对象调用地址中的指令为类;接口调用地址中的而方法映射到由所述接口调用地址转换成的网页地址后直接保存至内存中,没有网页调用中所述的映射表。The difference between the interface call and the page call in this embodiment is that the instruction in the interface call address is a method, and the instruction in the object call address is a class; the interface calls the address and the method maps to the address conversion by the interface call. The resulting web page address is saved directly to memory and there is no mapping table as described in the web page call.
在实施例五中,基于实施例四的基础上,如图8所示,步骤S1包括以下分步骤:In the fifth embodiment, based on the fourth embodiment, as shown in FIG. 8, step S1 includes the following sub-steps:
S121、接收Web浏览器发送来的网页地址;S121. Receive a webpage address sent by a web browser.
S122、从内存找到与接收到的网页地址相对应的方法;S122. Find a method corresponding to the received webpage address from the memory;
S123、生成包含所述方法的接口调用地址;S123. Generate an interface call address that includes the method.
S124、根据所述接口调用地址找到相应的API接口。S124. Find a corresponding API interface according to the interface call address.
本实施例与实施例三的区别在于,最终找到的API接口,需要通过该接口再进一步去掉取页面打开,优点是通过接口打开的页面可以是动态的页面;而实施例三中找到的直接就是页面,只要将页面打开就可,但是该页面通常是固定的。The difference between this embodiment and the third embodiment is that the API interface finally found needs to be further removed from the interface through the interface. The advantage is that the page opened through the interface can be a dynamic page; and the direct solution found in the third embodiment is directly The page can be opened as long as the page is open, but the page is usually fixed.
此外,本申请一种计算机可读存储介质,该计算机可读存储介质内存储有实现web与原生功能交互的系统20,该实现web与原生功能交互的系统20可被一个或多个处理器执行时,实现上述实现web与原生功能交互的方法或电子装置的操作。Moreover, the present application is a computer readable storage medium having stored therein a system 20 that implements web-to-native function interaction, the system 20 that implements web interaction with native functions can be executed by one or more processors In the above, the method or the operation of the electronic device that implements the interaction between the web and the native function is implemented.
虽然以上描述了本申请的具体实施方式,但是本领域的技术人员应当理解,这仅是举例说明,本申请的保护范围是由所附权利要求书限定的。本领域的技术人员在不背离本申请的原理和实质的前提下,可以对这些实施方式做出多种变更或修改,但这些变更和修改均落入本申请的保护范围。While the embodiments of the present invention have been described above, it will be understood by those skilled in the art that the scope of the invention is defined by the appended claims. A person skilled in the art can make various changes or modifications to these embodiments without departing from the spirit and scope of the present application, and such changes and modifications fall within the scope of the present application.

Claims (16)

  1. 一种实现web与原生功能交互的方法,所述原生功能包括页面调用和接口调用,其特征在于,包括如下步骤:A method for implementing interaction between a web and a native function, the native function comprising a page call and an interface call, characterized in that the method comprises the following steps:
    S1、接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;S1: receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
    S2、判断网页地址中是否包含有参数值,若是执行步骤S3,若否执行步骤S4;S2, determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
    S3、将所述参数值传给所述对象或API接口,生成对应的页面;S3. Pass the parameter value to the object or the API interface to generate a corresponding page.
    S4、获取所述对象或API接口的默认参数值,生成对应的页面。S4. Obtain a default parameter value of the object or the API interface, and generate a corresponding page.
  2. 根据权利要求1所述的实现web与原生功能交互的方法,其特征在于,当原生功能为页面调用时,步骤S1之前还包括:The method for implementing interaction between a web and a native function according to claim 1, wherein when the native function is a page call, before step S1, the method further includes:
    S011、将页面调用所对应的页面封装成对象,并按预设的协议生成相应的对象调用地址,所述对象调用地址包括指令类型、类和默认参数值;S011, encapsulating the page corresponding to the page call into an object, and generating a corresponding object calling address according to a preset protocol, where the object calling address includes an instruction type, a class, and a default parameter value;
    S012、根据预设的网址转换规则,将所述对象调用地址转换为网页地址;S012. Convert the object call address to a webpage address according to a preset URL conversion rule.
    S013、将所述对象调用地址中包含的类映射到由该对象调用地址转换成的网页地址,形成类-网页地址映射关系,并将该映射关系保存至类-网页地址映射表中。S013: Mapping a class included in the object call address to a webpage address converted by the object call address, forming a class-web address mapping relationship, and saving the mapping relationship to the class-web address mapping table.
  3. 根据权利要求2所述的实现web与原生功能交互的方法,其特征在于,步骤S1包括以下分步骤:The method for implementing interaction between a web and a native function according to claim 2, wherein the step S1 comprises the following substeps:
    S111、接收Web浏览器发送来的网页地址;S111. Receive a webpage address sent by a web browser.
    S112、从类-网页地址映射表找到与接收到的网页地址相对应的类;S112. Find a class corresponding to the received webpage address from the class-webpage address mapping table.
    S113、生成包含所述类的对象调用地址;S113. Generate an object call address that includes the class.
    S114、根据所述对象调用地址动态生成相应的对象。S114. Dynamically generate a corresponding object according to the object calling address.
  4. 根据权利要求2所述的实现web与原生功能交互的方法,其特征在于,所述网页地址中包含有参数名,所述参数名与对象中包含的类相对应; 所述参数名之后带参数值或者不带参数值;所述步骤S2中,通过识别网页地址中的参数名来获取跟在所述参数名之后的参数值。The method for implementing interaction between a web and a native function according to claim 2, wherein the webpage address includes a parameter name, and the parameter name corresponds to a class included in the object; The value or the parameter value is not included; in the step S2, the parameter value following the parameter name is obtained by identifying the parameter name in the webpage address.
  5. 根据权利要求1所述的实现web与原生功能交互的方法,其特征在于,当原生功能为接口调用时,步骤S1之前还包括:The method for implementing interaction between a web and a native function according to claim 1, wherein when the native function is an interface call, before step S1, the method further includes:
    S021、将接口调用所对应的接口封装为API接口,按预设的协议生成相应的接口调用地址,所述接口调用地址包括指令类型、方法和默认参数值;S021. Encapsulate an interface corresponding to the interface call as an API interface, and generate a corresponding interface call address according to a preset protocol, where the interface call address includes an instruction type, a method, and a default parameter value;
    S022、根据预设的网址转换规则,将所述接口调用地址转换为网页地址;S022. Convert the interface call address to a webpage address according to a preset URL conversion rule.
    S023、将所述接口调用地址中包含的方法映射到由所述接口调用地址转换成的网页地址,并保存至内存中。S023: Map a method included in the interface call address to a webpage address converted by the interface call address, and save the file to an internal memory.
  6. 根据权利要求5所述的实现web与原生功能交互的方法,其特征在于,步骤S1包括以下分步骤:The method for implementing web interaction with a native function according to claim 5, wherein the step S1 comprises the following substeps:
    S121、接收Web浏览器发送来的网页地址;S121. Receive a webpage address sent by a web browser.
    S122、从内存找到与接收到的网页地址相对应的方法;S122. Find a method corresponding to the received webpage address from the memory;
    S123、生成包含所述方法的接口调用地址;S123. Generate an interface call address that includes the method.
    S124、根据所述接口调用地址找到相应的API接口。S124. Find a corresponding API interface according to the interface call address.
  7. 根据权利要求5所述的实现web与原生功能交互的方法,其特征在于,所述网页地址中包含有参数名,所述参数名与API接口中包含的方法相对应;所述参数名之后带参数值或者不带参数值;所述步骤S2中,通过识别网页地址中的参数名来获取跟在所述参数名之后的参数值。The method for implementing interaction between a web and a native function according to claim 5, wherein the webpage address includes a parameter name, and the parameter name corresponds to a method included in an API interface; The parameter value or no parameter value; in the step S2, the parameter value following the parameter name is obtained by identifying the parameter name in the webpage address.
  8. 一种电子装置,包括存储器和处理器,其特征在于,所述存储器上存储有可被所述处理器执行的实现web与原生功能交互的系统,所述实现web与原生功能交互的系统包括:An electronic device includes a memory and a processor, wherein the memory stores a system executable by the processor to implement interaction between a web and a native function, and the system for implementing interaction between the web and the native function includes:
    接收解析模块,用于接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;The receiving parsing module is configured to receive a webpage address sent by the web browser, and parse the webpage address to generate an object or an API interface according to a preset parsing rule;
    判断模块,用于判断网页地址中是否包含有参数值;a determining module, configured to determine whether a parameter value is included in the webpage address;
    传值模块,用于将网页地址中包含的参数值传给生成的对象或API接 口;a value passing module, configured to pass the parameter value included in the webpage address to the generated object or API interface;
    网页生成模块,用于生成对应的网页。A webpage generating module for generating a corresponding webpage.
  9. 根据权利要求8所述的电子装置,其特征在于,所述实现web与原生功能交互的系统还包括:The electronic device according to claim 8, wherein the system for implementing interaction between the web and the native function further comprises:
    封装模块,用于将页面调用所对应的页面封装成对象,以及将接口调用所对应的接口封装为API接口;a package module, configured to encapsulate a page corresponding to the page call into an object, and encapsulate the interface corresponding to the interface call as an API interface;
    调用地址生成模块,用于按预设的协议生成与所述对象相应的对象调用地址,所述对象调用地址包括指令类型、类和默认参数值,以及按预设的协议生成与所述API接口相应的接口调用地址,所述接口调用地址包括指令类型、方法和默认参数值;Calling an address generation module, configured to generate an object call address corresponding to the object according to a preset protocol, where the object call address includes an instruction type, a class, and a default parameter value, and generate an interface with the API according to a preset protocol. The corresponding interface calls an address, and the interface call address includes an instruction type, a method, and a default parameter value;
    地址转换模块,用于根据预设的网址转换规则,将所述对象调用地址和所述接口调用地址转换为相应的网页地址;An address conversion module, configured to convert the object call address and the interface call address into a corresponding webpage address according to a preset URL conversion rule;
    映射模块,用于将所述对象调用地址中包含的类映射到由该对象调用地址转换成的网页地址,形成类-网页地址映射关系,并将该映射关系保存至类-网页地址映射表中,以及将所述接口调用地址中包含的方法映射到由所述接口调用地址转换成的网页地址,并保存至内存中。a mapping module, configured to map a class included in the object call address to a webpage address converted by the object call address, form a class-web address mapping relationship, and save the mapping relationship into a class-web address mapping table. And mapping the method included in the interface call address to the webpage address converted by the interface call address, and saving to the memory.
  10. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质内存储有实现web与原生功能交互的系统,所述实现web与原生功能交互的系统可被至少一个处理器所执行,以实现以下步骤:A computer readable storage medium, wherein the computer readable storage medium stores a system for implementing interaction between a web and a native function, and the system for implementing interaction between the web and the native function is executable by at least one processor, To achieve the following steps:
    S1、接收Web浏览器发送来的网页地址,根据预设解析规则将所述网页地址解析生成对象或API接口;S1: receiving a webpage address sent by the web browser, and parsing the webpage address to generate an object or an API interface according to a preset parsing rule;
    S2、判断网页地址中是否包含有参数值,若是执行步骤S3,若否执行步骤S4;S2, determining whether the webpage address contains a parameter value, if it is step S3, if not step S4;
    S3、将所述参数值传给所述对象或API接口,生成对应的页面;S3. Pass the parameter value to the object or the API interface to generate a corresponding page.
    S4、获取所述对象或API接口的默认参数值,生成对应的页面。S4. Obtain a default parameter value of the object or the API interface, and generate a corresponding page.
  11. 根据权利要求10所述的计算机可读存储介质,其特征在于,当原 生功能为页面调用时,步骤S1之前还包括:The computer readable storage medium according to claim 10, wherein when the native function is a page call, before step S1, the method further comprises:
    S011、将页面调用所对应的页面封装成对象,并按预设的协议生成相应的对象调用地址,所述对象调用地址包括指令类型、类和默认参数值;S011, encapsulating the page corresponding to the page call into an object, and generating a corresponding object calling address according to a preset protocol, where the object calling address includes an instruction type, a class, and a default parameter value;
    S012、根据预设的网址转换规则,将所述对象调用地址转换为网页地址;S012. Convert the object call address to a webpage address according to a preset URL conversion rule.
    S013、将所述对象调用地址中包含的类映射到由该对象调用地址转换成的网页地址,形成类-网页地址映射关系,并将该映射关系保存至类-网页地址映射表中。S013: Mapping a class included in the object call address to a webpage address converted by the object call address, forming a class-web address mapping relationship, and saving the mapping relationship to the class-web address mapping table.
  12. 根据权利要求11所述的计算机可读存储介质,其特征在于,步骤S1包括以下分步骤:The computer readable storage medium of claim 11 wherein step S1 comprises the following substeps:
    S111、接收Web浏览器发送来的网页地址;S111. Receive a webpage address sent by a web browser.
    S112、从类-网页地址映射表找到与接收到的网页地址相对应的类;S112. Find a class corresponding to the received webpage address from the class-webpage address mapping table.
    S113、生成包含所述类的对象调用地址;S113. Generate an object call address that includes the class.
    S114、根据所述对象调用地址动态生成相应的对象。S114. Dynamically generate a corresponding object according to the object calling address.
  13. 根据权利要求11所述的计算机可读存储介质,其特征在于,所述网页地址中包含有参数名,所述参数名与对象中包含的类相对应;所述参数名之后带参数值或者不带参数值;所述步骤S2中,通过识别网页地址中的参数名来获取跟在所述参数名之后的参数值。The computer readable storage medium according to claim 11, wherein the webpage address includes a parameter name, the parameter name corresponding to a class included in the object; the parameter name is followed by a parameter value or not With the parameter value; in the step S2, the parameter value following the parameter name is obtained by identifying the parameter name in the webpage address.
  14. 根据权利要求10所述的计算机可读存储介质,其特征在于,当原生功能为接口调用时,步骤S1之前还包括:The computer readable storage medium according to claim 10, wherein when the native function is an interface call, before step S1, the method further comprises:
    S021、将接口调用所对应的接口封装为API接口,按预设的协议生成相应的接口调用地址,所述接口调用地址包括指令类型、方法和默认参数值;S021. Encapsulate an interface corresponding to the interface call as an API interface, and generate a corresponding interface call address according to a preset protocol, where the interface call address includes an instruction type, a method, and a default parameter value;
    S022、根据预设的网址转换规则,将所述接口调用地址转换为网页地址;S022. Convert the interface call address to a webpage address according to a preset URL conversion rule.
    S023、将所述接口调用地址中包含的方法映射到由所述接口调用地址转换成的网页地址,并保存至内存中。S023: Map a method included in the interface call address to a webpage address converted by the interface call address, and save the file to an internal memory.
  15. 根据权利要求14所述的计算机可读存储介质,其特征在于,步骤S1包括以下分步骤:The computer readable storage medium of claim 14, wherein step S1 comprises the following substeps:
    S121、接收Web浏览器发送来的网页地址;S121. Receive a webpage address sent by a web browser.
    S122、从内存找到与接收到的网页地址相对应的方法;S122. Find a method corresponding to the received webpage address from the memory;
    S123、生成包含所述方法的接口调用地址;S123. Generate an interface call address that includes the method.
    S124、根据所述接口调用地址找到相应的API接口。S124. Find a corresponding API interface according to the interface call address.
  16. 根据权利要求14所述的计算机可读存储介质,其特征在于,所述网页地址中包含有参数名,所述参数名与API接口中包含的方法相对应;所述参数名之后带参数值或者不带参数值;所述步骤S2中,通过识别网页地址中的参数名来获取跟在所述参数名之后的参数值。The computer readable storage medium according to claim 14, wherein the webpage address includes a parameter name, the parameter name corresponding to a method included in an API interface; the parameter name is followed by a parameter value or Without the parameter value; in the step S2, the parameter value following the parameter name is obtained by identifying the parameter name in the webpage address.
PCT/CN2018/083077 2018-02-07 2018-04-13 Method for realizing web and native function interaction, and electronic apparatus and readable storage medium WO2019153492A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201810127625.2A CN108363588B (en) 2018-02-07 2018-02-07 Method for realizing interaction between web and native function, electronic device and readable storage medium
CN201810127625.2 2018-02-07

Publications (1)

Publication Number Publication Date
WO2019153492A1 true WO2019153492A1 (en) 2019-08-15

Family

ID=63004793

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/083077 WO2019153492A1 (en) 2018-02-07 2018-04-13 Method for realizing web and native function interaction, and electronic apparatus and readable storage medium

Country Status (2)

Country Link
CN (1) CN108363588B (en)
WO (1) WO2019153492A1 (en)

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109144520B (en) * 2018-09-03 2022-05-13 武汉斗鱼网络科技有限公司 Information interaction method, device, equipment and storage medium among different objects in Android
CN110738024A (en) * 2019-09-24 2020-01-31 深圳丝路天地电子商务有限公司 Method for converting WebAPP into API service interface
CN112860230A (en) * 2021-02-18 2021-05-28 爱驰汽车有限公司 Service implementation method, device, equipment and storage medium for hybrid application
CN113065079B (en) * 2021-04-13 2023-10-13 开鑫金服(南京)信息服务有限公司 Method, equipment and storage medium for realizing calling of native page based on address protocol

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103226474A (en) * 2013-05-10 2013-07-31 北京奇虎科技有限公司 Method, device and system for interaction between webpage script and browser program
CN106790276A (en) * 2017-02-20 2017-05-31 山东威尔数据股份有限公司 A kind of browser-cross data interactive method and device based on browser protocol
CN107133322A (en) * 2017-05-04 2017-09-05 四川长虹电器股份有限公司 The implementation method for the common data channel that HTML is interacted with Native in Mobile solution
CN107562548A (en) * 2017-08-04 2018-01-09 北京趣拿软件科技有限公司 The method and apparatus for transmitting data
CN107623704A (en) * 2016-07-14 2018-01-23 腾讯科技(北京)有限公司 Data interactive method, client and browser in terminal device

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10050935B2 (en) * 2014-07-09 2018-08-14 Shape Security, Inc. Using individualized APIs to block automated attacks on native apps and/or purposely exposed APIs with forced user interaction
CN106060107B (en) * 2016-05-05 2019-11-08 北京思特奇信息技术股份有限公司 A kind of method and system that service request by all kinds of means is uniformly accessed into
CN107396186B (en) * 2017-08-11 2019-11-08 四川长虹电器股份有限公司 Linux equipment WebOS system application management method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103226474A (en) * 2013-05-10 2013-07-31 北京奇虎科技有限公司 Method, device and system for interaction between webpage script and browser program
CN107623704A (en) * 2016-07-14 2018-01-23 腾讯科技(北京)有限公司 Data interactive method, client and browser in terminal device
CN106790276A (en) * 2017-02-20 2017-05-31 山东威尔数据股份有限公司 A kind of browser-cross data interactive method and device based on browser protocol
CN107133322A (en) * 2017-05-04 2017-09-05 四川长虹电器股份有限公司 The implementation method for the common data channel that HTML is interacted with Native in Mobile solution
CN107562548A (en) * 2017-08-04 2018-01-09 北京趣拿软件科技有限公司 The method and apparatus for transmitting data

Also Published As

Publication number Publication date
CN108363588B (en) 2021-03-16
CN108363588A (en) 2018-08-03

Similar Documents

Publication Publication Date Title
CN111600909B (en) Data processing method, device, protocol conversion equipment and storage medium
WO2019153492A1 (en) Method for realizing web and native function interaction, and electronic apparatus and readable storage medium
CN107835178B (en) Multi-protocol service communication method and device and electronic equipment
US9424551B2 (en) Secure inter-module communication mechanism
US11025724B2 (en) Transport of control data in proxy-based network communications
US8356087B1 (en) Automatically configuring virtual private networks
US9350763B1 (en) HTTP tunnelling over websockets
US11330035B2 (en) Method and server for HTTP protocol-based data request
CN111722947A (en) Service calling method and system
US9225681B2 (en) Enabling mobile applications to acquire a MAC address for obtaining location information
CN110187986B (en) Command management method, system, device and computer readable storage medium
CN114866965A (en) MaaP-based 5G message communication method, system, electronic equipment and storage medium
CN110769009A (en) User identity authentication method and system
WO2016107120A1 (en) Application programming interface calling method and device
US20160308974A1 (en) System and method for backend control of frontend user interfaces
US7797405B2 (en) Streaming file transfer apparatus, systems, and methods
CN113220481A (en) Request processing and feedback method and device, computer equipment and readable storage medium
AU2018390863B2 (en) Computer system and method for extracting dynamic content from websites
US10769003B2 (en) Application server programming language cloud functions
CN113691484A (en) Apparatus and method for protocol adaptation
KR20190069284A (en) Method of converting and interworking ocf resourse of internet service, and an apparatus performing the same
CN108924773A (en) Message treatment method and device
JP7294577B2 (en) Methods, devices and computer programs for managing remote devices by managed devices
CN109587239B (en) Access request processing method, server and storage medium
CN104965909A (en) Dynamic web content request handling method

Legal Events

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

Ref document number: 18904661

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

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

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

122 Ep: pct application non-entry in european phase

Ref document number: 18904661

Country of ref document: EP

Kind code of ref document: A1