PHP示例

使用PHP Verion 5.2.13编写此代码和这些示例。 PHP配置了--With-Curl选项和启用JSON。看 PHP JSON.PHP卷曲 有关PHP功能的详细信息。

截至2014年10月,Secure_Token请求不再支持SSL V3。您可以通过调用“curl_setopt($ connection,curlopt_sslversion,curl_slversion_tlsv1);“ - 请注意,您可能还需要添加”CURLOPT_SSL_CIPHER_LIST => 'TLSv1'“到你的pphttpconfig.php - 如上所述 这个stackoverflow答案.

php示例fetchtoken

fetchtoken API调用没有任何输入。此呼叫是安全的API请求,并要求DEV名称和CERT名称标头。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印令牌。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$ args. = array();
$ post_fields. = "fetchtoken.Request";
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
$token = $响应['fetchtoken.Response']['authToken'];
echo "Token: $token \n";
echo "Response: \n";
print_r($响应);
Request: fetchTokenRequest
Token: GTL0jWeQat
Response:
Array
(
  [fetchTokenResponse] => Array
      (
          [hardExpirationTime] => 2011-12-16T06:20:58.000Z
          [authenticationURL] => //www.sanyili.com/login?apitoken=GTL0jWeQat
          [authToken] => GTL0jWeQat
      )
  [timestamp] => 2010-12-16T06:20:58.000Z
  [version] => 1.0beta
  [ack] => Success
)

PHP示例AddFixedPriceItem

通过提供标题,价格,数量,描述,图片,类别和运输$ arg,将项目添加到波兰琴。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是安全的API请求,并需要开发名称和证书名称标头。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印出项目ID。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$item['title'] = "My Item";
$item['price'] = 30.57;
$item['quantity'] = 1;
$item['description'] = "This item is great.  Any html here.";
$item['pictureDetails']['pictureURL'] = "http://www.google.com/images/logos/ps_logo2.png";
$item['primaryCategory']['categoryId'] = 377;
$item['itemSpecifics']['specifics'] = array();
$item['itemSpecifics']['specifics'][] = array('Condition', 'New');
$item['itemSpecifics']['specifics'][] = array('Genre', 'Romance');
$item['shippingDetails']['shippingServiceOptions']['freeShipping'] = true;
$ args. = array("item" => $item);
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$ post_fields. = "AddFixedPriceItem.=" .  urlencode(json_encode($ args.));
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
$itemId= $响应['AddFixedPriceItem.Response']['itemId'];
echo "itemId: $itemId \n";
echo "Response: \n";
print_r($响应);
Request: addFixedPriceItem={"item":{"title":"My Item","price":30.57,"quantity":1,"description":"This item is great.  Any html here.","pictureDetails":{"pictureURL":"http:\/\/www.google.com\/images\/logos\/ps_logo2.png"},"primaryCategory":{"categoryId":377},"shippingDetails":{"shippingServiceOptions":{"freeShipping":true}}},"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
itemId: 24018227
Response:
Array
(
  [timestamp] => 2010-12-16T06:40:01.000Z
  [addFixedPriceItemResponse] => Array
      (
          [sellingState] => Ready for sale
          [categoryId] => 377
          [itemId] => 24018227
      )
  [version] => 1.0beta
  [ack] => Success
)

PHP示例用于AddMultipleFixedPriceItems

添加多个固定价格项目是添加单个项目,并添加每个项目到外部项目数组。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);

$items = array();
$item0['title'] = "My Item 0";
$item0['price'] = 30.57;
$item0['quantity'] = 1;
$item0['description'] = "This item is great.  Any html here.";
$item0['primaryCategory']['categoryId'] = 397;
$items[] = array("item" => $item0);  # important step is to identify each item with an "item" key

$item1['title'] = "My Item 1";
$item1['price'] = 30.57;
$item1['quantity'] = 1;
$item1['primaryCategory']['categoryId'] = 397;
$item1['description'] = "This item is great.  Any html here.";
$items[] = array("item" => $item1);  # important step is to identify each item with an "item" key

$ args. = array("items" => $items);
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$ post_fields. = "AddMultipleFixedPriceItems.=" .  urlencode(json_encode($ args.));

echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);

$json_response = curl_exec($connection);

if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}

curl_close($connection);

$响应 = json_decode($json_response,true);
$itemId= $响应['AddFixedPriceItem.Response']['itemId'];
echo "itemId: $itemId \n";
echo "Response: \n";
print_r($响应);

ReviseFixedPriceItem的PHP示例

