Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 处理mandrillwebhook数据_Php_Mysql_Json - Fatal编程技术网

Php 处理mandrillwebhook数据

Php 处理mandrillwebhook数据,php,mysql,json,Php,Mysql,Json,我正在尝试处理Mandrill的webhook数据,当我收到回音时,我希望Mandrill告诉我的应用程序它是哪封电子邮件,并将各种数据保存在MySql数据库中 我在这里使用PHP,根据Mandrill的说法,他们发送一个URL,我给他们一个带有JSON数据的$u POST请求 通常我会对这个请求进行json_decode(),但当我这样做时,它看起来是空的。对我来说,JSON看起来格式不正确,但也许我需要先用它做些别的事情 这是我在脚本中收到的内容: [mandrill_events] =&g

我正在尝试处理Mandrill的webhook数据,当我收到回音时,我希望Mandrill告诉我的应用程序它是哪封电子邮件,并将各种数据保存在MySql数据库中

我在这里使用PHP,根据Mandrill的说法,他们发送一个URL,我给他们一个带有JSON数据的$u POST请求

通常我会对这个请求进行json_decode(),但当我这样做时,它看起来是空的。对我来说,JSON看起来格式不正确,但也许我需要先用它做些别的事情

这是我在脚本中收到的内容:

[mandrill_events] => 
[{\"event\":\"hard_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook@mandrillapp.com\",\"sender\":\"example.sender@mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"bad_mailbox\",\"bgtools_code\":10,\"diag\":\"smtp;550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces.\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa\",\"ts\":1390483382},{\"event\":\"soft_bounce\",\"msg\":{\"ts\":1365109999,\"subject\":\"This an example webhook message\",\"email\":\"example.webhook@mandrillapp.com\",\"sender\":\"example.sender@mandrillapp.com\",\"tags\":[\"webhook-example\"],\"state\":\"soft-bounced\",\"metadata\":{\"user_id\":111},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"_version\":\"exampleaaaaaaaaaaaaaaa\",\"bounce_description\":\"mailbox_full\",\"bgtools_code\":22,\"diag\":\"smtp;552 5.2.2 Over Quota\"},\"_id\":\"exampleaaaaaaaaaaaaaaaaaaaaaaaaa1\",\"ts\":1390483382}]
您在服务器中设置了该选项

您可以禁用它,或者只需从响应中删除后面的斜杠,然后执行
json\u解码

$response = json_decode(stripslashes($_RESPONSE['mandrill_events']), true);

关于stripslashes的更多信息:

尝试通过我们的工具运行它:值得一提的是,即使是2018年,WordPress也喜欢slashify$\u POST变量。在调用WordPress代码或wp_unslash()之前对其进行备份。非常讨厌。虽然这看起来像是从死亡中复活的魔法语录,但实际上这是WordPress试图以一种断章取义的方式提供帮助。为了谷歌的缘故提及这一点,以防其他人点击。