1.配置文件
'WB_AKEY' => '596119692',
'WB_SKEY' => 'a8efeb9fcca06d0d9bec8427e859363d',
'WB_CALLBACK_URL' => "http://frankliang.applinzi.com/index.php/Home/User/weibo",2.控制器里//微博绑定登录
public function weibo(){
$o = new \Think\SaeTOAuthV2(C('WB_AKEY'), C('WB_SKEY'));
if(null == I('code')){
$url = C('WB_CALLBACK_URL');
$auth = $o->getAuthorizeURL($url);
header("Location: ".$auth);
}else{
$code = I('code');
$keys['code'] = $code;
$keys['redirect_uri'] = C('WB_CALLBACK_URL');
$auth = $o->getAccessToken( 'code',$keys);
cookie('access_token', $auth['access_token'], time()+86400);
//获得access_token后就可以调用任意函数,需要获得用户的微博账号;
$c = new \Think\SaeTClientV2( C('WB_AKEY'), C('WB_SKEY') , $auth['access_token'] );
$ms = $c->home_timeline(); // done
$uid_get = $c->get_uid();
$uid = $uid_get['uid'];
$user_message = $c->show_user_by_id( $uid);//根据ID获取用户等基本信息
dump($user_message);
header('Location: '.U('Index/index'));
}
}3.新浪开放平台,我的应用
本文介绍了一种基于ThinkPHP框架实现的微博登录集成方法,包括配置文件设置、控制器代码详解及通过SaeTOAuthV2类库获取Access Token的过程。文章还展示了如何利用获取到的Access Token调用微博API来获取用户的基本信息。
1666

被折叠的 条评论
为什么被折叠?



