简体   繁体   中英

How to decode Json and receive server request using php

I have an android application which works like dialogueflow. Now there is option to connect to the server which is as below. The app receives message from whatsapp and gives replies...It is an autoresponder.

Connecting to my live server, I have the detail below.

This is the Request to server

{
"appPackage": "tkstudio.autoresponderforwa",
"messengerPackageName":"com.whatsapp",
"query":{
      "sender":"John Smith",
       "message":"This is an example!",
       "isGroup"; false,
       "ruleId": 42
}

This is my server response

{
"replies":[

  {
    "message": "Example reply 1"
     },

 {
    "message": "Example reply 2"
    }
         ]

}

I need a complete php code to implement this Api. The aim is when my whatsapp friend sends message like " I am John's Smith " and he will receive a reply like " hey John's Smith your age is 34 "

I have this but didn't work. Though am novice using json.

$json = '{
"replies":[

  {
    "message": "Example reply 1"
     },

 {
    "message": "Example reply 2"
    }
         ]

}';

$obj = json_decode($json);
print $obj->{'replies'}; // 12345

You can use json_decode() to decode the request.

$json_object = json_decode($_POST["request"]); //or GET

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM