将xml数据发布到ChartmogulWebhook[php]
要求: 我需要设置一个中继,将webhook从我的服务器转发到ChartMogul端点——这通常只需要在服务器上已经接收webhook的脚本中添加几行代码 我面临的麻烦 在PHP中使用cURL实用程序将数据发布到ChartmogulWebhook时,我遇到了一个问题。代码如下: 代码行将xml数据发布到ChartmogulWebhook[php],php,curl,http-post,webhooks,recurly,Php,Curl,Http Post,Webhooks,Recurly,要求: 我需要设置一个中继,将webhook从我的服务器转发到ChartMogul端点——这通常只需要在服务器上已经接收webhook的脚本中添加几行代码 我面临的麻烦 在PHP中使用cURL实用程序将数据发布到ChartmogulWebhook时,我遇到了一个问题。代码如下: 代码行 function updateChartmogul($xml) { $url = 'https://app.chartmogul.com/api/events/****/Yi*******
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>');
而我得到的回应是“ok”。我的chartmogul账户中的数据没有任何反映。我这样做对吗
注意
我已经传递了硬代码xml数据,这与每次调用Recury webhook时从Recury获得的数据相同。来自ChartMogul的Nick 看起来您对发送给ChartMogul的数据包使用了错误的编码。您应该使用UTF-8进行请求编码 XML是数据的格式,UTF-8应该是数据的编码
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