1

到目前为止,我正在集成 Shippo API,它运行良好,但是存在这个问题,当我发送创建货件的请求时正在创建货件,但费率数组中没有任何内容,但是当我通过邮递员发送相同的请求时,我得到了这些费率这是我发送的请求。

//    Receiver Information for making shipment.
$r_name = $result[0]->r_name;
$r_email = $result[0]->r_email;
$r_street = $result[0]->r_street;
$r_city = $result[0]->r_city;
$r_country = $result[0]->r_country;
$r_zip = $result[0]->r_zip;
$r_state = $result[0]->r_state;

// Sender Information for making Shipment.
$s_name = $result[0]->s_name;
$s_email = $result[0]->s_email;
$s_street = $result[0]->s_street;
$s_city = $result[0]->s_city;
$s_country = $result[0]->s_country;
$s_zip = $result[0]->s_zip;
$s_state = $result[0]->s_state;

// Parcel Information for making Shipment.
$p_qty = $result[0]->p_qty;
$p_name = $result[0]->p_name;
$p_price = $result[0]->p_price;
$p_weight = $result[0]->p_weight;
$p_unit = $result[0]->p_unit;

$shipment_array = array(
    'address_to' => array(
        'name' => $r_name,
        'street1' => $r_street,
        'city' => $r_city,
        'state' => $r_state,
        'zip' => $r_zip,
        'country' => $r_country,
        'phone' => '03212669686',
        'email' => $r_email
    ),
    'address_from' => array(
        'name' => $s_name,
        'street1' => $s_street,
        'city' => $s_city,
        'state' => $s_state,
        'zip' => $s_zip,
        'country' => $s_country,
        'phone' => '03227577798',
        'email' => $s_email
    ),
    'parcels' => array(
        array(
            "length" => "10",
            "width" => "15",
            "height" => "10",
            "distance_unit" => "in",
            "weight" => $p_weight,
            "mass_unit" => $p_unit
        )
    ),
    'async' => false
);

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.goshippo.com/shipments/",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => json_encode($shipment_array),
    CURLOPT_HTTPHEADER => array(
        "Authorization: ShippoToken shippo_test_742eabd1c83ece80052fbce9ee71163181eaee72",
        "Cache-Control: no-cache",
        "Content-Type: application/json",
        "Postman-Token: 906233f7-ac66-3951-f96a-4f0f88c8d419"
    ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

谁能帮我找出我在这里做错了什么。

4

0 回答 0