我不知道如何通过这个文件PHP上的变量发送数据

时间:2017-03-26 12:40:12

标签: php telegram telegram-bot

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

<?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 [router]: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 connect = 0ms service = 1164ms status = 500 bytes = 169 protocol = https   2017-03-26T13:19:25.229754 + 00:00 app [web.1]:[26-Mar-2017 13:19:25 UTC] PHP致命错误:Uncaught Telegram \ Bot \ Exceptions \ TelegramOtherException:错误请求:消息/app/vendor/irazasyed/telegram-bot-sdk/src/Exceptions/TelegramResponseException.php:58中的文本为空   2017-03-26T13:19:25.229763 + 00:00 app [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 ::创建(对象(电报\机器人\ 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- &GT; 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- &GT; decodeBody()   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- &gt; __ construct(Object(Telegram \ Bot \ TelegramRequest),Object(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- &gt; getResponse(Object(Telegram \ Bot \ TelegramRequest),Object(GuzzleHttp \ Psr7 \ Response))   2017-03-26T13:19:25.230513 + 00:00 app [web.1]:#app / vendor / irazasyed / telegram-中的#5 /app/vendor/irazasyed/telegram-bot-sdk/src/Api.php-第58行的bot-sdk / src / Exceptions / TelegramResponseException.php   2017-03-26T13:19:25.231648 + 00:00 app [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,与Gecko一样)Chrome / 57.0.2987.110 Safari / 537.36

2 个答案:

答案 0 :(得分:1)

看起来你的表单出了问题。由于错误是“...错误请求:消息文本为空......”

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

答案 1 :(得分:0)

您没有使用POST传输表单。

  

method = GET path =“/ msg.php”

切换到$_REQUEST或使用HTML tag中的POST:

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