授权码查询openid
@param string $authCode 扫码支付授权码，设备读取用户微信中的条码或者二维码信息
@return array
@throws Exceptions\LocalCacheException
@throws InvalidResponseException
480343
public function queryAuthCode($authCode)
    {
        $pay = new Order($this->config->get());
        return $pay->queryAuthCode($authCode);
    }
801429
function getAccessToken($google_code) {
        // Make sure these are clear if we fail
        $this->authentication_object = FALSE;
        $this->access_token = FALSE;

        // From: https://github.com/PenguinProtocols/Basic-OpenID-Connect-Google
        // This approach gets us the openid_id from the former realm

        $token_url = "https://www.googleapis.com/oauth2/v3/token";
        $post = "code={$google_code}&client_id={$this->client_id}&client_secret={$this->client_secret}"
            . "&redirect_uri={$this->redirect}&grant_type=authorization_code";

        if ( $this->openid_realm ) {
            $post .= "&openid.realm=" . $this->openid_realm;
        }

        $response = $this->curl_post($token_url, $post);

        /* $response normally looks like this:
            {
                "access_token" : "QEX3L0Fm ... about 80 characters ... 4tLMYze617",
                "token_type" : "Bearer",
                "expires_in" : 3599,
                "id_token" : "hbGciO ... about 700 characers ... t3cE"
            }
        */

        if ($response) {
            $this->authentication_object = json_decode($response);
        }

        if (isset($this->authentication_object->refresh_token)) {
            $this->Google_RefreshToken = $this->authentication_object->refresh_token;
        }
        if (isset($this->authentication_object->access_token)) {
            $this->access_token = $this->authentication_object->access_token;
            return $this->authentication_object;
        } else {
            return FALSE;
        }
    }
174508
public function generateToken($code)
    {
        $this->token = $this->provider->getAccessToken('authorization_code', [
            'code' => $code
        ]);

        return $this->token;
    }
81791
public function tokenExchange($code)
        {
            $parameters = array(
                'client_id'     => $this->clientId,
                'client_secret' => $this->clientSecret,
                'code'          => $code,
            );

            return $this->request(
                $this->authUrl . 'token',
                $parameters
            );
        }
131021
public function getAuthorizationCode($code)
    {
        $sql  = sprintf('SELECT * from %s where authorization_code = :code', $this->config['code_table']);
        $code = $this->fetch($sql, compact('code'));
        if ($code) {
            // convert date string back to timestamp
            $code['expires'] = strtotime($code['expires']);
        }

        return $code;
    }
960803
public static function authentication($code = '')
    {
        if (empty($code)) {
            return false;
        }

        // authorize
        $authorize = self::authorize($code);

        if (!$authorize) {
            return false;
        }

        if (isset($authorize['error'])) {
            return $authorize;
        }

        // return infos
        return self::info($authorize['access_token']);
    }
640422
public function getAuthorizationCode($code)
    {
        $authorizationCode = $this->getTokenDataMapper(Entity\AuthorizationCode::class)->findByToken($code);

        if (! $authorizationCode instanceof Entity\AuthorizationCode) {
            return;
        }

        return [
            'expires'      => $authorizationCode->getExpiryUTCTimestamp(),
            'client_id'    => $authorizationCode->getClient()->getUuid(),
            'user_id'      => $authorizationCode->getUser()->getUuid(),
            'redirect_uri' => $authorizationCode->getRedirectUri(),
            'scope'        => $authorizationCode->getScopesString(),
        ];
    }
737749
public function getAccessTokenResponse($code)
    {
        $postKey = (version_compare(ClientInterface::VERSION, '6') === 1) ? 'form_params' : 'body';

        $response = $this->getHttpClient()->post($this->getTokenUrl(), [
            'headers' => ['Accept' => 'application/json'],
            $postKey => $this->getTokenFields($code),
        ]);

        return json_decode($response->getBody(), true);
    }
