<?php

namespace app\extra\tools;

use yzh52521\EasyHttp\Http;

class DouyinUserInfo
{

    public function curlPost($url, $data)
    {
        return Http::asJson()->withHeaders([
            "Authorization" => "Bearer jJgmOt0B7nmPxWOrR4io+BiJDRmuAZpGyQnao1XbTtuX1l2xP12RWgyiEQ=="
        ])->post("https://api.tikhub.dev".$url, $data)->array();
    }

    public function curlGet($url, $data)
    {
        return Http::asJson()->withHeaders([
            "Authorization" => "Bearer jJgmOt0B7nmPxWOrR4io+BiJDRmuAZpGyQnao1XbTtuX1l2xP12RWgyiEQ=="
        ])->get("https://api.tikhub.dev".$url, $data)->array();
    }

    public function getDyInfo(string $url = ""): array
    {
        $scIdData = $this->curlGet("/api/v1/douyin/web/get_sec_user_id",['url'=>$url]);
        if ($scIdData['code'] <> 200) return [0,$scIdData['message_zh']];
        $scId = $scIdData['data'];
        $userData = $this->curlGet("/api/v1/douyin/web/handler_user_profile",['sec_user_id' => $scId]);
        if ($userData['code'] <> 200) return [0,$userData['message_zh']];
        return [1,$userData['data']['user']];
    }

}