当您需要连接到需要发送额外标头的服务时,使用此方法。
以下是使用 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 "商品已删除!";
}
?>