我在这里很新,拼命寻求帮助来解决使用Curl调用LPS API的一些问题
以下是我们使用的代码
$xml = '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:gen="http://www.auspost.com.au/Schema/ProductandServiceFulfilment/LodgementManagement/generateLabel:v1">
<soap:Header />
<soap:Body>
<gen:get>
<Generate>
<InterfaceHeader>
<InterfaceName>generateLabel</InterfaceName>
<InterfaceVersion>1.0</InterfaceVersion>
<MessageType>Request</MessageType>
<BusinessReferenceID>12121212</BusinessReferenceID>
<SourceSystemID>Merchant</SourceSystemID>
<Timestamp>2013-05-08T12:45:12</Timestamp>
</InterfaceHeader>
<ServiceHeader>
<RequestType>PDF</RequestType>
<RequesterId>12345</RequesterId>
<LabelMessage>test</LabelMessage>
</ServiceHeader>
<LabelGroup>
<Layout>A4-1pp</Layout>
<Branding>true</Branding>
<LeftOffset>12</LeftOffset>
<TopOffset>12</TopOffset>
<Label>
<TemplateName>EPARCEL</TemplateName>
<InternationalPrintList>LABEL</InternationalPrintList>
<ArticleId>3NZ12000001601000600206</ArticleId>
<Barcode/>
<Source>12345</Source>
<OrderRef>34567567</OrderRef>
<ConsignmentId>1000310</ConsignmentId>
<ArticleCount>1</ArticleCount>
<TotalArticles>1</TotalArticles>
<Product>12345</Product>
<DeliverySignatureCapture>True</DeliverySignatureCapture>
<PickupSignatureCapture>True</PickupSignatureCapture>
<!-- Zero or more repetitions: -->
<PostagePaidIndicator>true</PostagePaidIndicator>
<ParcelCharacteristics>
<DeliveryInstructions>DELIVER 5 PM - 7 PM. IF PREMISES UNATTENDED, LEAVE IN A SECURE LOCATION OUT OF THE WEATHER.</DeliveryInstructions>
<PickupInstructions>pick</PickupInstructions>
<DangerousGoodsIndicator>true</DangerousGoodsIndicator>
<HeavyGoodIndicator>true</HeavyGoodIndicator>
<Fragile>false</Fragile>
<Contents>
<ContentQuantity>12</ContentQuantity>
<ContentWeight>21.22</ContentWeight>
<ContentUnitValue>12.22</ContentUnitValue>
<TotalContentValue>1222.22</TotalContentValue>
</Contents>
<TotalConsignmentValue>1212</TotalConsignmentValue>
<ExportClearanceNumber>12344</ExportClearanceNumber>
<Height>5655</Height>
<Length>234</Length>
<Width>123</Width>
<Weight>10</Weight>
</ParcelCharacteristics>
<RecipientAddress>
<Name>Greg E Burns</Name>
<AddressLine>111 Bourke St</AddressLine>
<Suburb>Melbourne</Suburb>
<State>VIC</State>
<Postcode>3000</Postcode>
<CountryCode>AU</CountryCode>
<Phone>0397654321</Phone>
</RecipientAddress>
<SenderAddress>
<Name>Greg E Burns</Name>
<AddressLine>111 Bourke St</AddressLine>
<Suburb>Melbourne</Suburb>
<State>VIC</State>
<Postcode>3000</Postcode>
<CountryCode>AU</CountryCode>
<Phone>0397654321</Phone>
</SenderAddress>
</Label>
</LabelGroup>
</Generate>
</gen:get>
</soap:Body>
&#39 ;;
$url = 'https://webapi.auspost.com.au/soap/LodgementManagement_MerchantTest_v1';
$ch = curl_init();
$header[] = "Content-Type: application/soap+xml";
$header[] = "charset=UTF-8";
$header[] = "Accept:application/xml";
$header[] = "action=\"generateLabel\"";
$timeout = 300;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); //no ssl
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, 'lps_merchant_testing:LPSprodtesting@1'); //user,password
$xmls = curl_exec($ch);
if(curl_errno($ch)){
print curl_error($ch);
}
curl_close($ch);
print_r($xmls);
如果我们使用Linux平台就可以了,没有错误,但是,当切换到PHP时会出现问题
答案 0 :(得分:0)
您可以使用exec()从PHP运行cURL LPS SOAP请求。我还注意到你错过了肥皂信封并从$ xml行的末尾引用:
...
</soap:Envelope>';
使用exec()运行:
$start = time();
$filename = "tmp_label_".$start.".xml";
$handle = file_put_contents($filename, $xml);
$credentials = "lps_merchant_testing:LPSprodtesting@1";
$url = "https://webapi.auspost.com.au/soap/LodgementManagement_MerchantTest_v1";
$header = '"Content-Type: application/soap+xml;charset=UTF-8;action=\"generateLabel\""';
exec("curl -v -X POST -d@$filename $url --header $header --insecure --user $credentials", $response);
unlink($filename);
print_r($response);
似乎可以胜任这份工作!