java高仿新浪微博短連結地址產生工具ShortUrlGenerator.java,新浪微博二維碼產生
原文:仿新浪微博 短連結地址產生工具 ShortUrlGenerator.java
原始碼:http://www.zuidaima.com/share/1550463378934784.htm
仿新浪微博 短連結地址產生工具
ShortUrlGenerator.java
String sLongUrl = "http://www.zuidaima.com/share/1550463378934784.htm"; // 3BD768E58042156E54626860E241E999
String[] aResult = shortUrl(sLongUrl);
// 列印出結果
for (int i = 0; i < aResult.length; i++) {
System.out.println("[" + i + "]:::" + aResult[i]);
}
///// 控制台輸出如下: [0]:::7nUFJn [1]:::f6Zzy2 [2]:::j6jmQb [3]:::2eAjea
/* * Copyright 2012-2013 The Haohui Network Corporation */package com.zuidaima.haohui.common.utils;/** * @project baidamei * @author cevencheng <cevencheng@gmail.com> www.zuidaima.com * @create 2012-11-10 上午1:15:05 */public class ShortUrlGenerator {/** * @param args */public static void main(String[] args) {// 長串連: http://www.zuidaima.com/share/1550463378934784.htm// 新浪解析後的短連結為: http://t.cn/h1jGSCString sLongUrl = "http://www.zuidaima.com/share/1550463378934784.htm"; // 3BD768E58042156E54626860E241E999String[] aResult = shortUrl(sLongUrl);// 列印出結果for (int i = 0; i < aResult.length; i++) {System.out.println("[" + i + "]:::" + aResult[i]);}}public static String[] shortUrl(String url) {// 可以自訂產生 MD5 加密字元傳前的混合 KEYString key = "wuguowei";// 要使用產生 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"};// 對傳入網址進行 MD5 加密//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++) {// 把加密字元按照 8 位一組 16 進位與 0x3FFFFFFF 進行位與運算String sTempSubString = hex.substring(i * 8, i * 8 + 8);// 這裡需要使用 long 型來轉換,因為 Inteper .parseInt() 只能處理 31 位 , 首位為符號位 , 如果不用// long ,則會越界long lHexLong = 0x3FFFFFFF & Long.parseLong(sTempSubString, 16);String outChars = "";for (int j = 0; j < 6; j++) {// 把得到的值與 0x0000003D 進行位與運算,取得字元數組 chars 索引long index = 0x0000003D & lHexLong;// 把取得的字元相加outChars += chars[(int) index];// 每次迴圈按位右移 5 位lHexLong = lHexLong >> 5;}// 把字串存入對應索引的輸出數組resUrl[i] = outChars;}return resUrl;}}
高仿Iphone4可以下載新浪微部落格戶端?此iphone支援20平台與JAR格式、JAVA 怎下載?
在新浪網找手機應用,在裡面就有手機軟體,或者你可以直接百度新浪微部落格戶端手機版,找JAR格式的程式。