php - Webhook XML 始终为空
问题描述
我正在使用 recurly webhook 更新联系人,但 XML 始终为空,这是我尝试过的:
$xmlString = file_get_contents('php://input');
$dom = new DomDocument();
$dom->loadXML($xmlString);
但是,当我查看文件时,它始终为空:
$rsn = $dom->getElementsByTagName('successful_payment_notification');
if($rsn->length != 0){
//.. do something
}
但我注意到 $dom 始终为空,这是 XML 重复发送的内容:
<?xml version="1.0" encoding="UTF-8"?>
<successful_payment_notification>
<account>
<account_code>89728427a3caa0b21b2ds31223c0fad6f443b82</account_code>
<first_name>Michael</first_name>
<last_name>Scott</last_name>
<company_name nil="true"></company_name>
<phone nil="true"></phone>
</account>
<transaction>
<id>467fc116288ab89c8d7c954bbca565a8</id>
<invoice_id>467fc11613dcd438d4410c4ca0bc03e8</invoice_id>
<invoice_number_prefix></invoice_number_prefix>
<invoice_number type="integer">1379</invoice_number>
<test type="boolean">false</test>
<voidable type="boolean">false</voidable>
<refundable type="boolean">true</refundable>
</transaction>
</successful_payment_notification>
allow_url_fopen 已打开,不确定是什么原因造成的,我正在使用 AWS Lightsail 和 Bitnami。
解决方案
我找到了答案,我将其更改为:
$xml = new SimpleXMLElement(file_get_contents('php://input'));
$data = json_decode(json_encode($xml), true);
switch ($xml->getName()) {
case "renewed_subscription_notification":
sendEmail("renewed_subscription_notification");
break;
}
推荐阅读
- angularjs - 发布时没有 console.log 答案
- java - What is the difference between hash()%n and n%hash()
- python - 使用Python在特定数字范围内向上/向下计数
- symfony - 在 Symfony 3 中的 FOSUserBundle 和自定义实体之间创建多对多关系
- python - 'FlatMap 只能用于可调用对象...'
- c# - ASP.NET Core 2.x 中间件的自定义依赖注入解析器?
- angular - ng-packagr cssUrl 不在衬里样式或模板中
- jquery - jQuery 切换类让我很难过
- java - 您可以为每个线程(用于测试)创建一个不同的 Hibernate 内存数据库吗?
- highcharts - 在下载的 Highcharts 副本上,在获得许可之前是否禁用自定义?