diff --git a/app/environment.ini b/app/environment.ini index f19a7d00..d0ca7b00 100644 --- a/app/environment.ini +++ b/app/environment.ini @@ -32,6 +32,9 @@ SSO_CCP_URL = https://sisilogin.testeveonline.com SSO_CCP_CLIENT_ID = SSO_CCP_SECRET_KEY = +; CCP XML APIv2 +CCP_XML = https://api.testeveonline.com + ; SMTP settings (optional) SMTP_HOST = localhost SMTP_PORT = 25 @@ -68,6 +71,9 @@ SSO_CCP_URL = https://login.eveonline.com SSO_CCP_CLIENT_ID = SSO_CCP_SECRET_KEY = +; CCP XML APIv2 +CCP_XML = https://api.eveonline.com + ; SMTP settings (optional) SMTP_HOST = localhost SMTP_PORT = 25 diff --git a/app/main/controller/ccp/sso.php b/app/main/controller/ccp/sso.php index 7a05acaf..b0051766 100644 --- a/app/main/controller/ccp/sso.php +++ b/app/main/controller/ccp/sso.php @@ -589,13 +589,25 @@ class Sso extends Api\User{ ], $additionalOptions); if( !empty($endpoint) ){ - $characterData->character = (new Mapper\CrestCharacter($endpoint))->getData(); + $crestCharacterData = (new Mapper\CrestCharacter($endpoint))->getData(); + $characterData->character = $crestCharacterData + ; if(isset($endpoint['corporation'])){ $characterData->corporation = (new Mapper\CrestCorporation($endpoint['corporation']))->getData(); } + + // IMPORTANT: alliance data is not yet available over CREST! + // -> we need to request them over the XML api + /* if(isset($endpoint['alliance'])){ $characterData->alliance = (new Mapper\CrestAlliance($endpoint['alliance']))->getData(); } + */ + + $xmlCharacterData = (new Xml())->getPublicCharacterData( (int)$crestCharacterData['id'] ); + if(isset($xmlCharacterData['alli'])){ + $characterData->alliance = $xmlCharacterData['alli']; + } } return $characterData; diff --git a/app/main/controller/ccp/xml.php b/app/main/controller/ccp/xml.php new file mode 100644 index 00000000..5fcce469 --- /dev/null +++ b/app/main/controller/ccp/xml.php @@ -0,0 +1,74 @@ + 4, + 'user_agent' => $this->getUserAgent(), + 'follow_location' => false // otherwise CURLOPT_FOLLOWLOCATION will fail + ]; + + return $requestOptions; + } + + /** + * request character data from CCP API + * @param int $characterId + * @return array + */ + public function getPublicCharacterData($characterId){ + $characterData = []; + $apiPath = self::getEnvironmentData('CCP_XML') . '/eve/CharacterInfo.xml.aspx'; + + $baseOptions = $this->getRequestOptions(); + $requestOptions = [ + 'method' => 'GET', + 'content' => [ + 'characterID' => (int)$characterId + ] + + ]; + + $requestOptions = array_merge($baseOptions, $requestOptions); + $apiResponse = Lib\Web::instance()->request($apiPath, $requestOptions ); + if( + $apiResponse['body'] && + ($xml = simplexml_load_string($apiResponse['body'])) + ){ + + if( + isset($xml->result) && + is_object($rowApiData = $xml->result->children()) + ){ + foreach($rowApiData as $item){ + // map attributes to array + if(count($item->children()) == 0){ + $characterData[$item->getName()] = strval($item); + } + } + } + } + + $data = (new Mapper\CcpCharacterMapper($characterData))->getData(); + + return $data; + } + +} \ No newline at end of file diff --git a/app/main/data/mapper/ccpcharactermapper.php b/app/main/data/mapper/ccpcharactermapper.php new file mode 100644 index 00000000..c3c59a53 --- /dev/null +++ b/app/main/data/mapper/ccpcharactermapper.php @@ -0,0 +1,37 @@ + ['character' => 'id'], + 'characterName' => ['character' => 'name'], + + 'race' => 'race', + + 'bloodlineID' => ['blood' => 'id'], + 'bloodline' => ['blood' => 'name'], + + 'ancestryID' => ['origin' => 'id'], + 'ancestry' => ['origin' => 'name'], + + 'corporationID' => ['corp' => 'id'], + 'corporation' => ['corp' => 'name'], + 'corporationDate' => ['corp' => 'date'], + + 'allianceID' => ['alli' => 'id'], + 'alliance' => ['alli' => 'name'], + 'allianceDate' => ['alli' => 'date'], + + 'securityStatus' => 'security' + ]; +} \ No newline at end of file diff --git a/app/pathfinder.ini b/app/pathfinder.ini index 9a5eadfe..0b187e92 100644 --- a/app/pathfinder.ini +++ b/app/pathfinder.ini @@ -112,7 +112,5 @@ DELETE_ACCOUNT = account_delete ; API ============================================================================================= [PATHFINDER.API] -; CCP XML APIv2 -CCP_XML = https://api.eveonline.com ; GitHub Developer API GIT_HUB = https://api.github.com