我想调用这个函数中当code为password时,将一个微博账号进行授权(微博应用内定向将微博推送至指定账号而非当前登陆账号)但是函数传递不是很会,烦请高手指点我在一个页面里全局定义了账号和密码~define( "WB_ID" , '***********@qq.com' );
define( "WB_PWD" , '**********' );/**
 * access_token接口
 *
 * 对应API:{@link http://open.weibo.com/wiki/OAuth2/access_token OAuth2/access_token}
 *
 * @param string $type 请求的类型,可以为:code, password, token
 * @param array $keys 其他参数:
 *  - 当$type为code时: array('code'=>..., 'redirect_uri'=>...)
 *  - 当$type为password时: array('username'=>..., 'password'=>...)
 *  - 当$type为token时: array('refresh_token'=>...)
 * @return array
 */
function getAccessToken( $type = 'code', $keys ) {
$params = array();
$params['client_id'] = $this->client_id;
$params['client_secret'] = $this->client_secret;
if ( $type === 'token' ) {
$params['grant_type'] = 'refresh_token';
$params['refresh_token'] = $keys['refresh_token'];
} elseif ( $type === 'code' ) {
$params['grant_type'] = 'authorization_code';
$params['code'] = $keys['code'];
$params['redirect_uri'] = $keys['redirect_uri'];
} elseif ( $type === 'password' ) {
$params['grant_type'] = 'password';
$params['username'] = $keys['username'];
$params['password'] = $keys['password'];
} else {
throw new OAuthException("wrong auth type");
} $response = $this->oAuthRequest($this->accessTokenURL(), 'POST', $params);
$token = json_decode($response, true);
if ( is_array($token) && !isset($token['error']) ) {
$this->access_token = $token['access_token'];
$this->refresh_token = $token['refresh_token'];
} else {
throw new OAuthException("get access token failed." . $token['error']);
}
return $token;
}