Ejemplo n.º 1
0
// 回调地址,避免到处修改
$auth_url = 'https://oauth.taobao.com/authorize';
// 获取授权码的网址
$args = array('client_id' => TB_KEY, 'response_type' => 'code', 'redirect_uri' => $callback);
$auth_url .= '?' . http_build_query($args);
// echo '<pre>';
// $tb = new IdeaRateTaobao ();
// $token = $tb->tb_oauth ( $_REQUEST ['code'], TB_KEY, TB_SECRET_KEY, $user_ID, $callback );
// var_dump ( $token );
// exit ();
$is_logged = is_user_logged_in();
if ('yes' == get_option('idea_enable_tb_rate')) {
    $tips = '淘宝自动评价系统没有启用,请联系管理员';
} elseif ($is_logged && isset($_REQUEST['code'])) {
    $tb = new IdeaRateTaobao();
    $token = $tb->tb_oauth($_REQUEST['code'], TB_KEY, TB_SECRET_KEY, $user_ID, $callback);
    if (is_wp_error($token)) {
        // 授权失败,可能是网络原因也可能是淘宝错误
        $tips = $token->get_error_code() . ':' . $token->get_error_message() . '<br />重新登录试试呢';
    } else {
        $tips = $token->taobao_user_nick . '你的令牌' . $token->access_token . '将于' . date('Y/n/j H:i:s', time() + $token->expires_in) . '过期';
    }
}
?>
<div id="primary" class="content-area">
	<div id="content" class="site-content" role="main">
		<article class="hentry">
			<header class="entry-header">
				<h1 class="entry-title"><?php 
echo $is_logged ? $user_identity : wp_loginout();
?>