对 SOAP 请求的 XML 响应将类似于:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<findPublisherCommissionsResponse xmlns="http://api.cj.com">
<out xmlns="http://api.cj.com">
<publisherCommissions xmlns="http://transaction.service.cj.com">
<ns1:PublisherCommissionV2 xmlns:ns1="http://transaction.domain.cj.com">
<actionStatus xmlns="http://transaction.domain.cj.com">
closed
</actionStatus>
<actionType xmlns="http://transaction.domain.cj.com">
sale
</actionType>
<adId xmlns="http://transaction.domain.cj.com">
13123123
</adId>
<advertiserId xmlns="http://transaction.domain.cj.com">
12312312
</advertiserId>
<advertiserName xmlns="http://transaction.domain.cj.com">
Merchant UK ltd
</advertiserName>
<commissionAmount xmlns="http://transaction.domain.cj.com">
25
</commissionAmount>
<country xmlns="http://transaction.domain.cj.com">
</country>
<eventDate xmlns="http://transaction.domain.cj.com">
2009-08-28T20:30:44-07:00
</eventDate>
<lockingDate xmlns="http://transaction.domain.cj.com">
2009-09-10T00:00:00-07:00
</lockingDate>
<orderId xmlns="http://transaction.domain.cj.com">
1231232
</orderId>
<original xmlns="http://transaction.domain.cj.com">
true
</original>
<originalActionId xmlns="http://transaction.domain.cj.com">
12312321312
</originalActionId>
<postingDate xmlns="http://transaction.domain.cj.com">
2009-08-28T23:30:03-07:00
</postingDate>
<sId xmlns="http://transaction.domain.cj.com">
googlelink
</sId>
<saleAmount xmlns="http://transaction.domain.cj.com">
25
</saleAmount>
<transactionId xmlns="http://transaction.domain.cj.com">
123123123
</transactionId>
<websiteId xmlns="http://transaction.domain.cj.com">
1231231
</websiteId>
</ns1:PublisherCommissionV2>
</publisherCommissions>
<sortBy xmlns="http://transaction.service.cj.com">
</sortBy>
<totalResults xmlns="http://transaction.service.cj.com">
1
</totalResults>
</out>
</findPublisherCommissionsResponse>
</soap:Body>
</soap:Envelope>
您可能在将 xml 响应解析为 SimpleXml 对象时遇到问题,因为 SimpleXML 不喜欢标签和属性名称SOAP 和 SimpleXML中的冒号 (:) 。还要在这里查看SimpleXML & Namespaces
您的 SOAP 请求应该已经是一个对象,所以我不确定您为什么要尝试使用 SimpleXML 解析它。如果您需要作为 XML 的响应,那么您总是可以使用序列化程序。
以我自己的脚本为例,我使用如下内容:
//这里的代码 $cj_devkey = "CJ KEY HERE";
$ini = ini_set( "soap.wsdl_cache_enabled", "0" );
$client = new SoapClient( "https://pubcommission.api.cj.com/wsdl/version2/publisherCommissionServiceV2.wsdl", array(
'trace' => true,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
'proxy_host' => "proxy"
) );
$object = $client->findPublisherCommissions( array(
"developerKey" => $cj_devkey,
"date" => '08/28/2009',
"dateType" => 'event',
"advertiserIds" => '',
"websiteIds" => '123456',
"actionStatus" => '',
"actionTypes" => 'sale',
"adIds" => '',
"countries" => 'all',
"correctionStatus" => 'all',
"sortBy" => '',
"sortOrder" => ''
) );
使用 print_r($object) 的示例响应将返回:
stdClass Object
(
[out] => stdClass Object
(
[publisherCommissions] => stdClass Object
(
[PublisherCommissionV2] => stdClass Object
(
[actionStatus] => closed
[actionType] => sale
[adId] => 123123213
[advertiserId] => 2313531
[advertiserName] => MERCHANT HERE
[commissionAmount] => 25
[country] =>
[eventDate] => 2009-08-28T20:30:44-07:00
[lockingDate] => 2009-09-10T00:00:00-07:00
[orderId] => 123123
[original] => 1
[originalActionId] => 123123
[postingDate] => 2009-08-28T23:30:03-07:00
[sId] => sports
[saleAmount] => 25
[transactionId] => 12312312
[websiteId] => 123123
)
)
[sortBy] =>
[totalResults] => 1
)
)
如果要遍历对象元素,可以使用以下内容:
$num_results = $object->out->totalResults;
或使用以下内容循环支付每笔佣金:
foreach ( $object->out->publisherCommissions as $commission ) {
$user_id = $commission->{'sId'};
$transaction_id = $commission->{'transactionId'};
$program_id = $commission->{'advertiserId'};
$post_date = $commission->{'postingDate'};
$action_status = $commission->{'actionStatus'};
$amount = $commission->{'commissionAmount'};
}