【发布时间】:2017-05-29 14:37:10
【问题描述】:
我在电报中创建机器人以显示餐厅附近我的机器人必须按下第一个按钮以插入地理坐标餐厅和我的服务器接收纬度和经度并保存它我创建第一个按钮和良好的工作 但我不能创建第二个按钮来显示附近的餐厅这是我的代码 请帮我 谢谢
<?php
//$json=file_get_contents('php://input');
$update = json_decode(file_get_contents('php://input'));
//main input
$message = $update->message->text;
$chatid = $update->message->chat->id;
$last_name = $update->message->from->last_name;
$first_name = $update->message->from->first_name;
$usernameid = $update->message->from->username;
$latitude = $update->message->location->latitude;
$longitude = $update->message->location->longitude;
$text1 = "insert location";
$text2 = "show near restaurant";
$token = '';
$servername = "localhost";
$dbname = "";
$username = "";
$password = "";
//$rep=json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&text=".urldecode($json)));
$reply_markup = json_encode(["keyboard" =>
[
[["text" => $text1, "request_location" => true]],
//[["text"=>$text1]],
[["text" => $text2]],
],
"resize_keyboard" => true]);
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
mysqli_query($conn, 'set names "utf8"');
// Check connection
if ($conn->connect_error) {
die("Connection failed: ".$conn->connect_error);
}
echo "Connected successfully";
date_default_timezone_set("Asia/Tehran");
$time = date("h:i:sa");
$date = date("Y/m/d");
if ($message == "/start") {
$starttxt = "hello".$first_name." ".$last_name."how are you?"."✌️✌️✌️";
$rep = json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&reply_markup=".$reply_markup."&text=".urldecode($starttxt)));
$sql = "INSERT INTO user_info (date,time,T_id,T_firstname,T_lastname,T_username) VALUES ('$date','$time','$chatid','$first_name','$last_name','$usernameid')";
$result = $conn->query($sql);
}
if ($longitude != null) {
$rep = json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&reply_markup=".$reply_markup."&text=".urldecode("long is: ".$longitude." lat is: ".$latitude)));
$sql = "INSERT INTO insert_location (T_id,T_username,date,time,latitude,longitude) VALUES ('$chatid','$usernameid','$date','$time','$latitude','$longitude')";
$result = $conn->query($sql);
}
if ($message == "show near restaurant") {
$rep = json_decode(file_get_contents("https://api.telegram.org/bot".$token."/SendMessage?chat_id=".$chatid."&reply_markup=".$reply_markup."&text=".urldecode($starttxt)));
$sql = SELECT id, (3959 * acos(cos(radians(37)) * cos(radians(latitude)) * cos(radians(longitude) - radians(-122)) + sin(radians(37)) * sin(radians(latitude)))) AS distance FROM insert_location HAVING distance < 25 ORDER BY distance LIMIT 0 , 20;
$result = $conn->query($sql);
}
?>
当用户单击第一个按钮时,此图像会形成 mysql
【问题讨论】:
标签: php mysql location bots telegram