修改项目 24018227 更新标题,价格和数量 $ args.。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是安全的API请求,并需要开发名称和证书名称标头。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$itemId = 24018227;
$item = array();
$item['title'] = "My Item - revised";
$item['price'] = 30.99;
$item['quantity'] = 2;
$ args. = array("item" => $item, "itemId" => $itemId);
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$ post_fields. = "ReviseFixedPriceItem.=" .  urlencode(json_encode($ args.));
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: reviseFixedPriceItem={"item":{"title":"My Item - revised","price":30.99,"quantity":2},"itemId":24018227,"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
Response:
Array
(
  [timestamp] => 2010-12-16T09:29:01.000Z
  [reviseFixedPriceItemResponse] => Array
      (
          [sellingState] => Ready for sale
          [categoryId] => 377
          [itemId] => 24018227
      )
  [version] => 1.0beta
  [ack] => Success
)

GetunlistedItem的PHP示例

获取包含项目ID的未列出的项目的详细信息 24018222。您还需要提供授权令牌 $ args.。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是安全的API请求,并需要开发名称和证书名称标头。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$itemId = 24018222;
$ args. = array("itemId" => $itemId);
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$ post_fields. = "getunlisteditem=" .  json_encode($ args.);
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: getUnlistedItem={"itemId":24018222,"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
Response:
Array
(
  [timestamp] => 2010-12-16T09:54:40.000Z
  [getUnlistedItemResponse] => Array
      (
          [item] => Array
              (
                  [primaryCategory] => Array
                      (
                          [categoryName] => Books >> Fiction Books
                          [categoryId] => 377
                      )
                  [seller] => Array
                      (
                          [feedbackRatingStar] =>
                          [membershipLevel] =>
                          [sellerUserName] => MyUser
                          [availableForChat] => true
                          [userPicture] =>
                          [positiveFeedbackPercent] => 0.0
                      )
                  [convertedBuyItNowPrice] => 30.99
                  [paymentMethods] => Array
                      (
                      )
                  [listingType] => FixedPriceItem
                  [title] => My Item - revised
                  [quantity] => 2
                  [listingStatus] => Ready for sale
                  [country] => US
                  [currentPrice] => 30.99
                  [shippingCostSummary] => Array
                      (
                          [shippingServiceCost] => 0
                          [shippingType] => Free
                          [shipToLocations] => US
                      )
                  [buyItNowPrice] => 30.99
                  [itemID] => 24018222
                  [postalCode] => 98607
                  [pictureURL] => Array
                      (
                          [0] => http://bonanzleimages.s3.amazonaws.com/afu/images/9585/6344/ps_logo2.png
                      )
                  [description] => This item is great.  Any html here.
                  [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/9585/6344/ps_logo2_thumb155_crop.png
                  [storeFront] => Array
                      (
                          [storeName] => MyUser booth
                          [storeDiscount] =>
                          [storeURL] => http://www.sanyili.com/booths/MyUser
                          [storeHasBonanza] => false
                          [storeItemCount] => 5
                      )
                  [lastChangeTime] => 2010-12-16T09:29:01.000Z
              )
      )
  [version] => 1.0beta
  [ack] => Success
)

UpdateBooth的PHP示例

UpdateBooth呼叫只有1个输入,这是令牌。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是安全的API请求,并需要开发名称,证书名称和授权令牌。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$ args. = array();
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$ post_fields. = "updatebooth.Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: updateBoothRequest={"requesterCredentials":{"bonanzleAuthToken":"zzz"}}
Response:
Array
(
  [updateBoothResponse] => Array
      (
          [success] => 1
          [resultMessage] => Booth queued for update
      )
  [timestamp] => 2010-12-11T17:05:20.000Z
  [version] => 1.0beta
  [ack] => Success
)

获取3项404027,404175和23997948的结帐链接。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印出链接。打印完整的响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ids = array(404027,404175,23997948);
$ args. = array("itemIds" => $ids);
$ post_fields. = "getCheckoutlink.Request=" .  json_encode($ args.);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
$url = $响应['getCheckoutlink.Response']['checkoutUrl'];
echo "url: $url  \n";
echo "Response: \n";
print_r($响应);
Request: getCheckoutLinkRequest={"itemIds":[404027,404175,23997948]}
url: //www.sanyili.com/offers/make_cart_from_items?item_ids=404027,404175,23997948
Response:
Array
(
  [timestamp] => 2010-12-15T12:51:30.000Z
  [getCheckoutLinkResponse] => Array
      (
          [checkoutUrl] => //www.sanyili.com/offers/make_cart_from_items?item_ids=404027,404175,23997948
      )
  [version] => 1.0beta
  [ack] => Success
)

GetUserProfile的PHP示例

使用“Hollee”的ID获取用户的反馈和评级信息。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印出用户评级和明星信息。打印完整的响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ args. = array("userId" => "BluePennyLady");
$ post_fields. = "GetUserProfile.Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
$rating = $响应['GetUserProfile.Response']['feedbackHistory']['averageRatingDetails']['rating'];
$star = $响应['GetUserProfile.Response']['user']['feedbackRatingStar'];
echo "Rating: $rating  Star: $star \n";
echo "Response: \n";
print_r($响应);
Request: getUserProfileRequest={"userId":"hollee"}
Rating: 99.9  Star: Red
Response:
Array
(
  [getUserProfileResponse] => Array
      (
          [feedbackHistory] => Array
              (
                  [uniquePositiveFeedbackCount] => 5000
                  [uniqueNeutralFeedbackCount] => 8
                  [uniqueNegativeFeedbackCount] => 3
                  [averageRatingDetails] => Array
                      (
                          [rating] => 99.9
                          [ratingCount] => 4997
                      )
              )
          [user] => Array
              (
                  [newUser] => true
                  [feedbackRatingStar] => Red
                  [aboutMeURL] => //www.sanyili.com/users/2163/profile
                  [userId] => 2163
                  [feedbackDetailsURL] => //www.sanyili.com/users/2163/user_feedbacks
                  [status] => active
                  [registrationDate] => 2008-09-02T06:33:06.000Z
              )
      )
  [timestamp] => 2010-12-15T12:23:31.000Z
  [version] => 1.0beta
  [ack] => Success
)

GetSingleItem的PHP示例

获取Bonanza Item ID 23266642的数据。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ args. = array("itemId" => "23266642");
$ post_fields. = "getsingleitem.Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: getSingleItem={"itemId":"23266642"} 
Response:
Array (
  [timestamp] => 2010-12-11T17:00:23.000Z
  [version] => 1.0beta
  [getSingleItemResponse] => Array
      (
          [item] => Array
              (
                  [primaryCategory] => Array
                      (
                          [categoryName] => Clothing, Shoes amp; Accessories >> Women's Accessories amp; Handbags >> Hats >> Beret, Newsboy
                          [categoryId] => 45233
                      )
                  [seller] => Array
                      (
                          [feedbackRatingStar] => Red
                          [membershipLevel] => 2
                          [sellerUserName] => samiamsxa
                          [availableForChat] => false
                          [userPicture] => http://bonanzleimages.s3.amazonaws.com/user_profile_image/afu/user_profile_images/0049/1894/thriftyvaultwithnameTM-2-1.jpg
                          [positiveFeedbackPercent] => 100
                      )
                  [convertedBuyItNowPrice] => 14.99
                  [paymentMethods] => Array
                      (
                          [0] => GoogleCheckout
                          [1] => MOCC
                          [2] => Paypal
                      )
                  [listingType] => FixedPriceItem
                  [title] => Red Crochet Beret Winter Hat
                  [quantity] => 1
                  [listingStatus] => Active
                  [country] => US
                  [currentPrice] => 14.99
                  [shippingCostSummary] => Array
                      (
                          [shippingServiceCost] => 3.5
                          [shippingType] => Flat
                          [shipToLocations] => US
                      )
                  [buyItNowPrice] => 14.99
                  [itemSpecifics] => Array
                      (
                          [0] => Array
                              (
                                  [nameValueList] => Array
                                      (
                                          [name] => Condition
                                          [value] => New: With Tags
                                      )
                              )
                      )
                  [itemID] => 23266642
                  [postalCode] => 70535
                  [pictureURL] => Array
                      (
                          [0] => http://s3.amazonaws.com/bonanzleimages/afu/images/9157/4427/red_crochet_beret_hat.jpg
                      )
                  [description] => Red Crochet Beret Winter Hat, brand new. One size fits most. Other colors available in store.
                  [galleryURL] => http://s3.amazonaws.com/bonanzleimages/afu/images/9157/4427/red_crochet_beret_hat_thumb155_crop.jpg
                  [storeFront] => Array
                      (
                          [storeName] => Thrifty Vaultââ??¢ booth
                          [storeDiscount] => 
                          [storeURL] => http://www.sanyili.com/booths/samiamsxa
                          [storeHasBonanza] => false
                          [storeItemCount] => 1424
                      )
                  [lastChangeTime] => 2010-11-26T23:57:40.000Z
              )
      )
  [ack] => Success
)

GetMultipleItems的PHP示例

获取具有404027和404175的ID的2个Bonanza项目的数据。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。循环通过返回的数据并打印每个项目的价格和标题。打印完整的响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ids = array(404027,404175);
$ args. = array("itemId" =>  $ids);
$ post_fields. = "getMultipleItems.Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$item) = each($响应['getMultipleItems.Response']['item'])) {
  echo "  " . $item['currentPrice'] . " - " . $item['title'] . "\n";
}
echo "Response: \n";
print_r($响应);
Request: getMultipleItemsRequest={"itemId":[404027,404175]}
Loop thru the data
599.99 - Vintge HAWAIIAN HULA Dancer RHINESTONE ENAMEL Fur Clips
20 - RETRO Vintage MINT GREEN ENAMEL on METAL HOOP Earrings
Response:
Array
(
  [timestamp] => 2010-12-15T12:10:05.000Z
  [version] => 1.0beta
  [getMultipleItemsResponse] => Array
      (
          [item] => Array
              (
                  [0] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Jewelry amp; Watches >> Vintage amp; Antique Jewelry
                                  [categoryId] => 48579
                              )
                          [seller] => Array
                              (
                                  [feedbackRatingStar] => Red
                                  [membershipLevel] =>
                                  [sellerUserName] => hollee
                                  [availableForChat] => false
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0036/7420/photo-147.jpg
                                  [positiveFeedbackPercent] => 99.9
                              )
                          [convertedBuyItNowPrice] => 599.99
                          [paymentMethods] => Array
                              (
                                  [0] => Paypal
                              )
                          [listingType] => FixedPriceItem
                          [title] => Vintge HAWAIIAN HULA Dancer RHINESTONE ENAMEL Fur Clips
                          [quantity] => 1
                          [listingStatus] => Active
                          [country] => US
                          [currentPrice] => 599.99
                          [shippingCostSummary] => Array
                              (
                                  [shippingServiceCost] => 8
                                  [shippingType] => Flat
                                  [shipToLocations] => US
                              )
                          [buyItNowPrice] => 599.99
                          [itemID] => 404027
                          [postalCode] => 07722
                          [pictureURL] => Array
                              (
                                  [0] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall.jpg
                              )
                          [description] => ...
                          [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall_thumb155_crop.jpg
                          [storeFront] => Array
                              (
                                  [storeName] => hollee's booth
                                  [storeDiscount] =>
                                  [storeURL] => http://www.sanyili.com/booths/hollee
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 620
                              )
                          [lastChangeTime] => 2010-11-18T21:33:42.000Z
                      )
                  [1] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Jewelry amp; Watches >> Vintage amp; Antique Jewelry
                                  [categoryId] => 48579
                              )
                          [seller] => Array
                              (
                                  [feedbackRatingStar] => Red
                                  [membershipLevel] =>
                                  [sellerUserName] => hollee
                                  [availableForChat] => false
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0036/7420/photo-147.jpg
                                  [positiveFeedbackPercent] => 99.9
                              )
                          [convertedBuyItNowPrice] => 20
                          [paymentMethods] => Array
                              (
                                  [0] => Paypal
                              )
                          [listingType] => FixedPriceItem
                          [title] => RETRO Vintage MINT GREEN ENAMEL on METAL HOOP Earrings
                          [quantity] => 1
                          [listingStatus] => Active
                          [country] => US
                          [currentPrice] => 20
                          [shippingCostSummary] => Array
                              (
                                  [shippingServiceCost] => 3
                                  [shippingType] => Flat
                                  [shipToLocations] => US
                              )
                          [buyItNowPrice] => 20
                          [itemID] => 404175
                          [postalCode] => 07722
                          [pictureURL] => Array
                              (
                                  [0] => http://s3.amazonaws.com/bonanzleimages/afu/images/0155/8535/grnenamhoopears808gall.jpg
                              )
                          [description] => ....
                          [galleryURL] => http://s3.amazonaws.com/bonanzleimages/afu/images/0155/8535/grnenamhoopears808gall_thumb155_crop.jpg
                          [storeFront] => Array
                              (
                                  [storeName] => hollee's booth
                                  [storeDiscount] =>
                                  [storeURL] => http://www.sanyili.com/booths/hollee
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 620
                              )
                          [lastChangeTime] => 2008-10-20T10:26:46.000Z
                      )
              )
      )
  [ack] => Success
)

