我的Php电报机器人(php)有错误

时间:2017-04-25 13:44:02

标签: php telegram-bot

  

[Mon Apr 24 15:27:18.386224 2017] [:error] [pid 13455:tid 140239221724928] [client 66.102.9.3:51192] PHP注意:尝试在/ home / parsprog /中获取非对象的属性第51行的domains / parsprog.ir / private_html / bot / itseprofile / index.php,referer:Google

<?php
date_default_timezone_set('UTC');
//connect To DB
$servername = "localhost";
$dbusername = "parsprog_wsmpp";
$dbpassword = "13721372";
$dbname = "parsprog_wsmpp";
$conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
    die("Connection failed: ".$conn->connect_error);
}
//show welcome message From DB
$result = $conn->query("SELECT * FROM messages WHERE subject LIKE 'welcome'") or die($conn->error);
while($row = $result->fetch_assoc()) {
   $welcomemsg =  $row['message'];
   echo $welcomemsg;
}
    $userid = '';
    $username = '';
    $fname = '';
    $lname = '';
    $date = '';
//Telegram BOT Connection
$url = "https://api.telegram.org/token";
$data = json_decode(file_get_contents("php://input"));
$keyboard = array(
    'keyboard' => array(
        array('A'),
        array('B'),
        array('C'),
    ),
'resize_keyboard' => true
);
//IF text is: /start
$welcometxt = "hi ".$data->message->from->first_name." dear";
if($data->message->text == '/start'){
    file_get_contents($url.'sendmessage?chat_id='.$data->message->chat->id."&text=".urlencode($welcometxt).".&reply_markup=".json_encode($keyboard));
    $userid = $data->message->chat->id;
    $username = $data->message->from->username;
    $fname = $data->message->from->first_name;
    $lname = $data->message->from->last_name;
    $date = date("y-m-d");
    $result = $conn->query("INSERT INTO members (id,userid,username,fname,lname,datesignup) VALUES (,$userid,$username,$fname,$lname,$date)");
}
if($data->message->text == 'A'){
    file_get_contents($url."sendmessage?chat_id=".$data->message->chat->id."&text=hi ".$data->message->from->first_name." dear .&reply_markup=".json_encode($keyboard));
}
$conn->close();
?>

1 个答案:

答案 0 :(得分:0)

我不能评论喷气机如此: 您在代码中写了一个纯文本密码并发布了!我建议你立即改变它!

对于您的原始问题:如果您要发送消息,则需要以下https://api.telegram.org/botYOURBOTTOKEN/sendmessage?chat_id=YOURCHATID&text=YOURMESSAGE通过简短查看代码,我看到有$url = "https://api.telegram.org/token";后来file_get_contents($url.'sendmessage?chat_id='.$data->message->chat->id."&text=".urlencode($welcometxt).".&reply_markup=".json_encode($keyboard));可以发送任何东西。从那里开始,看看它是怎么回事,我不能保证你这是唯一的错误。

顺便说一下:你提交的代码只有49行,你提供的错误代码是第51行,所以我猜你没有提交正确的文章或什么?

希望有帮助...