Php 使用Curl调用LPS API时出错
我对这里还很陌生,非常希望能通过使用Curl调用lpsapi来解决一些问题 这是我们一直在使用的代码Php 使用Curl调用LPS API时出错,php,curl,Php,Curl,我对这里还很陌生,非常希望能通过使用Curl调用lpsapi来解决一些问题 这是我们一直在使用的代码 $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"> <so
$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>
如果我们使用Linux平台,则没有错误,但是,当切换到PHP时,问题如下所示
您可以使用exec()从PHP运行SOAP请求。我还注意到,您缺少$xml行末尾的soap信封和报价:
...
</soap:Envelope>';
看来我能胜任这项工作 欢迎来到堆栈溢出。我修正了你的代码降价,它需要在行首有4个空格。你期待着其他人付出一些努力来帮助你。所以,你需要付出努力,让他们更容易。没有指向图像的点,请将6个单词的错误消息复制到您的帖子中。
...
</soap:Envelope>';
$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);