A method and terminal for restoring short links to long links

CN114692027BActive Publication Date: 2024-09-20FUJIAN TIANQUAN EDUCATION TECH LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202011591439.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-29
Publication Date
2024-09-20
Estimated Expiration
2040-12-29

AI Technical Summary

Technical Problem

但在实际应用中,往往又需要实现短链接还原为原来实际的长链接,做一些业务上的操作,比如判断该链接是否为合法链接,不合法就不进行跳转,但合法链接一般为长链接,此时,请求是一个跳转到合法长链接上的短链接的话,因为无法还原为长链接,就无法判断此次请求的合法性,从而会被认为是不合法的链接而不进行跳转,因此无法达到业务需求

Benefits of technology

[0016] The beneficial effect of the present invention is that: the present invention loads the short link by creating an iframe, thereby obtaining the long link corresponding to the short link through the src of the iframe, realizing the restoration of the short link into a long link, thereby satisfying the security legality judgment. , whitelisting, address filtering and other business requirements that require long links to achieve.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114692027B
    Figure CN114692027B
Patent Text Reader

Abstract

The present invention discloses a method and a terminal for restoring a short link into a long link. The present invention obtains a short link to be restored. An iframe is inserted into the body part of an HTML page, and a loading event of the iframe is monitored. The src attribute of the iframe is set to the short link to be restored, and the page of the iframe is loaded. When the loading event of the iframe is monitored to be that the page has been loaded, the src attribute of the iframe is obtained to obtain a long link corresponding to the short link to be restored. The present invention loads a page of a short link by creating an iframe, thereby obtaining a long link corresponding to the short link through the src of the iframe, and restoring the short link into a long link, thereby meeting business requirements such as security and legality judgment, whitelist and address filtering that require long links to achieve.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a method and a terminal for restoring a short link to a long link. Background Art

[0002] Because some applications have word count requirements for information release, we often need to convert long links into short links. Generating short links from long links generally requires the use of the md5 algorithm to generate a 32-bit signature string or a hexadecimal string bitwise AND operation, etc., because md5 and some algorithm bit operations are generally irreversible after generating short links. However, in actual applications, it is often necessary to restore short links to the original actual long links and perform some business operations, such as determining whether the link is a legal link. If it is not legal, no redirection will be performed. However, legal links are generally long links. At this time, if the request is a short link that jumps to a legal long link, because it cannot be restored to a long link, it is impossible to determine the legality of this request, and it will be considered an illegal link and will not be redirected, so it cannot meet business needs. Summary of the invention

[0003] The technical problem to be solved by the present invention is to provide a method and a terminal for restoring a short link to a long link, so as to realize restoring a short link to a long link, thereby meeting the needs of a specific service.

[0004] In order to solve the above technical problems, the technical solution adopted by the present invention is:

[0005] A method for restoring a short link to a long link, comprising:

[0006] S1. Obtain the short link to be restored;

[0007] S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe.

[0008] S3, setting the src attribute of the iframe to the short link to be restored, and loading the page of the iframe;

[0009] S4. When the loading event of the iframe is monitored to indicate that the page has been loaded, the src attribute of the iframe is obtained to obtain a long link corresponding to the short link to be restored.

[0010] In order to solve the above technical problems, another technical solution adopted by the present invention is:

[0011] A terminal for restoring a short link to a long link, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:

[0012] S1. Obtain the short link to be restored;

[0013] S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe.

[0014] S3, setting the src attribute of the iframe to the short link to be restored, and loading the page of the iframe;

[0015] S4. When the loading event of the iframe is monitored to indicate that the page has been loaded, the src attribute of the iframe is obtained to obtain a long link corresponding to the short link to be restored.

[0016] The beneficial effect of the present invention is that the present invention creates an iframe to load a short link page, thereby obtaining the long link corresponding to the short link through the src of the iframe, and realizing the restoration of the short link to the long link, thereby meeting the business requirements such as security and legality judgment, whitelist and address filtering that require long links to achieve. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] Figure 1 A flowchart of a method for restoring a short link to a long link according to an embodiment of the present invention;

