コード例 #1
0
function xt_taobao_refreshtoken()
{
    $app = xt_taobao_is_session_ready();
    if ($app) {
        if (isset($app['token']['refresh_token']) && !empty($app['token']['refresh_token'])) {
            //请求参数
            $postfields = array('grant_type' => 'refresh_token', 'client_id' => $app['appKey'], 'client_secret' => $app['appSecret'], 'refresh_token' => $app['token']['refresh_token']);
            include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/TopClient.php';
            $client = new TopClient();
            try {
                $token = json_decode($client->curl(XT_TAOBAO_TOKEN_URL, $postfields), true);
                $token['expires_in_date'] = date('Y-m-d H:i:s', current_time('timestamp') + $token['expires_in']);
            } catch (Exception $e) {
                wp_die($e->getMessage());
            }
            if (isset($token['expires_in']) && !empty($token['expires_in']) && isset($token['re_expires_in']) && !empty($token['re_expires_in'])) {
                $app['token'] = $token;
                $option_platform = get_option(XT_OPTION_PLATFORM);
                $option_platform['taobao'] = $app;
                update_option(XT_OPTION_PLATFORM, $option_platform);
            }
        }
    }
}
コード例 #2
0
ファイル: xt-login.php プロジェクト: aspirin/wp-xintaoke
function xt_platform_taobao_token()
{
    $app = xt_get_app_taobao();
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/TopClient.php';
    //请求参数
    $postfields = array('grant_type' => 'authorization_code', 'client_id' => $app['appKey'], 'client_secret' => $app['appSecret'], 'code' => $_GET['code'], 'redirect_uri' => xt_platform_taobao_authorize_url());
    $client = new TopClient();
    try {
        $token = json_decode($client->curl(XT_TAOBAO_TOKEN_URL, $postfields), true);
        $token['expires_in_date'] = date('Y-m-d H:i:s', current_time('timestamp') + $token['expires_in']);
    } catch (Exception $e) {
        wp_die($e->getMessage());
    }
    $access_token = $token['access_token'];
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/RequestCheckUtil.php';
    include_once XT_PLUGIN_DIR . '/xt-core/sdks/taobao/request/UserBuyerGetRequest.php';
    $client->format = 'json';
    $client->appkey = $app['appKey'];
    $client->secretKey = $app['appSecret'];
    $req = new UserBuyerGetRequest();
    $req->setFields("nick,sex,buyer_credit,avatar,has_shop,vip_info");
    try {
        $resp = (array) $client->execute($req, $access_token);
    } catch (Exception $e) {
        wp_die($e->getMessage());
    }
    if (isset($resp['code'])) {
        wp_die($resp['msg']);
    }
    $user = (array) $resp['user'];
    return array('id' => $user['nick'], 'display_name' => $user['nick'], 'token' => $token, 'sex' => $user['sex'] == 'm' ? '男' : '女', 'avatar' => $user['avatar'], 'user' => $user);
}