我正在我的一个网站中集成Zoyto API https://test.zoyto.com/zfulfillment/api/。我测试了API调用它的函数 getOrderStatus ,它工作正常。但是当我尝试调用函数 newOrders 时,我得到了响应。
object(stdClass)#2 (1) { ["newOrdersResult"]=> object(stdClass)#3 (4) { ["timestamp"]=> string(20) "2015-09-15T03:45:26Z" ["result_code"]=> string(3) "200" ["error_message"]=> string(48) "The request was valid and is processed by Zoyto." ["order_statuses"]=> object(stdClass)#4 (1) { ["Order_Status"]=> object(stdClass)#5 (5) { ["client_order_id"]=> string(8) "TESTPN01" ["zoyto_order_id"]=> int(0) ["order_status_code"]=> string(8) "REJECTED" ["order_type"]=> string(14) "CUSTOMER_ORDER" ["error_message"]=> string(24) "411:The city is invalid." } } } }
以下是我的代码:
date_default_timezone_set('UTC');
function createSignature($api_secret, $method, $timestamp, $service_name) {
$toSign = strtolower($service_name) . strtolower($method) . strtolower($timestamp);
$sig = hash_hmac('sha1', $toSign, $api_secret, true);
return base64_encode($sig);
}
/********Test API*******/
$api_key = '3D84D210-AA9B-4968-B6A1-25FB6A8D556D';
$url = "https://test.zoyto.com/zfulfillment/api/?WSDL";
$api_secret = 'EEF53F44E6914C2799F2A19AAF28F27B';
//$method = 'getOrderStatus';
$method = 'newOrders';
$timestamp = date('Y-m-d').'T'.date("h:i:s").'Z';
$service_name = 'Zoyto Fulfillment Service';
$sig = createSignature($api_secret, $method, $timestamp, $service_name);
//echo $timestamp;
$client = new SoapClient($url);
/* Set your parameters for the request */
$orderStatus = array(
"api_key" => $api_key,
"timestamp" => $timestamp,
"signature" => $sig,
"version" => "2.0",
"order_ids" => array("RTSC100052438")
);
$shipping = array(
"first_name" => "Calvin",
"last_name" => "Hart",
"address_1" => "Apt 1",
"address_2" => "5143 West Bellfort Ave",
"zip_code" => "77035",
"state" => "CA",
"country" => "USA",
"country_code" => "US",
"phone_number" => "0401234567",
"city" => "Riva",
"email" => "myemail@gmail.com"
);
$billing = $shipping;
$line_item = array(
"client_line_item_id" => "1",
"quantity" => "1",
"ship_method_code" => "PRIT",
"client_part_number" => "SAFARI-XXL",
"description" => "Description",
"parent_line_item_id" => 0,
"line_item_amount" => 1.00
);
$newOrder = array(
"api_key" => $api_key,
"timestamp" => $timestamp,
"signature" => $sig,
"version" => "2.0",
"orders" => array(array( "shipping_address" => $shipping,
"billing_address" => $billing,
"client_order_id" => "TESTPN01",
"order_type" => "CUSTOMER_ORDER",
"line_items" => array($line_item),
"created_at" => $timestamp,
"total_product_amount" => 1.00,
"total_discount_amount" => 0.00,
"total_tax_amount" => 0.00,
"total_shipping_amount" => 0.00,
"total_handling_amount" => 0.00,
"total_order_amount" => 1.00,
"group_shipment_number" => 0
)
)
);
//$params = $orderStatus;
$params = $newOrder;
/* Invoke webservice method with your parameters, in this case: Function1 */
$response = $client->__soapCall($method, array($params));
/* Print webservice response */
var_dump($response);
//var_dump($client->__getFunctions());
//var_dump($client->__getTypes());
看起来在准备送货地址时出现了一些错误。有没有人可以帮忙。我是从最近两天搜索但没有成功。
提前感谢所有读者。
答案 0 :(得分:0)
使用https://test.zoyto.com/zfulfillment/api/Service.asmx?WSDL中的WSDL,您可以从wsdltophp.com生成相应的包,以确保如何在PHP中构造您的请求,因为每个元素都是具有setter / getters的PHP对象。 如果您需要任何其他帮助,请与我们联系,