[0018] Figure 2 This is a structural diagram of a terminal that restores a short link to a long link according to an embodiment of the present invention;

[0019] Figure 3 A specific flow chart of a method for restoring a short link to a long link according to an embodiment of the present invention;

[0020] Description of labels:

[0021] 1. A terminal for restoring a short link to a long link; 2. A processor; 3. A memory. DETAILED DESCRIPTION

[0022] In order to explain the technical content, achieved objectives and effects of the present invention in detail, the following is an explanation in combination with the implementation modes and the accompanying drawings.

[0023] Please refer to Figure 1 as well as Figure 3 , a method for restoring a short link to a long link, comprising:

[0024] S1. Obtain the short link to be restored;

[0025] S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe.

[0026] S3, setting the src attribute of the iframe to the short link to be restored, and loading the page of the iframe;

[0027] S4. When the loading event of the iframe is monitored to indicate that the page has been loaded, the src attribute of the iframe is obtained to obtain a long link corresponding to the short link to be restored.

[0028] From the above description, it can be seen that the beneficial effect of the present invention is that: the present invention creates an iframe to load a short link page, thereby obtaining the long link corresponding to the short link through the src of the iframe, and realizing the restoration of the short link to the long link, thereby meeting the business requirements that require long links to achieve, such as security and legality judgment, whitelist and address filtering.

[0029] Furthermore, the page loading of the iframe in step S3 is specifically performed as follows:

[0030] Access the short link to be restored, receive the returned long link and redirect to the long link to load the page.

[0031] As can be seen from the above description, when accessing the short link to be restored, the third-party server will return the long link corresponding to the short link to redirect to the long link page, thereby changing the src attribute of the iframe to the long link.

[0032] Furthermore, the width and height of the iframe are 1 pixel respectively.

[0033] From the above description, it can be seen that setting the width and height of the iframe to one pixel ensures that the browser will not ignore the loading of the iframe, but will not let the user see the iframe and affect the user's operation.

[0034] Furthermore, when there are multiple short links to be restored in step S1, the processing methods of steps S2 to S4 are performed on each short link to be restored at the same time.

[0035] It can be seen from the above description that when there are multiple short links to be restored, multiple restoration steps can be started simultaneously to ensure the restoration speed.

[0036] Furthermore, when there are multiple short links to be restored in step S1, the processing method of steps S2 to S4 is performed on one of the short links to be restored. After step S4 is completed, the process returns to step S2 to process the next short link to be restored until all the short links to be restored are processed.

[0037] It can be seen from the above description that when there are multiple short links to be restored, they can be restored one by one to reduce resource usage.

[0038] Please refer to Figure 2 , a terminal for restoring a short link to a long link, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:

[0039] S1. Obtain the short link to be restored;

[0040] S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe.

[0041] S3, setting the src attribute of the iframe to the short link to be restored, and loading the page of the iframe;

[0042] S4. When the loading event of the iframe is monitored to indicate that the page has been loaded, the src attribute of the iframe is obtained to obtain a long link corresponding to the short link to be restored.

[0043] From the above description, it can be seen that the beneficial effect of the present invention is that: the present invention creates an iframe to load a short link page, thereby obtaining the long link corresponding to the short link through the src of the iframe, and realizing the restoration of the short link to the long link, thereby meeting the business requirements that require long links to achieve, such as security and legality judgment, whitelist and address filtering.

[0044] Furthermore, the page loading of the iframe in step S3 is specifically performed as follows:

[0045] Access the short link to be restored, receive the returned long link and redirect to the long link to load the page.

[0046] As can be seen from the above description, when accessing the short link to be restored, the third-party server will return the long link corresponding to the short link to redirect to the long link page, thereby changing the src attribute of the iframe to the long link.

[0047] Furthermore, the width and height of the iframe are 1 pixel respectively.

