简体   繁体   English

如何使用 php 解码 Json 并接收服务器请求

[英]How to decode Json and receive server request using php

I have an android application which works like dialogueflow.我有一个像对话流一样工作的 android 应用程序。 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.该应用程序从 whatsapp 接收消息并给出回复......它是一个自动回复器。

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.我需要一个完整的 php 代码来实现这个 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 "目的是当我的 whatsapp 朋友发送诸如“我是 John's Smith ”之类的消息时,他会收到诸如“嘿 John's Smith 你的年龄是 34 岁”之类的回复

I have this but didn't work.我有这个但没有工作。 Though am novice using json.虽然是使用 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_decode()来解码请求。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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