|
- package tide.juyun.com.utils;
- import java.io.UnsupportedEncodingException;
- import java.security.MessageDigest;
- import java.util.ArrayList;
- import java.util.Iterator;
- import java.util.regex.Pattern;
- import org.apache.commons.codec.binary.Base64;
- public class getLiveUrl {
- private static MessageDigest md5;
- static {
- md5 = null;
- try {
- md5 = MessageDigest.getInstance("MD5");
- } catch (Exception e) {
- System.out.println(e.getMessage());
- }
- }
- public static String getMd5(String str) {
- byte[] bs = md5.digest(str.getBytes());
- StringBuilder sb = new StringBuilder(40);
- for (byte x : bs) {
- if (((x & 255) >> 4) == 0) {
- sb.append("0").append(Integer.toHexString(x & 255));
- } else {
- sb.append(Integer.toHexString(x & 255));
- }
- }
- return sb.toString();
- }
- public static String replaceSomeWhere(String SourceStr, String str, int index) {
- String strbefore;
- String strafter;
- if (index != 1) {
- strbefore = SourceStr.substring(0, index - 1);
- strafter = SourceStr.substring(index);
- } else {
- strbefore = "";
- strafter = SourceStr.substring(index);
- }
- return strbefore + str + strafter;
- }
- public static String getLiveToken(String channelid, String appid) throws UnsupportedEncodingException {
- String TimeStamp = (System.currentTimeMillis() / 1000) + "";
- String STR1 = getMd5(channelid + "Tide" + appid);
- String STR3 = getMd5("tide" + TimeStamp + (STR1.substring(0, 2) + STR1.substring(4, 8) + STR1.substring(14, 15) + STR1.substring(13, 14) + STR1.substring(12, 13) + STR1.substring(25, 29) + STR1.substring(30, 31) + STR1.substring(29, 30) + STR1.substring(28, 29) + STR1.substring(27, 28) + STR1.substring(26, 27)));
- String STR4 = new String(Base64.encodeBase64(("t=" + TimeStamp + "&c=" + channelid + "&a=" + appid + "&v=" + (STR3.substring(4, 5) + STR3.substring(16, 17) + STR3.substring(31, 32) + STR3.substring(17, 18) + STR3.substring(8, 9))).getBytes("UTF-8"))).replace("=", "|");
- String numberBefore = Pattern.compile("[^1-9]").matcher(STR4).replaceAll("").trim();
- ArrayList<Integer> arr = new ArrayList<>();
- for (int i = 0; i < numberBefore.length(); i++) {
- String number = numberBefore.substring(i, i + 1);
- if (!arr.contains(Integer.valueOf(Integer.parseInt(number)))) {
- arr.add(Integer.valueOf(Integer.parseInt(number)));
- }
- }
- Iterator it = arr.iterator();
- while (it.hasNext()) {
- System.out.println(((Integer) it.next()).intValue());
- }
- String Result = STR4;
- Iterator it2 = arr.iterator();
- while (it2.hasNext()) {
- int num = ((Integer) it2.next()).intValue();
- if (num % 2 == 0) {
- String SourceLetter = STR4.substring(num - 1, num);
- if ("abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ".indexOf(SourceLetter) != -1) {
- int destIndex = ("abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ".indexOf(SourceLetter) + (num * num)) % 52;
- Result = replaceSomeWhere(Result, "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ".substring(destIndex, destIndex + 1), num);
- }
- } else {
- String SourceLetter2 = STR4.substring(num - 1, num);
- if ("abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ".indexOf(SourceLetter2) != -1) {
- int destIndex2 = ("abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ".indexOf(SourceLetter2) + num) % 52;
- Result = replaceSomeWhere(Result, "abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ".substring(destIndex2, destIndex2 + 1), num);
- }
- }
- }
- return Result;
- }
- }
复制代码 getLiveUrl(this.td_liveid, "jushilive"); // appid = jushilive
自己玩吧,有点南昌的意思 应该是appid部分不同目测,没仔细看,翻翻我那个掌上南昌,看看
|
|