您好我有我想在我的localhost上运行的脚本。 PHP中的代码,当我运行我的localhost时,它说
解析错误:语法错误,意外'>'在第23行的/Applications/XAMPP/xamppfiles/htdocs/bot/course.php
这是代码:
<?php
ob_start();
$API_KEY = '';
define('API_KEY',$API_KEY);
function bot($method,$datas=[]){
$url = "https://api.telegram.org/bot".API_KEY."/".$method;
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$datas);
$res = curl_exec($ch);
if(curl_error($ch)){
var_dump(curl_error($ch));
}else{
return json_decode($res);
}
}
$update = json_decode(file_get_contents('php://input'));
$message = $update- >message;
$text = $message- >text;
$chat_id = $message- >chat- >id;
if ($text =='/start') {
bot('sendMessage',[
'chat_id' => $chat_id,
'text'=> 'Welcome',
]);
}
第23行是$ message,我真的没有看到任何错误?
答案 0 :(得分:1)
我看到了你的这段代码
$message = $update- >message;
$text = $message- >text;
$chat_id = $message- >chat- >id;
尝试
$message = $update->message;
$text = $message->text;
$chat_id = $message->chat->id;