文本与代码预览

gemini-code-1795829937101.html

html · 16.05 KB

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>自动参数拼接与 Music URL 解读器</title>
  <style>
    body {
      font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
      max-width: 1040px;
      margin: 24px auto;
      padding: 0 16px 48px;
      background: #f4f6f9;
      color: #1f2937;
    }
    .card {
      background: #fff;
      border-radius: 10px;
      padding: 16px 20px;
      margin-bottom: 16px;
      box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }
    h1 { font-size: 20px; margin: 0 0 6px; }
    h2 { font-size: 16px; margin: 0 0 12px; }
    .meta { font-size: 13px; color: #6b7280; margin-bottom: 10px; }
    .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
    label { font-size: 13px; font-weight: 600; color: #374151; }
    input[type="text"], select, textarea {
      padding: 8px 10px;
      border: 1px solid #d1d5db;
      border-radius: 6px;
      font-size: 13px;
      font-family: inherit;
    }
    input[type="text"], select { flex: 1; min-width: 200px; }
    textarea { width: 100%; min-height: 76px; box-sizing: border-box; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
    .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
    button {
      padding: 8px 12px;
      border: 1px solid #2563eb;
      background: #2563eb;
      color: #fff;
      border-radius: 6px;
      font-size: 13px;
      cursor: pointer;
    }
    button:hover { background: #1d4ed8; }
    button.secondary { background: #fff; color: #2563eb; }
    button.secondary:hover { background: #eff6ff; }
    .param-grid {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
      gap: 10px;
      margin-bottom: 12px;
    }
    .param-box {
      border: 1px solid #e5e7eb;
      background: #f9fafb;
      border-radius: 8px;
      padding: 10px;
    }
    .param-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 12px; }
    .badge { padding: 2px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; }
    .badge-auto { background: #dcfce7; color: #166534; }
    .badge-fallback { background: #fef3c7; color: #92400e; }
    table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
    th, td { border: 1px solid #e5e7eb; padding: 7px 9px; text-align: left; word-break: break-all; vertical-align: top; }
    th { background: #f3f4f6; color: #374151; width: 150px; }
    pre {
      background: #0f172a;
      color: #e2e8f0;
      padding: 12px 14px;
      border-radius: 8px;
      font-size: 12px;
      line-height: 1.5;
      overflow: auto;
      max-height: 300px;
      margin: 0;
    }
  </style>
</head>
<body>
  <script>
    var SERVER_DATA = {
      "weather": { "city_code": "101010100" },
      "guess_track": false,
      "qhback_domain": {},
      "h360comHuid": "",
      "qttk": null,
      "request_id": "a0ca70201844c2d46caf2b5b96a0e27e"
    };
    var PAGE_START_TIME = (new Date).getTime(), WEBINDEXCK = "360WEBINDEXCK", DEBUG = 0;
    var API_VERSION = { "hotwordinject": "1.0" }, API_SNAPSHOTNUM = {};
    var PROJECT = 'v2022';
    var HAO_CONFIG = {
      version: 2.0,
      dataConf: { host: 'https://api.dhrest.com/dataconfapi', threshold: 300000 },
      cube: {
        host: 'https://i.dhrest.com',
        api: {
          tool: 'gw/APPQ2TDvvFr3kT/toolplate/list/v1',
          content: 'gw/APPQ2TDvvFr3kT/contentplate/list/v1'
        }
      }
    };
  </script>

  <div class="card">
    <h1>自动获取参数拼接地址 &amp; Music URL 解读器</h1>
    <div class="meta">优先自动读取可用上下文参数;无法获取时自动回退至抓包固定值,并支持直接拆解 Music 网关链接。</div>
    <div class="actions">
      <button id="btnReDetect">重新自动提取参数</button>
      <button class="secondary" id="btnBuildUrl">生成拼接后的请求 URL</button>
      <button id="btnSendJsonp">发起 JSONP 请求</button>
      <button class="secondary" id="btnParseBuilt">解读当前拼接的 URL</button>
    </div>
    <div class="param-grid" id="paramGrid"></div>
    <div class="row">
      <label for="bizTypeSelect">接口类型:</label>
      <select id="bizTypeSelect">
        <option value="playlist">歌单列表 (/openapi/music/basic/playlist/oftag/get/v2)</option>
        <option value="artist">歌手列表 (/openapi/music/basic/artists/list/bytype/get/v2)</option>
        <option value="playurl">播放地址 (/cube-music163/v1/music/playurl)</option>
        <option value="dataconf">数据配置 (https://api.dhrest.com/dataconfapi)</option>
      </select>
      <label for="bizOrSongInput">biz / song_id / uniqid:</label>
      <input id="bizOrSongInput" type="text" value='{"tag":"流行","limit":4}' />
    </div>
    <label for="builtUrlBox">拼接后的完整 URL:</label>
    <textarea id="builtUrlBox" readonly></textarea>
  </div>

  <div class="card">
    <h2>Music 地址 URL 解读器</h2>
    <div class="row">
      <button class="secondary" data-sample="playlist">填入歌单示例</button>
      <button class="secondary" data-sample="artist">填入歌手示例</button>
      <button class="secondary" data-sample="playurl">填入 playurl 示例</button>
      <button id="btnDecodeUrl">开始解读 URL</button>
    </div>
    <textarea id="rawUrlInput"></textarea>
    <div id="decodeResult"></div>
  </div>

  <div class="card">
    <h2>运行日志</h2>
    <pre id="logBox">就绪。</pre>
  </div>

  <script>
    const FALLBACKS = {
      huid: '11JciMzF1bG29BO8VSXqMIXkgE/LsaJYv06H+tLUot+Bc=',
      guid: '234898968.226933813978302900.1795827206558.7744',
      uid: 'fe63e70bdb66fe9ab18626bfa4650a94',
      at: 'lf41feb88f48e6548bd2b181ec5fd6a06e2a9bd30c6054686q',
      mid: '',
      asc: '',
      uniqid: 'Nm7qzd4hFGLFgq92'
    };

    const SAMPLES = {
      playlist: 'https://gw.dhrest.com/cube-music163/v1/music/biz?mid=&huid=11JciMzF1bG29BO8VSXqMIXkgE%2FLsaJYv06H%2BtLUot%2BBc%3D&guid=234898968.226933813978302900.1795827206558.7744&asc=&uri=%2Fopenapi%2Fmusic%2Fbasic%2Fplaylist%2Foftag%2Fget%2Fv2&uid=fe63e70bdb66fe9ab18626bfa4650a94&at=lf41feb88f48e6548bd2b181ec5fd6a06e2a9bd30c6054686q&biz=%7B%22tag%22%3A%22%E6%B5%81%E8%A1%8C%22%2C%22limit%22%3A4%7D&callback=__jsonp9__&t=179582722',
      artist: 'https://gw.dhrest.com/cube-music163/v1/music/biz?mid=&huid=11JciMzF1bG29BO8VSXqMIXkgE%2FLsaJYv06H%2BtLUot%2BBc%3D&guid=234898968.226933813978302900.1795827206558.7744&asc=&uri=%2Fopenapi%2Fmusic%2Fbasic%2Fartists%2Flist%2Fbytype%2Fget%2Fv2&uid=fe63e70bdb66fe9ab18626bfa4650a94&at=lf41feb88f48e6548bd2b181ec5fd6a06e2a9bd30c6054686q&biz=%7B%22type%22%3A1%2C%22limit%22%3A6%7D&callback=__jsonp10__&t=179582722',
      playurl: 'https://gw.dhrest.com/cube-music163/v1/music/playurl?mid=&huid=11JciMzF1bG29BO8VSXqMIXkgE%2FLsaJYv06H%2BtLUot%2BBc%3D&guid=234898968.226933813978302900.1795827206558.7744&asc=&song_id=A8EC1B53CB356BB6B7493A6AFC973D0E&callback=__jsonp14__&t=359165684'
    };

    const state = {
      huid: { value: '', source: 'fallback' },
      guid: { value: '', source: 'fallback' },
      uid: { value: '', source: 'fallback' },
      at: { value: '', source: 'fallback' },
      mid: { value: '', source: 'fallback' },
      asc: { value: '', source: 'fallback' }
    };

    let jsonpCounter = 20;
    const paramGridEl = document.getElementById('paramGrid');
    const bizTypeSelectEl = document.getElementById('bizTypeSelect');
    const bizOrSongInputEl = document.getElementById('bizOrSongInput');
    const builtUrlBoxEl = document.getElementById('builtUrlBox');
    const rawUrlInputEl = document.getElementById('rawUrlInput');
    const decodeResultEl = document.getElementById('decodeResult');
    const logBoxEl = document.getElementById('logBox');

    function log(title, detail) {
      const time = new Date().toLocaleTimeString();
      const text = typeof detail === 'string' ? detail : JSON.stringify(detail, null, 2);
      logBoxEl.textContent = `[${time}] ${title}\n${text}\n\n` + logBoxEl.textContent;
    }

    function readCookie(name) {
      const match = document.cookie.match(new RegExp('(?:^|; )' + name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + '=([^;]*)'));
      return match ? decodeURIComponent(match[1]) : '';
    }

    function detectParams() {
      const sp = new URLSearchParams(location.search);
      const pick = (key, candidates, fallbackVal) => {
        for (const c of candidates) {
          if (typeof c === 'string' && c.trim() !== '') {
            return { value: c.trim(), source: 'auto' };
          }
        }
        return { value: fallbackVal, source: 'fallback' };
      };

      state.huid = pick('huid', [
        window.SERVER_DATA && SERVER_DATA.h360comHuid,
        sp.get('huid'),
        localStorage.getItem('huid'),
        readCookie('__huid')
      ], FALLBACKS.huid);

      state.guid = pick('guid', [
        sp.get('guid'),
        localStorage.getItem('guid'),
        readCookie('__guid')
      ], FALLBACKS.guid);

      state.uid = pick('uid', [
        sp.get('uid'),
        localStorage.getItem('uid'),
        readCookie('uid')
      ], FALLBACKS.uid);

      state.at = pick('at', [
        sp.get('at'),
        localStorage.getItem('at'),
        readCookie('at')
      ], FALLBACKS.at);

      state.mid = pick('mid', [
        sp.get('mid'),
        window.hao360 && hao360.mid
      ], FALLBACKS.mid);

      state.asc = pick('asc', [
        sp.get('asc'),
        window.hao360 && hao360.asc
      ], FALLBACKS.asc);

      renderParamInputs();
    }

    function renderParamInputs() {
      const keys = ['huid', 'guid', 'uid', 'at', 'mid', 'asc'];
      paramGridEl.innerHTML = keys.map((k) => {
        const item = state[k];
        const isAuto = item.source === 'auto';
        return `
          <div class="param-box">
            <div class="param-head">
              <strong>${k}</strong>
              <span class="badge ${isAuto ? 'badge-auto' : 'badge-fallback'}">${isAuto ? '自动获取' : '固定回退'}</span>
            </div>
            <input type="text" data-param="${k}" value="${item.value.replace(/"/g, '&quot;')}" />
          </div>
        `;
      }).join('');

      paramGridEl.querySelectorAll('input[data-param]').forEach((input) => {
        input.addEventListener('input', (e) => {
          const k = e.target.getAttribute('data-param');
          state[k].value = e.target.value;
          buildUrl();
        });
      });
    }

    function buildUrl() {
      const mode = bizTypeSelectEl.value;
      const rawVal = bizOrSongInputEl.value.trim();
      const cbName = `__jsonp${++jsonpCounter}__`;
      const t = Math.floor(Date.now() / 1000);

      if (mode === 'dataconf') {
        const q = new URLSearchParams({
          uniqid: rawVal || FALLBACKS.uniqid,
          callback: cbName,
          t: String(t)
        });
        const url = `${HAO_CONFIG.dataConf.host}?${q.toString()}`;
        builtUrlBoxEl.value = url;
        return { url, cbName };
      }

      const common = {
        mid: state.mid.value,
        huid: state.huid.value,
        guid: state.guid.value,
        asc: state.asc.value
      };

      if (mode === 'playurl') {
        const q = new URLSearchParams({
          ...common,
          song_id: rawVal || 'A8EC1B53CB356BB6B7493A6AFC973D0E',
          callback: cbName,
          t: String(t)
        });
        const url = `https://gw.dhrest.com/cube-music163/v1/music/playurl?${q.toString()}`;
        builtUrlBoxEl.value = url;
        return { url, cbName };
      }

      const uri = mode === 'artist'
        ? '/openapi/music/basic/artists/list/bytype/get/v2'
        : '/openapi/music/basic/playlist/oftag/get/v2';

      const biz = rawVal || (mode === 'artist' ? '{"type":1,"limit":6}' : '{"tag":"流行","limit":4}');
      const q = new URLSearchParams({
        ...common,
        uri,
        uid: state.uid.value,
        at: state.at.value,
        biz,
        callback: cbName,
        t: String(t)
      });
      const url = `https://gw.dhrest.com/cube-music163/v1/music/biz?${q.toString()}`;
      builtUrlBoxEl.value = url;
      return { url, cbName };
    }

    function sendJsonp() {
      const { url, cbName } = buildUrl();
      const script = document.createElement('script');
      const cleanup = () => {
        delete window[cbName];
        if (script.parentNode) script.parentNode.removeChild(script);
      };
      const timer = setTimeout(() => {
        cleanup();
        log('JSONP 超时或未触发回调', url);
      }, 7000);

      window[cbName] = (data) => {
        clearTimeout(timer);
        cleanup();
        log('JSONP 回调返回', { url, data });
      };
      script.onerror = () => {
        clearTimeout(timer);
        cleanup();
        log('JSONP 加载失败(可能受鉴权/过期/环境限制)', url);
      };
      script.src = url;
      log('已发起 JSONP 请求', url);
      document.body.appendChild(script);
    }

    function decodeMusicUrl(inputStr) {
      const trimmed = (inputStr || '').trim();
      if (!trimmed) {
        decodeResultEl.innerHTML = '<div class="meta">请输入或选择一条 URL。</div>';
        return;
      }
      try {
        const parsed = new URL(trimmed);
        const rows = [
          ['协议 / 域名', `${parsed.protocol}//${parsed.host}`],
          ['请求路径', parsed.pathname],
          ['业务类型判断', parsed.pathname.includes('playurl') ? '音频播放地址接口 (playurl)' : (parsed.pathname.includes('/biz') ? '音乐业务网关接口 (/biz)' : '其他接口')]
        ];

        for (const [k, v] of parsed.searchParams.entries()) {
          if (k === 'biz') {
            let prettyBiz = v;
            try { prettyBiz = JSON.stringify(JSON.parse(v)); } catch (_) {}
            rows.push([`参数: ${k}`, `${prettyBiz}(已解码)`]);
          } else {
            rows.push([`参数: ${k}`, v || '(空)']);
          }
        }

        decodeResultEl.innerHTML = `
          <table>
            <thead><tr><th>字段 / 参数</th><th>解码后内容</th></tr></thead>
            <tbody>${rows.map(([a, b]) => `<tr><td><strong>${a}</strong></td><td>${b}</td></tr>`).join('')}</tbody>
          </table>
        `;
        log('已解读 Music URL', { origin: parsed.origin, pathname: parsed.pathname, params: Object.fromEntries(parsed.searchParams.entries()) });
      } catch (err) {
        decodeResultEl.innerHTML = `<div class="meta">URL 格式无效:${err.message}</div>`;
        log('URL 解读失败', err.message);
      }
    }

    bizTypeSelectEl.addEventListener('change', () => {
      const v = bizTypeSelectEl.value;
      if (v === 'playlist') bizOrSongInputEl.value = '{"tag":"流行","limit":4}';
      else if (v === 'artist') bizOrSongInputEl.value = '{"type":1,"limit":6}';
      else if (v === 'playurl') bizOrSongInputEl.value = 'A8EC1B53CB356BB6B7493A6AFC973D0E';
      else bizOrSongInputEl.value = FALLBACKS.uniqid;
      buildUrl();
    });

    bizOrSongInputEl.addEventListener('input', buildUrl);
    document.getElementById('btnReDetect').addEventListener('click', () => { detectParams(); buildUrl(); log('已重新提取参数', state); });
    document.getElementById('btnBuildUrl').addEventListener('click', () => { const res = buildUrl(); log('已生成请求 URL', res.url); });
    document.getElementById('btnSendJsonp').addEventListener('click', sendJsonp);
    document.getElementById('btnParseBuilt').addEventListener('click', () => {
      const { url } = buildUrl();
      rawUrlInputEl.value = url;
      decodeMusicUrl(url);
    });
    document.getElementById('btnDecodeUrl').addEventListener('click', () => decodeMusicUrl(rawUrlInputEl.value));
    document.querySelectorAll('button[data-sample]').forEach((btn) => {
      btn.addEventListener('click', () => {
        const key = btn.getAttribute('data-sample');
        rawUrlInputEl.value = SAMPLES[key];
        decodeMusicUrl(SAMPLES[key]);
      });
    });

    detectParams();
    buildUrl();
    rawUrlInputEl.value = SAMPLES.playlist;
    decodeMusicUrl(SAMPLES.playlist);
  </script>
</body>
</html>