webhookイベントオブジェクトの構造を参考にUserIDを取得する
### webhookイベントオブジェクト
https://developers.line.biz/ja/reference/messaging-api/#webhook-event-objects
これを見ると、sourceのuserIdがあるので、これをキーに出来そう
{
"destination": "xxxxxxxxxx",
"events": [
{
"type": "message",
"message": {
"type": "text",
"id": "14353798921116",
"text": "Hello, world"
},
"timestamp": 1625665242211,
"source": {
"type": "user",
"userId": "U80696558e1aa831..."
},
"replyToken": "757913772c4646b784d4b7ce46d12671",
"mode": "active",
"webhookEventId": "01FZ74A0TDDPYRVKNK77XKC3ZR",
"deliveryContext": {
"isRedelivery": false
}
},
{
"type": "follow",
"timestamp": 1625665242214,
"source": {
"type": "user",
"userId": "Ufc729a925b3abef..."
},
"replyToken": "bb173f4d9cf64aed9d408ab4e36339ad",
"mode": "active",
"webhookEventId": "01FZ74ASS536FW97EX38NKCZQK",
"deliveryContext": {
"isRedelivery": false
}
},
{
"type": "unfollow",
"timestamp": 1625665242215,
"source": {
"type": "user",
"userId": "Ubbd4f124aee5113..."
},
"mode": "active",
"webhookEventId": "01FZ74B5Y0F4TNKA5SCAVKPEDM",
"deliveryContext": {
"isRedelivery": false
}
}
]
}
ソースコード上ではこのように取得する
$message = $jsonObj->{"events"}[0]->{"message"};
$userID = $jsonObj->{"events"}[0]->{"source"}->{"userId"};
さあ、mysqlの構造をどうするかですね。
その前にレスポンスのバリエーションを確認したい。