Getbooth的PHP示例

获取用户ID“TABE_DELIVERED”的展位。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ args. = array("userId" => "rooms_delivered");
$ post_fields. = "Getbooth.Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: getBoothRequest={"userId":"rooms_delivered"}
Response:
Array
(
  [timestamp] => 2010-12-15T06:41:27.000Z
  [getBoothResponse] => Array
      (
          [store] => Array
              (
                  [subscriptionLevel] => 0
                  [name] => rooms-delivered's booth
                  [url] => http://www.sanyili.com/booths/rooms_delivered
                  [logo] => Array
                      (
                          [url] => http://bonanzapublic.s3.amazonaws.com/images/booth/template_images/Paintbrushes.jpg
                      )
                  [lastUpdated] => 2010-12-06T15:58:15.000Z
                  [policies] =>
                  [description] =>
                  [syndicated] => false
              )
      )
  [version] => 1.0beta
  [ack] => Success
)

GetboothItems的PHP示例

通过提供展位ID和 - 可选地检索来自指定展位的项目 - 所需项目的状态。您可以通过指定页码来检索和/或每页列出的项目数量来通过展位中的所有项目页面 $ args..

在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是安全的API请求,并需要开发名称和证书名称标头。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印出项目ID。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$ args. = array( 'userId' => 'rooms_delivered', 'itemStatus' => array('for_sale', 'ready_to_post'), 'itemsPerPage' => 10, 'page' => 2);
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;   // only necessary if specifying an itemStatus other than "for_sale"
$请求_name = "GetboothItems.Request";
$ post_fields. = "$请求_name=" . json_encode($ args.) . " \n";
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  // data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: getBoothItemsRequest
Response:
Array
(
  [timestamp] => 2010-12-15T12:10:05.000Z
  [version] => 1.0beta
  [getBoothItemsRequest] => Array
      (
          [currentPage] => 2,
          [size] => 10,
          [totalEntries] => 37,
          [items] => Array
              (
                  [0] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Jewelry amp; Watches >> Vintage amp; Antique Jewelry
                                  [categoryId] => 48579
                              )
                          [seller] => Array
                              (
                                  [feedbackRatingStar] => Red
                                  [membershipLevel] =>
                                  [sellerUserName] => hollee
                                  [availableForChat] => false
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0036/7420/photo-147.jpg
                                  [positiveFeedbackPercent] => 99.9
                              )
                          [convertedBuyItNowPrice] => 599.99
                          [paymentMethods] => Array
                              (
                                  [0] => Paypal
                              )
                          [listingType] => FixedPriceItem
                          [title] => Vintge HAWAIIAN HULA Dancer RHINESTONE ENAMEL Fur Clips
                          [quantity] => 1
                          [listingStatus] => Active
                          [country] => US
                          [currentPrice] => 599.99
                          [shippingCostSummary] => Array
                              (
                                  [shippingServiceCost] => 8
                                  [shippingType] => Flat
                                  [shipToLocations] => US
                              )
                          [buyItNowPrice] => 599.99
                          [itemID] => 404027
                          [postalCode] => 07722
                          [pictureURL] => Array
                              (
                                  [0] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall.jpg
                              )
                          [description] => ...
                          [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/0155/7677/hulaclips707gall_thumb155_crop.jpg
                          [storeFront] => Array
                              (
                                  [storeName] => hollee's booth
                                  [storeDiscount] =>
                                  [storeURL] => http://www.sanyili.com/booths/hollee
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 620
                              )
                          [lastChangeTime] => 2010-11-18T21:33:42.000Z
                      )
                 ...
              )
      )
  [ack] => Success
)

