Search

CN-116738085-B - Short link generation method, device and medium

CN116738085BCN 116738085 BCN116738085 BCN 116738085BCN-116738085-B

Abstract

The invention discloses a method, equipment and a medium for generating a short link, which comprises the steps of inquiring whether a corresponding long-short link mapping relation exists in a database according to a long link, returning the short link according to the long-short link mapping relation if the corresponding long-short link mapping relation exists, converting the long link into a short link code according to a short link code generation rule and a table dropping rule if the short link mapping relation does not exist, inquiring whether a record of the short link code exists in the database according to the short link code, determining that the short link is successfully generated according to the short link code, storing the long link and the short link code into the database and returning the short link to a calling party, adding m-bit random numbers at the tail of the long link if the short link exists, and continuously repeating the steps 2-4 based on the new long link until the short link is successfully generated. The invention solves the problems of poor short link performance, easy data leakage, lack of data life cycle management and the like in the prior art.

Inventors

  • CHEN HAO
  • ZHOU RAN
  • WU HANXUE

Assignees

  • 中国人民财产保险股份有限公司

Dates

Publication Date
20260512
Application Date
20230529

Claims (9)

  1. 1. A method for generating a short link, comprising: step 1, inquiring whether a corresponding long-short link mapping relation exists in a database according to a long link, and returning a short link according to the long-short link mapping relation if the corresponding long-short link mapping relation exists; Step 2, if not, converting the long link into a short link code according to a short link code generation rule and a table falling rule, wherein the method specifically comprises the steps of carrying out hash on the long link based on MurmurHash algorithm to obtain a hash value, carrying out Base62 coding on the hash value, determining a character string with the length of six bits and 62 system as the first 6 bits of the short link code, inquiring a service field routing table according to a short link to short link request, determining a short link storage table identifier, positioning a year vernier table according to the short link storage table identifier and the table falling rule, and splicing the last bit of the table name of the year vernier table with the first 6 bits of the short link code to obtain a 7-bit short link code; Step 3, inquiring whether the record of the short link code exists in the database according to the unique index of the short link code; Step 4: if not, generating a short link according to the short link code, determining that the short link is successfully generated, storing the long link and the short link code into the database, and returning the short link to a calling party; And 4.2, if the new long-chain link exists, adding an m-bit random number to the tail of the long-chain link to generate a new long-chain link, and continuously repeating the steps 2-4 based on the new long-chain link until the short-chain link is successfully generated.
  2. 2. The method according to claim 1, wherein the method further comprises: and when the repetition times exceed a preset value n, returning short link generation failure information.
  3. 3. The method according to claim 1, wherein the positioning the year cursor table according to the short link storage table identifier and the table falling rule specifically comprises: determining a short link storage table to which the short link belongs according to the short link storage table identifier; determining a year table to which the short link belongs in the short link storage table according to the current year; Acquiring a value in a key value pair according to a request ID in the long-link-to-short-link request; And positioning a year vernier list to which the short link belongs in the year list according to the value.
  4. 4. The method of claim 1, wherein prior to storing the long link and the short link code in the database, the method further comprises: dividing a short link storage list in the same service field into 36 year vernier lists; dividing the 36 year vernier tables into 6 parts, wherein each part is a year table which needs to be operated for the corresponding year; and marking the last bit of the table name of the 36 year vernier tables with A-Z and 0-9 respectively.
  5. 5. The method according to claim 3, wherein the determining the year table to which the short link in the short link storage table belongs according to the current year specifically includes: taking the life cycle time of each short link storage table as a remainder; Taking the online year of the product system as the reduced number; the years of the year table is determined according to the following formula: Years = ((current year-reduced number)% remainder) +1 And determining a year table according to the years of the years.
  6. 6. The method of claim 3, wherein the positioning the year cursor table to which the short link belongs in the year table according to the value specifically includes: Triggering the current value in the key value pair to carry out self-increment according to the long-link-short-link request ID to obtain a self-increment value; The position of the year cursor table is determined according to the following formula: N value=value% 6+1 of the N Zhang Nianfen th cursor table; and positioning the year vernier list according to the N value.
  7. 7. The method according to claim 1, wherein the generating a short link according to the short link code specifically comprises: Acquiring a short link prefix path of the service domain, which is the same as the short link code, in a service domain routing table; and splicing the short link code and the short link prefix path to obtain a short link.
  8. 8. A short link generation apparatus, comprising: at least one processor, and A memory communicatively coupled to the at least one processor via a bus, wherein, The memory stores instructions executable by the at least one processor to implement: step 1, inquiring whether a corresponding long-short link mapping relation exists in a database according to a long link, and returning a short link according to the long-short link mapping relation if the corresponding long-short link mapping relation exists; Step 2, if not, converting the long link into a short link code according to a short link code generation rule and a table falling rule, wherein the method specifically comprises the steps of carrying out hash on the long link based on MurmurHash algorithm to obtain a hash value, carrying out Base62 coding on the hash value, determining a character string with the length of six bits and 62 system as the first 6 bits of the short link code, inquiring a service field routing table according to a short link to short link request, determining a short link storage table identifier, positioning a year vernier table according to the short link storage table identifier and the table falling rule, and splicing the last bit of the table name of the year vernier table with the first 6 bits of the short link code to obtain a 7-bit short link code; Step 3, inquiring whether the record of the short link code exists in the database according to the unique index of the short link code; Step 4: if not, generating a short link according to the short link code, determining that the short link is successfully generated, storing the long link and the short link code into the database, and returning the short link to a calling party; And 4.2, if the new long-chain link exists, adding an m-bit random number to the tail of the long-chain link to generate a new long-chain link, and continuously repeating the steps 2-4 based on the new long-chain link until the short-chain link is successfully generated.
  9. 9. A non-volatile storage medium storing computer executable instructions, wherein the computer executable instructions are executed by a processor to perform the steps of: step 1, inquiring whether a corresponding long-short link mapping relation exists in a database according to a long link, and returning a short link according to the long-short link mapping relation if the corresponding long-short link mapping relation exists; Step 2, if not, converting the long link into a short link code according to a short link code generation rule and a table falling rule, wherein the method specifically comprises the steps of carrying out hash on the long link based on MurmurHash algorithm to obtain a hash value, carrying out Base62 coding on the hash value, determining a character string with the length of six bits and 62 system as the first 6 bits of the short link code, inquiring a service field routing table according to a short link to short link request, determining a short link storage table identifier, positioning a year vernier table according to the short link storage table identifier and the table falling rule, and splicing the last bit of the table name of the year vernier table with the first 6 bits of the short link code to obtain a 7-bit short link code; Step 3, inquiring whether the record of the short link code exists in the database according to the unique index of the short link code; Step 4: if not, generating a short link according to the short link code, determining that the short link is successfully generated, storing the long link and the short link code into the database, and returning the short link to a calling party; And 4.2, if the new long-chain link exists, adding an m-bit random number to the tail of the long-chain link to generate a new long-chain link, and continuously repeating the steps 2-4 based on the new long-chain link until the short-chain link is successfully generated.

