在Windows Powershell 3.0中,新加入了一个Get-FileHash命令,其参数Algorithm可指定不同的计算方式。
Get-FileHash -Path D:\r.html -Algorithm sha1Get-FileHash -Path D:\r.html -Algorithm sha256
Get-FileHash -Path D:\r.html -Algorithm md5
如果Powershell版本($host)版本低于3.0,建议更新Powershell。当然,也可以通过一系列计算,算出校验值,以下是个示例(来自网络):
function Get-Checksum{
Param (
[string]$File=$(throw("You must specify a filename to get the checksum of.")),
[ValidateSet("sha1","md5")]
[string]$Algorithm="sha1"
)
$fs = new-object System.IO.FileStream $File, "Open"
$algo = [type]"System.Security.Cryptography.$Algorithm"
$crypto = $algo::Create()
$hash = [BitConverter]::ToString($crypto.ComputeHash($fs)).Replace("-", "")
$fs.Close()
$hash
}
直接上例子,最后拼得的url可以用MediaElement控件在线播放
QQ音乐
https://c.y.qq.com/soso/fcgi-bin/client_search_cp?aggr=1&cr=1&flag_qc=0&p=1&n=2&w=九张机
//songmid可以从歌曲信息中取到,filename根据songmid生成。比如,songmid是003lghpv0jfFXG,则filename就是前缀加上C400,后缀加上.m4a,即C400003lghpv0jfFXG.m4a。其他字段format、platform、cid、guid可以写死,但都是必须的。
string response = HttpGet(url, postData)
//请求地址:https://c.y.qq.com/base/fcgi-bin/fcg_music_express_mobile3.fcg
//请求参数:?format=json205361747&platform=yqq&cid=205361747&songmid=001hwLQi3sUBnL&filename=C400001hwLQi3sUBnL.m4a&guid=4942741185
Get请求后解析json,保存获取的vkey
//url的path就是上文中用到的filename。参数中的几个字段都是必须的:guid要和请求token时使用的guid保持一致,vkey即token中的vkey字段,fromtag随意指定一个整数,可以写死为0。
//我拼的url:http://dl.stream.qqmusic.qq.com/C400001hwLQi3sUBnL.m4a?guid=4942741185&vkey=A83D03264ABF4CA5BEA69BBFD0AB47B10AB2A0AE904C6A47E8BDC23FD4946F51E148781D9FD098875A237D117DED0B6A040524F13A6075E7&fromtag=66
string url= "http://dl.stream.qqmusic.qq.com/" + filename + "?guid=" + guid + "&vkey=" + vkey + "&fromtag=66"
酷狗音乐-搜索歌曲
//必选参数:keyword(关键字)歌手或者歌曲名,这里需要转换urldecode
//可选参数:page(第几页),pagesize(一页的搜索结果数目)
//请求地址:http://songsearch.kugou.com/song_search_v2
//请求参数:keyword=%e5%91%8a%e7%99%bd%e6%b0%94%e7%90%83&page=1&pagesize=1&userid=-1&clientver=&platform=WebFilter&tag=em&filter=2&iscorrection=1&privilege_filter=0
string kgresponse = HttpGet(kgUrl, kgParmas)
Get请求后解析json,保存获取的FileHash 、AlbumID
//请求地址:http://www.kugou.com/yy/index.php
//请求参数 :r=play/getdata&hash=" + FileHash + "&album_id=" + AlbumID
Get请求后解析json,这里获取的play_url贴到浏览器可以直接播放
}