2

我正在制作一个 php 脚本,该脚本将创建/构建 XML 请求,压缩 xml,然后将其编码为 base64。

这是我的代码片段:

$url = "http://cc-dev.com/servlet/Integration";

$xml = "<Transactions>\n";
$xml.= "<Search_Criteria>\n";
$xml.= "<CC_enquiry>Y</CC_enquiry>\n";
$xml.= "<CCPlusCPA_enquiry>N</CCPlusCPA_enquiry>\n";
$xml.= "<NLR_enquiry>N</NLR_enquiry>\n";
$xml.= "<CON_enquiry>N</CON_enquiry>\n";
$xml.= "<Identity_number>{$idnum}</Identity_number>\n";
$xml.= "<Surname>{$lname}</Surname>\n";
$xml.= "<Forename>{$fname}</Forename>\n";
$xml.= "<Forename2></Forename2>\n";
$xml.= "<Forename3></Forename3>\n";
$xml.= "<Gender>{$gender}</Gender>\n";
$xml.= "<Passport_flag>{$passport}</Passport_flag>\n";
$xml.= "<DateOfBirth>{$birthday}</DateOfBirth>\n";
$xml.= "<Address1>{$address1}</Address1>\n";
$xml.= "<Address2></Address2>\n";
$xml.= "<Address3></Address3>\n";
$xml.= "<Address4></Address4>\n";
$xml.= "<PostalCode>{$postalcode}</PostalCode>\n";
$xml.= "<HomeTelCode></HomeTelCode>\n";
$xml.= "<HomeTelNo></HomeTelNo>\n";
$xml.= "<WorkTelCode></WorkTelCode>\n";
$xml.= "<WorkTelNo></WorkTelNo>\n";
$xml.= "<CellTelNo></CellTelNo>\n";
$xml.= "<ResultType>XML</ResultType>\n";
$xml.= "<RunCodix>N</RunCodix>\n";
$xml.= "<Adrs_Mandatory>N</Adrs_Mandatory>\n";
$xml.= "<Enq_Purpose>18</Enq_Purpose>\n";
$xml.= "<Run_CompuScore>N</Run_CompuScore>\n";
$xml.= "</Search_Criteria>\n";
$xml.= "</Transactions>\n";


$ttype = urlencode(base64_encode("Normal_Search"));
$dll = urlencode(base64_encode("Direct01"));
$un = urlencode(base64_encode($username));
$pw = urlencode(base64_encode($password));
$origin = urlencode(base64_encode("TestProgram"));
$trans = urlencode(base64_encode(gzencode($xml)));

header("Location: $url?pTransType=$ttype&pUsrnme=$un&pPasswrd=$pw&pDLL_Version=$dll&pMyOrigin=$origin&pTransaction=$trans");        

$trans 的输出应如下所示:

UEsDBBQAAgAIAFhtdUFbdvjAZwEAAJADAAAWAAAATm9ybWFsU2VhcmNoVjVYTWh0LnhtbGWTa0%2BDMBSGP8/E31IuM5tJ02SibhrHlo1E/UTqOHNEaFkvifx7odwKfjvv%2B7zt4ZBTHAnKJD2plDNJbm9m%2BAhUnC5xIFIFIqW1N8NBEAO76lSU5BMjS7V0n2kZ7Ffj0NQ02fDtYKds2dy1C3sjrG6xpOEvCTCVqjJmOv8CQRZzZ%2Bkt71xn4SwdjKbYnDlqwWgOZM35ucSok4Y9cwFGvWqpMOrlCHpkIN4Y%2BRbyG7QGllSttxi1lXH3VMqCCxWfM/pdjzY2TOaRKtidH1KhLsS9b0bDyHZNbJUkAqR0q9Z9aQNvAN4I%2BAPwR2A%2BgHn7uVwqmgU8gQpZwsANzyGCjtrKxiEfYFUb9M7Fz3DSVjY2J4e6WQzIsg4NtUEHkDpTUVkA%2BdhuIowsowloVvVIf%2Bvf3tft/ELGW8oSqnizcRPHpJ7YNd5rUXAJxPUwsnXXIA54XujjqdqFerEnTv2y0P%2BnhdHk/f0BUEsBAhYLFAACAAgAWG11QVt2%2BMBnAQAAkAMAABYAAAAAAAAAAQAgAICBAAAAAE5vcm1hbFNlYXJjaFY1WE1odC54bWxQSwUGAAAAAAEAAQBEAAAAmwEAAAAA

