Esempio n. 1
0
function savePackageLable($packageSns)
{
    $dispatcher = array('category' => 'direct-express', 'handler' => 'package', 'action' => 'print-label');
    $request_data = array('token' => getToken(), 'user_key' => getUserKey(), 'format' => 'classic_a4');
    $api_address = getApiBaseAddress() . join("/", $dispatcher);
    $api_address .= "?" . http_build_query($request_data);
    $api_address .= get_label_params_string($packageSns, 'package_sn');
    echo $api_address;
    $response = rest_helper($api_address, null, 'GET', 'binary');
    $packageSnsStr = join("-", $packageSns);
    $fd = fopen("label-{$packageSnsStr}.pdf", 'wb');
    fwrite($fd, $response);
    fclose($fd);
}
Esempio n. 2
0
<?php

require "http_request.php";
require "auth.php";
$dispatcher = array('category' => 'direct-express', 'handler' => 'package', 'action' => 'readd-to-order');
$api_address = $api_base . join("/", $dispatcher);
$auth = array('token' => $token, 'user_key' => $user_key);
$post_params = array('package_sn' => 'EUB120418TST000009', 'order_sn' => 'STST12042400003');
$url = $api_address . "?" . http_build_query($auth);
echo "<br>Request URL {$url} <br>";
$response = rest_helper($url, $post_params, 'POST');
echo "<pre>";
print_r($response);
echo "</pre>";
Esempio n. 3
0
<?php

require "http_request.php";
require "auth.php";
// 参数为要打印标签的包裹处理号列表
$packageSns = array('CET141010TST000087', 'CET141010TST000088', 'CET141010TST000087', 'CET141010TST000088');
$dispatcher = array('category' => 'direct-express', 'handler' => 'package', 'action' => 'print-label');
$request_data = array('token' => getToken(), 'user_key' => getUserKey(), 'format' => 'classic_a4');
$api_address = $api_base . join("/", $dispatcher);
$api_address .= "?" . http_build_query($request_data);
$api_address .= get_repeat_string_params_string($packageSns, 'package_sn');
echo $api_address;
try {
    $response = rest_helper($api_address, null, 'GET', 'binary');
    $r = json_decode($response);
    if ($r === null) {
        //throw new Exception("failed to decode $res as json");
        //if not json return, save file
        $file = "label/label-mutiply-packageSns.pdf";
        saveFile($file, $response);
        echo "<br />";
        echo "save ok " . $file;
    } else {
        echo "<pre>";
        print_r($r);
        echo "</pre>";
    }
} catch (exception $e) {
    echo $e;
}
function saveFile($filename, $response)
<?php

require "http_request.php";
require "auth.php";
$dispatcher = array('category' => 'outbound', 'handler' => 'package', 'action' => 'pricing-for-storage-nos');
$request_data = array('token' => $token, 'user_key' => $user_key, 'express_service' => 'USNUS', 'warehouse' => 'US', 'destination_type' => 'L', 'to_zip_code' => '95050', 'to_region' => 'US');
//storage number and count of products
$storage_nos = array(array('product' => 'LTST00000629', 'count' => '3'), array('product' => 'LTST00000632', 'count' => '2'));
$api_address = $api_base . join("/", $dispatcher);
$api_address .= "?" . http_build_query($request_data);
$api_address .= get_pricing_params_string($storage_nos, 'storage_no_array');
#echo $api_address;
$response = rest_helper($api_address, null, 'GET');
echo "<pre>";
print_r($response);
echo "</pre>";
<?php

