src/AppBundle/Component/OAuthClient/WeiboOAuthClient.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace AppBundle\Component\OAuthClient;

class WeiboOAuthClient extends AbstractOAuthClient
{
    public function getAuthorizeUrl($callbackUrl)
    {
        $params = array();
        $params['client_id'] = $this->config['key'];
        $params['response_type'] = 'code';
        $params['redirect_uri'] = $callbackUrl;

        return 'https://api.weibo.com/oauth2/authorize?'.http_build_query($params);
    }

    public function getAccessToken($code, $callbackUrl)
    {
        $params = array();
        $params['client_id'] = $this->config['key'];
        $params['client_secret'] = $this->config['secret'];
        $params['authorization_code'] = 'code';
        $params['redirect_uri'] = $callbackUrl;
        $params['code'] = $code;

        $data = $this->postRequest('https://api.weibo.com/oauth2/access_token?'.http_build_query($params), array());

        $rawToken = json_decode($data, true);

        if (array_key_exists('error', $rawToken)) {
            return array(
                'token' => null,
                'userId' => null,
                'expiredTime' => null,
            );
        }

        $token = array(
            'token' => $rawToken['access_token'],
            'userId' => $rawToken['uid'],
            'expiredTime' => $rawToken['expires_in'],
        );

        return $token;
    }

    public function getUserInfo($token)
    {
        $params = array();

        $params['access_token'] = $token['token'];
        $params['uid'] = $token['userId'];

        $data = $this->getRequest('https://api.weibo.com/2/users/show.json', $params);
        $userInfo = json_decode($data, true);

        $this->checkError($userInfo);

        return $this->convertUserInfo($userInfo);
    }

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。