要求 :
我需要设置一个中继以将 webhook 从我的服务器转发到 ChartMogul 端点 - 这通常只涉及向已经在服务器上接收 webhook 的脚本添加几行代码。
我面临的麻烦
我在使用 PHP 中的 cURL 实用程序将数据发布到 chartmogul webhook 时遇到了麻烦。这是代码:
代码行
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>test@test.com</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
当我得到“好的”回应时。我的图表大亨帐户中的数据没有任何反映。我做得对吗?
注意 我已经传递了硬代码 xml 数据,这与我每次调用 recurly webhook 时从 recurly 获得的数据相同。