1
我需要安裝一箇中繼從我的服務器轉發網絡掛接到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被調用時從反覆得到的相同。