Commission Junction Daily Publisher Commission Service

时间:2010-12-06 13:12:40

标签: php soap commission-junction

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

  1. 实际的响应将与给定的完全相同。我的意思是它包括<soapenv:Envelope
    事情或它只是从ns1开始。???

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

    $ result_xml = simplexml_load_string($结果);

  3. 但是它显示了在命名空间中未定义ns1的错误。然后我把<soapenv:Envelope的东西放到了顶部。现在错误消失了。但result_xml变量为空。

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

    先谢谢。

1 个答案:

答案 0 :(得分: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,则可以始终使用serializer

在我自己的脚本中作为一个例子,我使用这样的东西:

//代码在这里  $ 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'};
}