Skip to content

Instantly share code, notes, and snippets.

@marshluca
Created February 17, 2011 09:15
Show Gist options
  • Save marshluca/831365 to your computer and use it in GitHub Desktop.
Save marshluca/831365 to your computer and use it in GitHub Desktop.
腾讯微薄OAuth授权
<!-- 这里是OAuth入口 -->
<?php
@header('Content-Type:text/html;charset=utf-8');
session_start();
require_once('config.php'); //配置AppKey, AppSecret
require_once('oauth.php');
require_once('opent.php');
$o = new MBOpenTOAuth( MB_AKEY , MB_SKEY );
$keys = $o->getRequestToken('http://api.5yi.com/qq/callback.php');//这里填上你的回调URL
$aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false,'');
$_SESSION['keys'] = $keys;
header("Location: ".$aurl);
?>
<!-- OAuth回调地址,绑定我易网用户 -->
<?php
@header('Content-Type:text/html;charset=utf-8');
session_start();
@require_once('config.php');
@require_once('oauth.php');
@require_once('opent.php');
@require_once('api_client.php');
// 获取Acess Token
$o = new MBOpenTOAuth( MB_AKEY , MB_SKEY , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret'] );
$last_key = $o->getAccessToken( $_REQUEST['oauth_verifier'] );
$_SESSION['last_key'] = $last_key;
// 获取用户的信息
$c = new MBApiClient( MB_AKEY , MB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] );
$response = $c->getUserInfo();
// 重定向到我易网登录API,绑定我易网用户id
$url = "http://api.5yi.com:9080/third_login/t_qq?token=".$last_key['oauth_token']."&secret=".$last_key['oauth_token_secret']."&uid=".$response['data']['name']."&uname=".$response['data']['nick']."&source=tqq";
header("Location: ".$url);
?>
<!-- 调用PHP接口,发送微博信息 -->
<?php
@header('Content-Type:text/html;charset=utf-8');
session_start();
@require_once('config.php');
@require_once('oauth.php');
@require_once('opent.php');
@require_once('api_client.php');
//$c = new MBApiClient( MB_AKEY , MB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret'] );
$c = new MBApiClient( MB_AKEY , MB_SKEY , $_REQUEST['oauth_token'] , $_REQUEST['oauth_token_secret'] );
//发消息
$p =array(
'c' => ''.$_REQUEST["text"],
'ip' => $_SERVER['REMOTE_ADDR'],
'j' => '',
'w' => ''
);
var_dump($c->postOne($p));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment