Get the captcha json responses
@param $response
@return JsonResponse
483684
private function captchaResponse($response)
    {
        $errors = ['g-recaptcha-response' => ['Oops, something went wrong']];
        foreach ($response->getErrorCodes() as $k => $code) {
            if ($code == 'missing-input-response') {
                $code = 'Please confirm you are not a robot.';
            }
            $errors['g-recaptcha-response'][$k] = $code;
        }

        return new JsonResponse($errors, 422);
    }
823456
public static function toResponse($request, $response)
    {
        if ($response instanceof Responsable) {
            $response = $response->toResponse($request);
        }

        if ($response instanceof PsrResponseInterface) {
            $response = (new HttpFoundationFactory)->createResponse($response);
        } elseif ($response instanceof Model && $response->wasRecentlyCreated) {
            $response = new JsonResponse($response, 201);
        } elseif (! $response instanceof SymfonyResponse &&
                   ($response instanceof Arrayable ||
                    $response instanceof Jsonable ||
                    $response instanceof ArrayObject ||
                    $response instanceof JsonSerializable ||
                    is_array($response))) {
            $response = new JsonResponse($response);
        } elseif (! $response instanceof SymfonyResponse) {
            $response = new Response($response);
        }

        if ($response->getStatusCode() === Response::HTTP_NOT_MODIFIED) {
            $response->setNotModified();
        }

        return $response->prepare($request);
    }
922227
public function displayCaptchaPicture()
    {
        $app = Application::getFacadeApplication();
        $responseFactory = $app->make(ResponseFactoryInterface::class);

        return $responseFactory->notFound('Captcha without image');
    }
1053224
protected function parseJson($response) {
		try {
			$result = json_decode($response);
			$error = $this->fetchJsonError($result);
			if (!isset($result)) {
				throw new EAuthException(Yii::t('eauth', 'Invalid response format.', array()), 500);
			}
			else {
				if (isset($error) && !empty($error['message'])) {
					throw new EAuthException($error['message'], $error['code']);
				}
				else {
					return $result;
				}
			}
		} catch (Exception $e) {
			throw new EAuthException($e->getMessage(), $e->getCode());
		}
	}
618209
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            $markNames = (new Collection($jsonData['result']['gmarklist']))->combine('uin', 'markname')
                ->toArray();
            $groups = [];
            foreach ($jsonData['result']['gnamelist'] as $groupData) {
                $groupId = $groupData['gid'];
                $groupData['id'] = $groupData['gid'];
                $groupData['markName'] = isset($markNames[$groupId]) ? $markNames[$groupId] : '';
                $group = EntityFactory::createEntity(Group::class, $groupData);
                $groups[] = $group;
            }

            return new EntityCollection($groups);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
1127599
protected function processTogglResponse($response)
    {
        // We only need to do something if results are paginated
        if ($response->total_count <= 50) {
            return $response->data;
        }

        $reqdata = [];
        $reqdata = json_encode($reqdata);
        $pages = ceil($response->total_count / 50);
        $curr_page = 1;
        $data = $response->data;

        $orig_uri = $this->uri;

        while ($curr_page < $pages) {
            $curr_page++;
            $this->uri .= '&page=' . $curr_page;
            $response = $this->processRequest($reqdata, self::GET);
            $this->_handleError($reqdata, $response);
            foreach ($response->data as $entry) {
                $data[] = $entry;
            }
            $this->uri = $orig_uri;
        }

        return $data;
    }
1248642
public function getUserFromTokenResponse($response)
    {
        $user = $this->mapUserToObject($this->getUserByToken(
            $token = $this->parseAccessToken($response)
        ));

        $this->credentialsResponseBody = $response;

        if ($user instanceof User) {
            $user->setAccessTokenResponseBody($this->credentialsResponseBody);
        }

        return $user->setToken($token)
            ->setRefreshToken($this->parseRefreshToken($response))
            ->setExpiresIn($this->parseExpiresIn($response));
    }
271999
public function response($response)
    {
        if (!($response instanceof ResponseInterface)) {
            if (is_array($response) || $response instanceof \stdClass || $response instanceof \JsonSerializable) {
                $response = Response::make(json_encode($response));
                $response = $response->withHeader('Content-Type', 'application/json');
            } elseif (is_object($response) && method_exists($response, 'render')) {
                $response = Response::make($realResponse->render());
            } elseif (is_string($response) || is_numeric($response) || is_bool($response)) {
                $response = Response::make($response);
            } else {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid response "%s"; must be an string or object has render method',
                    gettype($response)
                ));
            }
        }
        return $response;
    }
684069
public function recaptcha($response, $ipClient = null)
    {
        if ($this->getOptions()->getGRecaptchaKey()) {
            $client = new \Zend\Http\Client($this->getOptions()->getGRecaptchaUrl());
            $client->setParameterPost(array(
                'secret'  => $this->getOptions()->getGRecaptchaKey(),
                'response' => $response,
                'remoteip'   => $ipClient,
            ));
            $client->setMethod(\Zend\Http\Request::METHOD_POST);
    
            $result = $client->send();
            if ($result) {
                $jsonResult = \Zend\Json\Json::decode($result->getBody());
                if ($jsonResult->success) {
                    return true;
                }
            }
        }

        return false;
    }
381943
protected function parseGetLanguagesResponse(Response $response)
    {
        $responseBody = $response->getBody();
        $responseData = json_decode($responseBody);
        $languages = [];
        foreach ($responseData as $language) {
            $translation = explode('-', $language);
            $from = $translation[0];
            $to = $translation[1];
            $languages[] = [$from,$to];
        }
        return $languages;
    }
19044
private static function getToken($captcha)
    {
        // Get the token values
        try {
            $token = Crypt::decrypt($captcha);
        } catch (\Exception $exception) {
            return false;
        }

        $token = @unserialize($token);

        // Token is null or unserializable
        if (!$token || !is_array($token) || empty($token)) {
            return false;
        }

        // Check token values
        if (empty($token['session_id']) ||
            empty($token['ip']) ||
            empty($token['user_agent']) ||
            $token['session_id'] !== session()->getId() ||
            $token['ip'] !== request()->ip() ||
            $token['user_agent'] !== request()->header('User-Agent')
        ) {
            return false;
        }

        return $token;
    }
660653
protected function formatResponse($response)
    {
        if (static::FORMAT_ARRAY === $this->output) {
            $response = static::xmlToArray($response);
        } else if (static::FORMAT_JSON === $this->output) {
            $response = static::xmlToArray($response);
            $response = json_encode($response, JSON_UNESCAPED_SLASHES);
        }

        return $response;
    }
1230521
private function formatResponse($response)
    {
        $this->last_response = $response;

        if (!empty($response['body'])) {
            return json_decode($response['body'], true);
        }

        return false;
    }
1333726
public static function parseResponse(Response $response)
    {
        $jsonData = \GuzzleHttp\json_decode($response->getBody(), true);
        if ($jsonData && 0 == $jsonData['retcode']) {
            //群成员的vip信息
            $vipInfos = (new Collection($jsonData['result']['vipinfo']))->combine('u', function ($entity) {
                return $entity;
            })->toArray();
            //群成员的名片信息, 如果全部成员都没有设置群名片则会不存在这个字段
            $cards = isset($jsonData['result']['cards']) ? (new Collection($jsonData['result']['cards']))
                ->combine('muin', 'card')
                ->toArray() : [];
            //群成员的简要信息
            $flags = (new Collection($jsonData['result']['ginfo']['members']))->combine('muin', 'mflag')
                ->toArray();
            //群基本详细信息
            $groupData = $jsonData['result']['ginfo'];
            $groupDetailData = [
                'gid' => $groupData['gid'],
                'name' => $groupData['name'],
                'code' => $groupData['code'],
                'owner' => $groupData['owner'],
                'level' => $groupData['level'],
                'createTime' => $groupData['createtime'],
                'flag' => $groupData['flag'],
                'memo' => $groupData['memo'],
                'members' => null,
            ];
            $members = [];
            foreach ($jsonData['result']['minfo'] as $memberData) {
                $uin = $memberData['uin'];
                $member = EntityFactory::createEntity(GroupMember::class, [
                    'flag' => isset($flags[$uin]) ? $flags[$uin] : null,
                    'nick' => $memberData['nick'],
                    'province' => $memberData['province'],
                    'gender' => $memberData['gender'],
                    'uin' => $uin,
                    'country' => $memberData['country'],
                    'city' => $memberData['city'],
                    'card' => isset($cards[$uin]) ? $cards[$uin] : null,
                    'isVip' => isset($vipInfos[$uin]) ? 1 == $vipInfos[$uin]['is_vip'] : false,
                    'vipLevel' => isset($vipInfos[$uin]) ? $vipInfos[$uin]['vip_level'] : 0,
                ]);
                $members[] = $member;
            }
            $groupDetailData['members'] = new EntityCollection($members);

            return EntityFactory::createEntity(GroupDetail::class, $groupDetailData);
        }
        throw new ResponseException($jsonData['retcode'], $response);
    }
347435
protected function getJsonFromResponse(Response $response)
    {
        $responseBody = $response->getBody();
        if ($response->getStatusCode() >= 400) {
            throw new Exception($responseBody);
        }
        $json = @json_decode($responseBody, true);
        if ($json === null) {
            throw new Exception('Failed to decode CommunityTranslation response');
        }

        return $json;
    }
329426
protected function fetchResponseError($response)
	{
		if (isset($response['error-code'])) {
			return [
				'code' => $response['error-code'],
				'message' => $response['message'],
			];
		} else if (isset($response['errorCode'])) {
			return [
				'code' => $response['errorCode'],
				'message' => $response['message'],
			];
		}
		return null;
	}
773806
protected function getResponseBody($response)
    {
        //Response must be string
        $body = $response;

        if ($response instanceof ResponseInterface) {
            //Fetch the body
            $body = $response->getBody();
        }

        if ($body instanceof StreamInterface) {
            $body = $body->getContents();
        }

        return (string) $body;
    }