Get类别的PHP示例

获取“Baby”类别(ID 2984)的子类别。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。循环通过数据和打印子类别ID和名称。打印响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ args. = array("categoryParent" => 2984);
$ post_fields. = "get类别Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$category) = each($响应['get类别Response']['categoryArray'])) {
  echo "  " . $category['categoryId'] . " - " . $category['categoryName'] . "\n";
}
echo "Response: \n";
print_r($响应);
Request: getCategoriesRequest={"categoryParent":2984}
Loop thru the data
1261 - Baby >> Other
19068 - Baby >> Toys for Baby
20394 - Baby >> Bathing & Grooming
20400 - Baby >> Feeding
20416 - Baby >> Nursery Bedding
20422 - Baby >> Nursery Furniture
20433 - Baby >> Baby Safety & Health
37631 - Baby >> Potty Training
45455 - Baby >> Diapering
48757 - Baby >> Wholesale Lots
66692 - Baby >> Car Safety Seats
66697 - Baby >> Nursery Decor
66698 - Baby >> Strollers
100223 - Baby >> Baby Gear
117388 - Baby >> Keepsakes & Baby Announcements
Response:
Array
(
  [getCategoriesResponse] => Array
      (
          [categoryArray] => Array
              (
                  [0] => Array
                      (
                          [categoryName] => Baby >> Other
                          [traitCount] => 1
                          [categoryId] => 1261
                          [categoryBriefName] => Other
                          [leafCategory] => true
                          [categoryLevel] => 2
                      )
                  [1] => Array
                      (
                          [categoryName] => Baby >> Toys for Baby
                          [traitCount] => 1
                          [categoryId] => 19068
                          [categoryBriefName] => Toys for Baby
                          [leafCategory] => false
                          [categoryLevel] => 2
                      )
                  [2] => Array
                      (
                          [categoryName] => Baby >> Bathing & Grooming
                          [traitCount] => 1
                          [categoryId] => 20394
                          [categoryBriefName] => Bathing & Grooming
                          [leafCategory] => false
                          [categoryLevel] => 2
                      )
                   ....
              )
      )
  [timestamp] => 2010-12-15T07:09:09.000Z
  [version] => 1.0beta
  [ack] => Success
)