[0048] From the above description, it can be seen that setting the width and height of the iframe to one pixel ensures that the browser will not ignore the loading of the iframe, but will not let the user see the iframe and affect the user's operation.

[0049] Furthermore, when the processor executes the computer program, if there are multiple short links to be restored in step S1, the processing methods of steps S2 to S4 are performed on each short link to be restored at the same time.

[0050] It can be seen from the above description that when there are multiple short links to be restored, multiple restoration steps can be started simultaneously to ensure the restoration speed.

[0051] Furthermore, when the processor executes the computer program, when there are multiple short links to be restored in step S1, steps S2 to S4 are performed on one of the short links to be restored, and after step S4 is completed, the processor returns to step S2 to process the next short link to be restored until all short links to be restored are processed.

[0052] It can be seen from the above description that when there are multiple short links to be restored, they can be restored one by one to reduce resource usage.

[0053] Please refer to Figure 1 as well as Figure 3 , Embodiment 1 of the present invention is:

[0054] In this embodiment, teachers and students conduct remote teaching. We preset a whitelist of shareable domain names on the teacher side. Only domain names in the whitelist can be shared, and domain names not in the whitelist cannot be shared. In this embodiment, there is only the domain name https: / / www.101.com in the whitelist. When the domain name entered by the teacher to share is https: / / www.101.com, it can be shared and passed normally. If the teacher needs to share a short link of https: / / www.101.com, such as https: / / 4m.cn / CFRXL, the domain name is obviously not https: / / www.101.com, but it jumps to the short link address of https: / / www.101.com. However, according to normal logic, it is impossible to judge whether it can be shared, so it is necessary to execute the following method to parse it and make a judgment.

[0055] A method for restoring a short link to a long link, comprising:

[0056] S1. Obtain the short link to be restored;

[0057] S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe.

[0058] The width and height of the iframe are 1 pixel respectively;

[0059] S3, setting the src attribute of the iframe to the short link to be restored, and loading the page of the iframe;

[0060] The page loading of the iframe in step S3 is specifically performed as follows:

[0061] Access the short link to be restored, receive the returned long link and redirect to the long link to load the page;

[0062] In this embodiment, the program automatically obtains the short link to be restored https: / / 4m.cn / CFRXL, creates an iframe with a width and height of 1 pixel, and the ID is analyzeShortUrl, appends it to the body of the html, listens to the onload event of the iframe, and sets the src of the iframe to https: / / 4m.cn / CFRXL. The body is a necessary element of the html page, indicating the page content; the src attribute of the iframe is an attribute of the iframe element in html, indicating the URL of the content displayed in the iframe.

[0063] In this embodiment, after the src of the iframe is set to https: / / 4m.cn / CFRXL, the page of the iframe will be loaded and an access request will be sent to the third-party server corresponding to https: / / 4m.cn / CFRXL. The third-party server obtains the corresponding long link https: / / www.101.com from their server according to the hash value of the short link and returns it. At this time, the iframe will redirect the returned long link https: / / www.101.com, and the src of the iframe will automatically become https: / / www.101.com.

[0064] S4. When the loading event of the iframe is monitored as page loading, the src attribute of the iframe is obtained to obtain a long link corresponding to the short link to be restored;

[0065] In this embodiment, when the callback of the onload event is monitored, the src of the iframe is obtained, that is, the long link https: / / www.101.com of https: / / 4m.cn / CFRXL is obtained. The src of the iframe can be obtained by executing document.getElementById("analyzeShortUrl").src.

[0066] In this embodiment, after obtaining the long link, it can be searched in the whitelist according to the long link https: / / www.101.com, and it can be determined whether it is legal and can be shared with students.

[0067] When there are multiple short links to be restored in step S1, the processing methods of steps S2 to S4 are performed on each short link to be restored at the same time;

[0068] When there are multiple short links to be restored in step S1, the processing method of steps S2 to S4 is performed on one of the short links to be restored. After step S4 is completed, the process returns to step S2 to process the next short link to be restored until all the short links to be restored are processed.

