omatech/gls-tracker

从asmred获取GLS跟踪数据

dev-master 2020-08-26 14:45 UTC

This package is auto-updated.

Last update: 2024-09-26 23:25:14 UTC


README

从ASMRED的XML web服务获取信息以跟踪包裹

用法

获取一次派送的状态信息

use Omatech\GLSTracker\GLSTracker;

...

$uid_cliente='6BAB7A53-3B6D-4D5A-9450-xxxxxxx';                   // Unique code of the customer, you must ask your GLS representative for that code
$webservice_url='https://wsclientes.asmred.com/b2b.asmx?wsdl';    // URL of the webservice of asmred (GLS in Spain)
$code='86387468743';                                              // Expedition code

$gls_tracker=new GLSTracker($uid_cliente, $webservice_url);       // Create a new gls_tracker object initialized with the UID of the client and the webservice url
$result=$gls_tracker->getClientExpedition($code);                 // Get the expedition info of that code
if (!$result) die('Error getting expedition');                    // If there's an error getClientExpedition returns false

$status=$gls_tracker->getExpeditionStatus();                      // Get expedition status, possible values are GRABADO, EN REPARTO, ENTREGADO

获取一次派送的所有信息

use Omatech\GLSTracker\GLSTracker;

...

$uid_cliente='6BAB7A53-3B6D-4D5A-9450-xxxxxxx';                   // Unique code of the customer, you must ask your GLS representative for that code
$webservice_url='https://wsclientes.asmred.com/b2b.asmx?wsdl';    // URL of the webservice of asmred (GLS in Spain)
$code='86387468743';                                              // Expedition code

$gls_tracker=new GLSTracker($uid_cliente, $webservice_url);       // Create a new gls_tracker object initialized with the UID of the client and the webservice url
$result=$gls_tracker->getClientExpedition($code);                 // Get the expedition info of that code
if (!$result) die('Error getting expedition');                    // If there's an error getClientExpedition returns false

$first_expedition=$gls_tracker->expediciones[0];                  // Get first expedition info
print_r($first_expedition);                                       // Show expedition info

在Laravel项目中使用它

安装新的Laravel项目

laravel new laravel-gls-tracker-example

进入项目并添加 omatech/gls-tracker

cd laravel-gls-tracker-example
composer require omatech/gls-tracker

在 .env 文件中添加环境变量

GLS_WEBSERVICE_URL=https://wsclientes.asmred.com/b2b.asmx?wsdl
GLS_UID_CLIENTE=6BAB7A53-3B6D-4D5A-9450-xxxxxx

编辑 routes/web.php

在顶部添加 use

use Omatech\GLSTracker\GLSTracker;

替换默认路由

Route::get('/{code?}'
, function ($code='61771040949189') {                                 // Default expedition code
    $webservice_url=env('GLS_WEBSERVICE_URL');                        // URL of the webservice of asmred (GLS in Spain)
    $uid_cliente=env('GLS_UID_CLIENTE');                              // Unique code of the customer, you must ask your GLS representative for that code
    
    echo "url=$webservice_url uid=$uid_cliente code=$code<br>";  // DEBUG info
    $gls_tracker=new GLSTracker($uid_cliente, $webservice_url);       // Create a new gls_tracker object initialized with the UID of the client and the webservice url
    $result=$gls_tracker->getClientExpedition($code);                 // Get the expedition info of that code
    if (!$result) die('Error getting expedition');                    // If there's an error getClientExpedition returns false
    
    $first_expedition=$gls_tracker->expediciones[0];                  // Get first expedition info
    dd($first_expedition);                                       // Show expedition info
});

现在您可以通过访问主页来获取派送信息,在我的案例中

http://laravel-gls-tracker-example.test/

或更改默认代码

http://laravel-gls-tracker.test/61771040888151

测试

使用以下命令运行所有测试

vendor\bin\phpunit