将XML数据chartmogul网络挂接[PHP]

问题描述:

要求:将XML数据chartmogul网络挂接[PHP]

我需要安装一个中继从我的服务器转发网络挂接到ChartMogul终点 - 这通常只涉及添加的代码的几行脚本已经收到您的服务器上的webhook。

麻烦我面对

我面对的麻烦,同时,发布数据到chartmogul网络挂接在PHP中使用卷曲工具。下面是代码:

代码的线

function updateChartmogul($xml) { 
     $url = 'https://app.chartmogul.com/api/events/****/Yi**********ArS***'; //Chartmogul webhook url 
     $ch = curl_init(); 
     curl_setopt($ch, CURLOPT_HEADER, array("Content-Type: application/xml")); 
     curl_setopt($ch, CURLOPT_URL, $url); 
     curl_setopt($ch, CURLOPT_POSTFIELDS,$xml); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); 
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // On dev server only! 
     $data = curl_exec($ch); 
     $response = curl_getinfo($ch); 
     curl_close($ch); 
    } 
    updateChartmogul('<?xml version="1.0" encoding="UTF-8"?> 
<new_subscription_notification> 
    <account> 
    <account_code>1</account_code> 
    <username>test1</username> 
    <email>[email protected]</email> 
    <first_name>testing</first_name> 
    <last_name>demo</last_name> 
    <company_name>demo</company_name> 
    </account> 
    <subscription> 
    <plan> 
     <plan_code>plan-b</plan_code> 
     <name>Plan-b</name> 
    </plan> 
    <uuid>2e3504c45933020c68368648ee998dd2</uuid> 
    <state>active</state> 
    <quantity type="integer">1</quantity> 
    <total_amount_in_cents type="integer">2000</total_amount_in_cents> 
    <subscription_add_ons type="array"/> 
    <activated_at type="datetime">2015-04-17T07:13:20Z</activated_at> 
    <canceled_at type="datetime" nil="true"></canceled_at> 
    <expires_at type="datetime" nil="true"></expires_at> 
    <current_period_started_at type="datetime">2015-04-17T07:13:20Z</current_period_started_at> 
    <current_period_ends_at type="datetime">2015-05-07T07:13:20Z</current_period_ends_at> 
    <trial_started_at type="datetime">2015-04-17T07:13:20Z</trial_started_at> 
    <trial_ends_at type="datetime">2015-05-07T07:13:20Z</trial_ends_at> 
    </subscription> 
</new_subscription_notification>'); 

我得到这样的响应:

output of $data : 

HTTP/1.1 100 Continue 

HTTP/1.1 200 OK 
Server: nginx/1.7.7 
Date: Thu, 23 Apr 2015 07:35:22 GMT 
Content-Type: text/html; charset=utf-8 
Transfer-Encoding: chunked 
Connection: keep-alive 
Status: 200 OK 
X-Frame-Options: SAMEORIGIN 
X-XSS-Protection: 1; mode=block 
X-Content-Type-Options: nosniff 
ETag: "444bcb3a3fcf83***467f27e1d6" 
Cache-Control: max-age=0, private, must-revalidate 
X-Request-Id: 05c27dd5-***-42bd-99ab-b506446d1305 
X-Runtime: 0.026330 
Strict-Transport-Security: max-age=0 

output of $response : ok 

虽然我得到的响应为 “OK”。我没有在我的chartmogul帐户中反映我的数据。我做对了吗?

注意 我已经通过硬编码xml数据,这是我每次重复webhook被调用时从反复得到的相同。

来自ChartMogul的Nick在这里。

看起来您正在使用错误的编码发送给ChartMogul的数据包。您应该使用UTF-8进行请求编码。

XML是数据的格式,UTF-8应该是数据的编码。