1

我正在创建一个带有 Commission Junction 链接的网站。现在我需要处理佣金报告以划分佣金。我计划使用 Daily Publisher Commission Service,因为它提供了在请求中包含日期的规定。现在我无法通过 CJ 链接进行购买,因此我使用了CJ 网站本身提供的示例查询。我是这些 wbservices 的新手,所以在这里有一些疑问。

  1. 实际响应将与给定的响应完全相同。我的意思是它会包含这些<soapenv:Envelope
    东西还是仅以ns1开头。???

  2. 我已将响应分配给变量 $result 并给出

    $result_xml=simplexml_load_string($result);

但它显示 ns1 未在命名空间中定义的错误。然后我把 <soapenv:Envelope 东西交给了上面。现在错误已经消失了。但是 result_xml 变量是空白的。

如果有人以前做过,请帮助我。或者请给我一些好的教程,以便我可以学习并做到这一点。如果有人可以提供完整的示例响应,那将非常有帮助,这样我就可以用它检查代码。

提前致谢。

4

1 回答 1

1

对 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'};
}
于 2011-01-05T18:04:13.533 回答