B
B
BorisBrejcha2018-09-25 01:33:43
PHP
BorisBrejcha, 2018-09-25 01:33:43

How can php process json request?

Hello.
I am not a php developer, and in principle a developer in any other language. Therefore, I ask for help.
The server receives a request of this type in JSON format, for example, to the address - domain.ru/alice/index.php

{
  "meta": {
    "locale": "ru-RU",
    "timezone": "Europe/Moscow",
    "client_id": "ru.yandex.searchplugin/5.80 (Samsung Galaxy; Android 4.4)"
  },
  "request": {
     "command": "где ближайшее отделение",
     "original_utterance": "Алиса спроси у Сбербанка где ближайшее отделение",
     "type": "SimpleUtterance",
     "markup": {
        "dangerous_context": true
     },
     "payload": {}
  },
  "session": {
    "new": true,
    "message_id": 4,
    "session_id": "2eac4854-fce721f3-b845abba-20d60",
    "skill_id": "3ad36498-f5rd-4079-a14b-788652932056",
    "user_id": "AC9WC3DF6FCE052E45A4566A48E6B7193774B84814CE49A922E163B8B29881DC"
  },
  "version": "1.0"
}

Documentation from Yandex on working with Yandex.Dialogues.
Question: What code is needed in index.php in order to process this request and put it into an array?
Googled the json_decode and json_encode functions, but the question is rather not how to work with json, but how the php script can accept a POST / GET request and then pass it all to json_decode. (Maybe I'm asking a stupid question, please point me in the right direction)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil Sapegin, 2018-09-25
@BorisBrejcha

The POST request to your script will be contained in the $_POST array in php
so all you need to get the array in php is where fieldname is the name of the variable that should be specified in the documentation from ya.dialogs

B
Bogdan Lashkov, 2018-09-25
@okeld

As far as I understand, this https://stackoverflow.com/questions/16700960/how-t... question is exactly the same as yours. You need to take a closer look at PHP cURL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question