php用于getCategorytraits的示例

Get the traits for the category "Books >> Fiction Books" (ID 377). This is a LEAF category。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。循环通过数据和打印特征ID和标签。打印响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$ args. = array("categoryId" => 377);
$ post_fields. = "getCategorytraits.Request=" .  json_encode($ args., JSON_HEX_AMP);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$trait) = each($响应['getCategorytraits.Response']['traitArray'])) {
  echo "  " . $trait['id'] . " - " . $trait['label'] . "\n";
}
echo "Response: \n";
print_r($响应);
Request: getCategoryTraitsRequest={"categoryId":377}
Loop thru the data
6248 - Condition
6249 - Format
6250 - Publication Year
6251 - Category
6254 - Special Attributes
6255 - Author
6256 - ISBN
6257 - Edition
6258 - Edition Description
6259 - Publisher
85886 - 1st Edition
85887 - Signed
95592 - Age Range
Response:
Array
(
  [timestamp] => 2010-12-15T07:27:42.000Z
  [getCategoryTraitsResponse] => Array
      (
          [traitArray] => Array
              (
                  [0] => Array
                      (
                          [label] => Condition
                          [parentTraitId] => 0
                          [id] => 6248
                          [traitValues] => Array
                              (
                                  [0] => Array
                                      (
                                          [name] => -
                                          [displayOrder] => 7
                                          [searchId] => 102439990
                                          [id] => 70742
                                      )
                                  [1] => Array
                                      (
                                          [name] => Brand New
                                          [displayOrder] => 2
                                          [searchId] => 102450425
                                          [id] => 70743
                                      )
                                  [2] => Array
                                      (
                                          [name] => Like New
                                          [displayOrder] => 3
                                          [searchId] => 102535784
                                          [id] => 70744
                                      )
                                  ....
                              )
                          [htmlInputType] => dropdown
                      )
                  [1] => Array
                      (
                          [label] => Format
                          [parentTraitId] => 0
                          [id] => 6249
                          [traitValues] => Array
                              (
                                  [0] => Array
                                      (
                                          [name] => -
                                          [displayOrder] => 1000
                                          [searchId] => 159609990
                                          [id] => 70748
                                      )
                                  [1] => Array
                                      (
                                          [name] => Hardcover
                                          [displayOrder] => 1000
                                          [searchId] => 159633732
                                          [id] => 70749
                                      )
                                  [2] => Array
                                      (
                                          [name] => Softcover
                                          [displayOrder] => 1000
                                          [searchId] => 159633733
                                          [id] => 70750
                                      )
                                  [3] => Array
                                      (
                                          [name] => Mixed Lot
                                          [displayOrder] => 1000
                                          [searchId] => 159633752
                                          [id] => 70751
                                      )
                                  [4] => Array
                                      (
                                          [name] => Other
                                          [displayOrder] => 1000
                                          [searchId] => 159609994
                                          [id] => 70752
                                      )
                              )
                          [htmlInputType] => dropdown
                      )
                  [2] => Array
                      (
                          [label] => Publication Year
                          [parentTraitId] => 0
                          [id] => 6250
                          [htmlInputType] => textfield
                      )
                 ....
              )
      )
  [version] => 1.0beta
  [ack] => Success
)

