Created
October 29, 2013 07:27
-
-
Save chuprik/7210387 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class WebMoneyRequest | |
{ | |
public static $url = 'https://passport.webmoney.ru/xml/XMLGetWMIDInfo.aspx'; | |
private static $_instance = null; | |
public static function getInstance() | |
{ | |
if (self::$_instance === null) { | |
self::$_instance = new self(); | |
} | |
return self::$_instance; | |
} | |
public function requestWmidInfo($wmid) | |
{ | |
$xml = new SimpleXMLElement('<request/>'); | |
$xml->wmid = $wmid; | |
$response = self::performRequest($xml->asXML()); | |
return $this->parseResponse($response); | |
} | |
protected function parseResponse($response) | |
{ | |
$xmlElement = new SimpleXmlElement($response); | |
$attestatInfo = current($xmlElement->xpath('//attestat/row')); | |
$wmidInfo = current($xmlElement->xpath('//wmids/row')); | |
$claimsInfo = current($xmlElement->xpath('//claims/row')); | |
$userInfo = current($xmlElement->xpath('//userinfo/value/row')); | |
$urlInfo = current($xmlElement->xpath('//urls/row')); | |
return array( | |
'bl' => (int)$wmidInfo['level'], | |
'certificateIcon' => (string)$urlInfo['attestaticonurl'], | |
'webMoneyInfo' => array( | |
'fullName' => implode(' ', array($userInfo['fname'], $userInfo['iname'], $userInfo['oname'], $userInfo['name'])), | |
'attestatType' => (int)$attestatInfo['tid'], | |
'attestatDescription' => (string)$attestatInfo['typename'], | |
'wmidLevel' => (int)$wmidInfo['level'], | |
'dateRegistration' => (string)$wmidInfo['datereg'], | |
'posCount' => (string)$claimsInfo['posclaimscount'], | |
'negCount' => (string)$claimsInfo['negclaimscount'], | |
'lastClaimDt' => (string)$claimsInfo['claimslastdate'], | |
), | |
); | |
} | |
protected function performRequest($data) | |
{ | |
$ch = curl_init(self::$url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$result = curl_exec($ch); | |
if (curl_errno($ch) != 0) { | |
$result = ""; | |
$result .= "<errno>" . curl_errno($ch) . "</errno>\n"; | |
$result .= "<error>" . curl_error($ch) . "</error>\n"; | |
} | |
curl_close($ch); | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment