我目前正在做一个项目,在那里我必须获得数据包的状态(与DHL一起发送)。我读到过DHL API,它返回一个XML,但不知何故没有很好的例子。我找到了一些代码片段,但我不知道在哪里注册API密钥。
有没有人能给我一些链接或例子?
致以最好的问候,卢卡斯
发布于 2014-07-28 05:54:58
还有一个PHP客户端可用于使用DHL XML API。它可以处理DHL公开的所有不同服务。
https://github.com/alfallouji/DHL-API
这个客户端不依赖于或依赖于任何框架,它应该很容易与您自己的代码集成。例如,您可以查看samples文件夹,了解如何使用它。
发布于 2013-02-16 04:43:12
https://github.com/jklz/DHL-API-Tracking-PHP
它用于连接到使用XML-PI的DHL,以使用Air Way Bill跟踪发货。它可以处理一个跟踪号,或者你输入多少个跟踪号(已经用250和其他测试过了,然后花点时间运行也没有问题)。自动获取跟踪编号数组并将其分解为块,然后将请求发送到DHL,确保不传递每个请求可以跟踪的最大编号,然后以数组形式返回结果。
发布于 2019-07-10 00:03:25
又快又脏,没有任何第三方库,使用官方API:
<?php
$mode = 'sandbox'; // sandbox or production
$username = ''; // dhl developer account name, not email
$password = ''; // dhl developer account pass
$appname = 'zt12345'; // sandbox app
$apppass = 'geheim'; // sandbox app
$endpoint = 'https://cig.dhl.de/services/' . $mode . '/rest/sendungsverfolgung';
$payload = simplexml_load_string( '<?xml version="1.0" encoding="UTF-8" standalone="no"?><data appname="' . $appname . '" language-code="de" password="' . $apppass . '" piece-code="" request="d-get-piece-detail"/>' );
$shipmentids = array(
'00340434161094015902' // in sandbox only special numbers are allowed
);
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Authorization: Basic " . base64_encode( "$username:$password" )
)
);
$context = stream_context_create( $opts );
foreach ( $shipmentids as $shipmentid ) {
$payload->attributes()->{'piece-code'} = $shipmentid;
$response = file_get_contents( $endpoint . '?' . http_build_query( array( 'xml' => $payload->saveXML() ) ), false, $context );
$responseXml = simplexml_load_string( $response );
$status = null;
// get last state
foreach ( $responseXml->data->data->data as $event ) {
$status = $event->attributes()->{'event-short-status'};
}
echo "Shipment " . $shipmentid . " is in state: " . $status . "\n";
}https://stackoverflow.com/questions/14902983
复制相似问题