Description

Short link generation method, device and medium Technical Field The present invention relates to the field of link conversion, and in particular, to a method, an apparatus, and a medium for generating a short link. Background In normal browsing of internet content, if a browser is used, the browser displays one or a short or longer address in the address bar of each web page. Such addresses are commonly referred to as links, or may also be referred to as long links. In the HTTP protocol specification, the links are not limited in length, but most browsers and web servers specify the requested link length. In some scenarios, the use of long links may catch the fly and even fail to use. For example, in the field of short messages, when a mobile phone short message is used for marketing activities, an active link is required to be sent to a target user through the short message, and too long links occupy too much short message content to cause too long total short message content, and each short message has maximum length limitation due to the limitation of international standards, and if the length is too long, the sending fails or is divided into multiple sending. For example, as the development of similar social media of microblogs is increased, more people like to sound on the social media, but the microblogs limit the length of single blog content sent by users in early stages, so that the problem of overlong content occurs when the users share other links by using the microblogs. It is desirable to solve the above-mentioned problems by converting long links into short links, making the links appear more concise, and improving the user experience. The method for generating short links by using the long links is generally as follows: 1. The method comprises the steps of generating a short link by a single Hash function, namely, carrying out Hash calculation on a long link by utilizing a single Hash algorithm such as MD5 and the like to obtain a Hash value, then carrying out Base64 coding on the Hash value, intercepting bits according to the short link required length, taking the short link, and storing the corresponding relation of the long link and the short link in a database. 2. Self-growing short links, namely, a self-growing secondary system natural number is maintained, then the natural number Base64 is encoded to obtain a series of short links, and the corresponding relation of the long and short links is stored in a database. The main disadvantages of the prior art are as follows: 1. the Hash collision rate calculated by the MD5 and other single Hash algorithms is high, the random distribution characteristics are poor, the generated short link repetition rate is high, and if repeated, the problem can be solved only by repeated calling, and the performance is poor. 2. Short links generated by the self-growing algorithm are blind-guessed and predictable, and part of customer information is displayed by the final access page of part of the short links, so that the risk of data leakage of the customer information is caused. 3. For data management of the corresponding relation of long and short link data, lack of data life cycle management indirectly results in higher repetition rate of short links. Disclosure of Invention The invention provides a short link generation method, short link generation equipment and a short link generation medium, which solve the problems of poor short link performance, easy data leakage, lack of data life cycle management and the like in the prior art. A short link generation method includes: step 1, inquiring whether a corresponding long-short link mapping relation exists in a database according to a long link, and returning a short link according to the long-short link mapping relation if the corresponding long-short link mapping relation exists; Step 2, if not, converting the long link into a short link code according to a short link code generation rule and a table falling rule; Step 3, inquiring whether records of the short link codes exist in the database according to the short link codes; Step 4: if not, generating a short link according to the short link code, determining that the short link is successfully generated, storing the long link and the short link code into the database, and returning the short link to a calling party; And 4.2, if the new long-chain link exists, adding an m-bit random number to the tail of the long-chain link to generate a new long-chain link, and continuously repeating the steps 2-4 based on the new long-chain link until the short-chain link is successfully generated. In one embodiment of the invention, the long link is converted into a short link code according to a short link code generation rule, and the method specifically comprises the steps of carrying out hash on the long link based on MurmurHash algorithm to obtain a hash value, carrying out Base62 coding on the hash value, determining a 62-bit character string with the length o