php接收到数据怎么储存,php – 接收webhook数据并将其保存在db中

我想处理数据,这是由trello webhook发出的.

有webhook帖子到网站,如site.com/tracker.php

在tracker.php中,我想将数据保存在数据库中.为此,我需要得到一些参数.

{

"action": {

"id":"51f9424bcd6e040f3c002412",

"idMemberCreator":"4fc78a59a885233f4b349bd9",

"data": {

"board": {

"name":"Trello Development",

"id":"4d5ea62fd76aa1136000000c"

},

"card": {

"idShort":1458,

"name":"Webhooks",

"id":"51a79e72dbb7e23c7c003778"

},

"voted":true

},

"type":"voteOnCard",

"date":"2013-07-31T16:58:51.949Z",

"memberCreator": {

"id":"4fc78a59a885233f4b349bd9",

"avatarHash":"2da34d23b5f1ac1a20e2a01157bfa9fe",

"fullName":"Doug Patti",

"initials":"DP",

"username":"doug"

}

},

"model": {

"id":"4d5ea62fd76aa1136000000c",

"name":"Trello Development",

"desc":"Trello board used by the Trello team to track work on Trello. How meta!\n\nThe development of the Trello API is being tracked at https://trello.com/api\n\nThe development of Trello Mobile applications is being tracked at https://trello.com/mobile",

"closed":false,

"idOrganization":"4e1452614e4b8698470000e0",

"pinned":true,

"url":"https://trello.com/b/nC8QJJoZ/trello-development",

"prefs": {

"permissionLevel":"public",

"voting":"public",

"comments":"public",

"invitations":"members",

"selfJoin":false,

"cardCovers":true,

"canBePublic":false,

"canBeOrg":false,

"canBePrivate":false,

"canInvite":true

},

"labelNames": {

"yellow":"Infrastructure",

"red":"Bug",

"purple":"Repro'd",

"orange":"Feature",

"green":"Mobile",

"blue":"Verified"

}

}

}

这是我当前的tracker.php文件:

$json = $_POST["actions"];

$action = json_decode($json);

$action_id = $action->id;

$card_id = $action->data->card->id;

var_dump($array);

我的问题:

> $_POST [“行动”]是对的吗?或者我在[]里面需要什么?

>我想让$action-> data-> card-> ID正确吗?

>有没有办法看到var_dump的结果?不知道如何看到webhook帖子的结果..

解决方法:

我不得不用这个:

$json = file_get_contents('php://input');

$action = json_decode($json, true);

据我所知,json请求不会自动拆分为$_POST.因此,您必须使用输入本身.

需要json_decode中的true参数来获取关联数组.没有它我只有一个空数组.

标签:php,webhooks

来源: https://codeday.me/bug/20190725/1528471.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值