我正在制作一个 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”吗?
我认为这与压缩有关,但我似乎找不到合适的使用。提前致谢。