【问题标题】:I don't know how to send data through variable on this file PHP我不知道如何通过这个文件 PHP 上的变量发送数据
【发布时间】:2017-03-26 12:40:12
【问题描述】:

我不知道如何通过此代码上的变量发送数据

<?php
require 'vendor/autoload.php';
use Telegram\Bot\Api;
$telegram = new Api('376072170:AAE2_y5EpVRCwc8Xbe-GHJLNP9yUdP2Zzto');
$chatid=$_POST['id'];
$text=$_POST['msg'];
$response = $telegram->sendMessage([
  'chat_id' => 'chatid', 
  'text' => 'some text here'
]);
$messageId = $response->getMessageId();

我做了这样的事情

<?php
require 'vendor/autoload.php';
use Telegram\Bot\Api;
$telegram = new Api('376072170:AAE2_y5EpVRCwc8Xbe-GHJLNP9yUdP2Zzto');
$chatid=$_POST['id'];
$text=$_POST['msg'];
$response = $telegram->sendMessage([
  'chat_id' => $chatid, 
  'text' => $text
]);
$messageId = $response->getMessageId();

但我得到的只是浏览器上的错误 500 我应该怎么做才能让它工作 我想通过表格发送数据,但我不知道该怎么做 感谢您的帮助

这是我的heroku日志

2017-03-26T13:19:25.215850+00:00 heroku[路由器]: at=info method=GET path="/msg.php" host=telebotyx.herokuapp.com request_id=cc595063-19ca-48a2- 9f19-5832d79d4603 fwd="200.73.16.3" dyno=web.1 连接=0ms 服务=1164ms 状态=500 字节=169 协议=https 2017-03-26T13:19:25.229754+00:00 app[web.1]: [26-Mar-2017 13:19:25 UTC] PHP 致命错误:未捕获的 Telegram\Bot\Exceptions\TelegramOtherException:错误请求:消息/app/vendor/irazasyed/telegram-bot-sdk/src/Exceptions/TelegramResponseException.php:58 中的文本为空 2017-03-26T13:19:25.229763+00:00 应用程序 [web.1]:堆栈跟踪: 2017-03-26T13:19:25.229821+00:00 app[web.1]:#0 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramResponse.php(174): Telegram\Bot\Exceptions\ TelegramResponseException::create(对象(Telegram\Bot\TelegramResponse)) 2017-03-26T13:19:25.229931+00:00 app[web.1]:#1 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramResponse.php(204): Telegram\Bot\TelegramResponse- >makeException() 2017-03-26T13:19:25.230043+00:00 app[web.1]: #2 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramResponse.php(65): Telegram\Bot\TelegramResponse- >解码体() 2017-03-26T13:19:25.230206+00:00 app[web.1]:#3 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramClient.php(138): Telegram\Bot\TelegramResponse- >__construct(对象(Telegram\Bot\TelegramRequest),对象(GuzzleHttp\Psr7\Response)) 2017-03-26T13:19:25.230367+00:00 app[web.1]:#4 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramClient.php(119): Telegram\Bot\TelegramClient- >getResponse(对象(Telegram\Bot\TelegramRequest),对象(GuzzleHttp\Psr7\Response)) 2017-03-26T13:19:25.230513+00:00 app[web.1]: #5 /app/vendor/irazasyed/telegram-bot-sdk/src/Api.php 在 /app/vendor/irazasyed/telegram-第 58 行的 bot-sdk/src/Exceptions/TelegramResponseException.php 2017-03-26T13:19:25.231648+00:00 应用程序 [web.1]: 10.179.109.26 - - [26/Mar/2017:13:19:24 +0000] “GET /msg.php HTTP/1.1” 500 - "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36

【问题讨论】:

  • 请启用调试模式并添加您的错误信息。
  • 这是我的heroku日志
  • “错误请求:消息文本为空”。您确定要传递 $_POST['msg'] 的文本吗?

标签: php telegram telegram-bot


【解决方案1】:

您的表单似乎出了点问题。由于错误是“...错误请求:消息文本为空...”

检查您的输入字段名称是否为“id”和“msg”。 还要检查您的表单方法是否为 POST。

【讨论】:

  • 是的,我的表单在另一个文件中,所以问题出在上面发布的代码中
  • 如果您尝试在 $text 中硬编码一条消息怎么办?您仍然收到错误消息吗?
【解决方案2】:

您没有使用POST 来传输您的表单。

method=GET path="/msg.php"

要么切换到$_REQUEST,要么在HTML tag中使用POST:

<form action="/msg.php" method="post">

【讨论】:

  • 那是我的表格
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-16
  • 2015-06-07
  • 1970-01-01
  • 1970-01-01
  • 2014-02-07
  • 2018-01-18
相关资源
最近更新 更多