php实现抖音开放平台账号授权获取码code、获取access_token

直接上代码

public function index(){ $code = $_GET['code']; $dyClientKey = xxx; $dyClientSecret = xxx; if(empty($code)){ $redirect_uri = "http://www.xxx.com"; //授权回调域名(要和在抖音平台申请的网站应用回调域名要一致) 用来接收抖音平台返回的code $redirect_uri = urlencode($redirect_uri); $url = "https://open.douyin.com/platform/oauth/connect/?client_key={$dyClientKey}&response_type=code&scope=user_info,video.create&redirect_uri={$redirect_uri}"; header("Location:" . $url); }else{ $get_access_token_url = "https://open.douyin.com/oauth/access_token?client_key={$dyClientKey}&client_secret={$dyClientSecret}&grant_type=authorization_code&code={$code}"; $access_token_info = $this->getJson($get_access_token_url); echo '
'; var_dump($access_token_info); } } //curl请求 public function getJson($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //为true,则会跟踪爬取重定向页面,否则,不会跟踪重定向页面 $output = curl_exec($ch); curl_close($ch); return json_decode($output, true); }

返回access_token信息截图
【php实现抖音开放平台账号授权获取码code、获取access_token】php实现抖音开放平台账号授权获取码code、获取access_token
文章图片

    推荐阅读