當您需要連線到需要傳送額外標頭的服務時,請使用此方法。
以下是如何使用 PHP 和 SoapClient 執行此操作
<?php
class exampleChannelAdvisorAuth
{
public $DeveloperKey;
public $Password;
public function __construct($key, $pass)
{
$this->DeveloperKey = $key;
$this->Password = $pass;
}
}
$devKey = "";
$password = "";
$accountId = "";
// 建立 SoapClient 實例
$url = "";
$client = new SoapClient($url, array("trace" => 1, "exception" => 0));
// 建立標頭
$auth = new ChannelAdvisorAuth($devKey, $password);
$header = new SoapHeader("http://www.example.com/webservices/", "APICredentials", $auth, false);
// 呼叫 wsdl 函式
$result = $client->__soapCall("DeleteMarketplaceAd", array(
"DeleteMarketplaceAd" => array(
"accountID" => $accountId,
"marketplaceAdID" => "9938745" // 廣告 ID
)
), NULL, $header);
// 顯示結果
echo "<pre>".print_r($result, true)."</pre>";
if($result->DeleteMarketplaceAdResult->Status == "Success")
{
echo "項目已刪除!";
}
?>