FindItemsbyKeyWords的PHP示例

查找与关键字“Levis Boot Cut”相关的Bonanza的项目,并在页面上显示5页。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是标准API请求,只需要DEV命名标题。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。循环通过数据和打印项目位置和标题。打印完整的响应。

$dev_name = "xxx";
$api_url = "//api.sanyili.com/api_requests/standard_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
$paginationInput['entriesPerPage'] = 5;
$paginationInput['pageNumber'] = 1;
$ args. = array("paginationInput"=> $paginationInput, "keywords" => "Levis Boot Cut");
$ post_fields. = "findItemsbyKeywords.Request=" .  json_encode($ args.);
echo "Request: $ post_fields. \n";
$connection = curl_init($api_url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "  Loop thru the data \n";
while (list(,$item) = each($响应['findItemsbyKeywords.Response']['item'])) {
  echo "  " . $item['location'] . " - " . $item['title'] . "\n";
}
echo "Response: \n";
print_r($响应);
Request: findItemsByKeywordsRequest={"paginationInput":{"entriesPerPage":5,"pageNumber":1},"keywords":"Levis Boot Cut"}
Loop thru the data
  Lutz, FL - 36X36 Levi Strauss & Co. Low Boot Cut Jeans NWT 36 X 36
  Birmingham, AL - LEVIS 517 Women's Slim Fit Boot Cut Blue Jeans Pants 9 Jr. M
  Texas - LEVI'S LEVIS Boot Cut Super Low Stretch Jeans Jrs 5 NWT
  Leopold, IN - Womens Blue Jeans Levi's 523 Boot Cut nouveau Low SZ 12
  Nashville, TN - Levi's 518 Superlow Boot Cut Jeans Juniors 9M
Response:
Array
(
  [timestamp] => 2010-12-16T13:55:52.000Z
  [version] => 1.0beta
  [findItemsByKeywordsResponse] => Array
      (
          [paginationOutput] => Array
              (
                  [totalEntries] => 64
                  [pageNumber] => 1
                  [entriesPerPage] => 5
              )
          [item] => Array
              (
                  [0] => Array
                      (
                          [primaryCategory] => Array
                              (
                                  [categoryName] => Clothing, Shoes amp; Accessories >> Men's Clothing >> Big amp; Tall >> Jeans
                                  [categoryId] => 155177
                              )
                          [listingInfo] => Array
                              (
                                  [price] => 14.99
                                  [convertedBuyItNowPrice] => 14.99
                                  [bestOfferEnabled] => false
                                  [listingType] => FixedPrice
                                  [buyItNowPrice] => 14.99
                                  [startTime] => 2010-12-15T20:10:41.000Z
                                  [lastChangeTime] => 2010-12-15T20:10:41.000Z
                              )
                          [viewItemURL] => http://www.sanyili.com/booths/espiwear/items/36X36_Levi_Strauss___Co__Low_Boot_Cut_Jeans_NWT_36_X_36
                          [location] => Lutz, FL
                          [title] => 36X36 Levi Strauss & Co. Low Boot Cut Jeans NWT 36 X 36
                          [sellerInfo] => Array
                              (
                                  [feedbackRatingStar] => Green
                                  [membershipLevel] => 2
                                  [sellerUserName] => espiwear
                                  [availableForChat] => true
                                  [userPicture] => http://s3.amazonaws.com/bonanzleimages/user_profile_image/afu/user_profile_images/0041/3750/logo_Espi.jpg
                                  [positiveFeedbackPercent] => 100
                              )
                          [affiliateCommission] => Array
                              (
                                  [enabled] => false
                              )
                          [itemId] => 24009380
                          [storeInfo] => Array
                              (
                                  [storeName] => ESPIWEAR CLOTHING 813-477-2215
                                  [storeDiscount] =>
                                  [storeURL] => http://www.sanyili.com/booths/espiwear
                                  [storeHasBonanza] => false
                                  [storeItemCount] => 1052
                              )
                          [shippingInfo] => Array
                              (
                                  [shippingServiceCost] =>
                                  [shippingType] => NotSpecified
                                  [shipToLocations] => US
                              )
                          [sellingStatus] => Array
                              (
                                  [convertedCurrentPrice] => 14.99
                                  [sellingState] => Active
                                  [currentPrice] => 14.99
                              )
                          [postalCode] => 33548
                          [paymentMethod] => Array
                              (
                                  [0] => MOCC
                                  [1] => Paypal
                              )
                          [galleryURL] => http://bonanzleimages.s3.amazonaws.com/afu/images/9580/3653/_b__j_9gbwk___kgrhqv__leez_5hpmtebnbvrppf5g__0_3_thumb155_crop.jpg
                          [globalId] => BONANZLE
                          [descriptionBrief] =>                                         36X36 Levi Strauss amp Co. Low Boot Cut Jeans NWT 36 X 36                Condition: New with tags, guaranteed to be 100 authentic Features: Levi Strauss amp Co. Low Boot Cut Low Rise Original Riveted 527 J...
                      )
                  ...
              )
      )
  [ack] => Success
)

SetNotificationPreferences的PHP示例

指定要接收通知的传递端点,并列出要订阅的通知(例如“arksellerquestion”)。在简单关联数组中构建API请求 $ args.。 JSON编码了 $ args. 在变量中 $ post_fields.。此呼叫是安全的API请求,并需要开发名称和证书名称标头。设置HTTP标头 $标题。使用curl发送API请求。将JSON响应解码为关联数组 $响应。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);

