要求:
我需要设置一个中继来将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
虽然我的回答是“好的”。我在我的chartmogul帐户中没有反映我的数据。我做得对吗?
注意 我已经传递了硬编码xml数据,这与我每次重复调用webhook时从重复中获得的数据相同。
答案 0 :(得分:1)
来自ChartMogul的尼克。
您似乎对发送给ChartMogul的数据包使用了错误的编码。您应该使用UTF-8进行请求编码。
XML是数据的格式,UTF-8应该是数据的编码。