[0069] When there are multiple short links to be restored, you can create multiple iframes for concurrent parsing, or you can create only one iframe to parse the short links one by one.

[0070] Please refer to Figure 2 , Embodiment 2 of the present invention is:

[0071] A terminal 1 for restoring a short link to a long link comprises a processor 2, a memory 3 and a computer program stored in the memory 3 and executable on the processor 2. When the processor 2 executes the computer program, the steps in the above embodiment 1 are implemented.

[0072] In summary, the present invention provides a method and terminal for restoring a short link to a long link. By creating an iframe to load the short link page, the long link corresponding to the short link is obtained through the src of the iframe, and the short link is restored to the long link, thereby meeting the business requirements of security and legality judgment, whitelist and address filtering that require long links to achieve; the present invention sets the length and width of the iframe to one pixel, which ensures that the browser will not ignore the loading of the iframe and will not affect the user's operation; and the present invention provides two solutions for restoring multiple short links, which can be selected according to needs.

[0073] The above descriptions are merely embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent transformations made using the contents of the present invention's specification and drawings, or directly or indirectly applied in related technical fields, are also included in the patent protection scope of the present invention.

Claims

1. A method for restoring a short link to a long link, characterized in that: include: S1. Obtain the short link to be restored; S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe. S3, setting the src attribute of the iframe to the short link to be restored, accessing the short link to be restored, receiving the long link returned by the third-party server and redirecting to the long link to load the page, thereby changing the src attribute of the iframe to the long link; S4. When the loading event of the iframe is monitored to be that the page has been loaded, the src attribute of the iframe is obtained, the long link corresponding to the short link to be restored is obtained, and the long link is judged according to the demand.

2. A method for restoring a short link to a long link according to claim 1, characterized in that: The width and height of the iframe are 1 pixel respectively.

3. A method for restoring a short link to a long link according to claim 1, characterized in that: When there are multiple short links to be restored in step S1, the processing methods of steps S2 to S4 are performed on each short link to be restored at the same time.

4. A method for restoring a short link to a long link according to claim 1, characterized in that: When there are multiple short links to be restored in step S1, the processing method of steps S2 to S4 is performed on one of the short links to be restored. After step S4 is completed, the process returns to step S2 to process the next short link to be restored until all the short links to be restored are processed.

5. A terminal for restoring a short link to a long link, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the following steps are implemented: S1. Obtain the short link to be restored; S2. Insert an iframe into the body of the HTML page and listen for the loading event of the iframe. S3, setting the src attribute of the iframe to the short link to be restored, accessing the short link to be restored, receiving the long link returned by the third-party server and redirecting to the long link to load the page, thereby changing the src attribute of the iframe to the long link; S4. When the loading event of the iframe is monitored to be that the page has been loaded, the src attribute of the iframe is obtained, the long link corresponding to the short link to be restored is obtained, and the long link is judged according to the demand.

6. A terminal for restoring a short link to a long link according to claim 5, characterized in that: The width and height of the iframe are 1 pixel respectively.

7. A terminal for restoring a short link to a long link according to claim 5, characterized in that: When the processor executes the computer program, if there are multiple short links to be restored in step S1, the processing methods of steps S2 to S4 are performed on each short link to be restored at the same time.

8. A terminal for restoring a short link to a long link according to claim 5, characterized in that: When the processor executes the computer program, when there are multiple short links to be restored in step S1, the processing method of steps S2 to S4 is performed on one of the short links to be restored, and after step S4 is completed, the processor returns to step S2 to process the next short link to be restored until all the short links to be restored are processed.

Citation Information

Patent Citations

  • Video playing method, apparatus and computer-readable storage medium

    CN109068153A

  • Short link skipping method and device, short link server and storage medium

    CN109918586A

  • Page access method and device

    CN110569464A

  • Short link generation method and device and server

    CN111026985A

  • Short link processing to improve service efficiency

    US20180307773A1