.Net实现真实下载地址与迅雷、QQ旋风等下载地址转换

public string Index()
        {
            StringBuilder sb = new StringBuilder();
            string OrgStr="http://down.qq.com/ava/full/W_full/AVA_Client_Ver_1230_full.exe";
            string ThunderStr="thunder://QUFodHRwOi8vZG93bi5xcS5jb20vYXZhL2Z1bGwvV19mdWxsL0FWQV9DbGllbnRfVmVyXzEyMzBfZnVsbC5leGVaWg==";
            string QQdlStr="qqdl://aHR0cDovL2Rvd24ucXEuY29tL2F2YS9mdWxsL1dfZnVsbC9BVkFfQ2xpZW50X1Zlcl8xMjMwX2Z1bGwuZXhl";
            string FlashGetStr="flashget://W0ZMQVNIR0VUXWh0dHA6Ly9kb3duLnFxLmNvbS9hdmEvZnVsbC9XX2Z1bGwvQVZBX0NsaWVudF9WZXJfMTIzMF9mdWxsLmV4ZVtGTEFTSEdFVF0=&";
            string orgAddr = GetOriginalString(QQdlStr);//原地址
            sb.AppendFormat("{0}<br>", orgAddr);
            string thunderAddr = "AA" + orgAddr + "ZZ";
            thunderAddr = "thunder://" + EncodeBase64(thunderAddr);
            sb.AppendFormat("{0}<br>", thunderAddr);
            string qqdlAddr = "qqdl://" + EncodeBase64(orgAddr);
            sb.AppendFormat("{0}<br>", qqdlAddr);
            string flashGetAddr = string.Format("{0}{1}{0}", "[FLASHGET]", orgAddr);
            flashGetAddr = "flashget://" + EncodeBase64(flashGetAddr) + "&";
            sb.AppendFormat("{0}<br>", flashGetAddr);
            return sb.ToString();
        }
        public string EncodeBase64(string orgStr)
        {
            try
            {
                return Convert.ToBase64String(Encoding.Default.GetBytes(orgStr));
            }
            catch
            {
                return "";
            }
        }
        public string DecodeBase64(string encodeStr)
        {
            try
            {
                return Encoding.Default.GetString(Convert.FromBase64String(encodeStr));

            }
            catch
            {
                return "";
            }
        }

        public string GetOriginalString(string str)
        {
            string thunderPrefix="thunder://";
            string qqdlPrefix = "qqdl://";
            string flashgetPrefix = "flashget://";
            if(str.StartsWith("http://")||str.StartsWith("https://"))
            {
                return str;
            }
            else if (str.StartsWith(thunderPrefix))
            {
                string thunderAddr = str.Substring(thunderPrefix.Length);//去掉前缀
                thunderAddr = DecodeBase64(thunderAddr);//base64解码
                thunderAddr = thunderAddr.Substring(2, thunderAddr.Length - 4);//去掉前两个A,后两个Z
                return thunderAddr;
            }
            else if(str.StartsWith(qqdlPrefix))
            {
                string qqdlAddr = str.Substring(qqdlPrefix.Length);
                qqdlAddr = DecodeBase64(qqdlAddr);//base64解码
                return qqdlAddr;
            }
            else if (str.StartsWith(flashgetPrefix))
            {
                string flashgetAddr = str.Substring(flashgetPrefix.Length);
                flashgetAddr = flashgetAddr.Substring(0,flashgetAddr.Length-1);//去掉最后一个&号 
                flashgetAddr = DecodeBase64(flashgetAddr);
                flashgetAddr = flashgetAddr.Substring(10,flashgetAddr.Length-20);//去掉前后的[FLASHGET]
                return flashgetAddr;
            }
            return "";
        }


上一篇:2019年企业新增长 从雇佣“机器人员工”开始


下一篇:基于SSH的实验室预约管理系统