Exemple #1
0
 private function getFormatDocumentLevel($aLevel, $aSpace)
 {
     $tSpace1 = str_repeat($aSpace, $aLevel + 1);
     $tTagName = $this->getFirstTagName();
     if ($tTagName === null) {
         return $this;
     }
     $tXMLString = "\n";
     $tXMLDocument = new XMLDocument($this->iXMLString);
     while (($tTagName = $tXMLDocument->getFirstTagName()) !== null) {
         $tTemp = $tXMLDocument->getValue($tTagName);
         $tSpace = "";
         if ($tTemp->getFirstTagName() !== null) {
             $tSpace = $tSpace1;
         }
         $tXMLString = "{$tXMLString}{$tSpace1}<{$tTagName}>" . $tTemp->getFormatDocumentLevel($aLevel + 1, $aSpace) . "{$tSpace}</{$tTagName}>\n";
         $tXMLDocument = $tXMLDocument->deleteFirstTagDocument();
     }
     return new XMLDocument($tXMLString);
 }
 public static function verifySignXML($aMessage)
 {
     self::bundle();
     $aMessage = new XMLDocument($aMessage);
     $tTrxResponse = $aMessage->getValue('Message');
     if ($tTrxResponse == null) {
         throw new TrxException(TrxException::TRX_EXC_CODE_1301, TrxException::TRX_EXC_MSG_1301, '无[Message]段!');
     }
     $tAlgorithm = $aMessage->getValue('Signature-Algorithm');
     if ($tAlgorithm == null) {
         throw new TrxException(TrxException::TRX_EXC_CODE_1301, TrxException::TRX_EXC_MSG_1301, '无[Signature-Algorithm]段!');
     }
     $tSignBase64 = $aMessage->getValue('Signature');
     if ($tSignBase64 == null) {
         throw new TrxException(TrxException::TRX_EXC_CODE_1301, TrxException::TRX_EXC_MSG_1301, '无[Signature]段!');
     }
     $tSign = base64_decode($tSignBase64);
     $key = openssl_pkey_get_public(self::$iTrustpayCertificate);
     $data = strval($tTrxResponse);
     if (openssl_verify($data, $tSign, $key, OPENSSL_ALGO_SHA1) == 1) {
     } else {
         throw new TrxException(TrxException::TRX_EXC_CODE_1302, TrxException::TRX_EXC_MSG_1302);
     }
 }