<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="skins/JinnStyleV1/article.xslt"?><blog view="693508" processed="0.079" queries="8" focusMarkup="" xslt="skins/JinnStyleV1/article.xslt"><panels><panel id="1" sn="0" sys="true"><name>Blog Main</name><content><article id="180" disComm="false"><title>从千千静听的歌词服务器查询音乐的 LRC 歌词 [Java]</title><category id="20"><name>学习随笔</name><icon>images/icons/3.gif</icon></category><content><![CDATA[&#26368;&#36817;&#35201;&#25630;&#36825;&#20010;&#65292;&#30334;&#24230;&#19968;&#19979;&#65292;&#21457;&#29616;&#26377; php &#29256;&#26412;&#30340;&#20195;&#30721;&#65292;&#25630;&#26469;&#32763;&#35793;&#19968;&#19979;&#12290; <br /><br /><textarea name='code' class='js' cols='50'>package org.iscripts.services;

import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.iscripts.common.net.HttpGet;

/**
* @author &#28151;&#28151;(&lt;b&gt;ialvin.cn&lt;/b&gt;) &#24191;&#19996;&#183;&#26222;&#23425;&#183;&#37324;&#28246;
*/
public class LrcGet {
  public static void main(String[] args) throws Exception {
    System.out.println(query(&quot;&#20320;&#25226;&#29233;&#24773;&#32473;&#20102;&#35841;&quot;, &quot;&#29579;&#24378;&quot;));
  }

  public static String query(String title, String artist)
      throws DocumentException, NumberFormatException, IOException {
    String URL = &quot;http://ttlrcct.qianqian.com/dll/lyricsvr.dll?sh?Artist={ar}&amp;Title={ti}&amp;Flags=0&quot;;
    URL = URL.replace(&quot;{ar}&quot;, encode(artist))
        .replace(&quot;{ti}&quot;, encode(title));
    String result = &quot;&quot;;
    try {
      result = HttpGet.get(URL);
    } catch (Exception e) {
      e.printStackTrace();
    }
    // &#38656;&#35201; dom4j-1.6.1.jar , &#20351;&#29992;&#21487;&#21442;&#32771; dom4j &#25163;&#20876;
    Document doc = new SAXReader().read(new StringReader(result));
    // XML&#20013;&#21487;&#33021;&#21253;&#21547;&#22810;&#20010;&#21305;&#37197;&#32467;&#26524;&#65292;&#25105;&#20204;&#21482;&#21462;&#19968;&#20010;
    Node n = doc.selectSingleNode(&quot;/result/lrc&quot;);
    if (n == null)
      return null;
    Element e = (Element) n;
    result = e.attributeValue(&quot;id&quot;);
    artist = e.attributeValue(&quot;artist&quot;);
    title = e.attributeValue(&quot;title&quot;);

    URL = &quot;http://ttlrcct2.qianqian.com/dll/lyricsvr.dll?dl?Id={id}&amp;Code={code}&quot;;
    URL = URL.replace(&quot;{id}&quot;, result).replace(&quot;{code}&quot;,
        verifyCode(artist, title, Integer.parseInt(result, 10)));
    return HttpGet.get(URL);
  }

  public static String verifyCode(String artist, String title, int lrcId)
      throws UnsupportedEncodingException {
    byte[] bytes = (artist + title).getBytes(&quot;UTF-8&quot;);
    int[] song = new int[bytes.length];
    for (int x = 0; x &lt; bytes.length; x++)
      song[x] = bytes[x] &amp; 0xff;
    int intVal1 = 0, intVal2 = 0, intVal3 = 0;
    intVal1 = (lrcId &amp; 0xFF00) &gt;&gt; 8;
    if ((lrcId &amp; 0xFF0000) == 0) {
      intVal3 = 0xFF &amp; ~intVal1;
    } else {
      intVal3 = 0xFF &amp; ((lrcId &amp; 0x00FF0000) &gt;&gt; 16);
    }
    intVal3 = intVal3 | ((0xFF &amp; lrcId) &lt;&lt; 8);
    intVal3 = intVal3 &lt;&lt; 8;
    intVal3 = intVal3 | (0xFF &amp; intVal1);
    intVal3 = intVal3 &lt;&lt; 8;
    if ((lrcId &amp; 0xFF000000) == 0) {
      intVal3 = intVal3 | (0xFF &amp; (~lrcId));
    } else {
      intVal3 = intVal3 | (0xFF &amp; (lrcId &gt;&gt; 24));
    }
    int uBound = bytes.length - 1;
    while (uBound &gt;= 0) {
      int c = song[uBound];
      if (c &gt;= 0x80)
        c = c - 0x100;
      intVal1 = c + intVal2;
      intVal2 = intVal2 &lt;&lt; (uBound % 2 + 4);
      intVal2 = intVal1 + intVal2;
      uBound -= 1;
    }
    uBound = 0;
    intVal1 = 0;
    while (uBound &lt;= bytes.length - 1) {
      int c = song[uBound];
      if (c &gt;= 128)
        c = c - 256;
      int intVal4 = c + intVal1;
      intVal1 = intVal1 &lt;&lt; (uBound % 2 + 3);
      intVal1 = intVal1 + intVal4;
      uBound += 1;
    }
    int intVal5 = intVal2 ^ intVal3;
    intVal5 = intVal5 + (intVal1 | lrcId);
    intVal5 = intVal5 * (intVal1 | intVal3);
    intVal5 = intVal5 * (intVal2 ^ lrcId);
    return String.valueOf(intVal5);
  }

  private static String encode(String value) {
    if (value == null)
      value = &quot;&quot;;
    value = value.replace(&quot; &quot;, &quot;&quot;).replace(&quot;'&quot;, &quot;&quot;).toLowerCase();
    byte[] bytes = null;
    try {
      bytes = value.getBytes(&quot;UTF-16LE&quot;);
    } catch (UnsupportedEncodingException e) {
      e.printStackTrace();
      bytes = value.getBytes();
    }
    return stringify(bytes);
  }

  final private static char[] digit = { '0', '1', '2', '3', '4', '5', '6',
      '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };

  private static String stringify(byte[] bytes) {
    char[] str = new char[2];
    StringBuilder builder = new StringBuilder();
    for (byte byteValue : bytes) {
      str[0] = digit[(byteValue &gt;&gt;&gt; 4) &amp; 0X0F];
      str[1] = digit[byteValue &amp; 0X0F];
      builder.append(str);
    }
    return builder.toString();
  }
}</textarea><br /><br />&#20854;&#20013; HttpGet.get(.....)　&#26041;&#27861;&#26159; HTTP &#25235;&#21462;&#30340;&#21151;&#33021;&#65292;&#21442;&#32771;&#65306;<br /><a href='http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=84' target='_blank'>http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=84</a><br /><br /><a href='http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=86' target='_blank'>ASP &#29256;&#30340;&#21315;&#21315;&#38745;&#21548; LRC &#27468;&#35789;&#26597;&#35810; &#35831;&#28857;&#36825;&#37324;</a><br /><br />&#21407;&#25991;&#38142;&#25509;&#65306;<a href='http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=85' target='_blank'>http://www.iscripts.org/forum.php?mod=viewthread&amp;tid=85</a>]]></content><publish>2011-05-03 00:42:25</publish><update>2011-05-22 22:44:36</update><comment>0</comment><view>2590</view></article><comments/><previous id="179"><title>ASP 版的千千静听 LRC 歌词查询 [jscript]</title></previous><next id="181"><title>[JavaScript]网页中音乐LRC歌词同步显示</title></next></content></panel></panels><modules><module id="4" sn="3" sys="true"><name>Category</name><title>日志分类</title></module><module id="6" sn="4" sys="true"><name>Archive</name><title>日志归档</title></module><module id="5" sn="5" sys="true"><name>User Panel</name><title>控制面板</title></module><module id="10" sn="6" sys="true"><name>Recent Article</name><title>最新日志</title></module><module id="8" sn="7" sys="true"><name>Search</name><title>查询搜索</title></module><module id="7" sn="8" sys="true"><name>Recent Comments</name><title>最新评论</title></module><module id="2" sn="9" sys="true"><name>Statistics</name><title>统计信息</title></module></modules><user><usn></usn><status>3</status><login>false</login></user></blog>