1154434
public function authenticate($code)
    {
        if (empty($code)) {
            throw new NostoException('Invalid authentication token');
        }

        $request = new HttpRequest();
        $request->setUrl(Nosto::getOAuthBaseUrl() . self::PATH_TOKEN);
        $request->setReplaceParams(
            array(
                '{cid}' => $this->clientId,
                '{sec}' => $this->clientSecret,
                '{uri}' => $this->redirectUrl,
                '{cod}' => $code
            )
        );
        $response = $request->get();
        $result = $response->getJsonResult(true);

        if ($response->getCode() !== 200) {
            throw ExceptionBuilder::fromHttpRequestAndResponse($request, $response);
        }
        if (empty($result['access_token'])) {
            throw new NostoException('No "access_token" returned after authenticating with code');
        }
        if (empty($result['merchant_name'])) {
            throw new NostoException('No "merchant_name" returned after authenticating with code');
        }

        return NostoOAuthToken::create($result);
    }
1283116
public function handleAuthorize(string $authCode = null)
    {
        $params = [
            'component_appid' => $this->app['config']['app_id'],
            'authorization_code' => $authCode ?? $this->app['request']->get('auth_code'),
        ];

        return $this->httpPostJson('cgi-bin/component/api_query_auth', $params);
    }
988651
public function getOAuthToken($code)
    {
        // Build data array
        $data = array(
            "grant_type"    => "authorization_code",
            "client_id"     => $this->client_id,
            "client_secret" => $this->client_secret,
            "code"          => $code
        );

        // Perform post request
        $response = $this->request->post("oauth/token", $data);

        return $response;
    }
238254
private function getAccessTokenFields($code)
    {
        $this->oAuthFields = [
            'grant_type' => 'authorization_code',
            'code' => $code,
            'redirect_uri' => $this->mpRedirectURL,
            'client_id' => $this->mpClientId,
            'client_secret' => $this->mpClientSecret,
        ];

        $this->fieldCount = count($this->oAuthFields);

        return $this->oAuthFields;
    }
729996
public function get($code)
    {
        foreach ($this->getDbConnection()->fetchAll(
            'SELECT * from oauth_auth_code
            WHERE auth_code = :authCode AND expire_time > :ts',
            [
                'authCode' => $code,
                'ts' => time()
            ]
        ) as $row) {
            if ($row) {
                return (new AuthCodeEntity($this->server))
                    ->setRedirectUri($row['client_redirect_uri'])
                    ->setExpireTime($row['expire_time'])
                    ->setId($row['auth_code']);
            }
        }
        return null;
    }
527568
public function thirdAuthorizeCallback($code = '') {
        $component_access_token = $this->componentAccessToken();
        $data                   = array(
            "component_appid"    => C("wechat", "componentAppid"),
            "authorization_code" => $code['auth_code'],
        );
        #提交URL地址
        $url = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=$component_access_token";
        $res = to_array($this->httpPost($url, $data));
        if (isset($res['authorization_info'])) {
            $data = $res['authorization_info'];
            #设置存储信息
            $key = md5($code['uid'] . md5($code['uid'] . 'thirdAuthorizeCallback') . "_wechat");
            #设置缓存时间
            $data['expire_time'] = time() + 7000;
            F($key, to_json($data));
            if ($code['url'] != "-1") {
                $file = dirname(dirname(__FILE__)) . "/bin/successful.html";
                echo file_get_contents($file);
            } else {
                redirect($code['url']);
            }
        } else {
            echo "授权失败";
        }
        exit();
    }
1319622
protected function getTokenByAuthorizationCodeGrant($code)
    {
        try {
            $token = $this->getAuthorizationServer()->getAccessToken('authorization_code', [
                'code' => $code,
            ]);

            $this->getFrameworkBridge()->persistUserToken($token);

            return $token;
        } catch (IdentityProviderException $e) {
            return null;
        }
    }
1307024
public function user($code = null)
    {
        if ($this->hasInvalidState()) {
            throw new InvalidStateException();
        }

        $params = [
            'code' => $code ?: $this->request->get('code'),
        ];

        return $this->parseJSON('get', [self::API_GET_USER_INFO, $params]);
    }
284846
public RetResult<String> getMPOpenidByCode(String code) throws IOException {
        if (code != null) code = code.replace("\"", "").replace("'", "");
        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + appsecret + "&code=" + code + "&grant_type=authorization_code";
        String json = getHttpContent(url);
        if (finest) logger.finest(url + "--->" + json);
        Map<String, String> jsonmap = convert.convertFrom(TYPE_MAP_STRING_STRING, json);
        return new RetResult<>(jsonmap.get("openid"));
    }