Original: Sina Weibo short link address generation tool Shorturlgenerator.java
Source code: Http://www.zuidaima.com/share/1550463378934784.htm
Imitation Sina Weibo short link address generation tool
Shorturlgenerator.java
String Slongurl = "http://www.zuidaima.com/share/1550463378934784.htm"; 3bd768e58042156e54626860e241e999
string[] Aresult = Shorturl (Slongurl);
Print out results
for (int i = 0; i < aresult.length; i++) {
System.out.println ("[" + i + "]:::" + aresult[i]);
}
The console output is as follows: [0]:::7NUFJN [1]:::f6zzy2 [2]:::J6JMQB] [3]:::2eajea
/* Copyright 2012-2013 the Haohui Network Corporation */package com.zuidaima.haohui.common.utils;/** * @project Baida Mei * @author Cevencheng <[email protected]> www.zuidaima.com * @create 2012-11-10 a.m. 1:15:05 */public class Sho Rturlgenerator {/** * @param args */public static void main (string[] args) {//Long connection: http://www.zuidaima.com/share/15504633 78934784.htm//Sina After the analysis of the short link is: http://t.cn/h1jGSCString slongurl = "Http://www.zuidaima.com/share/1550463378934784.htm" ; 3bd768e58042156e54626860e241e999string[] Aresult = Shorturl (Slongurl);//print out the result for (int i = 0; i < aresult.length; i+ +) {System.out.println ("[" + i + "]:: (:" + aresult[i]);}} public static string[] Shorturl (String URL) {//can be customized to generate MD5 encryption word Nginx before the hybrid keystring key = "Wuguowei";//To use the character that generated the URL string[] chars = new string[] {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "s", "T", "U", "V", "w", "X", "Y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C","D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};//to the incoming URL For MD5 encryption//string Smd5encryptresult = (new Cmyencrypt ()). GETMD5OFSTR (key + URL); String Smd5encryptresult = md5.md5encode (key + URL); String hex = Smd5encryptresult; string[] Resurl = new String[4];for (int i = 0; i < 4; i++) {//encrypts characters according to 8 bits a set of 16 binary and 0X3FFFFFFF bitwise AND Operation String STEMPSUBST Ring = hex.substring (i * 8, I * 8 + 8);//This needs to be converted by a long type, because Inteper. parseint () can only handle 31 bits, the first is the sign bit, if not//long, it will cross the LO ng Lhexlong = 0x3fffffff & Long.parselong (stempsubstring, 16); String outchars = ""; for (int j = 0; J < 6; J + +) {//0x0000003d the resulting value and operation, get the character array chars indexed long index = 0x0000003d & lhexlong;//Add the acquired characters Outchars + = chars[(int) index];//Each loop bitwise right SHIFTS 5 bits Lhexlong = Lhexlong >> 5;} The output array in which the string is stored in the corresponding index resurl[i] = outchars;} return resurl;}}
Java high imitation Sina Weibo short link address generation tool Shorturlgenerator.java