require "http_request.php";
require "auth.php";
$dispatcher = array('category' => 'outbound', 'handler' => 'package', 'action' => 'pricing-for-m2c-storage-no');
$request_data = array('token' => $token, 'user_key' => $user_key, 'express_service' => 'USNUS', 'warehouse' => 'US', 'destination_type' => 'L', 'to_zip_code' => '95050', 'to_region' => 'US', 'storage_no' => 'LRMP00000001');
$api_address = $api_base . join("/", $dispatcher);
//echo $api_address;
$response = rest_helper($api_address, $request_data, 'GET');
echo "<pre>";
print_r($response);
echo "</pre>";
function aws_signed_request($region, $params, $public_key, $private_key)
{
    /*
    Copyright (c) 2009 Ulrich Mierendorff
    
    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
    to deal in the Software without restriction, including without limitation
    the rights to use, copy, modify, merge, publish, distribute, sublicense,
    and/or sell copies of the Software, and to permit persons to whom the
    Software is furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
    THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
    DEALINGS IN THE SOFTWARE.
    */
    /*
    Parameters:
        $region - the Amazon(r) region (ca,com,co.uk,de,fr,jp)
        $params - an array of parameters, eg. array("Operation"=>"ItemLookup",
                        "ItemId"=>"B000X9FLKM", "ResponseGroup"=>"Small")
        $public_key - your "Access Key ID"
        $private_key - your "Secret Access Key"
    */
    // some paramters
    $method = "GET";
    if ($region == 'it') {
        $host = "webservices.amazon." . $region;
    } else {
        $host = "ecs.amazonaws." . $region;
    }
    $uri = "/onca/xml";
    // additional parameters
    $params["Service"] = "AWSECommerceService";
    $params["AWSAccessKeyId"] = $public_key;
    // GMT timestamp
    $params["Timestamp"] = gmdate("Y-m-d\\TH:i:s\\Z");
    // API version
    $params["Version"] = "2011-08-01";
    $params["AssociateTag"] = "coole20-20";
    // sort the parameters
    ksort($params);
    // create the canonicalized query
    $canonicalized_query = array();
    foreach ($params as $param => $value) {
        $param = str_replace("%7E", "~", rawurlencode($param));
        $value = str_replace("%7E", "~", rawurlencode($value));
        $canonicalized_query[] = $param . "=" . $value;
    }
    $canonicalized_query = implode("&", $canonicalized_query);
    // create the string to sign
    $string_to_sign = $method . "\n" . $host . "\n" . $uri . "\n" . $canonicalized_query;
    // calculate HMAC with SHA256 and base64-encoding
    $signature = base64_encode(hash_hmac("sha256", $string_to_sign, $private_key, True));
    // encode the signature for the request
    $signature = str_replace("%7E", "~", rawurlencode($signature));
    $request = "http://" . $host . $uri . "?" . $canonicalized_query . "&Signature=" . $signature;
    return rest_helper($request, null, "GET", "xml");
}
require "http_request.php";
require "auth.php";
// 参数为要打印标签的包裹处理号列表
$packageSns = array('CGT141014TST000001', 'CGT141014TST000002', 'CGT141014TST000002', 'CGT141014TST000002');
$dispatcher = array('category' => 'direct-express', 'handler' => 'package', 'action' => 'print-label');
$request_data = array('token' => getToken(), 'user_key' => getUserKey(), 'format' => 'classic_a4');
$api_address = $api_base . join("/", $dispatcher);
$api_address .= "?" . http_build_query($request_data);
echo $api_address;
//echo "<br />";
//echo get_repeat_string_params_string($packageSns, 'package_sn');
//&package_sn=CGT141014TST000001&package_sn=CGT141014TST000002
$post_data = get_repeat_string_params_string($packageSns, 'package_sn');
try {
    $response = rest_helper($api_address, $post_data, 'POST', 'binary', false);
    $r = json_decode($response);
    if ($r === null) {
        //throw new Exception("failed to decode $res as json");
        //if not json return, save file
        $file = "label/label-mutiply-post-packageSns.pdf";
        saveFile($file, $response);
        echo "<br />";
        echo "save ok " . $file;
    } else {
        echo "<pre>";
        print_r($r);
        echo "</pre>";
    }
} catch (exception $e) {
    echo $e;
 public function invoice_delete($invoice_id)
 {
     $data['X-API-KEY'] = $this->api_key;
     $data['id'] = $invoice_id;
     $result = rest_helper($this->api_url . "invoices/delete", $data, 'POST');
     return $result;
 }