PHP:抖音主页链接解析个人信息
2022-07-07 本文已影响0人
DD生活
封装代码如下
public function douyin($url)
{
$redirect_url = $this->get_redirect_url($url);
$sec_user_id = str_replace(['https://www.douyin.com/user/','?previous_page=app_code_link'],['',''],$redirect_url);
$info_url ='https://www.iesdouyin.com/web/api/v2/user/info/?sec_uid='.$sec_user_id;
$output = file_get_contents($info_url);
$res = json_decode($output,true);
if (isset($res['user_info'])){
$result = $res['user_info'];
return [
'nickname' =>$result['nickname'],
'home_url' => $url,
'platform' => 'douyin',
'uid' => $result['uid'],
'video_uid' => $result['unique_id'],
'fans_total'=>$result['follower_count'],
'avatar' => $result['avatar_medium']['url_list'][0],
'signature' => $result['signature'],
'sec_uid' => $sec_user_id
];
}else{
return false;
}
}
获取301、302跳转地址
/**
* 重定向地址
* @param $url
* @return mixed
*/
public function get_redirect_url($url){
$header = get_headers($url, 1);
if (strpos($header[0], '301') !== false || strpos($header[0], '302') !== false) {
if(is_array($header['Location'])) {
return $header['Location'][count($header['Location'])-1];
}else{
return $header['Location'];
}
}else {
return $url;
}
}