php教程

php网易云热评ap接口源码

我的站长站 2020-10-01 人阅读

php网易云热评ap接口源码,实时抓取网易云音乐热门评论,随机热评。

标准链接格式为:xxx.com/xxx.php?format=textJSON

数据输出格式:xxx.xxx/xxx.php?format=json

GitHubhttps://github.com/ljhe/GetWangYiYunComments

php网易云热评ap接口源码

网易云热评API接口源码

<?php
header('Content-type: text/json;charset=utf-8');
$format =$_GET['format'];;
$post = 'params=RWWaVrwvMRFMFc6r%2BrKTq66XIh8o1s%2BP%2BebgYma%2FWimi6K5F3KtWHtpXfC%2Fgh77TtCtc3rmpHuknSe%2BDi%2FNBycqi9m7nISKeQx9Z46RmucLioCQeGmOKJ%2FJJ2FFquMvqj0U2NAoD%2BmN1zc7l39CKLQm4A%2Bz4yt2r9n2EJPc4XZpGorDx7fvTY4ulvRg93keo5r4cpfihdIAara8uU1k3IW6ohE%2BLuguCMstPnzQJgDU%3D&encSecKey=0be524c8f3210f9fe781abc2682012b97d13f843e74b92b42955ab0ddb0964ffdf7c8a01138342307bfc0d2544f8a1131c9dc72c95b8fae31dc603bf5c00d090f730428b9d73eb151d563bf7b816518d1a1c5ad4a37f4fffa1700469151025f2fc282edbb70d6217d3054c2cb90649aa2b645ad38baaccbfb90eb28e720ef56a';
$music = get_music_list($post);
if($format == 'text') {
$result  =  $music['content'].PHP_EOL;
$result  .=  '来自@'. $music['nickname'];
$result  .=  '在「'.$music['name'].'」'.PHP_EOL;
$result  .=  '歌曲下方的评论'.PHP_EOL;
$result  .=  $music['copyright'];  
print_r($result);
}else{
$result  =  json_encode(array(
'code'  =>  1,
'data'  =>  $music
),320);
print_r($result);
}
function get_music_list($post){
$rel = G163_curl('https://music.163.com/weapi/playlist/detail', $post);
$arr = json_decode($rel,true)['result']['tracks'];
$music = $arr[array_rand($arr,1)];
$rel = G163_curl('https://music.163.com/weapi/v1/resource/comments/R_SO_4_'.$music['id'], $post);
$arr = json_decode($rel,true)['hotComments'];
$hotComments = $arr[array_rand($arr,1)];
$data = array(
'name'      =>  $music['name']
,'url'      =>  'http://music.163.com/song/media/outer/url?id='.$music['id'].'.mp3'
,'picurl'    =>  $music['album']['picUrl']
,'artistsname'  =>  $music['artists'][0]['name']
,'avatarurl'  =>  $hotComments['user']['avatarUrl']
,'nickname'    =>  $hotComments['user']['nickname']
,'content'    =>  $hotComments['content']
,'copyright'    =>  '空木白博客wuzuhua.cn'
);
return $data;
}
function G163_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0){
$ch = curl_init();
$ip = rand(0,255).'.'.rand(0,255).'.'.rand(0,255).'.'.rand(0,255) ;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$httpheader[] = "Accept:application/json";
$httpheader[] = "Accept-Encoding:gzip, deflate, br";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Accept-Type:application/x-www-form-urlencoded";
$httpheader[] = "Origin:https://music.163.com";
$httpheader[] = "Origin:https://music.163.com";
$httpheader[] = 'X-FORWARDED-FOR:'.$ip;
$httpheader[] = 'CLIENT-IP:'.$ip;
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($post) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($header) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
if($referer){
if($referer==1){
curl_setopt($ch, CURLOPT_REFERER, 'https://music.163.com/outchain/player?type=0&id=2250011882&auto=1');
}else{
curl_setopt($ch, CURLOPT_REFERER, $referer);
}
}
if ($ua) {
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
}
else {
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1");
}
if ($nobaody) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_INTERFACE, '172.21.0.'.rand(10,27));
$ret = curl_exec($ch);
//$Headers = curl_getinfo($ch);
curl_close($ch);
return $ret;
}


相关推荐
  • API接口
  • API源码
  • 支付宝企业账户转账个人账户php接口代码

    前言支付宝企业账户转账个人账户php接口代码,该接口主要用于平台对用户奖励的发放,场景也很简单就是我在你平台上有余额,我提现,平台给钱。只不过项目中是用的官方的SDK调用的,仔细看了下那个SDK目录,把很多无用的接口(目前自己用不上)也包含在里面,作为强...

    php教程 159 1年前
  • QQ互联API申请教程(图文)

    1、登录QQ互联在浏览器上打开网址:http://connect.qq.com/。点击右上角【登录】按钮,使用QQ账号登录。2、管理中心点击【管理中心】进入应用管理页面。(图中位置1)完善开发者资料,如果手册登录需要完善开发者资料。点击【创建应用】,开始创建应用。(图中位...

    经验分享 1185 4年前
  • 苹果CMS开放API相关服务接口

    开放式API数据接口-声明本接口仅供学习研究使用,请勿用于生产环境和非法渠道;不能保证稳定性和正确性;请牢记苹果cms官方域名: www.maccms.com(暂时关闭) www.maccms.net; 网路出现多个盗版苹果v10的程序,改头换面加入后门,请误下载使用没有诚信的盗版程序...

    苹果cms教程 940 4年前
  • PHP智云V1.3全能API接口网站源码
    PHP智云V1.3全能API接口网站源码

    智云全能API接口PHP源码V1.3版本接口数据由智云平台开发及整理源码直接上传即可访问,无需数据库,不支持上传二级目录访问!源码上传后请访问:你的域名/inde.html(可以将inde.html重新修改其他名称访问)...

    php源码 542 3年前
  • 2020年最新HTML+API版防红网站模板
    2020年最新HTML+API版防红网站模板

    2020年最新HTML+API版防红网站模板,HTML+JS+API框架,打开即可使用,不需要任何环境。支持多种防红方式,多种短域名后缀。

    html模板 450 4年前
  • HTML+API美腿zipa图片瀑布流网站模板
    HTML+API美腿zipa图片瀑布流网站模板

    HTML+API美腿zipa图片瀑布流网站模板,图片采集与自葫芦侠,流量不走本地,虚拟空间都能部署,适合引流请在下载后24小时内删除,否则一切法律后果请自行承担...

    html模板 647 4年前
最新更新