<div style="font-weight: 400;">

<p>网易云官方有个这个东西http://music.163.com/song/media/outer/url?id=id.mp3,将id换为歌曲id进行访问就会302到歌曲地址。</p><p>其实这就可以拿来直接用了,但是他默认的都是http渠道的而非https,即使你访问https://music.163.com/song/media/outer/url?id=id.mp3最后他跳转到的也是http的音乐链接。</p><p>其实他本身是支持https的,只是全都默认http,这就很难受,所以我用php写了个小工具。</p><div><pre><span><span><?php</span>
<span>$id</span><span>=</span><span>$_SERVER</span><span>[</span><span>"QUERY_STRING"</span><span>]</span><span>;</span>
<span>$reg</span> <span>=</span> <span>'/^[0-9][0-9]*$/'</span><span>;</span>
<span>if</span><span>(</span><span>preg_match</span><span>(</span><span>$reg</span><span>,</span><span>$id</span><span>)</span><span>)</span><span>{</span>
<span>$url</span> <span>=</span> <span>'http://music.163.com/song/media/outer/url?id='</span><span>.</span><span>$id</span><span>.</span><span>'.mp3'</span><span>;</span>
<span>$headers</span> <span>=</span> <span>get_headers</span><span>(</span><span>$url</span><span>,</span> <span>TRUE</span><span>)</span><span>;</span>

<span>$url</span> <span>=</span> <span>$headers</span><span>[</span><span>'Location'</span><span>]</span><span>;</span>
<span>$url</span> <span>=</span> <span>str_replace</span><span>(</span><span>"http:"</span><span>,</span><span>"https:"</span><span>,</span><span>$url</span><span>)</span><span>;</span>
<span>if</span><span>(</span><span>$url</span><span>==</span><span>"https://music.163.com/404"</span><span>)</span><span>{</span>
<span>header</span><span>(</span><span>"Location: https://music.163.com/song/media/outer/url?id="</span><span>.</span><span>$id</span><span>.</span><span>".mp3"</span><span>)</span><span>;</span>
exit<span>;</span>
<span>}</span><span>else</span><span>{</span>
<span>header</span><span>(</span><span>"Location: "</span><span>.</span><span>$url</span><span>.</span><span>""</span><span>)</span><span>;</span>
exit<span>;</span>
<span>}</span>
<span>}</span><span>else</span><span>{</span>
<span>echo</span> <span>"非法参数"</span><span>;</span>
<span>}</span>
<span>?></span></span>
</pre></div><p>访问php?id即可302转到https渠道的音乐链接。</p><p>大家可以看到里面有个if判断,判断是否是404的,因为部分音乐可能因为xx原因,用这个php获取不到,获取不到就会返回404地址,如果返回这个的话,就302跳转到原来默认的http渠道链接。</p></div>