【发布时间】:2017-07-21 09:14:36
【问题描述】:
当您收到请求时,您的履行必须返回响应
我有一个 HTTPS 端点,它接收通过谷歌助手发送的命令(我的 Fulfillment URL)。但我想为每个发出的请求向用户返回一个文本
例如:
用户请求:“告诉‘应用名称’来做等等等等”
助理回答:“好的,当然”
如本文所述 --> https://developers.google.com/actions/components/fulfillment (RESPONSE FORMAT) ,我已根据上面链接中所说的格式对 json 文件进行了编码
但它说您的履行必须返回响应
响应.JSON
"finalResponse": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "sure thing",
"displayText": "Sure, thing!"
}
]
}
}
在我的 Fulfillment 终点,我执行了上述操作。
fulfillment.php
$file = [
"expectUserResponse" => false,
"finalResponse" => [
"richResponse" => [
"items" => [
[
"simpleResponse" => [
"textToSpeech" => "Sure thing!",
"displayText" => "Sure, thing?"
]
]
]
]
]
];
echo json_encode($file);
header('Content-Type: application/json');
如何在 php 中将此文件返回给谷歌助手? 我正在使用 PHP :)
【问题讨论】:
-
将您的
$data变量设为关联数组。通过使用浏览器访问上述 URL 来验证响应。 -
如何把它变成一个关联数组?我需要上述格式的json文件
-
请阅读this。是的,
json_encode会将关联数组转换为 json 对象。你自己检查过回复吗?
标签: php actions-on-google