我正在使用一个名为 ViaPost 的网站为我的企业邮寄信件。我正在使用 SoapClient。上传的文件必须是 base64binary 格式。我正在使用以下代码,但返回空。
$pdf_data = file_get_contents('test.pdf');
$pdf_data = base64_encode($pdf_data);
print $pdf_data;
扩展上述内容:
POST /viapostcustomer.asmx HTTP/1.1
Host: api.viapost.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://api.viapost.com/CreateLetter"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CreateLetter xmlns="http://api.viapost.com">
<loginToken>string</loginToken>
<name>string</name>
<description>string</description>
<FileContents>base64Binary</FileContents>
<dynamic>boolean</dynamic>
<shareLetterWithGroup>boolean</shareLetterWithGroup>
<returnMessage>string</returnMessage>
<letterID>long</letterID>
</CreateLetter>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<CreateLetterResponse xmlns="http://api.viapost.com">
<CreateLetterResult>boolean</CreateLetterResult>
<returnMessage>string</returnMessage>
<letterID>long</letterID>
</CreateLetterResponse>
</soap:Body>
</soap:Envelope>
<?php
$client = new SoapClient("http://api.viapost.com/viapostcustomer.asmx?WSDL");
$params = array('sUserName'=>'USERNAME','sPassword'=>'PASSWORD','sLoginToken'=>'','sReturnMessage'=>'');
$SignIn = $client->__soapCall('SignIn', array($params));
$sLoginToken = $SignIn->sLoginToken;
$pdf_data = file_get_contents('test.pdf');
$pdf_data = base64_encode($pdf_data);
$params = array('loginToken'=>$sLoginToken,'name'=>'testname','description'=>'testdescription','fileContents'=>$pdf_data,'dynamic'=>'true','shareLetterWithGroup'=>'false','returnMessage'=>'','letterID'=>'');
$CreateLetter = $client->__soapCall('CreateLetter', array($params));
$returnMessage = $CreateLetter->returnMessage;
print $returnMessage;
?>
它返回:保存文件时出现问题。请再试一次。
我做了一些我知道我做过的愚蠢的事情。