$delivery_preferences = array();
$delivery_preferences['applicationEnable'] = "Enable";
$delivery_preferences['deliveryURLDetails'] = array(
  'deliveryURL' => "http://foo.com/notifications",
  'status' => "Enable" 
);

$subscribed_notifications = array('notificationEnable' => array());
$notification = array(
  'eventEnable' => "Enable",
  'eventType' => "askSellerQuestion",
  'detailed' => true
);
array_push($subscribed_notifications['notificationEnable'], $notification);

$ args. = array('applicationDeliveryPreferences' => $delivery_preferences, 'userDeliveryPreferenceArray' => $subscribed_notifications);
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$ post_fields. = "setnotificationPreferences.=" .  json_encode($ args.);
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: setnotificationPreferences.={"applicationDeliveryPreferences":{"applicationEnable":"Enable","deliveryURLDetails":{"deliveryURL":"http:\/\/foo.com\/notifications","status":"Enable"}},"userDeliveryPreferenceArray":{"notificationEnable":[{"eventEnable":"Enable","eventType":"askSellerQuestion","detailed":true}]},"requesterCredentials":{"bonanzleAuthToken":"XehKe4HUVP"}}
Response:
Array
(
    [ack] => Success
    [version] => 1.0
    [timestamp] => 2018-02-20T11:38:49.000Z
    [setnotificationPreferences.Response] => Array
        (
            [notificationId] => 69537
            [deliveryURLsProcessed] => 1
            [eventsProcessed] => 1
        )

)

UpdateInventory.的PHP示例

