* payload is no AES encrypted as in the mobile app
* async+poll query changed to sync+parse
This commit is contained in:
parent
b6ff7bae5c
commit
a7b2bd4e50
1
data/.gitignore
vendored
1
data/.gitignore
vendored
@ -1 +1,2 @@
|
||||
*.db
|
||||
config-cache.php
|
||||
|
||||
@ -1,13 +0,0 @@
|
||||
<SOAP-ENV:Envelope
|
||||
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
|
||||
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<SOAP-ENV:Body>
|
||||
<m:getWorkflowState
|
||||
xmlns:m="urn:MWAccess"
|
||||
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<arg0 xsi:type="xsd:string">%s</arg0>
|
||||
</m:getWorkflowState>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>
|
||||
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><StartWorkflow>
|
||||
<TemplateName>BANKKARTYASZAMLAEGYENLEGLEKERDEZES</TemplateName><Variables>
|
||||
<isClientCode>BANKKARTYASUGYFEL</isClientCode>
|
||||
<isIdentificationData>%s</isIdentificationData>
|
||||
<isSecretData>%s</isSecretData>
|
||||
<isStartDate>%s</isStartDate>
|
||||
<isEndDate>%s</isEndDate>
|
||||
<TemplateName>BANKKARTYASZAMLAEGYENLEGLEKERDEZES</TemplateName><Variables>
|
||||
<isClientCode>BANKKARTYASUGYFEL</isClientCode>
|
||||
<isIdentificationData>%s</isIdentificationData>
|
||||
<isSecretData>%s</isSecretData>
|
||||
<isStartDate>%s</isStartDate>
|
||||
<isEndDate>%s</isEndDate>
|
||||
</Variables></StartWorkflow>
|
||||
@ -4,9 +4,9 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<SOAP-ENV:Body>
|
||||
<m:startWorkflow xmlns:m="urn:MWAccess" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<m:startWorkflowSynch xmlns:m="urn:MWAccess" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
|
||||
<arg0 xsi:type="xsd:string">SZEPKARTYASZAMLATORTENET</arg0>
|
||||
<arg1 xsi:type="xsd:string"><![CDATA[%s]]></arg1>
|
||||
</m:startWorkflow>
|
||||
</m:startWorkflowSynch>
|
||||
</SOAP-ENV:Body>
|
||||
</SOAP-ENV:Envelope>
|
||||
@ -8,8 +8,7 @@ use GuzzleHttp\Client;
|
||||
|
||||
class SZEPManagerService
|
||||
{
|
||||
const TEMPLATE_WORKFLOW_START = "data/soap-xmls/SZEP_startWorkflow.xml";
|
||||
const TEMPLATE_WORKFLOW_STATE = "data/soap-xmls/SZEP_getWorkflowState.xml";
|
||||
const TEMPLATE_WORKFLOW = "data/soap-xmls/SZEP_startWorkflowSynch.xml";
|
||||
const TEMPLATE_QUERY_CARD = "data/soap-xmls/SZEP_queryCard.xml";
|
||||
|
||||
const CERTIFICATE_WEB_PATH = "https://www.otpbankdirekt.hu/homebank/mobilalkalmazas/certificate";
|
||||
@ -23,6 +22,19 @@ class SZEPManagerService
|
||||
const TAG_POCKET_FOOD = 'SZÉP kártya';
|
||||
const TAG_POCKET_SPORT = 'SZÉP kártya - szabadidő';
|
||||
|
||||
const AES_KEY = [
|
||||
11, 67, -99,-119,-110, -76, 76, -86,
|
||||
-105, -40, -7, 73,-113, 126, -53,-100,
|
||||
29, 52, 43, 98,-101, 41, 121, -68,
|
||||
122, 40, 67,-123, -85, -61, 79,-107
|
||||
];
|
||||
const IV_PARAM = [
|
||||
45, 84, 55, 96,
|
||||
22,-119, 113, -64,
|
||||
116, -64, 106, 56,
|
||||
-100, 114,-123, -81
|
||||
];
|
||||
|
||||
/** @var array */
|
||||
private $config;
|
||||
|
||||
@ -54,17 +66,16 @@ class SZEPManagerService
|
||||
*/
|
||||
public function pollRecent()
|
||||
{
|
||||
$workflowResult = $this->startWorkflow();
|
||||
$pollResult = $this->pollResult($workflowResult);
|
||||
$this->parseResult($pollResult);
|
||||
if (null !== ($pollResult = $this->getRecentXml())) {
|
||||
$this->parseResult($pollResult);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init the soap workflow
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function startWorkflow(): string
|
||||
private function getRecentXml(): ?string
|
||||
{
|
||||
$certificate = $this->getCertificate();
|
||||
openssl_public_encrypt($this->config['szep.card'], $cryptCardId, $certificate, OPENSSL_PKCS1_PADDING);
|
||||
@ -81,41 +92,20 @@ class SZEPManagerService
|
||||
$endDate->format("Y.m.d")
|
||||
);
|
||||
|
||||
$soapXml = sprintf(file_get_contents(self::TEMPLATE_WORKFLOW_START), $query);
|
||||
$soapResponseXml = $this->doSoapRequest($soapXml);
|
||||
$soapXml = sprintf(file_get_contents(self::TEMPLATE_WORKFLOW), $this->encryptPayload($query));
|
||||
try{
|
||||
$soapResponseXml = $this->doSoapRequest($soapXml);
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$domDocument = new \DOMDocument();
|
||||
$domDocument->loadXML($soapResponseXml);
|
||||
|
||||
$documentXpath = new \DOMXPath($domDocument);
|
||||
/** @var \DOMElement $returnElement */
|
||||
$returnElement = $documentXpath->query('//return')->item(0);
|
||||
return $returnElement->textContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Poll until the result is ready
|
||||
* @param string $workflowResult
|
||||
* @return string
|
||||
*/
|
||||
private function pollResult(string $workflowResult): string
|
||||
{
|
||||
$soapXml = sprintf(file_get_contents(self::TEMPLATE_WORKFLOW_STATE), $workflowResult);
|
||||
do {
|
||||
sleep(1);
|
||||
$soapResponseXml = $this->doSoapRequest($soapXml);
|
||||
|
||||
$domDocument = new \DOMDocument();
|
||||
$domDocument->loadXML($soapResponseXml);
|
||||
|
||||
$documentXpath = new \DOMXPath($domDocument);
|
||||
/** @var \DOMElement $completedElement */
|
||||
$completedElement = $documentXpath->query('//completed')->item(0);
|
||||
} while ($completedElement->textContent != "true");
|
||||
|
||||
/** @var \DOMElement $resultElement */
|
||||
$resultElement = $documentXpath->query('//result')->item(0);
|
||||
return base64_decode($resultElement->textContent);
|
||||
$returnElement = $documentXpath->query('//return/result')->item(0);
|
||||
return base64_decode($returnElement->textContent);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,6 +216,20 @@ class SZEPManagerService
|
||||
return $tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns AES encrypted base64 encoded $payload
|
||||
* @param string $payload
|
||||
* @param array $key
|
||||
* @param array $iv
|
||||
* @return string
|
||||
*/
|
||||
private function encryptPayload(string $payload, $key = self::AES_KEY, $iv = self::IV_PARAM): string
|
||||
{
|
||||
$aesKeyString = call_user_func_array("pack", array_merge(array("c*"), $key));
|
||||
$ivParamStr = call_user_func_array("pack", array_merge(array("c*"), $iv));
|
||||
return openssl_encrypt($payload, "AES-256-CBC", $aesKeyString, 0, $ivParamStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $soapXml
|
||||
* @return string
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user