大家好,来来为大家解答以下问题,怎么获取自己的抖音账号..?很多人还不知道,现在让我们一起来看看吧!
一.获取抖音授权..
第一步:拿到抖音应用的client_key;
第二步:获取收取Scope,如:video.create,video.delete,video.data,可以写多个,中间用","隔开;
第三步:设置授权后的回调Url:
https://www.xxxx.com/api/oauth/douyinu0026state=1
也即当扫码授权成功后,会跳转到该url上
第三步:组装抖音授权Url:
授权url: https://open.douyin.com/platform/oauth/connent?client_key=u0026#39;+client_key+u0026#39;u0026response_type=codeu0026scope=u0026#39;+scope+u0026#39;u0026redirect_uri=u0026#39;+callback
通过第三方生成..组件,生成抖音授权..
二.当用户扫码之后,抖音会生成一个code,附带到回调的url上
服务端获取到code的方式:
$code = Request::param(u0026#39;codeu0026#39;, false);
// 根据state获取是那种授权
$state = Request::param(u0026#39;stateu0026#39;, false);
通过这个临时的code,获取access_token
if(!$code) {
return error_code(10003);
}
$dyApp = new Dyapp();
$result = $dyApp-u0026gt;initToken($code, $state);
if(!$result[u0026#39;statusu0026#39;]) {
return error_code(10003);
}
$oid = $result[u0026#39;datau0026#39;][u0026#39;open_idu0026#39;];
到这里就获取到了,open_id, access_token,refresh_token等参数
三.如果scope里面填写了,mobile_alert,还将获取用户的手机号码
php的获取方式如下:
/**
* 获取用户手机号码,手机号码解密
*/
private function getUserMobile($encrypt_mobile)
{
$client_secret = getSetting(u0026#39;douyin_client_secretu0026#39;);
$encrypt_mobile_str = base64_decode($encrypt_mobile);
$key = $client_secret;
$iv = substr($client_secret, 0, 16);
$aes = new Aes($key, u0026#39;AES-256-CBCu0026#39;, $iv, OPENSSL_RAW_DATA);
$mobile = $aes-u0026gt;decrypt($encrypt_mobile_str);
return $mobile;
}
本文到此结束,希望对大家有所帮助。