更新Bonanza项目1234的价格和数量,并在同一请求中更新Bonanza项5678的数量。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$url = "//api.sanyili.com/api_requests/secure_request";
$标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
$updates = array();
$updates["1234"] = array("quantity" => 12, "price" => 14.99);
$updates["5678"] = array("quantity" => 3);
$ args. = array("updates" => $updates);
$ args.["requesterCredentials"]["bonanzleAuthToken"] = $token;
$ post_fields. = "UpdateInventory.=" .  urlencode(json_encode($ args.));
echo "Request: $ post_fields. \n";
$connection = curl_init($url);
$curl_options = array(CURLOPT_HTTPHEADER=>$标题, CURLOPT_POSTFIELDS=>$ post_fields.,
                CURLOPT_POST=>1, CURLOPT_RETURNTRANSFER=>1);  # data will be returned as a string
curl_setopt_array($connection, $curl_options);
$json_response = curl_exec($connection);
if (curl_errno($connection) > 0) {
  echo curl_error($connection) . "\n";
  exit(2);
}
curl_close($connection);
$响应 = json_decode($json_response,true);
echo "Response: \n";
print_r($响应);
Request: updateInventory=%7B%22updates%22%3A%7B%22782383635%22%3A%7B%22quantity%22%3A12%2C%22price%22%3A14.99%7D%2C%22782383633%22%3A%7B%22quantity%22%3A3%7D%7D%2C%22requesterCredentials%22%3A%7B%22bonanzleAuthToken%22%3A%22AnOz8BOaaP%22%7D%7D
Response:
Array
(
    [ack] => Success
    [version] => 1.1.2
    [timestamp] => 2020-02-27T15:56:52.000Z
    [updateInventoryResponse] => Array
        (
            [1234] => Array
                (
                    [success] => 1
                )
            [5678] => Array
                (
                    [success] => 1
                )
        )
)

PHP示例 - 可以加速开发的功能

PHP示例 - 基本功能

这4个功能将有助于使用PHP进行API调用。您可以在进行API调用时隐藏大量详细信息。请参阅下面的示例使用情况。

# $dev_name = developer name (ID)
# $cert_name = certificate name (ID)
function BonapititSecureApiCall($dev_name, $cert_name, $api_call_and_args) {
  $url = "//api.sanyili.com/api_requests/secure_request";
  $标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name, "X-BONANZLE-API-CERT-NAME: " . $cert_name);
  $resp = BonapititSendHttpRequest($url,$标题, $api_call_and_args);
  return $resp;
}
# $dev_name = developer ID
# $api_call_and_args - string of the form: api_call={json_data}
function BonapititStandardApiCall($dev_name, $api_call_and_args) {
  $url = "//api.sanyili.com/api_requests/standard_request";
  $标题 = array("X-BONANZLE-API-DEV-NAME: " . $dev_name);
  $resp = BonapititSendHttpRequest($url,$标题, $api_call_and_args);
  return $resp;
}
# $url - string - url of the bonanza api
# $headers - string - http headers containing X-BONANZLE-API-DEV-NAME and/or X-BONANZLE-API-CERT-NAME
# $post_fields - string - data that will be posted to the $url.
function BonapititSendHttpRequest($url, $标题, $ post_fields.) {
  $connection = curl_init();
  curl_setopt($connection, CURLOPT_URL, $url);
  curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);  //stop CURL from verifying the peer's certificate
  curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($connection, CURLOPT_HTTPHEADER, $标题); //set the headers using the array of headers
  curl_setopt($connection, CURLOPT_POST, 1);  //set method as POST
  curl_setopt($connection, CURLOPT_POSTFIELDS, $ post_fields.);
  curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);  //set it to return the transfer as a string from curl_exec
  $响应 = curl_exec($connection);
  curl_close($connection);
  return $响应;
}
# $api_call_name - string - like UpdateBooth
# $assoc_array - array - associative array of data
function BonapititBuildRequest($api_call_name, $assoc_array) {
  $请求_name = $api_call_name . "Request";
  $json = json_encode($assoc_array, JSON_HEX_AMP);
  $请求 = $请求_name . "=" .  $json;
  return $请求;
}

PHP示例 - UpdateBooth功能的使用情况

使用bonapitit函数(上面)更新展位。建立 $请求。制作安全API调用。使用JSON解码响应。打印完整的响应。

$dev_name = "xxx";
$cert_name = "yyy";
$token = "zzz";
$ args. = array();
$ args.['requesterCredentials']['bonanzleAuthToken'] = $token;
$请求 = BonapititBuildRequest("updatebooth.",$ args.);
$json_response = BonapititSecureApiCall($dev_name, $cert_name, $请求);
$响应 = json_decode($json_response,true);
print_r($响应);

PHP示例 - 用于GetSingleItem的功能的使用

使用bonapitit函数(上面)获取项目ID 23266642.构建GetSingle项 $请求。制作标准API调用。使用JSON解码响应。打印完整的响应。

$dev_name = "xxx";
$ args. = array("itemId" => "23266642");
$请求 = BonapititBuildRequest("getsingleitem.",$ args.);
$json_response =  BonapititStandardApiCall($dev_name, $请求);
$响应 = json_decode($json_response,true);
print_r($响应);