Data communication method and communication system
By encrypting the communication data between the mini-program and the H5 terminal and appending an encrypted identifier ID to the HTTP link, the security issues in traditional communication and errors caused by excessive data volume are resolved, thus achieving secure and reliable data transmission.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-18
- Publication Date
- 2026-03-27
AI Technical Summary
There are security issues when traditional mini-programs communicate with H5 clients, and excessive data volume can lead to HTTP GET request 414 errors, affecting normal user experience.
By encrypting the data to be transmitted, an encrypted string to be transmitted is generated, and the encrypted identifier ID is appended to the HTTP link, so that the H5 client can obtain it from the URL parameters of the WebView component, and the server stores and manages the encrypted data mapping relationship.
It achieves secure data transmission between the mini-program client and the H5 client, avoids information leakage caused by plaintext transmission, and solves the problem of errors triggered by excessively long HTTP links, ensuring the security and reliability of data transmission.
Smart Images

Figure CN116318691B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, in particular to a data communication method and a communication system. BACKGROUND
[0002] For mobile services, the H5 application of the HTML5 (HyperText Markup Language 5, the fifth generation of HyperText Markup Language) web carrier has the advantages of hot updating and easy iteration, and has advantages in mobile App applications, WeChat / alipay applets, and often carries a large number of operation activities, transaction marketing processes, content publicity and other services. In the mobile App, the H5 end and the native interaction can be realized by means of JSBridge, and the native application (i.e., an application program that can run directly on the current operating system) can safely and efficiently transmit user information, device information and other data to the H5 end. However, due to the limitations of the applet engine, it is difficult for the applet client to transmit application / system information and other data to the H5 end, and the H5 end is also difficult to communicate with the applet client in real time.
[0003] When the traditional applet communicates with the H5 end, the data in the applet client that needs to be transmitted to the H5 end is usually concatenated in plaintext in the URL and transmitted to the WebView component, and the H5 end obtains the data transmitted by the applet client from the URL. This method has obvious security problems, and attackers can easily intercept sensitive information on the URL through packet capture tools, resulting in information leakage. At the same time, when the amount of data to be transmitted is too large, directly concatenating the data to be transmitted may also cause the HTTP link to be too long to trigger the HTTP Get request 414 error, affecting normal use of the user. SUMMARY
[0004] Therefore, the purpose of the present application is to provide a data communication method and a communication system to solve the communication security problem when the traditional applet communicates with the H5 end, and if the amount of data to be transmitted is too large during the communication process, directly concatenating the data to be transmitted on the HTTP link will cause the HTTP link to be too long to trigger the HTTP Get request 414 error.
[0005] In order to achieve the above purpose, the technical solutions adopted by the embodiments of the present application are as follows:
[0006] In a first aspect, the embodiments of the present application provide a data communication method applied to an applet client in a communication system, wherein the communication system further includes a server and an H5 end, the applet client is in communication connection with the server and the H5 end, and the applet client is provided with a WebView component;
[0007] The method comprises:
[0008] obtaining a to-be-transmitted string based on the to-be-transmitted data;
[0009] encrypting the to-be-transmitted string to obtain an encrypted to-be-transmitted string;
[0010] sending a data transmission request to the server, the data transmission request containing the encrypted to-be-transmitted string and an identification ID representing the applet client;
[0011] receiving the encrypted identification ID sent by the server based on the data transmission request, and concatenating the encrypted identification ID on an HTTP link, so that the H5 end obtains the encrypted identification ID from the HTTP link of the WebView component, wherein the HTTP link is contained in the URL parameter of the WebView component.
[0012] In an optional implementation, the step of obtaining a to-be-transmitted string based on the to-be-transmitted data includes:
[0013] serializing the to-be-transmitted data to obtain a serialized string;
[0014] converting the serialized string into a base64 string data to obtain the to-be-transmitted string.
[0015] In an optional implementation, the serialization is JSON serialization.
[0016] In an optional implementation, the step of encrypting the to-be-transmitted string to obtain an encrypted to-be-transmitted string includes:
[0017] obtaining a preset integer value;
[0018] segmenting the to-be-transmitted string according to the integer value to obtain a first string and a second string;
[0019] adding the first string and the second string in reverse order to obtain a third string;
[0020] reversing the third string to obtain the encrypted to-be-transmitted string.
[0021] In an optional implementation, the step of concatenating the encrypted identification ID on an HTTP link, so that the H5 end obtains the encrypted identification ID from the HTTP link of the WebView component, includes:
[0022] Splicing the encrypted identification ID on the HTTP link to obtain a spliced HTTP link;
[0023] Passing the spliced HTTP link in the URL parameter of the WebView component to enable the H5 end to obtain the encrypted identification ID from the HTTP link of the WebView component.
[0024] In a second aspect, an embodiment of the present application provides a data communication method applied to a server of a communication system, the communication system further comprising a small program client and an H5 end, the server being in communication connection with the small program client and the H5 end;
[0025] The method comprises:
[0026] Responding to a data transmission request sent by the small program client, wherein the data transmission request contains to-be-transmitted data and an identification ID representing the small program client;
[0027] Encrypting the identification ID, generating a mapping relationship between the encrypted identification ID and the to-be-transmitted data, and obtaining a mapping list;
[0028] Storing the to-be-transmitted data in Redis and storing the mapping list in a local cache;
[0029] Sending the encrypted identification ID to the small program client to enable the small program client to receive and process the encrypted identification ID;
[0030] Responding to a data query request sent by the H5 end, wherein the data query request contains a to-be-queried identification ID representing the encrypted identification ID of the small program client;
[0031] Sending the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end.
[0032] In an optional implementation, the step of sending the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end comprises:
[0033] Judging whether the to-be-transmitted data corresponding to the to-be-queried identification ID exists in the local cache;
[0034] If yes, sending the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end;
[0035] If no, decrypting the to-be-queried identification ID;
[0036] In case of successful decryption, the data to be transmitted corresponding to the to-be-queried identification ID is queried in a mapping list of the Redis, and the data to be transmitted corresponding to the to-be-queried identification ID is sent to the H5 end.
[0037] In a third aspect, the embodiments of the present application provide a data communication method, applied to an H5 end of a communication system, the communication system further comprising a mini-program client and a server, the H5 end being in communication connection with the mini-program client and the server, and the mini-program client being provided with a WebView component;
[0038] The method comprises:
[0039] An encrypted identification ID is obtained from an HTTP link of the WebView component, wherein the encrypted identification ID represents an encrypted identification ID of the mini-program client, and the HTTP link is contained in a URL parameter of the WebView component;
[0040] A data query request is sent to the server based on the encrypted identification ID;
[0041] Data corresponding to the encrypted identification ID sent by the server based on the data query request is received;
[0042] The data is decoded to restore the data to be transmitted.
[0043] In an optional implementation, the step of decoding the data to restore the data to be transmitted comprises:
[0044] A preset integer value is obtained;
[0045] The data is segmented according to the integer value to obtain a fourth string and a fifth string;
[0046] The fourth string and the fifth string are sequentially reversed and added to obtain a sixth string;
[0047] The sixth string is processed by inversion to obtain Base64 string data;
[0048] The Base64 string data is Base64 decoded to restore the data to be transmitted.
[0049] In a fourth aspect, the embodiments of the present application provide a communication system comprising a mini-program client, a server and an H5 end.
[0050] The mini-program client is configured to perform the data communication method provided in the first aspect and / or some possible implementation manners in combination with the first aspect.
[0051] The server is configured to perform the data communication method provided in the second aspect and / or some possible implementation manners of the second aspect.
[0052] The H5 end is configured to perform the data communication method provided in the third aspect and / or some possible implementation manners of the third aspect.
[0053] The beneficial effects of the embodiments of the present application include, for example:
[0054] The data communication method and the communication system provided by the embodiments of the present application obtain a to-be-transmitted string based on to-be-transmitted data, and encrypt the to-be-transmitted string to obtain an encrypted to-be-transmitted string, so that the process of transmitting data from the applet client to the H5 end does not exist plaintext transmission, is more secure, and realizes that the H5 service can safely and reliably undertake various core services in the applet environment.
[0055] Meanwhile, since the applet client only splices the encrypted identification ID on the HTTP link, the H5 end can obtain the encrypted identification ID from the HTTP link in the URL parameter of the WebView component, so that the H5 end can subsequently obtain corresponding data through the encrypted identification ID, and the data communication method does not need to consider the case that the data amount of the to-be-transmitted data is too large, and directly splice the to-be-transmitted data on the HTTP link, which causes the problem that the HTTP link is too long to trigger the HTTP Get request 414 error.
[0056] In order to make the above objectives, characteristics and advantages of the present application more apparent, the following will describe a preferred embodiment in detail, and the accompanying drawings will be described as follows. BRIEF DESCRIPTION OF DRAWINGS
[0057] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation to the scope, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.
[0058] Figure 1 An exemplary structural block diagram of a communication system provided by the embodiments of the present application is shown;
[0059] Figure 2 An exemplary structural block diagram of an electronic device provided by the embodiments of the present application is shown;
[0060] Figure 3A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0061] Figure 4 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0062] Figure 5 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0063] Figure 6 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0064] Figure 7 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0065] Figure 8 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0066] Figure 9 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0067] Figure 10 A flow diagram of a data communication method provided by an embodiment of the present application is shown.
[0068] Icon: 100-communication system; 101-applet client; 103-server; 102-H5 end; 300-electronic device; 301-memory; 302-processor; 303-communication interface. DETAILED DESCRIPTION
[0069] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments of the present application. The components of the embodiments of the present application described and shown in the accompanying drawings can be arranged and designed in various different configurations.
[0070] Therefore, the detailed description of the embodiments of the present application provided in the accompanying drawings below is not intended to limit the scope of the claimed present application, but only represents selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present application.
[0071] It should be noted that the terms "first", "second" and the like are used to distinguish one entity or operation from another, but do not necessarily require or imply any actual relationship or order between such entities or operations. Moreover, the terms "include", "contain" or any other variant thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "includes a" does not exclude the presence of additional identical elements in the process, method, article or device that includes the element.
[0072] It should be noted that the features in the embodiments of the application can be combined with each other without conflict.
[0073] Please refer to Figure 1 , Figure 1 An exemplary structural block diagram of a communication system 100 provided by an embodiment of the application is shown, which can include a small program client 101, a server 103 and an H5 end 102.
[0074] The small program client 101 is configured to encrypt the data to be transmitted and send it to the server 103 for storage.
[0075] The server 103 is configured to store the encrypted data to be transmitted, and encrypt the unique identifier ID of the small program client 101 and send it to the small program client 101.
[0076] The H5 end 102 is configured to obtain the encrypted unique identifier ID from the small program client 101, obtain the data corresponding to the encrypted unique identifier ID from the server 103, and restore it to the data to be transmitted, so as to complete the information interaction between the small program client 101 and the H5 end 102.
[0077] It should be noted that the above H5 end 102 can be a webpage in a browser, and the small program client 101 can be a small program client 101 developed by an individual, organization or enterprise, which is not limited in the present application.
[0078] In the embodiments of the application, the above small program client 101 can run in an electronic device, which can also display the H5 end 102, and can communicate with the server 103.
[0079] Based on this, please refer to Figure 2 , Figure 2An exemplary structural block diagram of an electronic device 300 provided by an embodiment of the present application is shown in FIG. 1. Figure 2 As shown in FIG. 1, the electronic device 300 includes a memory 301, a processor 302 and a communication interface 303, which are electrically connected to each other directly or indirectly to realize the transmission or interaction of data. For example, these elements can be electrically connected to each other through one or more communication buses or signal lines.
[0080] The memory 301 can be used to store software programs and modules, and the processor 302 can execute various functional applications and data processing by executing the software programs and modules stored in the memory 301. The communication interface 303 can be used for signaling or data communication with other node devices.
[0081] The memory 301 can be, but is not limited to, a random access memory (RAM), a read only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM) and the like.
[0082] The processor 302 can be an integrated circuit chip with signal processing capability. The processor 302 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP) and the like; or can be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.
[0083] Please refer to Figure 3 , Figure 3 A flowchart of a data communication method provided by an embodiment of the present application is shown in FIG. 2. As shown in FIG. 2, Figure 3As shown, the data communication method is applied to the applet client 101 in the communication system 100, the communication system 100 further comprises a server 103 and an H5 end 102, the applet client 101 is in communication connection with the server 103 and the H5 end 102, and the applet client 101 is provided with a WebView component.
[0084] The data communication method can comprise the following steps:
[0085] S210, obtaining a to-be-transmitted string based on to-be-transmitted data.
[0086] S220, encrypting the to-be-transmitted string to obtain an encrypted to-be-transmitted string.
[0087] S230, sending a data transmission request to the server, the data transmission request comprising the encrypted to-be-transmitted string and an identification ID representing the applet client.
[0088] S240, receiving an encrypted identification ID sent by the server based on the data transmission request, and splicing the encrypted identification ID on an HTTP link, so that the H5 end obtains the encrypted identification ID from the HTTP link of the WebView component, wherein the HTTP link is contained in a URL parameter of the WebView component.
[0089] The above steps realize the process that the to-be-transmitted data is encrypted, sent to the server together with the identification ID of the applet client, and the encrypted identification ID is obtained from the server for processing, so that the H5 end can obtain the encrypted identification ID.
[0090] S210 is a pre-processing process of the to-be-transmitted data, for example, the applet client serializes and converts the to-be-transmitted data in the onShow life cycle to obtain the to-be-transmitted string.
[0091] In the embodiment of the application, all to-be-transmitted data of the applet client is contained in an object structure, for example, if the to-be-transmitted data is: userId: 1, ticketName: 'abcde', token: 'aabbccdd', the object structure containing the to-be-transmitted data can be:
[0092] {
[0093] userId: 1,
[0094] ticketName: 'abcde',
[0095] token: 'aabbccdd'
[0096] }
[0097] The pre-processing of the data to be transmitted in the object structure can obtain the to-be-transmitted string {"userId": 1, "ticketName": "abcde", "token": "aabbccdd"}. After obtaining the to-be-transmitted string, the step S220 is executed to encrypt the to-be-transmitted string to obtain the encrypted to-be-transmitted string.
[0098] Specifically, the encryption of the to-be-transmitted string in the step S220 can be implemented based on a corresponding encryption algorithm or encryption rule. For example, the to-be-transmitted string can be reversed to obtain the encrypted to-be-transmitted string.
[0099] After the to-be-transmitted string is encrypted, the step S230 is executed to send a data transmission request containing the encrypted to-be-transmitted string and an identification ID representing the applet client to the server.
[0100] In the embodiment of the present application, after the server responds to the above data transmission request, the identification ID contained in the data transmission request is encrypted, and then the encrypted to-be-transmitted string contained in the data transmission request is stored in the Redis (Remote Dictionary Server, a database that can store data).
[0101] Further, after the identification ID is encrypted, the server generates a mapping relationship between the encrypted to-be-transmitted string and the encrypted identification ID, and stores the mapping list in the local cache after obtaining the mapping list. This process can ensure that the corresponding encrypted to-be-transmitted string can be queried based on the encrypted identification ID when the data needs to be queried.
[0102] After the server performs the above processing, the encrypted identification ID is sent to the applet client. After the applet client receives the encrypted identification ID sent by the server based on the data transmission request, the step S240 is executed to splice the encrypted identification ID on the HTTP link, so that the H5 end can obtain the encrypted identification ID from the HTTP link in the URL parameter of the WebView component, so that the H5 end can subsequently obtain the corresponding data from the server through the encrypted identification ID.
[0103] It should be noted that the above-mentioned WebView component is used to display a Web page, and the WebView component is built-in with a lightweight browser that can render HTML code, that is, can display and render web pages.
[0104] The data communication method provided by the embodiment of the present application is more secure, and the H5 service can safely and reliably undertake various core services in the mini-program environment.
[0105] Meanwhile, since the encrypted identifier ID is spliced on the HTTP link by the mini-program client, the H5 end can obtain the encrypted identifier ID from the HTTP link in the URL parameter of the WebView component, so that the H5 end can subsequently obtain corresponding data through the encrypted identifier ID. The data communication method does not need to consider the case that the data amount of the to-be-transmitted data is too large, and directly splicing the to-be-transmitted data on the HTTP link can cause the problem of HTTP Get request 414 error due to the long HTTP link.
[0106] Optionally, the process of obtaining the to-be-transmitted string based on the to-be-transmitted data in S210 is a process of converting the to-be-transmitted data to obtain the to-be-transmitted string, and the process can be implemented through the following steps:
[0107] Please refer to Figure 4 , Figure 4 Fig. 2 shows a flowchart of a data communication method provided by the embodiment of the present application, and S210 includes the following steps:
[0108] S211, serializing the to-be-transmitted data to obtain a serialized string.
[0109] S212, converting the serialized string into a base64 string data to obtain the to-be-transmitted string.
[0110] The above steps implement the conversion process of the to-be-transmitted data.
[0111] By way of example, based on the object structure containing the to-be-transmitted data described in the foregoing example, the step of converting the to-be-transmitted data in the object structure can be specifically described as follows:
[0112] Step 1: the to-be-transmitted data is JSON serialized by the mini-program client in the onShow life cycle to obtain a string data: '{"userId":1,"ticketName":"abcde","token":"aabbccdd"}', and the string is set as string J (i.e., step S211).
[0113] Step two, convert the string J into a base64 string data, and get the string: eyJ1c2VySWQiOjEsInRpY2tldE5hbWUiOiJhYmNkZSIsInRva2VuIjoiYWFiYmNjZGQifQ==, set the string as string B (i.e., step S212), and get the length of string B as L.
[0114] Optionally, the serialization conversion is a JSON serialization conversion.
[0115] Optionally, the process of encrypting the to-be-transmitted string in step S220 to obtain the encrypted to-be-transmitted string is a process of performing reverse encryption on the to-be-transmitted string to obtain the encrypted to-be-transmitted string, and the process can be implemented through the following steps:
[0116] Please refer to Figure 5 , Figure 5 FIG. 3 shows a flow diagram of a data communication method according to an embodiment of the present application, and FIG. 4 shows a flow diagram of a step of encrypting a to-be-transmitted string to obtain an encrypted to-be-transmitted string in step S220 of the data communication method.
[0117] S221, obtaining a preset integer value.
[0118] S222, segmenting the to-be-transmitted string according to the integer value to obtain a first string and a second string.
[0119] S223, adding the first string and the second string in reverse order to obtain a third string.
[0120] S224, performing reverse processing on the third string to obtain the encrypted to-be-transmitted string.
[0121] The above steps implement the process of performing reverse encryption on the to-be-transmitted string.
[0122] By way of example, based on the object structure containing to-be-transmitted data described in the foregoing example, after the to-be-transmitted data in the object structure is converted to obtain the to-be-transmitted string B: “eyJ1c2VySWQiOjEsInRpY2tldE5hbWUiOiJhYmNkZSIsInRva2VuIjoiYWFiYmNjZGQifQ==”, the step of performing reverse encryption on the to-be-transmitted string can be specifically described as follows:
[0123] Step one, obtaining a preset integer value N, and setting the value of N as 20 (i.e., step S221).
[0124] Step two, string B is divided into two segments, namely 0-N is the first segment B1, N-L is the second segment B2 (i.e., step S222).
[0125] Step three, the first segment B1, the second segment B2 is added in sequence, that is, a new string B2+B1 (i.e., step S223).
[0126] Step four, the new string B2+B1 is reversed, and the encrypted to-be-transmitted string RB is obtained, and the value of RB is "pRnIsEjOiQWSyV2c1Jye==QfiQGZjNmYiFWYiojIuV2avRnIsISZkNmYhJiOiUWbh5Edlt2Y" (i.e., step S224).
[0127] Optionally, the encrypted identifier ID is spliced on the HTTP link in the S240 step, so that the H5 end obtains the encrypted identifier ID from the HTTP link of the WebView component. The specific process can be implemented through the following steps:
[0128] Please refer to Figure 6 , Figure 6 Fig. 4 shows a flowchart of a data communication method provided by an embodiment of the application. The step of splicing the encrypted identifier ID on the HTTP link in the S240 step, so that the H5 end obtains the encrypted identifier ID from the HTTP link of the WebView component, comprises:
[0129] S241, the encrypted identifier ID is spliced on the HTTP link to obtain a spliced HTTP link.
[0130] S242, the spliced HTTP link is transmitted in the URL parameter of the WebView component, so that the H5 end obtains the encrypted identifier ID from the HTTP link of the WebView component.
[0131] The above steps realize the process of splicing the encrypted identifier ID as a parameter on the HTTP link to be accessed, so that the H5 end can obtain the parameter.
[0132] It should be noted that the above H5 end can be a webpage in the browser, that is, an H5 page, and the link is an HTTP link. If the encrypted identifier ID sent by the server based on the data transmission request is set as K, when the HTTP link spliced with K is transmitted in the URL parameter of the WebView component, the WebView component of the applet client starts to perform the rendering operation of the H5 page.
[0133] At this time, when the H5 page is loaded, the encrypted identification ID in the URL parameter will be obtained in the callback of document. ready (or any rendering completion event provided by the front-end framework), so that the H5 page can subsequently obtain the corresponding data from the server 103 through the encrypted identification ID.
[0134] In the embodiment of the application, the data communication method is also applied to the server 103 of the communication system 100, so that the server 103 encrypts the identification ID of the applet client 101 through the method, stores the to-be-transmitted data, and interacts with the applet client 101 and the H5 terminal 102. Therefore, the specific process of the method applied to the server 103 of the communication system 100 can be realized through the following steps:
[0135] Please refer to Figure 7 , Figure 7 Fig. 5 shows a flowchart of a data communication method provided by an embodiment of the application. The data communication method is applied to a server 103 of a communication system 100. The communication system 100 further includes an applet client 101 and an H5 terminal 102. The server 103 is in communication connection with the applet client 101 and the H5 terminal 102.
[0136] The above-mentioned data communication method can include the following steps:
[0137] S250, in response to the data transmission request sent by the applet client, wherein the data transmission request contains to-be-transmitted data and an identification ID representing the applet client.
[0138] S251, the identification ID is encrypted, and a mapping relationship between the encrypted identification ID and the to-be-transmitted data is generated to obtain a mapping list.
[0139] S252, the to-be-transmitted data is stored in Redis, and the mapping list is stored in the local cache.
[0140] S253, the encrypted identification ID is sent to the applet client, so that the applet client receives and processes the encrypted identification ID.
[0141] S254, in response to the data query request sent by the H5 terminal, wherein the data query request contains a to-be-queried identification ID representing the encrypted identification ID of the applet client.
[0142] S255, the to-be-transmitted data corresponding to the to-be-queried identification ID is sent to the H5 terminal.
[0143] The above steps achieve encryption of the identification ID of the applet client by the server, storage of the to-be-transmitted data, and interaction with the applet client and the H5 end.
[0144] Exemplarily, based on the object structure containing the to-be-transmitted data illustrated in the foregoing, the to-be-transmitted data in the object structure is subjected to conversion processing and reverse encryption processing to obtain a to-be-transmitted string RB: “pRnIsEjOiQWSyV2c1Jye==QfiQGZjNmYiFWYiojIuV2avRnIsISZkNmYhJiOiUWbh5Edlt2Y”, and the data transmission request sent by the applet client contains the to-be-transmitted string RB and the identification ID of the applet client, in which case:
[0145] Supposing that the identification ID of the applet client is U, the steps of encryption of the identification ID of the applet client by the server, storage of the to-be-transmitted data, and interaction with the applet client and the H5 end can be exemplarily described as follows:
[0146] Step one, the server responds to the data transmission request sent by the applet client, the data transmission request containing the to-be-transmitted string RB and U (i.e., step S250).
[0147] Step two, the server performs encryption processing on U contained in the data transmission request to obtain an encrypted identification ID, supposing that the encrypted identification ID is K, the server generates an object data structure, in which K and the to-be-transmitted string RB are in a one-to-one correspondence (i.e., a mapping relationship between K and the to-be-transmitted string RB is generated), to obtain a mapping list (i.e., step S251), so as to ensure that the to-be-transmitted string RB can be queried through K.
[0148] Step three, the server stores the to-be-transmitted string RB in Redis and stores the mapping list in the local cache (i.e., step S252), wherein the to-be-transmitted string RB is stored in Redis with a 5-minute expiration time, and the to-be-transmitted string RB will be deleted when the expiration time is exceeded.
[0149] Step four, K is sent to the applet client, so that the applet client receives and processes K (i.e., step S253).
[0150] In the embodiment of the application, when the H5 end sends a data query request to the server, the server responds to the data query request sent by the H5 end, the data query request containing a to-be-queried identification ID, the server uses the to-be-queried identification ID to find the corresponding to-be-transmitted data in the order of finding the local cache and finding Redis, and sends the to-be-transmitted data corresponding to the to-be-queried identification ID found to the H5 end (i.e., steps S254 and S255).
[0151] Optionally, the specific process that the server sends the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end in the S255 step can be implemented through the following steps:
[0152] Please refer to Figure 8 , Figure 8 Fig. 6 shows a flowchart of a data communication method provided by an embodiment of the application, and the step of sending the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end in the S255 step comprises the following steps:
[0153] S2551, determining whether the to-be-transmitted data corresponding to the to-be-queried identification ID exists in the local cache.
[0154] S2552, if yes, sending the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end.
[0155] S2553, if no, decrypting the to-be-queried identification ID.
[0156] S2554, in the case of successful decryption, querying the to-be-transmitted data corresponding to the to-be-queried identification ID in the mapping list of Redis, and sending the to-be-transmitted data corresponding to the to-be-queried identification ID to the H5 end.
[0157] If the decryption fails, a Fail response is directly returned.
[0158] The above steps implement the process that the server, after responding to the data query request of the H5 end, finds the to-be-transmitted data based on the to-be-queried identification ID contained in the data query request and sends the to-be-transmitted data to the H5 end.
[0159] Exemplarily, if the to-be-queried identification ID contained in the data query request of the H5 end is K, which is obtained by the H5 end from the HTTP link of the WebView component of the applet client, the steps that the server finds the to-be-transmitted data based on K contained in the data query request and sends the to-be-transmitted data to the H5 end can be specifically described as follows:
[0160] Step one, the server preferentially uses K to query the local cache, if the to-be-transmitted data corresponding to K is a string RB, which is queried from the local cache, the server does not query Redis any more, and sends the string RB to the H5 end (i.e., the step S2551 and the step S2552).
[0161] Step two, if the to-be-transmitted data corresponding to K is not queried from the local cache, K is decrypted (i.e., the step S2553).
[0162] If the decryption fails, it is indicated that K may be a request of a malicious attacker tampering with a mock, and a Fail response is directly returned.
[0163] If the decryption is successful, the K is used to query the corresponding to-be-transmitted data of the K in the mapping list of the Redis as a string RB, and the string RB is sent to the H5 end (i.e., step S2554).
[0164] It should be noted that, based on the above scheme, after the server sends the queried string RB to the H5 end, the H5 end will process the string RB according to the corresponding decoding rule to restore the to-be-transmitted data.
[0165] In the embodiment of the application, there is another more secure scheme to make the transmission of data from the service end to the H5 end by the final applet client more secure, which can be specifically described as follows:
[0166] After the service end queries the above-mentioned string RB, the service end will parse the string RB into plaintext data, and set the plaintext data as J. The service end will set J in the Cookie of the H5 end, and the Cookie will have Http-Only and Secure attributes to avoid being tampered with during data transmission. Based on the above setting, when the H5 end interacts with the service end, the H5 end will not actively transmit data to the service end, and the service end API will obtain the information transmitted by the applet client to the H5 end through the Cookie.
[0167] In the embodiment of the application, the data communication method is also applied to the H5 end 102 of the communication system 100, so that the H5 end 102 obtains an encrypted identifier ID from the HTTP link of the WebView component of the applet client 101 through the method, obtains data corresponding to the encrypted identifier ID through the service end 103 based on the encrypted identifier ID, and restores the data to to-be-transmitted data. Therefore, the specific process of the method applied to the H5 end 102 of the communication system 100 can be realized through the following steps:
[0168] Please refer to Figure 9 , Figure 9 Fig. 7 shows a flow diagram of a data communication method provided by an embodiment of the application, which is applied to the H5 end 102 of the communication system 100. The communication system 100 further includes an applet client 101 and a service end 103. The H5 end 102 is in communication connection with the applet client 101 and the service end 103. The applet client 101 is provided with a WebView component.
[0169] The above-mentioned data communication method can include the following steps:
[0170] S260, an encrypted identifier ID is obtained from the HTTP link of the WebView component, wherein the encrypted identifier ID represents an encrypted identifier ID of the applet client, and the HTTP link is contained in the URL parameter of the WebView component.
[0171] S261, sending a data query request based on the encrypted identifier ID to the server.
[0172] S262, receiving data corresponding to the encrypted identifier ID sent by the server based on the data query request.
[0173] S263, decoding the data to restore the data to the to-be-transmitted data.
[0174] The above steps realize the process that the H5 end obtains the encrypted identifier ID from the HTTP link of the WebView component of the applet client, obtains the data corresponding to the encrypted identifier ID through the server based on the encrypted identifier ID, and restores the data to the to-be-transmitted data.
[0175] It should be noted that the process that the H5 end receives the data corresponding to the encrypted identifier ID sent by the server based on the data query request and decodes the data is based on the scheme that the server directly sends the queried data to the H5 end in response to the data query request sent by the H5 end.
[0176] Therefore, the specific process that the H5 end decodes the data to restore the data to the to-be-transmitted data in the S263 step can be realized through the following steps:
[0177] Please refer to Figure 10 , Figure 10 Fig. 8 shows a flowchart of a data communication method provided by an embodiment of the application, and the step of decoding the data to restore the data to the to-be-transmitted data in the S263 step includes:
[0178] S2631, obtaining a preset integer value.
[0179] S2632, splitting the data according to the integer value to obtain a fourth string and a fifth string.
[0180] S2633, adding the fourth string and the fifth string in reverse order to obtain a sixth string.
[0181] S2634, performing reverse processing on the sixth string to obtain a Base64 string data.
[0182] S2635, Base64 decoding the Base64 string data to restore the data to the to-be-transmitted data.
[0183] The above steps realize the process that the H5 end decodes the data corresponding to the encrypted identifier ID received from the server to restore the data to the to-be-transmitted data.
[0184] The process of splitting the data and adding the reversed split strings in steps S2632 and S2633 is the same as the process of processing the to-be-transmitted string in steps S222 and S223 in the applet client, and thus will not be described again.
[0185] Further, after the Base64 string data obtained in step S2634 is decoded by Base64, the plaintext data obtained is the to-be-transmitted data. At this time, in order to further ensure the security of data transmission, the H5 end also needs to compress and obfuscate the front-end code to avoid malicious attackers querying the source code through Chrome DevTools (a set of web writing and debugging tools embedded in the Chrome browser) to analyze the code process of parsing the data corresponding to the encrypted identifier ID to the Base64 string data.
[0186] Based on the above data communication method, a communication system 100 is given below, wherein the communication system 100 includes an applet client 101, a server 103, and an H5 end 102, the applet client 101 is used to execute each flow step of steps S210 to S240, the server 103 is used to execute each flow step of steps S250 and S255, and the H5 end 102 is used to execute each flow step of steps S260 and S263 and achieve the corresponding technical effects.
[0187] Specifically, please refer to Figure 1 The communication system 100 includes an applet client 101, a server 103, and an H5 end 102.
[0188] The applet client 101 is used to execute the data communication method provided by steps S210 to S240.
[0189] The server 103 is used to execute the data communication method provided by steps S250 and S255.
[0190] The H5 end 102 is used to execute the data communication method provided by steps S260 and S263.
[0191] The applet client 101 and the H5 end 102 can be stored in the memory 301 shown in Figure 1 in the form of software or firmware (Firmware) or solidified in the operating system (Operating System, OS) of the electronic device 300, and can be executed by Figure 1The processor 302 in the terminal device 100 executes the program codes stored in the memory 301. At the same time, the data, program codes and the like required for executing the above-mentioned applet client 101 and H5 end 102 can be stored in the memory 301.
[0192] Based on the same inventive concept, the embodiments of the present application further provide a computer readable storage medium, which stores a computer program, and the computer program is executed by the processor 302 to implement the data communication method provided in the above-mentioned embodiments.
[0193] The steps executed by the computer program when running are not described here again, and can be referred to the above-mentioned explanation and description of the data communication method.
[0194] In the several embodiments provided by the present application, it should be understood that the disclosed system and method can be implemented in other ways. The system embodiments described above are only schematic. For example, the flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architectures, functions and operations of the methods and computer program products according to the embodiments of the present application. In this regard, each block in the flowcharts or block diagrams can represent a module, a segment or a portion of code which comprises one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur out of the order noted in the accompanying drawings. For example, two blocks shown in succession may, in fact, be executed substantially concurrently or in the reverse order, depending on the functionality involved. It will also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented by dedicated hardware-based systems which perform the specified functions or acts, or can be implemented by a combination of dedicated hardware and computer instructions.
[0195] The above descriptions are only the preferred embodiments of the present application, but not used to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A data communication method, characterized in that, A mini-program client is used in a communication system, which also includes a server and an H5 client. The mini-program client communicates with the server and the H5 client. The mini-program client is equipped with a WebView component. The method includes: The string to be transmitted is obtained based on the data to be transmitted; The string to be transmitted is encrypted to obtain an encrypted string to be transmitted; Send a data transmission request to the server. The data transmission request includes the encrypted string to be transmitted and an identifier ID representing the mini-program client. The system receives the encrypted identifier ID sent by the server based on the data transmission request, and appends the encrypted identifier ID to the HTTP link so that the H5 client can obtain the encrypted identifier ID from the HTTP link of the WebView component, wherein the HTTP link is included in the URL parameters of the WebView component.
2. The data communication method according to claim 1, characterized in that, The step of obtaining the string to be transmitted based on the data to be transmitted includes: The data to be transmitted is serialized to obtain a serialized string; The serialized string is converted into base64 string data to obtain the string to be transmitted.
3. The data communication method according to claim 2, characterized in that, The serialization is converted to JSON serialization.
4. The data communication method according to claim 2, characterized in that, The step of encrypting the string to be transmitted to obtain the encrypted string to be transmitted includes: Get the preset integer value; The string to be transmitted is divided according to the integer value to obtain a first string and a second string; The first string and the second string are added together in reverse order to obtain the third string, wherein the entire first string and the entire second string are added together in reverse order. The third string is reversed to obtain the encrypted string to be transmitted.
5. The data communication method according to claim 1, characterized in that, The step of appending the encrypted identifier ID to the HTTP link so that the H5 client can obtain the encrypted identifier ID from the HTTP link of the WebView component includes: The encrypted identifier ID is appended to the HTTP link to obtain the appended HTTP link; The concatenated HTTP link is passed into the URL parameter of the WebView component so that the H5 client can obtain the encrypted identifier ID from the HTTP link of the WebView component.
6. A data communication method, characterized in that, A server-side application for a communication system, the communication system also including a mini-program client and an H5 client, the server-side communicating with the mini-program client and the H5 client; The method includes: Responding to a data transmission request sent by the mini-program client, wherein the data transmission request includes data to be transmitted and an identifier ID representing the mini-program client; The identifier ID is encrypted, and a mapping relationship between the encrypted identifier ID and the data to be transmitted is generated to obtain a mapping list; The data to be transmitted is stored in Redis, and the mapping list is stored in a local cache; The encrypted identifier ID is sent to the mini-program client so that the mini-program client receives and processes the encrypted identifier ID. Responding to the data query request sent by the H5 client, wherein the data query request includes a query identifier ID, and the query identifier ID represents the encrypted identifier ID of the mini-program client; Send the data to be transmitted corresponding to the ID to be queried to the H5 terminal.
7. The data communication method according to claim 6, characterized in that, The step of sending the data to be transmitted corresponding to the query identifier ID to the H5 terminal includes: Determine whether the data to be transmitted corresponding to the query identifier ID exists in the Redis repository; If so, send the data to be transmitted corresponding to the ID to be queried to the H5 terminal; If not, decrypt the ID to be queried; If decryption is successful, query the data to be transmitted corresponding to the query identifier ID in the mapping list of the local cache, and send the data to be transmitted corresponding to the query identifier ID to the H5 terminal.
8. A data communication method, characterized in that, The H5 terminal is applied to a communication system, which also includes a mini-program client and a server. The H5 terminal communicates with the mini-program client and the server. The mini-program client is equipped with a WebView component. The method includes: Obtain the encrypted identifier ID from the HTTP link of the WebView component, wherein the encrypted identifier ID represents the identifier ID of the encrypted mini-program client, and the HTTP link is included in the URL parameters of the WebView component; A data query request is sent to the server based on the encrypted identifier ID; Receive the data corresponding to the encrypted identifier ID sent by the server based on the data query request; The data is decoded to restore it to the data to be transmitted.
9. The data communication method according to claim 8, characterized in that, The step of decoding the data to restore it to the data to be transmitted includes: Get the preset integer value; The data is divided according to the integer value to obtain the fourth string and the fifth string; The fourth and fifth strings are added together in reverse order to obtain the sixth string, wherein the fourth string as a whole and the fifth string in reverse order are added together. The sixth string is reversed to obtain Base64 string data; The Base64 string data is Base64 decoded to restore the data to be transmitted.
10. A communication system, characterized in that, This includes the mini-program client, server, and H5 platform; The mini-program client is used to execute the data communication method as described in any one of claims 1-5; The server is used to execute the data communication method as described in any one of claims 6-7; The H5 terminal is used to execute the data communication method as described in any one of claims 8-9.
Citation Information
Patent Citations
H5 page verification method and device
CN109299415A
Control parameter transmission method and device, client, electronic equipment and storage medium
CN114398568A