通过微博图片url反推得到博主的主页

url的生成规则

在v2ex发现了一个帖子

代码

于是,我写了一个根据url反推博主主页的小工具 WeiboHack

public class WeiBoHack {

    public static String getIndexPage(String picUrl) {
        String fileName = picUrl.substring(picUrl.lastIndexOf("/") + 1, picUrl.lastIndexOf("."));
        if (fileName.startsWith("00")) {
            String front8Letter = fileName.substring(0, 8);
            long uuid = Base62Utils.decodeBase62(front8Letter);
            return appendUUID(uuid);
        } else {
            String front8Letter = fileName.substring(0, 8);
            long uuid = Long.valueOf(front8Letter, 16);
            return appendUUID(uuid);
        }
    }

    private static String appendUUID(long uuid) {
        return "https://weibo.com/u/" + uuid;
    }
}

Base62Utils 的工具类代码如下

public class Base62Utils {

    private static final String base62Char = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

    public static long decode(String str) {
        char[] chars = new StringBuilder(str).reverse().toString().toCharArray();
        long count = 1;
        long result = 0;
        for (char aChar : chars) {
            result += base62Char.indexOf(aChar) * count;
            count *= 62;
        }
        return result;
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,198评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,982评论 25 708
  • 文/纪镇涛 那一年,我家养了一只猫,它眼睛有点蓝,条纹灰色毛,简直就是一只小老虎。家人...
    纪镇涛阅读 509评论 0 3