我尝试过使用 gzencode()、gzdeflate() 和 gzcompress(),但它没有给出我想要的结果。你能帮我实现以下格式的字符串:“UEsDBBQ....AA”吗?

我认为这与压缩有关,但我似乎找不到合适的使用。提前致谢。

4

1 回答 1

1

Thanks for all the comments. I've found a solution to my problem. The ZipArchive function is used to zip the xml.

Here's the code:

<?php

header('Content-Type: text/plain');

$s = '<Transactions>
    <Search_Criteria>
        <CC_enquiry>Y</CC_enquiry>
        <CCPlusCPA_enquiry>Y</CCPlusCPA_enquiry>
        <NLR_enquiry>Y</NLR_enquiry>
        <CON_enquiry>N</CON_enquiry>
        <Identity_number>7408285107080</Identity_number>
        <Surname>Goofy</Surname>
        <Forename>Just</Forename>
        <Forename2></Forename2>
        <Forename3></Forename3>
        <Gender>M</Gender>
        <Passport_flag>N</Passport_flag>
        <DateOfBirth>19740828</DateOfBirth>
        <Address1></Address1>
        <Address2></Address2>
        <Address3></Address3>
        <Address4></Address4>
        <PostalCode></PostalCode>
        <HomeTelCode></HomeTelCode>
        <HomeTelNo></HomeTelNo>
        <WorkTelCode></WorkTelCode>
        <WorkTelNo></WorkTelNo>
        <CellTelNo></CellTelNo>
        <ResultType>XMHT</ResultType>
        <RunCodix>N</RunCodix>
        <Adrs_Mandatory>N</Adrs_Mandatory>
        <Enq_Purpose>12</Enq_Purpose>
        <Run_CompuScore>Y</Run_CompuScore>
    </Search_Criteria>
</Transactions>';

@unlink('s.zip');

$zip = new ZipArchive;
$res = $zip->open('s.zip', ZipArchive::CREATE);

if ($res === true) {

    $zip->addFromString('NormalSearchV5XMht.xml', $s);
    $zip->close();

    $s = file_get_contents('s.zip');
    $s = base64_encode($s);
    $s = urlencode($s);

    echo $s;
    // UEsDBBQAAAAIAIO7tEJLe43NZwEAAI4DAAAWAAAATm9ybWFsU2VhcmNoVjVYTWh0LnhtbGWTa0%2BDMBSGP8%2FE31IuM5tJ02SibhrHlo1E%2FUTqOHNEaFkvifx7odwKfjvv%2B7zt4ZBTHAnKJD2plDNJbm9m%2BAhUnC5xIFIFIqW1N8NBEAO76lSU5BMjS7V0n2kZ7Ffj0NQ02fDtYKds2dy1C3sjrG6xpOEvCTCVqjJmOv8CQRZzZ%2Bkt71xn4SwdjKbYnDlqwWgOZM35ucSok4Y9cwFGvWqpMOrlCHpkIN4Y%2BRbyG7QGllSttxi1lXH3VMqCCxWfM%2FpdjzY2TOaRKtidH1KhLsS9b0bDyHZNbJUkAqR0q9Z9aQNvAN4I%2BAPwR2A%2BgHn7uVwqmgU8gQpZwsANzyGCjtrKxiEfYFUb9M7Fz3DSVjY2J4e6WQzIsg4NtUEHkDpTUVkA%2BdhuIowsowloVvVIf%2Bvf3tft%2FELGW8oSqnizcRPHpJ7YNd5rUXAJxPUwsnXXIA54XujjqdqFerEnTv2y0P%2BnhdHo%2Ff0BUEsBAgAAFAAAAAgAg7u0Qkt7jc1nAQAAjgMAABYAAAAAAAAAAAAAAAAAAAAAAE5vcm1hbFNlYXJjaFY1WE1odC54bWxQSwUGAAAAAAEAAQBEAAAAmwEAAAAA

}
else {
    echo 'failed';
}

@unlink('s.zip'); 

?>

Thanks to Mr. Ramon Alivio for helping me.

于 2013-05-21T02:09:23.887 回答