Micro-blog address URL (ID) and mid to convert to Java version

Source: Internet
Author: User

Principle:

The URL of Sina Weibo is as follows: Http://weibo.com/2480531040/z8ElgBLeQ such three parts.

The first part (green part) is the domain name of Sina Weibo, the second part (red part) is the blogger Uid, the third part (blue) is a string of seemingly random strings.

If the method can calculate the blue string and the returned array in the corresponding relationship is much better solved.

First group the blue string, 4 characters from the forward, and then the following three groups of characters are obtained:
Z
8Elg
Bleq

The numbers that are converted to 62 are 35, 2061702, 8999724 and they are grouped together to be a string of 3520617028999724 similar strings.

By discovering a field in the returned two-dimensional array that has a [mid], the return result is 3520617028999724. just the corresponding.

Http://weibo.com/aj/v6/mblog/info/big?ajwvr=6&id=3919740416635598&page=1

 Packagestep0;/*** * @ClassName: mid2idutil java version * @Description: Sina uid forwarding URL (ID to mid) *@authorZeze * @date April 10, 2016 morning 10:49:40 **/ Public classId2midutil { Public Static voidMain (string[] args) {System.out.println (Uid2mid ("Aw8wrzaes")); System.out.println (Mid2uid ("3676608718380816"));//Mid2id    }    Private StaticString[] Str62keys = {"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", "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" };  Public Staticstring IntToEnode62 (Integer int10) {string S62= ""; intR = 0;  while(Int10! = 0) {R= int10% 62; S62= Str62keys[r] +S62; Int10= (int) Math.floor (int10/62.0); }        returnS62; }         //62 binary into 10 binary     Public Staticstring Str62toint (String str62) {Longi64 = 0;  for(inti = 0; I < str62.length (); i++)        {            LongVi = (Long) Math.pow (Str62.length ()-i-1)); String T= Str62.substring (i,i+1); I64+ = Vi *FindIndex (t); }       //System.out.println (i64);        returnlong.tostring (i64); }         Public Static intFindIndex (String t) {intIndex=0;  for(inti=0;i<str62keys.length;i++)        {            if(Str62keys[i].equals (t)) {index=i;  Break; }        }        returnindex; }       Public Staticstring Uid2mid (string mid) {string id= "";  for(inti = Mid.length ()-4; i >-4; i = i-4)//read URL characters from the last forward with 4 bytes for a group            {                intOffset1 = i < 0? 0: i; intLen = i < 0? Mid.length ()% 4:4; String Str= Mid.substring (Offset1, offset1+Len); //System.out.println (offset1+ "" +len+ "" +str ");Str=str62toint (str); if(Offset1 > 0)//if it is not the first group, it will be less than 7 bit 0                {                     while(Str.length () < 7) {str= "0" +str; }} ID= str +ID; }            returnID; }             Public Staticstring Mid2uid (String str10) {string Mid= ""; intCount = 1 ;  for(inti = Str10.length ()-7; i >-7; i = i-7)//read characters from the last forward with 7 bytes in a group        {            intoffset = i < 0? 0: i; intLen = i < 0? Str10.length ()% 7:7; String Temp= str10.substring (offset, offset +Len); String URL=IntToEnode62 (integer.valueof (temp)); if(count!=3) {//Z XGHM uxym generated links from right to left first 2 groups, 4 bits a group, less than 4 bits of complement 0                 for(intJ=0;j<4-url.length (); j + +) {URL= "0" +URL; }} Mid= url+mid; Count++; }        returnmid; }}

Micro-blog address URL (ID) and mid to convert to Java version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.